comparison VMS.c @ 212:df00af7eb307

try 40 cores
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 09 Mar 2012 18:58:33 +0100
parents f6d81915512c
children
comparison
equal deleted inserted replaced
92:2f607d866f4d 95:f4705ed9048c
191 #ifdef DETECT_LOOP_GRAPH 191 #ifdef DETECT_LOOP_GRAPH
192 192
193 #endif 193 #endif
194 194
195 #ifdef MEAS__PERF_COUNTERS 195 #ifdef MEAS__PERF_COUNTERS
196 /*
197 _VMSMasterEnv->counter_history = VMS__malloc(10*sizeof(void*));
198 _VMSMasterEnv->counter_history_array_info = makePrivDynArrayInfoFrom((void***)&(_VMSMasterEnv->counter_history),10);
199 */
200 //printf("Creating HW counters...");
201 /*
202 FILE* output;
203 int n;
204 char filename[255];
205 for(n=0;n<255;n++)
206 {
207 sprintf(filename, "./counters/Counters.%d.csv",n);
208 output = fopen(filename,"r");
209 if(output)
210 {
211 fclose(output);
212 }else{
213 break;
214 }
215 }
216 printf("Saving Counter measurements to File: %s ...\n", filename);
217 output = fopen(filename,"w+");
218 _VMSMasterEnv->counteroutput = output;
219 */
220
221 struct perf_event_attr hw_event; 196 struct perf_event_attr hw_event;
222 memset(&hw_event,0,sizeof(hw_event)); 197 memset(&hw_event,0,sizeof(hw_event));
223 hw_event.type = PERF_TYPE_HARDWARE; 198 hw_event.type = PERF_TYPE_HARDWARE;
224 hw_event.size = sizeof(hw_event); 199 hw_event.size = sizeof(hw_event);
225 hw_event.disabled = 1; 200 hw_event.disabled = 1;
226 hw_event.freq = 0; 201 hw_event.freq = 0;
227 hw_event.inherit = 1; /* children inherit it */ 202 hw_event.inherit = 1; /* children inherit it */
228 hw_event.pinned = 1; /* must always be on PMU */ 203 hw_event.pinned = 1; /* must always be on PMU */
229 hw_event.exclusive = 0; /* only group on PMU */ 204 hw_event.exclusive = 0; /* only group on PMU */
230 hw_event.exclude_user = 0; /* don't count user */ 205 hw_event.exclude_user = 0; /* don't count user */
231 hw_event.exclude_kernel = 1; /* ditto kernel */ 206 hw_event.exclude_kernel = 0; /* ditto kernel */
232 hw_event.exclude_hv = 1; /* ditto hypervisor */ 207 hw_event.exclude_hv = 0; /* ditto hypervisor */
233 hw_event.exclude_idle = 0; /* don't count when idle */ 208 hw_event.exclude_idle = 0; /* don't count when idle */
234 hw_event.mmap = 0; /* include mmap data */ 209 hw_event.mmap = 0; /* include mmap data */
235 hw_event.comm = 0; /* include comm data */ 210 hw_event.comm = 0; /* include comm data */
236 211
237 212
258 if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){ 233 if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){
259 fprintf(stderr,"On core %d: ",coreIdx); 234 fprintf(stderr,"On core %d: ",coreIdx);
260 perror("Failed to open instrs counter"); 235 perror("Failed to open instrs counter");
261 } 236 }
262 } 237 }
263 prctl(PR_TASK_PERF_EVENTS_ENABLE); 238 //uint64 tmpc,tmpi;
264 uint64 tmpc,tmpi; 239 //saveCyclesAndInstrs(0,tmpc,tmpi);
265 saveCyclesAndInstrs(0,tmpc,tmpi); 240 //printf("Start: cycles = %llu, instrs = %llu\n",tmpc,tmpi);
266 printf("Start: cycles = %llu, instrs = %llu\n",tmpc,tmpi);
267 #endif 241 #endif
268 242
269 //======================================================================== 243 //========================================================================
270 244
271 } 245 }
312 // stuff before the coreLoops set off. 286 // stuff before the coreLoops set off.
313 _VMSMasterEnv->setupComplete = 0; 287 _VMSMasterEnv->setupComplete = 0;
314 288
315 //Make the threads that animate the core loops 289 //Make the threads that animate the core loops
316 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 290 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
317 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) ); 291 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) + CACHE_LINE ); //make sure there is no false sharing
318 coreLoopThdParams[coreIdx]->coreNum = coreIdx; 292 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
293 coreLoopThdParams[coreIdx]->sent_ctr = 0;
294 coreLoopThdParams[coreIdx]->ret_tsc = 0;
319 295
320 retCode = 296 retCode =
321 pthread_create( &(coreLoopThdHandles[coreIdx]), 297 pthread_create( &(coreLoopThdHandles[coreIdx]),
322 thdAttrs, 298 thdAttrs,
323 &coreLoop, 299 &coreLoop,
324 (void *)(coreLoopThdParams[coreIdx]) ); 300 (void *)(coreLoopThdParams[coreIdx]) );
325 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(1);} 301 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(1);}
326 } 302 }
303 prctl(PR_TASK_PERF_EVENTS_ENABLE);
327 } 304 }
328 305
329 /*Semantic layer calls this when it want the system to start running.. 306 /*Semantic layer calls this when it want the system to start running..
330 * 307 *
331 *This starts the core loops running then waits for them to exit. 308 *This starts the core loops running then waits for them to exit.
735 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); 712 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
736 } 713 }
737 #ifdef MEAS__PERF_COUNTERS 714 #ifdef MEAS__PERF_COUNTERS
738 uint64 tmpc,tmpi; 715 uint64 tmpc,tmpi;
739 saveCyclesAndInstrs(0,tmpc,tmpi); 716 saveCyclesAndInstrs(0,tmpc,tmpi);
740 printf("End: cycles = %llu, instrs = %llu\n",tmpc,tmpi); 717 //printf("End: cycles = %llu, instrs = %llu\n",tmpc,tmpi);
741 prctl(PR_TASK_PERF_EVENTS_DISABLE);
742 /* 718 /*
743 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ){ 719 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ){
744 close(_VMSMasterEnv->cycles_counter_fd[coreIdx]); 720 close(_VMSMasterEnv->cycles_counter_fd[coreIdx]);
745 close(_VMSMasterEnv->instrs_counter_fd[coreIdx]); 721 close(_VMSMasterEnv->instrs_counter_fd[coreIdx]);
746 } 722 }
787 //Before getting rid of everything, print out any measurements made 763 //Before getting rid of everything, print out any measurements made
788 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist ); 764 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist );
789 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile); 765 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile);
790 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHist ); 766 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHist );
791 767
792 768 prctl(PR_TASK_PERF_EVENTS_DISABLE);
793 #ifdef MEAS__TIME_PLUGIN 769 #ifdef MEAS__TIME_PLUGIN
794 printHist( _VMSMasterEnv->reqHdlrLowTimeHist ); 770 printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
795 saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist ); 771 saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist );
796 printHist( _VMSMasterEnv->reqHdlrHighTimeHist ); 772 printHist( _VMSMasterEnv->reqHdlrHighTimeHist );
797 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist ); 773 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist );
877 printf("%s",msgStr); 853 printf("%s",msgStr);
878 fflush(stdin); 854 fflush(stdin);
879 exit(1); 855 exit(1);
880 } 856 }
881 857
858 __inline__ uint64_t rdtsc(void){
859 uint32_t lo, hi;
860 __asm__ __volatile__ ( // serialize
861 "xorl %%eax,%%eax \n cpuid"
862 ::: "%rax", "%rbx", "%rcx", "%rdx");
863 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
864 /* asm volatile("RDTSC;"
865 "movl %%eax, %0;"
866 "movl %%edx, %1;"
867 : "=m" (lo), "=m" (hi)
868 :
869 : "%eax", "%edx"
870 ); */
871 return (uint64_t)hi << 32 | lo;
872 }
873
874 uint64 tsc_offset_send(ThdParams* thisCoresThdParams, uint64 initval){
875 uint64 ret_tsc_curr; //local copy of coreLoopThdParams->ret_tsc
876 uint64 ret_tsc_prev;
877 uint64 local_before;
878 uint64 local_after;
879
880 ret_tsc_prev = initval;
881 ret_tsc_curr = initval;
882 local_before = rdtsc();
883 thisCoresThdParams->sent_ctr++;
884 while(ret_tsc_curr == ret_tsc_prev)
885 ret_tsc_curr = thisCoresThdParams->ret_tsc;
886 local_after = rdtsc();
887 ret_tsc_prev = ret_tsc_curr;
888
889 int i;
890 for(i=0;i<3;++i){
891 local_before = rdtsc();
892 thisCoresThdParams->sent_ctr++;
893 while(ret_tsc_curr == ret_tsc_prev)
894 ret_tsc_curr = thisCoresThdParams->ret_tsc;
895 local_after = rdtsc();
896 int64 midpoint = local_before + (local_after-local_before)/2;
897 int64 difference;
898 if (midpoint > ret_tsc_curr)
899 difference = midpoint - (int64)ret_tsc_curr;
900 else
901 difference = (int64)ret_tsc_curr - midpoint;
902 //printf("TSC: %llu (Core %d) = %llu (Core %d) // difference=%llu\n",midpoint,thisCoresThdParams->coreNum,ret_tsc_curr,thisCoresThdParams->coreNum + 1,difference);
903 ret_tsc_prev = ret_tsc_curr;
904 }
905
906 return ret_tsc_curr;
907 }
908
909 int tsc_offset_resp(ThdParams* sendCoresThdParams, int initialctrval){
910
911 int send_ctr_curr = initialctrval;
912 int send_ctr_prev = initialctrval;
913
914
915 while(send_ctr_curr == send_ctr_prev)
916 send_ctr_curr = sendCoresThdParams->sent_ctr;
917 sendCoresThdParams->ret_tsc = rdtsc();
918 send_ctr_prev = send_ctr_curr;
919
920 int i;
921 for(i=0;i<3;++i){
922 while(send_ctr_curr == send_ctr_prev)
923 send_ctr_curr = sendCoresThdParams->sent_ctr;
924 sendCoresThdParams->ret_tsc = rdtsc();
925 send_ctr_prev = send_ctr_curr;
926 }
927 return send_ctr_curr;
928 }