/* Copyright (c) 2003-2005 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include "sisci_types.h" #include "sisci_api.h" #include "sisci_error.h" //#include "sisci_demolib.h" #include #include #define NO_CALLBACK NULL #define NO_FLAGS 0 #define DATA_TRANSFER_READY 8 sci_error_t error; sci_desc_t sdOne; sci_desc_t sdTwo; sci_local_segment_t localSegmentOne; sci_local_segment_t localSegmentTwo; sci_remote_segment_t remoteSegmentOne; sci_remote_segment_t remoteSegmentTwo; sci_map_t localMapOne; sci_map_t localMapTwo; sci_map_t remoteMapOne; sci_map_t remoteMapTwo; unsigned int localAdapterNo = 0; unsigned int standbyAdapterNo = 1; unsigned int localNodeId1; unsigned int localNodeId2; unsigned int remoteNodeId1 = 0; unsigned int remoteNodeId2 = 0; unsigned int localSegmentId; unsigned int remoteSegmentId1; unsigned int remoteSegmentId2; unsigned int segmentSize = 8192; unsigned int offset = 0; unsigned int client = 0; unsigned int server = 0; unsigned int *localbufferPtr; static int data; static int interruptConnected=0; /*********************************************************************************/ /* U S A G E */ /* */ /*********************************************************************************/ void Usage() { printf("Usage of shmem\n"); printf("shmem -rn -client/server [ -adapterno -size ] \n\n"); printf(" -rn : Remote node-id\n"); printf(" -client : The local node is client\n"); printf(" -server : The local node is server\n"); printf(" -adapterno : Local adapter number (default %d)\n", localAdapterNo); printf(" -size : Segment block size (default %d)\n", segmentSize); printf(" -help : This helpscreen\n"); printf("\n"); } /*********************************************************************************/ /* P R I N T P A R A M E T E R S */ /* */ /*********************************************************************************/ void PrintParameters(void) { printf("Test parameters for %s \n",(client) ? "client" : "server" ); printf("----------------------------\n\n"); printf("Local node-id1 : %d\n",localNodeId1); printf("Local node-id2 : %d\n",localNodeId2); // printf("Remote node-id : %d\n",remoteNodeId); printf("Local adapter no. : %d\n",localAdapterNo); printf("Segment size : %d\n",segmentSize); printf("----------------------------\n\n"); } /*********************************************************************************/ /* F I L L S E G M E N T W I T H D A T A */ /* */ /*********************************************************************************/ sci_error_t GetLocalNodeId(Uint32 localAdapterNo, Uint32* localNodeId) { sci_query_adapter_t queryAdapter; sci_error_t error; unsigned int _localNodeId; queryAdapter.subcommand = SCI_Q_ADAPTER_NODEID; queryAdapter.localAdapterNo = localAdapterNo; queryAdapter.data = &_localNodeId; SCIQuery(SCI_Q_ADAPTER,&queryAdapter,NO_FLAGS,&error); *localNodeId=_localNodeId; return error; } sci_error_t SendInterrupt(sci_desc_t sd, Uint32 localAdapterNo, Uint32 localSciNodeId, Uint32 remoteSciNodeId, Uint32 interruptNo){ sci_error_t error; sci_remote_interrupt_t remoteInterrupt; Uint32 timeOut = SCI_INFINITE_TIMEOUT; // Now connect to the other sides interrupt flag do { SCIConnectInterrupt(sd, &remoteInterrupt, remoteSciNodeId, localAdapterNo, interruptNo, timeOut, NO_FLAGS, &error); } while (error != SCI_ERR_OK); if (error != SCI_ERR_OK) { fprintf(stderr, "SCIConnectInterrupt failed - Error code 0x%x\n", error); return error; } // Trigger interrupt printf("\nNode %u sent interrupt (0x%x) to node %d\n",localSciNodeId, interruptNo, remoteSciNodeId); SCITriggerInterrupt(remoteInterrupt, NO_FLAGS, &error); if (error != SCI_ERR_OK) { fprintf(stderr, "SCITriggerInterrupt failed - Error code 0x%x\n", error); return error; } // Disconnect and remove interrupts SCIDisconnectInterrupt(remoteInterrupt, NO_FLAGS, &error); if (error != SCI_ERR_OK) { fprintf(stderr, "SCIDisconnectInterrupt failed - Error code 0x%x\n", error); return error; } return error; } sci_error_t ReceiveInterrupt(sci_desc_t sd, Uint32 localAdapterNo, Uint32 localSciNodeId, Uint32 interruptNo, Uint32 timeout) { sci_error_t error; sci_local_interrupt_t localInterrupt; Uint32 timeOut = SCI_INFINITE_TIMEOUT; // Create an interrupt SCICreateInterrupt(sd, &localInterrupt, localAdapterNo, &interruptNo, 0, NULL, SCI_FLAG_FIXED_INTNO, &error); if (error != SCI_ERR_OK) { fprintf(stderr, "SCICreateInterrupt failed - Error code 0x%x\n", error); return error; } // Wait for an interrupt SCIWaitForInterrupt(localInterrupt, timeOut, NO_FLAGS, &error); printf("\nNode %u received interrupt (0x%x)\n", localSciNodeId, interruptNo); // Remove interrupt SCIRemoveInterrupt(localInterrupt, NO_FLAGS, &error); if (error != SCI_ERR_OK) { fprintf(stderr, "SCIRemoveInterrupt failed - Error code 0x%x\n", error); return error; } return error; } sci_error_t FillSegmentWithData(unsigned int segmentSize, int reverse) { unsigned int i; unsigned int nostores; nostores = (segmentSize) / sizeof(unsigned int); /* Allocate buffer */ localbufferPtr = (unsigned int*)malloc( segmentSize ); if ( localbufferPtr == NULL ) { /* * Unable to create local buffer - Insufficient memory available */ return SCI_ERR_NOSPC; } if(reverse) { /* Fill in the data into a local buffer */ printf("Filling forward order \n"); for (i=0;i\n"); // exit(-1); //} if (server == 0 && client == 0) { fprintf(stderr,"You must specify a client node or a server node\n"); exit(-1); } if (server == 1 && client == 1) { fprintf(stderr,"Both server node and client node is selected.\n"); fprintf(stderr,"You must specify either a client or a server node\n"); exit(-1); } /* Initialize the SISCI library */ SCIInitialize(NO_FLAGS, &error); if (error != SCI_ERR_OK) { fprintf(stderr,"SCIInitialize failed - Error code: 0x%x\n",error); exit(error); } /* Open a file descriptor */ SCIOpen(&sdOne,NO_FLAGS,&error); if (error != SCI_ERR_OK) { if (error == SCI_ERR_INCONSISTENT_VERSIONS) { fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n"); } fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error); exit(error); } /* Open a file descriptor */ SCIOpen(&sdTwo,NO_FLAGS,&error); if (error != SCI_ERR_OK) { if (error == SCI_ERR_INCONSISTENT_VERSIONS) { fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n"); } fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error); exit(error); } /* Get local node-id */ error = GetLocalNodeId(localAdapterNo, &localNodeId1); error = GetLocalNodeId(standbyAdapterNo, &localNodeId2); if (error != SCI_ERR_OK) { fprintf(stderr,"Could not find the local adapter %d\n", localAdapterNo); SCIClose(sdOne,NO_FLAGS,&error); SCIClose(sdTwo,NO_FLAGS,&error); exit(-1); } /* Print parameters */ PrintParameters(); if (client) { remoteNodeId1=324; remoteNodeId2=328; ShmemClientNode(); } else { remoteNodeId1=452; remoteNodeId2=456; ShmemServerNode(); } /* Close the file descriptor */ SCIClose(sdOne,NO_FLAGS,&error); SCIClose(sdTwo,NO_FLAGS,&error); if (error != SCI_ERR_OK) { fprintf(stderr,"SCIClose failed - Error code: 0x%x\n",error); } /* Free allocated resources */ SCITerminate(); return SCI_ERR_OK; }