Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison VMS.c @ 109:659299627e70
counters done
| author | Nina Engelhardt |
|---|---|
| date | Tue, 02 Aug 2011 17:16:12 +0200 |
| parents | 3bc3b89630c7 |
| children | 724c7a0b687f |
comparison
equal
deleted
inserted
replaced
| 49:626b11cad78c | 50:549f4f51e4d4 |
|---|---|
| 14 #include "VMS.h" | 14 #include "VMS.h" |
| 15 #include "ProcrContext.h" | 15 #include "ProcrContext.h" |
| 16 #include "Queue_impl/BlockingQueue.h" | 16 #include "Queue_impl/BlockingQueue.h" |
| 17 #include "Histogram/Histogram.h" | 17 #include "Histogram/Histogram.h" |
| 18 | 18 |
| 19 #include <unistd.h> | |
| 20 #include <fcntl.h> | |
| 21 #include <linux/types.h> | |
| 19 #include <linux/perf_event.h> | 22 #include <linux/perf_event.h> |
| 20 #include <syscall.h> | 23 #include <errno.h> |
| 21 #include <sys/prctl.h> | 24 #include <sys/syscall.h> |
| 25 #include <linux/prctl.h> | |
| 26 | |
| 22 | 27 |
| 23 #define thdAttrs NULL | 28 #define thdAttrs NULL |
| 24 | 29 |
| 25 //=========================================================================== | 30 //=========================================================================== |
| 26 void | 31 void |
| 179 "master lock high time hist"); | 184 "master lock high time hist"); |
| 180 #endif | 185 #endif |
| 181 | 186 |
| 182 MakeTheMeasHists(); | 187 MakeTheMeasHists(); |
| 183 | 188 |
| 184 #ifdef MEAS__PERF_COUNTER | 189 #ifdef MEAS__PERF_COUNTERS |
| 185 printf("Creating HW counters..."); | 190 printf("Creating HW counters..."); |
| 186 struct perf_event_attr hw_event; | 191 struct perf_event_attr hw_event; |
| 192 memset(&hw_event,0,sizeof(hw_event)); | |
| 187 hw_event.type = PERF_TYPE_HARDWARE; | 193 hw_event.type = PERF_TYPE_HARDWARE; |
| 188 hw_event.size = sizeof(struct perf_event_attr); | 194 hw_event.size = sizeof(hw_event); |
| 189 hw_event.disabled = 1; | 195 hw_event.disabled = 1; |
| 196 hw_event.freq = 0; | |
| 190 hw_event.inherit = 1; /* children inherit it */ | 197 hw_event.inherit = 1; /* children inherit it */ |
| 191 hw_event.pinned = 1; /* must always be on PMU */ | 198 hw_event.pinned = 1; /* must always be on PMU */ |
| 192 hw_event.exclusive = 0; /* only group on PMU */ | 199 hw_event.exclusive = 0; /* only group on PMU */ |
| 193 hw_event.exclude_user = 0; /* don't count user */ | 200 hw_event.exclude_user = 0; /* don't count user */ |
| 194 hw_event.exclude_kernel = 1; /* ditto kernel */ | 201 hw_event.exclude_kernel = 1; /* ditto kernel */ |
| 195 hw_event.exclude_hv = 1; /* ditto hypervisor */ | 202 hw_event.exclude_hv = 1; /* ditto hypervisor */ |
| 196 hw_event.exclude_idle = 0; /* don't count when idle */ | 203 hw_event.exclude_idle = 0; /* don't count when idle */ |
| 197 hw_event.mmap = 0; /* include mmap data */ | 204 hw_event.mmap = 0; /* include mmap data */ |
| 198 hw_event.comm = 0; /* include comm data */ | 205 hw_event.comm = 0; /* include comm data */ |
| 199 | 206 |
| 207 | |
| 200 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) | 208 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) |
| 201 { | 209 { |
| 202 hw_event.config = PERF_COUNT_HW_CPU_CYCLES; //cycles | 210 hw_event.config = 0x0000000000000000; //cycles |
| 203 _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, | 211 _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, |
| 204 0,//pid_t pid, | 212 0,//pid_t pid, |
| 205 coreIdx,//int cpu, | 213 -1,//int cpu, |
| 206 -1,//int group_fd, | 214 -1,//int group_fd, |
| 207 0//unsigned long flags | 215 0//unsigned long flags |
| 208 ); | 216 ); |
| 209 hw_event.config = PERF_COUNT_HW_INSTRUCTIONS; //instrs | 217 if (_VMSMasterEnv->cycles_counter_fd[coreIdx]<0){ |
| 218 fprintf(stderr,"On core %d: ",coreIdx); | |
| 219 perror("Failed to open cycles counter"); | |
| 220 } | |
| 221 hw_event.config = 0x0000000000000001; //instrs | |
| 210 _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, | 222 _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, |
| 211 0,//pid_t pid, | 223 0,//pid_t pid, |
| 212 coreIdx,//int cpu, | 224 -1,//int cpu, |
| 213 -1,//int group_fd, | 225 -1,//int group_fd, |
| 214 0//unsigned long flags | 226 0//unsigned long flags |
| 215 ); | 227 ); |
| 228 if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){ | |
| 229 fprintf(stderr,"On core %d: ",coreIdx); | |
| 230 perror("Failed to open instrs counter"); | |
| 231 } | |
| 216 } | 232 } |
| 217 prctl(PR_TASK_PERF_EVENTS_ENABLE); | 233 prctl(PR_TASK_PERF_EVENTS_ENABLE); |
| 234 uint64 tmpc,tmpi; | |
| 235 saveCyclesAndInstrs(0,tmpc,tmpi); | |
| 236 printf("Start: cycles = %lu, instrs = %lu\n",tmpc,tmpi); | |
| 218 #endif | 237 #endif |
| 219 | 238 |
| 220 //======================================================================== | 239 //======================================================================== |
| 221 | 240 |
| 222 } | 241 } |
| 417 * free the struc, while VMS knows how to get the newPr if it wants it, and | 436 * free the struc, while VMS knows how to get the newPr if it wants it, and |
| 418 * it lets the lang have lang-specific data related to creation transported | 437 * it lets the lang have lang-specific data related to creation transported |
| 419 * to the plugin. | 438 * to the plugin. |
| 420 */ | 439 */ |
| 421 void | 440 void |
| 422 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ) | 441 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ) __attribute__ ((noinline)) |
| 442 | |
| 423 { VMSReqst req; | 443 { VMSReqst req; |
| 424 | 444 |
| 425 req.reqType = createReq; | 445 req.reqType = createReq; |
| 426 req.semReqData = semReqData; | 446 req.semReqData = semReqData; |
| 427 req.nextReqst = reqstingPr->requests; | 447 req.nextReqst = reqstingPr->requests; |
| 451 * never returns from this call, but instead the virtual processor's trace | 471 * never returns from this call, but instead the virtual processor's trace |
| 452 * gets suspended in this call and all the virt processor's state disap- | 472 * gets suspended in this call and all the virt processor's state disap- |
| 453 * pears -- making that suspend the last thing in the virt procr's trace. | 473 * pears -- making that suspend the last thing in the virt procr's trace. |
| 454 */ | 474 */ |
| 455 void | 475 void |
| 456 VMS__send_dissipate_req( VirtProcr *procrToDissipate ) | 476 VMS__send_dissipate_req( VirtProcr *procrToDissipate ) __attribute__ ((noinline)) |
| 457 { VMSReqst req; | 477 { VMSReqst req; |
| 458 | 478 |
| 459 req.reqType = dissipate; | 479 req.reqType = dissipate; |
| 460 req.nextReqst = procrToDissipate->requests; | 480 req.nextReqst = procrToDissipate->requests; |
| 461 procrToDissipate->requests = &req; | 481 procrToDissipate->requests = &req; |
| 510 /*This inserts the semantic-layer's request data into standard VMS carrier | 530 /*This inserts the semantic-layer's request data into standard VMS carrier |
| 511 * request data-struct is allocated on stack of this call & ptr to it sent | 531 * request data-struct is allocated on stack of this call & ptr to it sent |
| 512 * to plugin | 532 * to plugin |
| 513 *Then it does suspend, to cause request to be sent. | 533 *Then it does suspend, to cause request to be sent. |
| 514 */ | 534 */ |
| 515 inline void | 535 /*inline*/ void |
| 516 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ) | 536 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr ) __attribute__ ((noinline)) |
| 517 { VMSReqst req; | 537 { VMSReqst req; |
| 518 | 538 |
| 519 req.reqType = semantic; | 539 req.reqType = semantic; |
| 520 req.semReqData = semReqData; | 540 req.semReqData = semReqData; |
| 521 req.nextReqst = callingPr->requests; | 541 req.nextReqst = callingPr->requests; |
| 523 | 543 |
| 524 VMS__suspend_procr( callingPr ); | 544 VMS__suspend_procr( callingPr ); |
| 525 } | 545 } |
| 526 | 546 |
| 527 | 547 |
| 528 inline void | 548 /*inline*/ void |
| 529 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr ) | 549 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr ) __attribute__ ((noinline)) |
| 550 | |
| 530 { VMSReqst req; | 551 { VMSReqst req; |
| 531 | 552 |
| 532 req.reqType = VMSSemantic; | 553 req.reqType = VMSSemantic; |
| 533 req.semReqData = semReqData; | 554 req.semReqData = semReqData; |
| 534 req.nextReqst = callingPr->requests; //gab any other preceeding | 555 req.nextReqst = callingPr->requests; //gab any other preceeding |
| 676 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 697 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 677 { //Note, this is running in the master | 698 { //Note, this is running in the master |
| 678 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL ); | 699 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL ); |
| 679 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); | 700 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); |
| 680 } | 701 } |
| 681 | 702 #ifdef MEAS__PERF_COUNTERS |
| 703 uint64 tmpc,tmpi; | |
| 704 saveCyclesAndInstrs(0,tmpc,tmpi); | |
| 705 printf("End: cycles = %lu, instrs = %lu\n",tmpc,tmpi); | |
| 706 prctl(PR_TASK_PERF_EVENTS_DISABLE); | |
| 707 /* | |
| 708 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ){ | |
| 709 close(_VMSMasterEnv->cycles_counter_fd[coreIdx]); | |
| 710 close(_VMSMasterEnv->instrs_counter_fd[coreIdx]); | |
| 711 } | |
| 712 */ | |
| 713 #endif | |
| 682 } | 714 } |
| 683 | 715 |
| 684 | 716 |
| 685 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for | 717 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for |
| 686 * a special shutdown procr. Ended up with extra-complex shutdown sequence. | 718 * a special shutdown procr. Ended up with extra-complex shutdown sequence. |
| 716 //int coreIdx; | 748 //int coreIdx; |
| 717 //VirtProcr **masterVPs; | 749 //VirtProcr **masterVPs; |
| 718 //SchedSlot ***allSchedSlots; //ptr to array of ptrs | 750 //SchedSlot ***allSchedSlots; //ptr to array of ptrs |
| 719 | 751 |
| 720 //Before getting rid of everything, print out any measurements made | 752 //Before getting rid of everything, print out any measurements made |
| 721 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist ); | 753 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist ); |
| 722 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile); | 754 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile); |
| 723 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHistExt ); | 755 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHistExt ); |
| 724 #ifdef MEAS__TIME_PLUGIN | 756 #ifdef MEAS__TIME_PLUGIN |
| 725 printHist( _VMSMasterEnv->reqHdlrLowTimeHist ); | 757 printHist( _VMSMasterEnv->reqHdlrLowTimeHist ); |
| 726 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist ); | 758 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist ); |
| 727 printHist( _VMSMasterEnv->reqHdlrHighTimeHist ); | 759 printHist( _VMSMasterEnv->reqHdlrHighTimeHist ); |
