void* unmapSegment(void * arg) { char * freeAddr; char * mapAddr; ThreadData * threadData = (ThreadData*) arg; int start=0; int total=0; Uint32 mapSize = threadData->mapSize; Uint32 chunk = threadData->chunk; mapAddr = threadData->mapAddr; freeAddr = mapAddr+mapSize-chunk; NdbSleep_MilliSleep(100); for(Uint32 i=0;i<mapSize; i = i+chunk) { start=getMicro(); if(munmap(freeAddr, chunk) < 0){ ndbout << "munmap failed" << endl; exit(1); } total=(int)(getMicro()-start); freeAddr = freeAddr - chunk; NdbSleep_MilliSleep(10); ndbout << "unmap 4096 bytes : " << total << "microsecs" << endl; } return NULL; }
void malloctest(int loopcount, int memsize, int touch) { long long start=0; int total=0; int i=0, j=0; int size=memsize*1024*1024; /*bytes*/; float mean; char * ptr =0; printf("Staring malloctest "); if(touch) printf("with touch\n"); else printf("\n"); start=getMicro(); for(i=0; i<loopcount; i++){ ptr=(char *)malloc((size_t)(size)); if(ptr==0) { printf("failed to malloc!\n"); return; } if(touch) { for(j=0; j<size; j=j+4096) ptr[j]=1; } } total=(int)(getMicro()-start); mean=(float)((float)total/(float)loopcount); printf("Total time malloc %d bytes: %2.3f microsecs loopcount %d touch %d \n", size, mean,loopcount, touch); }
void freetest(int loopcount, int memsize) { long long start=0; int total=0; int i=0, j=0; int size=memsize*1024*1024; /*bytes*/; float mean; char * ptr =0; loopcount = 1; printf("Staring free test (loopcount = 1 no matter what you prev. set)\n"); for(i=0; i<loopcount; i++){ ptr=(char*)malloc((size_t)(size)); if(ptr==0) { printf("failed to malloc!\n"); return; } for(j=0; j<size; j=j+4096) ptr[j]='1'; start=getMicro(); free(ptr); total=(int)(getMicro()-start); } mean=(float)((float)total/(float)loopcount); printf("Total time free %d bytes: %2.3f microsecs loopcount %d \n", size, mean,loopcount); }
void unmaptest(loopcount, memsize) { long long start=0; int total=0; int i=0, j=0; char * ptr; int size=memsize*1024*1024; /*bytes*/; float mean; printf("Staring munmap test (loopcount = 1 no matter what you prev. set)\n"); loopcount = 1; for(i=0; i<loopcount; i++){ ptr =(char*) mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); if(ptr<0) { printf("failed to mmap!\n"); return; } for(j=0; j<size; j=j+1) ptr[j]='1'; start=getMicro(); if(munmap(ptr, size)<0) { printf("failed to munmap!\n"); return; } total=(int)(getMicro()-start); /* for(j=8192; j<size; j=j+4096) { *(ptr+j)='1'; } for(j=0; j<4096; j=j+4096) { *(ptr+j)='1'; } */ } mean=(float)((float)total/(float)loopcount); printf("Total time unmap %d bytes: %2.3f microsecs \n",size, mean); }
void mmaptest(int loopcount, int memsize, int touch) { long long start=0; int total=0; int i=0, j=0; char * ptr; int size=memsize*1024*1024; /*bytes*/; float mean; printf("Staring mmaptest "); if(touch) printf("with touch \n"); else printf("\n"); start=getMicro(); for(i=0; i<loopcount; i++){ ptr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); if(ptr<0) { printf("failed to mmap!\n"); return; } if(touch) { for(j=0; j<size; j=j+4096) ptr[j]=1; } } total=(int)(getMicro()-start); mean=(float)((float)total/(float)loopcount); printf("Total time mmap %d bytes: %2.3f microsecs \n",size, mean); }
void* mapSegment(void * arg) { ThreadData * threadArgs; long long start=0; int total=0; int id = *(int *)arg; threadArgs = new ThreadData [1]; Uint32 size=5*1024*1024; struct NdbThread* unmapthread_var; void *status = 0; int run = 1; int max=0, min =100000000, sum=0; while(run < 1001) { start=getMicro(); char * ptr =(char*) mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); total=(int)(getMicro()-start); ndbout << "T" << id << ": mmap took : " << total << " microsecs. " << " Run: " << run ; ndbout_c(" mapped @ %p \n", ptr); if(total>max) max = total; if(total<min) min=total; sum+=total; if(ptr<0) { ndbout << "failed to mmap!" << endl; exit(1); } threadArgs[0].mapAddr = (char *)ptr; threadArgs[0].mapSize = size; threadArgs[0].chunk = 4096; threadArgs[0].idx = 0; for(Uint32 j=0; j<size; j=j+4096) ptr[j]='1'; unmapthread_var = NdbThread_Create(unmapSegment, // Function (void**)&threadArgs[0],// Arg 32768, // Stacksize (char*)"unmapthread", // Thread name NDB_THREAD_PRIO_MEAN); // Thread prio if(NdbThread_WaitFor(unmapthread_var, &status) != 0) { ndbout << "test failed - exitting " << endl; exit(1); } run++; } ndbout << "MAX: " << max << " MIN: " << min; float mean = (float) ((float)sum/(float)run); ndbout_c(" AVERAGE: %2.5f\n",mean); }