00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include <ndb_global.h> 00018 00019 #include "sisci_types.h" 00020 #include "sisci_api.h" 00021 #include "sisci_error.h" 00022 //#include "sisci_demolib.h" 00023 #include <NdbTick.h> 00024 #include <NdbSleep.h> 00025 #define NO_CALLBACK NULL 00026 #define NO_FLAGS 0 00027 #define DATA_TRANSFER_READY 8 00028 00029 sci_error_t error; 00030 sci_desc_t sdOne; 00031 sci_desc_t sdTwo; 00032 sci_local_segment_t localSegmentOne; 00033 sci_local_segment_t localSegmentTwo; 00034 sci_remote_segment_t remoteSegmentOne; 00035 sci_remote_segment_t remoteSegmentTwo; 00036 sci_map_t localMapOne; 00037 sci_map_t localMapTwo; 00038 sci_map_t remoteMapOne; 00039 sci_map_t remoteMapTwo; 00040 unsigned int localAdapterNo = 0; 00041 unsigned int standbyAdapterNo = 1; 00042 unsigned int localNodeId1; 00043 unsigned int localNodeId2; 00044 unsigned int remoteNodeId1 = 0; 00045 unsigned int remoteNodeId2 = 0; 00046 unsigned int localSegmentId; 00047 unsigned int remoteSegmentId1; 00048 unsigned int remoteSegmentId2; 00049 unsigned int segmentSize = 8192; 00050 unsigned int offset = 0; 00051 unsigned int client = 0; 00052 unsigned int server = 0; 00053 unsigned int *localbufferPtr; 00054 static int data; 00055 static int interruptConnected=0; 00056 00057 /*********************************************************************************/ 00058 /* U S A G E */ 00059 /* */ 00060 /*********************************************************************************/ 00061 00062 void Usage() 00063 { 00064 printf("Usage of shmem\n"); 00065 printf("shmem -rn <remote node-id> -client/server [ -adapterno <adapter no> -size <segment size> ] \n\n"); 00066 printf(" -rn : Remote node-id\n"); 00067 printf(" -client : The local node is client\n"); 00068 printf(" -server : The local node is server\n"); 00069 printf(" -adapterno : Local adapter number (default %d)\n", localAdapterNo); 00070 printf(" -size : Segment block size (default %d)\n", segmentSize); 00071 printf(" -help : This helpscreen\n"); 00072 00073 printf("\n"); 00074 } 00075 00076 00077 /*********************************************************************************/ 00078 /* P R I N T P A R A M E T E R S */ 00079 /* */ 00080 /*********************************************************************************/ 00081 void PrintParameters(void) 00082 { 00083 00084 printf("Test parameters for %s \n",(client) ? "client" : "server" ); 00085 printf("----------------------------\n\n"); 00086 printf("Local node-id1 : %d\n",localNodeId1); 00087 printf("Local node-id2 : %d\n",localNodeId2); 00088 // printf("Remote node-id : %d\n",remoteNodeId); 00089 printf("Local adapter no. : %d\n",localAdapterNo); 00090 printf("Segment size : %d\n",segmentSize); 00091 printf("----------------------------\n\n"); 00092 00093 } 00094 00095 00096 /*********************************************************************************/ 00097 /* F I L L S E G M E N T W I T H D A T A */ 00098 /* */ 00099 /*********************************************************************************/ 00100 00101 sci_error_t GetLocalNodeId(Uint32 localAdapterNo, Uint32* localNodeId) 00102 { 00103 sci_query_adapter_t queryAdapter; 00104 sci_error_t error; 00105 unsigned int _localNodeId; 00106 00107 queryAdapter.subcommand = SCI_Q_ADAPTER_NODEID; 00108 queryAdapter.localAdapterNo = localAdapterNo; 00109 queryAdapter.data = &_localNodeId; 00110 00111 SCIQuery(SCI_Q_ADAPTER,&queryAdapter,NO_FLAGS,&error); 00112 00113 *localNodeId=_localNodeId; 00114 00115 return error; 00116 } 00117 00118 00119 00120 00121 00122 00123 sci_error_t SendInterrupt(sci_desc_t sd, 00124 Uint32 localAdapterNo, 00125 Uint32 localSciNodeId, 00126 Uint32 remoteSciNodeId, 00127 Uint32 interruptNo){ 00128 00129 sci_error_t error; 00130 sci_remote_interrupt_t remoteInterrupt; 00131 Uint32 timeOut = SCI_INFINITE_TIMEOUT; 00132 00133 // Now connect to the other sides interrupt flag 00134 do { 00135 SCIConnectInterrupt(sd, &remoteInterrupt, remoteSciNodeId, localAdapterNo, 00136 interruptNo, timeOut, NO_FLAGS, &error); 00137 } while (error != SCI_ERR_OK); 00138 00139 if (error != SCI_ERR_OK) { 00140 fprintf(stderr, "SCIConnectInterrupt failed - Error code 0x%x\n", error); 00141 return error; 00142 } 00143 00144 // Trigger interrupt 00145 printf("\nNode %u sent interrupt (0x%x) to node %d\n",localSciNodeId, interruptNo, remoteSciNodeId); 00146 SCITriggerInterrupt(remoteInterrupt, NO_FLAGS, &error); 00147 if (error != SCI_ERR_OK) { 00148 fprintf(stderr, "SCITriggerInterrupt failed - Error code 0x%x\n", error); 00149 return error; 00150 } 00151 00152 00153 // Disconnect and remove interrupts 00154 SCIDisconnectInterrupt(remoteInterrupt, NO_FLAGS, &error); 00155 if (error != SCI_ERR_OK) { 00156 fprintf(stderr, "SCIDisconnectInterrupt failed - Error code 0x%x\n", error); 00157 return error; 00158 } 00159 00160 return error; 00161 } 00162 00163 00164 sci_error_t ReceiveInterrupt(sci_desc_t sd, 00165 Uint32 localAdapterNo, 00166 Uint32 localSciNodeId, 00167 Uint32 interruptNo, 00168 Uint32 timeout) { 00169 00170 sci_error_t error; 00171 sci_local_interrupt_t localInterrupt; 00172 Uint32 timeOut = SCI_INFINITE_TIMEOUT; 00173 00174 // Create an interrupt 00175 SCICreateInterrupt(sd, &localInterrupt, localAdapterNo, 00176 &interruptNo, 0, NULL, SCI_FLAG_FIXED_INTNO, &error); 00177 if (error != SCI_ERR_OK) { 00178 fprintf(stderr, "SCICreateInterrupt failed - Error code 0x%x\n", error); 00179 return error; 00180 } 00181 00182 00183 // Wait for an interrupt 00184 SCIWaitForInterrupt(localInterrupt, timeOut, NO_FLAGS, &error); 00185 00186 printf("\nNode %u received interrupt (0x%x)\n", localSciNodeId, interruptNo); 00187 00188 // Remove interrupt 00189 00190 SCIRemoveInterrupt(localInterrupt, NO_FLAGS, &error); 00191 if (error != SCI_ERR_OK) { 00192 fprintf(stderr, "SCIRemoveInterrupt failed - Error code 0x%x\n", error); 00193 return error; 00194 } 00195 return error; 00196 } 00197 00198 00199 sci_error_t FillSegmentWithData(unsigned int segmentSize, int reverse) 00200 { 00201 unsigned int i; 00202 unsigned int nostores; 00203 00204 00205 nostores = (segmentSize) / sizeof(unsigned int); 00206 00207 /* Allocate buffer */ 00208 00209 localbufferPtr = (unsigned int*)malloc( segmentSize ); 00210 if ( localbufferPtr == NULL ) { 00211 /* 00212 * Unable to create local buffer - Insufficient memory available 00213 */ 00214 return SCI_ERR_NOSPC; 00215 } 00216 if(reverse) { 00217 /* Fill in the data into a local buffer */ 00218 printf("Filling forward order \n"); 00219 for (i=0;i<nostores;i++) { 00220 localbufferPtr[i] = i; 00221 } 00222 } 00223 else { 00224 int temp=nostores; 00225 printf("Filling reverse order \n"); 00226 for (i=0;i<nostores;i++) { 00227 localbufferPtr[i] = temp-- ; 00228 00229 } 00230 00231 } 00232 00233 return SCI_ERR_OK; 00234 } 00235 00236 00237 00238 00239 /*********************************************************************************/ 00240 /* P R I N T C L I E N T D A T A */ 00241 /* */ 00242 /*********************************************************************************/ 00243 00244 void PrintClientData(void) 00245 { 00246 unsigned int i; 00247 00248 printf("\nClient data: "); 00249 /* Print the first 20 entries in the segment */ 00250 for (i=0;i<20;i++) { 00251 printf("%d ",localbufferPtr[i]); 00252 } 00253 00254 printf("\n"); 00255 } 00256 00257 00258 /*********************************************************************************/ 00259 /* P R I N T S E R V E R D A T A */ 00260 /* */ 00261 /*********************************************************************************/ 00262 00263 void PrintServerData(volatile unsigned int *localMapAddr) 00264 { 00265 00266 unsigned int *buffer; 00267 int i; 00268 00269 // printf("\nServer data: "); 00270 buffer = (unsigned int *)localMapAddr; 00271 00272 /* Print the first 20 entries in the segment */ 00273 for (i=0; i< 20; i++) { 00274 00275 printf("%d ",buffer[i]); 00276 } 00277 printf("\n"); 00278 00279 } 00280 00281 00282 00283 /*********************************************************************************/ 00284 /* T R A N S F E R D A T A */ 00285 /* */ 00286 /*********************************************************************************/ 00287 00288 unsigned int TransferData(sci_map_t remoteMap, 00289 volatile unsigned int *remoteSegmentAddr1, 00290 volatile unsigned int *remoteSegmentAddr2, 00291 unsigned int segmentSize) 00292 00293 { 00294 00295 volatile unsigned int *remoteBuffer1; 00296 volatile unsigned int *remoteBuffer; 00297 volatile unsigned int *remoteBuffer2; 00298 static int times = 0; 00299 sci_sequence_t sequence; 00300 sci_error_t error; 00301 unsigned int nostores; 00302 unsigned int j; 00303 sci_sequence_status_t sequenceStatus; 00304 00305 00306 remoteBuffer1 = (volatile unsigned int *)remoteSegmentAddr1; 00307 remoteBuffer2 = (volatile unsigned int *)remoteSegmentAddr2; 00308 remoteBuffer=remoteBuffer1; 00309 00310 /* 4-byte test only */ 00311 nostores = (segmentSize) / sizeof(unsigned int); 00312 00313 /* Create a sequence for data error checking */ 00314 SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error); 00315 if (error != SCI_ERR_OK) { 00316 fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error); 00317 return error; 00318 } 00319 00320 00321 00322 /* Fill in the data into a local buffer */ 00323 error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY); 00324 00325 error = FillSegmentWithData(segmentSize, 0); 00326 00327 tryagain: 00328 PrintServerData(localbufferPtr); 00329 fprintf(stderr,"After recover \n"); 00330 while(1){ 00331 00332 00333 //data=0; 00334 00335 if (error != SCI_ERR_OK) { 00336 /* 00337 * Unable to create local buffer - Insufficient memory available 00338 */ 00339 printf( "Unable to create local buffer - Insufficient memory available\n" ); 00340 00341 return error; 00342 } 00343 00344 do { 00345 /* Start data error checking */ 00346 sequenceStatus = SCIStartSequence(sequence,NO_FLAGS,&error); 00347 } while (sequenceStatus != SCI_SEQ_OK) ; 00348 00349 00350 /* Transfer data to remote node */ 00351 for (j=0;j<nostores;j++) { 00352 remoteBuffer[j] = localbufferPtr[j]; 00353 } 00354 00355 /* Check for error after data transfer */ 00356 sequenceStatus = SCICheckSequence(sequence,NO_FLAGS,&error); 00357 if (sequenceStatus != SCI_SEQ_OK) { 00358 fprintf(stderr,"Data transfer failed\n"); 00359 if(times==0) { 00360 error = FillSegmentWithData(segmentSize, 1); 00361 00362 SCICreateMapSequence(remoteMapTwo,&sequence,NO_FLAGS,&error); 00363 if (error != SCI_ERR_OK) { 00364 fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error); 00365 return error; 00366 return SCI_ERR_TRANSFER_FAILED; 00367 } 00368 } 00369 else 00370 { 00371 error = FillSegmentWithData(segmentSize, 0); 00372 /* Create a sequence for data error checking */ 00373 SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error); 00374 if (error != SCI_ERR_OK) { 00375 fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error); 00376 return error; 00377 return SCI_ERR_TRANSFER_FAILED; 00378 } 00379 00380 } 00381 fprintf(stderr,"Recovery \n"); 00382 if(times==0) 00383 remoteBuffer=remoteBuffer2; 00384 else 00385 remoteBuffer=remoteBuffer1; 00386 times++; 00387 printf("remotebuffer %p times %d\n", remoteBuffer, times); 00388 goto tryagain; 00389 00390 } 00391 int timeout=0; 00392 // error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY); 00393 // NdbSleep_MilliSleep(100); 00394 //error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout); 00395 00396 } 00397 /* Remove the Sequence */ 00398 SCIRemoveSequence(sequence,NO_FLAGS, &error); 00399 if (error != SCI_ERR_OK) { 00400 fprintf(stderr,"SCIRemoveSequence failed - Error code 0x%x\n",error); 00401 return error; 00402 } 00403 00404 return SCI_ERR_OK; 00405 } 00406 00407 00408 /*********************************************************************************/ 00409 /* S H M E M C L I E N T N O D E */ 00410 /* */ 00411 /*********************************************************************************/ 00412 00413 unsigned int ShmemClientNode(void) 00414 { 00415 00416 volatile unsigned int *remoteMapAddr1; 00417 volatile unsigned int *remoteMapAddr2; 00418 printf("here?\n"); 00419 00420 00421 /* Create a segmentId */ 00422 remoteSegmentId1 = 1;//(remoteNodeId1 << 16) | localNodeId1; 00423 00424 /* Connect to remote segment */ 00425 00426 printf("Connect to remote segment .... \n"); 00427 printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 ); 00428 00429 do { 00430 SCIConnectSegment(sdOne, 00431 &remoteSegmentOne, 00432 remoteNodeId1, 00433 remoteSegmentId1, 00434 localAdapterNo, 00435 NO_CALLBACK, 00436 NULL, 00437 SCI_INFINITE_TIMEOUT, 00438 NO_FLAGS, 00439 &error); 00440 00441 } while (error != SCI_ERR_OK); 00442 00443 00444 printf("connected\n"); 00445 00446 // remoteSegmentId2 = (remoteNodeId2 << 16) | localNodeId2; 00447 // printf("segid = %d\n",remoteSegmentId2 ); 00448 printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 ); 00449 do { 00450 SCIConnectSegment(sdTwo, 00451 &remoteSegmentTwo, 00452 remoteNodeId2, 00453 remoteSegmentId1, 00454 standbyAdapterNo, 00455 NO_CALLBACK, 00456 NULL, 00457 SCI_INFINITE_TIMEOUT, 00458 NO_FLAGS, 00459 &error); 00460 00461 } while (error != SCI_ERR_OK); 00462 00463 00464 00465 printf("connected 3\n"); 00466 printf("Remote segment (id=0x%x) is connected.\n", remoteSegmentId2); 00467 00468 00469 /* Map remote segment to user space */ 00470 remoteMapAddr1 = (unsigned int*)SCIMapRemoteSegment(remoteSegmentOne,&remoteMapOne,offset,segmentSize,NULL,NO_FLAGS,&error); 00471 if (error == SCI_ERR_OK) { 00472 printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId1, remoteMapAddr1); 00473 } else { 00474 fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error); 00475 return 0; 00476 } 00477 00478 remoteMapAddr2 = (unsigned int *)SCIMapRemoteSegment(remoteSegmentTwo,&remoteMapTwo,offset,segmentSize,NULL,NO_FLAGS,&error); 00479 if (error == SCI_ERR_OK) { 00480 printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId2, remoteMapAddr2); 00481 } else { 00482 fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error); 00483 return 0; 00484 } 00485 00486 00487 /* Start data transfer and error checking */ 00488 error = (sci_error_t)TransferData(remoteMapOne,remoteMapAddr1, remoteMapAddr2,segmentSize); 00489 if (error == SCI_ERR_OK) { 00490 printf("Data transfer done!\n\n"); 00491 } else { 00492 fprintf(stderr,"Data transfer failed - Error code 0x%x\n\n",error); 00493 return 0; 00494 } 00495 00496 /* Send an interrupt to remote node telling that the data transfer is ready */ 00497 error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY); 00498 if (error == SCI_ERR_OK) { 00499 printf("\nInterrupt message sent to remote node\n"); 00500 } else { 00501 printf("\nInterrupt synchronization failed\n"); 00502 return 0; 00503 } 00504 00505 PrintClientData(); 00506 00507 /* Unmap remote segment */ 00508 SCIUnmapSegment(remoteMapOne,NO_FLAGS,&error); 00509 if (error == SCI_ERR_OK) { 00510 printf("The remote segment is unmapped\n"); 00511 } else { 00512 fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); 00513 return 0; 00514 } 00515 00516 SCIUnmapSegment(remoteMapTwo,NO_FLAGS,&error); 00517 if (error == SCI_ERR_OK) { 00518 printf("The remote segment is unmapped\n"); 00519 } else { 00520 fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); 00521 return 0; 00522 } 00523 /* Disconnect segment */ 00524 SCIDisconnectSegment(remoteSegmentOne,NO_FLAGS,&error); 00525 if (error == SCI_ERR_OK) { 00526 printf("The segment is disconnected\n"); 00527 } else { 00528 fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error); 00529 return 0; 00530 } 00531 00532 SCIDisconnectSegment(remoteSegmentTwo,NO_FLAGS,&error); 00533 if (error == SCI_ERR_OK) { 00534 printf("The segment is disconnected\n"); 00535 } else { 00536 fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error); 00537 return 0; 00538 } 00539 00540 00541 return 1; 00542 } 00543 00544 00545 /*********************************************************************************/ 00546 /* S H M E M S E R V E R N O D E */ 00547 /* */ 00548 /*********************************************************************************/ 00549 00550 unsigned int ShmemServerNode(void) 00551 { 00552 00553 unsigned int *localMapAddr; 00554 00555 /* Create a segmentId */ 00556 localSegmentId =1;// (localNodeId1 << 16) | remoteNodeId1; 00557 00558 /* Create local segment */ 00559 SCICreateSegment(sdOne,&localSegmentOne,localSegmentId, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error); 00560 if (error == SCI_ERR_OK) { 00561 printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize); 00562 } else { 00563 fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error); 00564 return 0; 00565 } 00566 00567 //localSegmentId = (localNodeId2 << 16) | remoteNodeId2; 00568 /* 00569 SCICreateSegment(sdTwo,&localSegmentTwo,localSegmentId+1, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error); 00570 if (error == SCI_ERR_OK) { 00571 printf("Local segment (id=%d, size=%d) is created (2). \n", localSegmentId, segmentSize); 00572 } else { 00573 fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error); 00574 return 0; 00575 } 00576 00577 printf("segment one %p segment 2 %p\n", localSegmentOne, localSegmentTwo); 00578 */ 00579 /* Prepare the segment */ 00580 SCIPrepareSegment(localSegmentOne,localAdapterNo,NO_FLAGS,&error); 00581 if (error == SCI_ERR_OK) { 00582 printf("Local segment (id=%d, size=%d) is prepared. \n", localSegmentId, segmentSize); 00583 } else { 00584 fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error); 00585 return 0; 00586 } 00587 00588 00589 /* Prepare the segment */ 00590 00591 SCIPrepareSegment(localSegmentOne,standbyAdapterNo,NO_FLAGS,&error); 00592 if (error == SCI_ERR_OK) { 00593 printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize); 00594 } else { 00595 fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error); 00596 return 0; 00597 } 00598 00599 00600 /* Map local segment to user space */ 00601 localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentOne,&localMapOne, offset,segmentSize, NULL,NO_FLAGS,&error); 00602 if (error == SCI_ERR_OK) { 00603 printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr); 00604 } else { 00605 fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error); 00606 return 0; 00607 } 00608 00609 00610 /* Map local segment to user space */ 00611 /* 00612 localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentTwo,&localMapTwo, offset,segmentSize, NULL,NO_FLAGS,&error); 00613 if (error == SCI_ERR_OK) { 00614 printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr); 00615 printf("Local segment (id=%d) is mapped to user space.\n", localSegmentId); 00616 } else { 00617 fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error); 00618 return 0; 00619 } 00620 */ 00621 00622 /* Set the segment available */ 00623 SCISetSegmentAvailable(localSegmentOne, localAdapterNo, NO_FLAGS, &error); 00624 if (error == SCI_ERR_OK) { 00625 printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId); 00626 } else { 00627 fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error); 00628 return 0; 00629 } 00630 00631 00632 SCISetSegmentAvailable(localSegmentOne, standbyAdapterNo, NO_FLAGS, &error); 00633 if (error == SCI_ERR_OK) { 00634 printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId); 00635 } else { 00636 fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error); 00637 return 0; 00638 } 00639 int timeout=0; 00640 error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout); 00641 00642 if (error == SCI_ERR_OK) { 00643 printf("\nThe data transfer is ready\n"); 00644 } else { 00645 printf("\nInterrupt synchronization failed\n"); 00646 return 0; 00647 } 00648 00649 00650 again: 00651 00652 // printf("Wait for the shared memory data transfer ....."); 00653 /* Wait for interrupt signal telling that block transfer is ready */ 00654 00655 //printf("\nData transfer done!\n"); 00656 //PrintClientData() 00657 PrintServerData(localMapAddr); 00658 /*Uint32 micros; 00659 Uint32 micros2; 00660 NDB_TICKS secs; 00661 NdbTick_CurrentMicrosecond(&secs, µs); 00662 error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY); 00663 NdbTick_CurrentMicrosecond(&secs, µs2); 00664 printf("TIME ELAPSED %d \n", micros2-micros); 00665 // NdbSleep_MilliSleep(100); 00666 */ 00667 goto again; 00668 00669 /* Unmap local segment */ 00670 SCIUnmapSegment(localMapTwo,NO_FLAGS,&error); 00671 if (error == SCI_ERR_OK) { 00672 printf("The local segment is unmapped\n"); 00673 } else { 00674 fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); 00675 return 0; 00676 } 00677 00678 /* Unmap local segment */ 00679 SCIUnmapSegment(localMapOne,NO_FLAGS,&error); 00680 if (error == SCI_ERR_OK) { 00681 printf("The local segment is unmapped\n"); 00682 } else { 00683 fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); 00684 return 0; 00685 } 00686 /* Remove local segment */ 00687 SCIRemoveSegment(localSegmentOne,NO_FLAGS,&error); 00688 if (error == SCI_ERR_OK) { 00689 printf("The local segment is removed\n"); 00690 } else { 00691 fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error); 00692 return 0; 00693 } 00694 00695 /* Remove local segment */ 00696 SCIRemoveSegment(localSegmentTwo,NO_FLAGS,&error); 00697 if (error == SCI_ERR_OK) { 00698 printf("The local segment is removed\n"); 00699 } else { 00700 fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error); 00701 return 0; 00702 } 00703 00704 00705 00706 00707 return 1; 00708 } 00709 00710 00711 00712 /*********************************************************************************/ 00713 /* M A I N */ 00714 /* */ 00715 /*********************************************************************************/ 00716 00717 int main(int argc,char *argv[]) 00718 { 00719 00720 int counter; 00721 00722 printf("\n %s compiled %s : %s\n\n",argv[0],__DATE__,__TIME__); 00723 00724 if (argc<3) { 00725 Usage(); 00726 exit(-1); 00727 } 00728 00729 00730 /* Get the parameters */ 00731 for (counter=1; counter<argc; counter++) { 00732 00733 if (!strcmp("-rn",argv[counter])) { 00734 // remoteNodeId = strtol(argv[counter+1],(char **) NULL,10); 00735 continue; 00736 } 00737 00738 if (!strcmp("-size",argv[counter])) { 00739 segmentSize = strtol(argv[counter+1],(char **) NULL,10); 00740 continue; 00741 } 00742 00743 if (!strcmp("-adapterno",argv[counter])) { 00744 localAdapterNo = strtol(argv[counter+1],(char **) NULL,10); 00745 continue; 00746 } 00747 00748 if (!strcmp("-client",argv[counter])) { 00749 client = 1; 00750 continue; 00751 } 00752 00753 if (!strcmp("-server",argv[counter])) { 00754 server = 1; 00755 continue; 00756 } 00757 00758 if (!strcmp("-help",argv[counter])) { 00759 Usage(); 00760 exit(0); 00761 } 00762 } 00763 00764 // if (remoteNodeId == 0) { 00765 // fprintf(stderr,"Remote node-id is not specified. Use -rn <remote node-id>\n"); 00766 // exit(-1); 00767 //} 00768 00769 if (server == 0 && client == 0) { 00770 fprintf(stderr,"You must specify a client node or a server node\n"); 00771 exit(-1); 00772 } 00773 00774 if (server == 1 && client == 1) { 00775 fprintf(stderr,"Both server node and client node is selected.\n"); 00776 fprintf(stderr,"You must specify either a client or a server node\n"); 00777 exit(-1); 00778 } 00779 00780 00781 /* Initialize the SISCI library */ 00782 SCIInitialize(NO_FLAGS, &error); 00783 if (error != SCI_ERR_OK) { 00784 fprintf(stderr,"SCIInitialize failed - Error code: 0x%x\n",error); 00785 exit(error); 00786 } 00787 00788 00789 /* Open a file descriptor */ 00790 SCIOpen(&sdOne,NO_FLAGS,&error); 00791 if (error != SCI_ERR_OK) { 00792 if (error == SCI_ERR_INCONSISTENT_VERSIONS) { 00793 fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n"); 00794 } 00795 fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error); 00796 exit(error); 00797 } 00798 00799 /* Open a file descriptor */ 00800 SCIOpen(&sdTwo,NO_FLAGS,&error); 00801 if (error != SCI_ERR_OK) { 00802 if (error == SCI_ERR_INCONSISTENT_VERSIONS) { 00803 fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n"); 00804 } 00805 fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error); 00806 exit(error); 00807 } 00808 00809 00810 /* Get local node-id */ 00811 error = GetLocalNodeId(localAdapterNo, &localNodeId1); 00812 error = GetLocalNodeId(standbyAdapterNo, &localNodeId2); 00813 if (error != SCI_ERR_OK) { 00814 fprintf(stderr,"Could not find the local adapter %d\n", localAdapterNo); 00815 SCIClose(sdOne,NO_FLAGS,&error); 00816 SCIClose(sdTwo,NO_FLAGS,&error); 00817 exit(-1); 00818 } 00819 00820 00821 /* Print parameters */ 00822 PrintParameters(); 00823 00824 if (client) { 00825 remoteNodeId1=324; 00826 remoteNodeId2=328; 00827 ShmemClientNode(); 00828 } else { 00829 remoteNodeId1=452; 00830 remoteNodeId2=456; 00831 ShmemServerNode(); 00832 } 00833 00834 /* Close the file descriptor */ 00835 SCIClose(sdOne,NO_FLAGS,&error); 00836 SCIClose(sdTwo,NO_FLAGS,&error); 00837 if (error != SCI_ERR_OK) { 00838 fprintf(stderr,"SCIClose failed - Error code: 0x%x\n",error); 00839 } 00840 00841 00842 /* Free allocated resources */ 00843 SCITerminate(); 00844 00845 return SCI_ERR_OK; 00846 } 00847 00848 00849 00850 00851 00852 00853 00854 00855 00856 00857 00858 00859 00860 00861 00862 00863
1.4.7

