unsigned int ShmemServerNode(void) { unsigned int *localMapAddr; /* Create a segmentId */ localSegmentId =1;// (localNodeId1 << 16) | remoteNodeId1; /* Create local segment */ SCICreateSegment(sdOne,&localSegmentOne,localSegmentId, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize); } else { fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error); return 0; } //localSegmentId = (localNodeId2 << 16) | remoteNodeId2; /* SCICreateSegment(sdTwo,&localSegmentTwo,localSegmentId+1, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=%d, size=%d) is created (2). \n", localSegmentId, segmentSize); } else { fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error); return 0; } printf("segment one %p segment 2 %p\n", localSegmentOne, localSegmentTwo); */ /* Prepare the segment */ SCIPrepareSegment(localSegmentOne,localAdapterNo,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=%d, size=%d) is prepared. \n", localSegmentId, segmentSize); } else { fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error); return 0; } /* Prepare the segment */ SCIPrepareSegment(localSegmentOne,standbyAdapterNo,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize); } else { fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error); return 0; } /* Map local segment to user space */ localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentOne,&localMapOne, offset,segmentSize, NULL,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr); } else { fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error); return 0; } /* Map local segment to user space */ /* localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentTwo,&localMapTwo, offset,segmentSize, NULL,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr); printf("Local segment (id=%d) is mapped to user space.\n", localSegmentId); } else { fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error); return 0; } */ /* Set the segment available */ SCISetSegmentAvailable(localSegmentOne, localAdapterNo, NO_FLAGS, &error); if (error == SCI_ERR_OK) { printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId); } else { fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error); return 0; } SCISetSegmentAvailable(localSegmentOne, standbyAdapterNo, NO_FLAGS, &error); if (error == SCI_ERR_OK) { printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId); } else { fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error); return 0; } int timeout=0; error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout); if (error == SCI_ERR_OK) { printf("\nThe data transfer is ready\n"); } else { printf("\nInterrupt synchronization failed\n"); return 0; } again: // printf("Wait for the shared memory data transfer ....."); /* Wait for interrupt signal telling that block transfer is ready */ //printf("\nData transfer done!\n"); //PrintClientData() PrintServerData(localMapAddr); /*Uint32 micros; Uint32 micros2; NDB_TICKS secs; NdbTick_CurrentMicrosecond(&secs, µs); error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY); NdbTick_CurrentMicrosecond(&secs, µs2); printf("TIME ELAPSED %d \n", micros2-micros); // NdbSleep_MilliSleep(100); */ goto again; /* Unmap local segment */ SCIUnmapSegment(localMapTwo,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("The local segment is unmapped\n"); } else { fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); return 0; } /* Unmap local segment */ SCIUnmapSegment(localMapOne,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("The local segment is unmapped\n"); } else { fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error); return 0; } /* Remove local segment */ SCIRemoveSegment(localSegmentOne,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("The local segment is removed\n"); } else { fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error); return 0; } /* Remove local segment */ SCIRemoveSegment(localSegmentTwo,NO_FLAGS,&error); if (error == SCI_ERR_OK) { printf("The local segment is removed\n"); } else { fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error); return 0; } return 1; }
sci_error_t SCI_Transporter::initLocalSegment() { DBUG_ENTER("SCI_Transporter::initLocalSegment"); Uint32 segmentSize = m_BufferSize; Uint32 offset = 0; sci_error_t err; if(!m_sciinit) { for(Uint32 i=0; i<m_adapters ; i++) { SCIOpen(&(sciAdapters[i].scidesc), FLAGS, &err); sciAdapters[i].localSciNodeId=getLocalNodeId(i); DBUG_PRINT("info", ("SCInode iD %d adapter %d\n", sciAdapters[i].localSciNodeId, i)); if(err != SCI_ERR_OK) { DBUG_PRINT("error", ("Cannot open an SCI virtual device. Error code 0x%x", err)); DBUG_RETURN(err); } } } m_sciinit=true; SCICreateSegment(sciAdapters[0].scidesc, &(m_SourceSegm[0].localHandle), hostSegmentId(localNodeId, remoteNodeId), segmentSize, 0, 0, 0, &err); if(err != SCI_ERR_OK) { DBUG_PRINT("error", ("Error creating segment, err = 0x%x", err)); DBUG_RETURN(err); } else { DBUG_PRINT("info", ("created segment id : %d", hostSegmentId(localNodeId, remoteNodeId))); } /** Prepare the segment*/ for(Uint32 i=0; i < m_adapters; i++) { SCIPrepareSegment((m_SourceSegm[0].localHandle), i, FLAGS, &err); if(err != SCI_ERR_OK) { DBUG_PRINT("error", ("Local Segment is not accessible by an SCI adapter. Error code 0x%x\n", err)); DBUG_RETURN(err); } } m_SourceSegm[0].mappedMemory = SCIMapLocalSegment((m_SourceSegm[0].localHandle), &(m_SourceSegm[0].lhm[0].map), offset, segmentSize, NULL, FLAGS, &err); if(err != SCI_ERR_OK) { DBUG_PRINT("error", ("Cannot map area of size %d. Error code 0x%x", segmentSize,err)); doDisconnect(); DBUG_RETURN(err); } /** Make the local segment available*/ for(Uint32 i=0; i < m_adapters; i++) { SCISetSegmentAvailable((m_SourceSegm[0].localHandle), i, FLAGS, &err); if(err != SCI_ERR_OK) { DBUG_PRINT("error", ("Local Segment is not available for remote connections. Error code 0x%x\n", err)); DBUG_RETURN(err); } } setupLocalSegment(); DBUG_RETURN(err); } // initLocalSegment()
sci_error_t sci_segment_create_and_export(sci_desc_t v_device, sci_local_segment_t *local_segment, sci_map_t *local_map, volatile int **local_address, unsigned int mem_id, unsigned int mem_size, struct client *cl) { sci_error_t error; // allocation du segment controle et du segment donnees SCICreateSegment(v_device, local_segment, mem_id, mem_size, local_segment_cb, (void*)cl, SCI_FLAG_USE_CALLBACK, &error); if (error != SCI_ERR_OK) { log_message("erreur SCICreateSegment local_ctl_segment\n"); log_message("%s",Sci_error(error)); return error; } log_message("creating segment %d size %d\n", mem_id, mem_size); /* mapping des segments locaux et reception des adresses */ *local_address = (int*)SCIMapLocalSegment(*local_segment, local_map, 0 /* offset */, mem_size, 0 /* address hint */, NO_FLAGS, &error); if (error != SCI_ERR_OK) { log_message("erreur SCIMapLocalSegment\n"); log_message("%s",Sci_error(error)); return error; } log_message("mapping segment %d size %d l_address=%p\n", mem_id, mem_size,*local_address); /* export local segment */ SCIPrepareSegment(*local_segment, ADAPTER_NO, NO_FLAGS, &error); if (error != SCI_ERR_OK) { log_message("erreur SCIPrepareSegment\n"); log_message("%s\n",Sci_error(error)); return error; } SCISetSegmentAvailable(*local_segment, ADAPTER_NO, NO_FLAGS, &error); if (error != SCI_ERR_OK) { log_message("erreur SCISetSegmentAvailable\n"); log_message("%s\n",Sci_error(error)); return error; } log_message("exporting segment %d size %d\n", mem_id, mem_size); return SCI_ERR_OK; }