19 #include <ndb_global.h>
21 #include "sisci_types.h"
22 #include "sisci_api.h"
23 #include "sisci_error.h"
27 #define NO_CALLBACK NULL
29 #define DATA_TRANSFER_READY 8
34 sci_local_segment_t localSegmentOne;
35 sci_local_segment_t localSegmentTwo;
36 sci_remote_segment_t remoteSegmentOne;
37 sci_remote_segment_t remoteSegmentTwo;
38 sci_map_t localMapOne;
39 sci_map_t localMapTwo;
40 sci_map_t remoteMapOne;
41 sci_map_t remoteMapTwo;
42 unsigned int localAdapterNo = 0;
43 unsigned int standbyAdapterNo = 1;
44 unsigned int localNodeId1;
45 unsigned int localNodeId2;
46 unsigned int remoteNodeId1 = 0;
47 unsigned int remoteNodeId2 = 0;
48 unsigned int localSegmentId;
49 unsigned int remoteSegmentId1;
50 unsigned int remoteSegmentId2;
51 unsigned int segmentSize = 8192;
53 unsigned int client = 0;
54 unsigned int server = 0;
55 unsigned int *localbufferPtr;
57 static int interruptConnected=0;
66 printf(
"Usage of shmem\n");
67 printf(
"shmem -rn <remote node-id> -client/server [ -adapterno <adapter no> -size <segment size> ] \n\n");
68 printf(
" -rn : Remote node-id\n");
69 printf(
" -client : The local node is client\n");
70 printf(
" -server : The local node is server\n");
71 printf(
" -adapterno : Local adapter number (default %d)\n", localAdapterNo);
72 printf(
" -size : Segment block size (default %d)\n", segmentSize);
73 printf(
" -help : This helpscreen\n");
83 void PrintParameters(
void)
86 printf(
"Test parameters for %s \n",(client) ?
"client" :
"server" );
87 printf(
"----------------------------\n\n");
88 printf(
"Local node-id1 : %d\n",localNodeId1);
89 printf(
"Local node-id2 : %d\n",localNodeId2);
91 printf(
"Local adapter no. : %d\n",localAdapterNo);
92 printf(
"Segment size : %d\n",segmentSize);
93 printf(
"----------------------------\n\n");
103 sci_error_t GetLocalNodeId(Uint32 localAdapterNo, Uint32* localNodeId)
105 sci_query_adapter_t queryAdapter;
107 unsigned int _localNodeId;
109 queryAdapter.subcommand = SCI_Q_ADAPTER_NODEID;
110 queryAdapter.localAdapterNo = localAdapterNo;
111 queryAdapter.data = &_localNodeId;
113 SCIQuery(SCI_Q_ADAPTER,&queryAdapter,NO_FLAGS,&error);
115 *localNodeId=_localNodeId;
125 sci_error_t SendInterrupt(sci_desc_t sd,
126 Uint32 localAdapterNo,
127 Uint32 localSciNodeId,
128 Uint32 remoteSciNodeId,
132 sci_remote_interrupt_t remoteInterrupt;
133 Uint32 timeOut = SCI_INFINITE_TIMEOUT;
137 SCIConnectInterrupt(sd, &remoteInterrupt, remoteSciNodeId, localAdapterNo,
138 interruptNo, timeOut, NO_FLAGS, &error);
139 }
while (error != SCI_ERR_OK);
141 if (error != SCI_ERR_OK) {
142 fprintf(stderr,
"SCIConnectInterrupt failed - Error code 0x%x\n", error);
147 printf(
"\nNode %u sent interrupt (0x%x) to node %d\n",localSciNodeId, interruptNo, remoteSciNodeId);
148 SCITriggerInterrupt(remoteInterrupt, NO_FLAGS, &error);
149 if (error != SCI_ERR_OK) {
150 fprintf(stderr,
"SCITriggerInterrupt failed - Error code 0x%x\n", error);
156 SCIDisconnectInterrupt(remoteInterrupt, NO_FLAGS, &error);
157 if (error != SCI_ERR_OK) {
158 fprintf(stderr,
"SCIDisconnectInterrupt failed - Error code 0x%x\n", error);
166 sci_error_t ReceiveInterrupt(sci_desc_t sd,
167 Uint32 localAdapterNo,
168 Uint32 localSciNodeId,
173 sci_local_interrupt_t localInterrupt;
174 Uint32 timeOut = SCI_INFINITE_TIMEOUT;
177 SCICreateInterrupt(sd, &localInterrupt, localAdapterNo,
178 &interruptNo, 0, NULL, SCI_FLAG_FIXED_INTNO, &error);
179 if (error != SCI_ERR_OK) {
180 fprintf(stderr,
"SCICreateInterrupt failed - Error code 0x%x\n", error);
186 SCIWaitForInterrupt(localInterrupt, timeOut, NO_FLAGS, &error);
188 printf(
"\nNode %u received interrupt (0x%x)\n", localSciNodeId, interruptNo);
192 SCIRemoveInterrupt(localInterrupt, NO_FLAGS, &error);
193 if (error != SCI_ERR_OK) {
194 fprintf(stderr,
"SCIRemoveInterrupt failed - Error code 0x%x\n", error);
201 sci_error_t FillSegmentWithData(
unsigned int segmentSize,
int reverse)
204 unsigned int nostores;
207 nostores = (segmentSize) /
sizeof(
unsigned int);
211 localbufferPtr = (
unsigned int*)malloc( segmentSize );
212 if ( localbufferPtr == NULL ) {
216 return SCI_ERR_NOSPC;
220 printf(
"Filling forward order \n");
221 for (i=0;i<nostores;i++) {
222 localbufferPtr[
i] =
i;
227 printf(
"Filling reverse order \n");
228 for (i=0;i<nostores;i++) {
229 localbufferPtr[
i] = temp-- ;
246 void PrintClientData(
void)
250 printf(
"\nClient data: ");
253 printf(
"%d ",localbufferPtr[i]);
265 void PrintServerData(
volatile unsigned int *localMapAddr)
268 unsigned int *buffer;
272 buffer = (
unsigned int *)localMapAddr;
275 for (i=0; i< 20; i++) {
277 printf(
"%d ",buffer[i]);
290 unsigned int TransferData(sci_map_t remoteMap,
291 volatile unsigned int *remoteSegmentAddr1,
292 volatile unsigned int *remoteSegmentAddr2,
293 unsigned int segmentSize)
297 volatile unsigned int *remoteBuffer1;
298 volatile unsigned int *remoteBuffer;
299 volatile unsigned int *remoteBuffer2;
300 static int times = 0;
301 sci_sequence_t sequence;
303 unsigned int nostores;
305 sci_sequence_status_t sequenceStatus;
308 remoteBuffer1 = (
volatile unsigned int *)remoteSegmentAddr1;
309 remoteBuffer2 = (
volatile unsigned int *)remoteSegmentAddr2;
310 remoteBuffer=remoteBuffer1;
313 nostores = (segmentSize) /
sizeof(
unsigned int);
316 SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
317 if (error != SCI_ERR_OK) {
318 fprintf(stderr,
"SCICreateMapSequence failed - Error code 0x%x\n",error);
325 error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
327 error = FillSegmentWithData(segmentSize, 0);
330 PrintServerData(localbufferPtr);
331 fprintf(stderr,
"After recover \n");
337 if (error != SCI_ERR_OK) {
341 printf(
"Unable to create local buffer - Insufficient memory available\n" );
348 sequenceStatus = SCIStartSequence(sequence,NO_FLAGS,&error);
349 }
while (sequenceStatus != SCI_SEQ_OK) ;
353 for (j=0;j<nostores;j++) {
354 remoteBuffer[j] = localbufferPtr[j];
358 sequenceStatus = SCICheckSequence(sequence,NO_FLAGS,&error);
359 if (sequenceStatus != SCI_SEQ_OK) {
360 fprintf(stderr,
"Data transfer failed\n");
362 error = FillSegmentWithData(segmentSize, 1);
364 SCICreateMapSequence(remoteMapTwo,&sequence,NO_FLAGS,&error);
365 if (error != SCI_ERR_OK) {
366 fprintf(stderr,
"SCICreateMapSequence failed - Error code 0x%x\n",error);
368 return SCI_ERR_TRANSFER_FAILED;
373 error = FillSegmentWithData(segmentSize, 0);
375 SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
376 if (error != SCI_ERR_OK) {
377 fprintf(stderr,
"SCICreateMapSequence failed - Error code 0x%x\n",error);
379 return SCI_ERR_TRANSFER_FAILED;
383 fprintf(stderr,
"Recovery \n");
385 remoteBuffer=remoteBuffer2;
387 remoteBuffer=remoteBuffer1;
389 printf(
"remotebuffer %p times %d\n", remoteBuffer, times);
400 SCIRemoveSequence(sequence,NO_FLAGS, &error);
401 if (error != SCI_ERR_OK) {
402 fprintf(stderr,
"SCIRemoveSequence failed - Error code 0x%x\n",error);
415 unsigned int ShmemClientNode(
void)
418 volatile unsigned int *remoteMapAddr1;
419 volatile unsigned int *remoteMapAddr2;
424 remoteSegmentId1 = 1;
428 printf(
"Connect to remote segment .... \n");
429 printf(
"segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
432 SCIConnectSegment(sdOne,
439 SCI_INFINITE_TIMEOUT,
443 }
while (error != SCI_ERR_OK);
446 printf(
"connected\n");
450 printf(
"segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
452 SCIConnectSegment(sdTwo,
459 SCI_INFINITE_TIMEOUT,
463 }
while (error != SCI_ERR_OK);
467 printf(
"connected 3\n");
468 printf(
"Remote segment (id=0x%x) is connected.\n", remoteSegmentId2);
472 remoteMapAddr1 = (
unsigned int*)SCIMapRemoteSegment(remoteSegmentOne,&remoteMapOne,
offset,segmentSize,NULL,NO_FLAGS,&error);
473 if (error == SCI_ERR_OK) {
474 printf(
"Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId1, remoteMapAddr1);
476 fprintf(stderr,
"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
480 remoteMapAddr2 = (
unsigned int *)SCIMapRemoteSegment(remoteSegmentTwo,&remoteMapTwo,
offset,segmentSize,NULL,NO_FLAGS,&error);
481 if (error == SCI_ERR_OK) {
482 printf(
"Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId2, remoteMapAddr2);
484 fprintf(stderr,
"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
490 error = (sci_error_t)TransferData(remoteMapOne,remoteMapAddr1, remoteMapAddr2,segmentSize);
491 if (error == SCI_ERR_OK) {
492 printf(
"Data transfer done!\n\n");
494 fprintf(stderr,
"Data transfer failed - Error code 0x%x\n\n",error);
499 error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
500 if (error == SCI_ERR_OK) {
501 printf(
"\nInterrupt message sent to remote node\n");
503 printf(
"\nInterrupt synchronization failed\n");
510 SCIUnmapSegment(remoteMapOne,NO_FLAGS,&error);
511 if (error == SCI_ERR_OK) {
512 printf(
"The remote segment is unmapped\n");
514 fprintf(stderr,
"SCIUnmapSegment failed - Error code 0x%x\n",error);
518 SCIUnmapSegment(remoteMapTwo,NO_FLAGS,&error);
519 if (error == SCI_ERR_OK) {
520 printf(
"The remote segment is unmapped\n");
522 fprintf(stderr,
"SCIUnmapSegment failed - Error code 0x%x\n",error);
526 SCIDisconnectSegment(remoteSegmentOne,NO_FLAGS,&error);
527 if (error == SCI_ERR_OK) {
528 printf(
"The segment is disconnected\n");
530 fprintf(stderr,
"SCIDisconnectSegment failed - Error code 0x%x\n",error);
534 SCIDisconnectSegment(remoteSegmentTwo,NO_FLAGS,&error);
535 if (error == SCI_ERR_OK) {
536 printf(
"The segment is disconnected\n");
538 fprintf(stderr,
"SCIDisconnectSegment failed - Error code 0x%x\n",error);
552 unsigned int ShmemServerNode(
void)
555 unsigned int *localMapAddr;
561 SCICreateSegment(sdOne,&localSegmentOne,localSegmentId, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error);
562 if (error == SCI_ERR_OK) {
563 printf(
"Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
565 fprintf(stderr,
"SCICreateSegment failed - Error code 0x%x\n",error);
582 SCIPrepareSegment(localSegmentOne,localAdapterNo,NO_FLAGS,&error);
583 if (error == SCI_ERR_OK) {
584 printf(
"Local segment (id=%d, size=%d) is prepared. \n", localSegmentId, segmentSize);
586 fprintf(stderr,
"SCIPrepareSegment failed - Error code 0x%x\n",error);
593 SCIPrepareSegment(localSegmentOne,standbyAdapterNo,NO_FLAGS,&error);
594 if (error == SCI_ERR_OK) {
595 printf(
"Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
597 fprintf(stderr,
"SCIPrepareSegment failed - Error code 0x%x\n",error);
603 localMapAddr = (
unsigned int *)SCIMapLocalSegment(localSegmentOne,&localMapOne,
offset,segmentSize, NULL,NO_FLAGS,&error);
604 if (error == SCI_ERR_OK) {
605 printf(
"Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr);
607 fprintf(stderr,
"SCIMapLocalSegment failed - Error code 0x%x\n",error);
625 SCISetSegmentAvailable(localSegmentOne, localAdapterNo, NO_FLAGS, &error);
626 if (error == SCI_ERR_OK) {
627 printf(
"Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
629 fprintf(stderr,
"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
634 SCISetSegmentAvailable(localSegmentOne, standbyAdapterNo, NO_FLAGS, &error);
635 if (error == SCI_ERR_OK) {
636 printf(
"Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
638 fprintf(stderr,
"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
642 error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout);
644 if (error == SCI_ERR_OK) {
645 printf(
"\nThe data transfer is ready\n");
647 printf(
"\nInterrupt synchronization failed\n");
659 PrintServerData(localMapAddr);
672 SCIUnmapSegment(localMapTwo,NO_FLAGS,&error);
673 if (error == SCI_ERR_OK) {
674 printf(
"The local segment is unmapped\n");
676 fprintf(stderr,
"SCIUnmapSegment failed - Error code 0x%x\n",error);
681 SCIUnmapSegment(localMapOne,NO_FLAGS,&error);
682 if (error == SCI_ERR_OK) {
683 printf(
"The local segment is unmapped\n");
685 fprintf(stderr,
"SCIUnmapSegment failed - Error code 0x%x\n",error);
689 SCIRemoveSegment(localSegmentOne,NO_FLAGS,&error);
690 if (error == SCI_ERR_OK) {
691 printf(
"The local segment is removed\n");
693 fprintf(stderr,
"SCIRemoveSegment failed - Error code 0x%x\n",error);
698 SCIRemoveSegment(localSegmentTwo,NO_FLAGS,&error);
699 if (error == SCI_ERR_OK) {
700 printf(
"The local segment is removed\n");
702 fprintf(stderr,
"SCIRemoveSegment failed - Error code 0x%x\n",error);
719 int main(
int argc,
char *argv[])
724 printf(
"\n %s compiled %s : %s\n\n",argv[0],__DATE__,__TIME__);
733 for (counter=1; counter<argc; counter++) {
735 if (!strcmp(
"-rn",argv[counter])) {
740 if (!strcmp(
"-size",argv[counter])) {
741 segmentSize = strtol(argv[counter+1],(
char **) NULL,10);
745 if (!strcmp(
"-adapterno",argv[counter])) {
746 localAdapterNo = strtol(argv[counter+1],(
char **) NULL,10);
750 if (!strcmp(
"-client",argv[counter])) {
755 if (!strcmp(
"-server",argv[counter])) {
760 if (!strcmp(
"-help",argv[counter])) {
771 if (server == 0 && client == 0) {
772 fprintf(stderr,
"You must specify a client node or a server node\n");
776 if (server == 1 && client == 1) {
777 fprintf(stderr,
"Both server node and client node is selected.\n");
778 fprintf(stderr,
"You must specify either a client or a server node\n");
784 SCIInitialize(NO_FLAGS, &error);
785 if (error != SCI_ERR_OK) {
786 fprintf(stderr,
"SCIInitialize failed - Error code: 0x%x\n",error);
792 SCIOpen(&sdOne,NO_FLAGS,&error);
793 if (error != SCI_ERR_OK) {
794 if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
795 fprintf(stderr,
"Version mismatch between SISCI user library and SISCI driver\n");
797 fprintf(stderr,
"SCIOpen failed - Error code 0x%x\n",error);
802 SCIOpen(&sdTwo,NO_FLAGS,&error);
803 if (error != SCI_ERR_OK) {
804 if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
805 fprintf(stderr,
"Version mismatch between SISCI user library and SISCI driver\n");
807 fprintf(stderr,
"SCIOpen failed - Error code 0x%x\n",error);
813 error = GetLocalNodeId(localAdapterNo, &localNodeId1);
814 error = GetLocalNodeId(standbyAdapterNo, &localNodeId2);
815 if (error != SCI_ERR_OK) {
816 fprintf(stderr,
"Could not find the local adapter %d\n", localAdapterNo);
817 SCIClose(sdOne,NO_FLAGS,&error);
818 SCIClose(sdTwo,NO_FLAGS,&error);
837 SCIClose(sdOne,NO_FLAGS,&error);
838 SCIClose(sdTwo,NO_FLAGS,&error);
839 if (error != SCI_ERR_OK) {
840 fprintf(stderr,
"SCIClose failed - Error code: 0x%x\n",error);