@@ -112,7 +112,7 @@ bool PCM::initWinRing0Lib()
112112
113113 if (result == FALSE )
114114 {
115- CloseHandle ( hOpenLibSys);
115+ DeinitOpenLibSys (& hOpenLibSys);
116116 hOpenLibSys = NULL ;
117117 return false ;
118118 }
@@ -161,9 +161,9 @@ class InstanceLock
161161public:
162162 InstanceLock (const bool global_) : globalSemaphoreName(PCM_INSTANCE_LOCK_SEMAPHORE_NAME), globalSemaphore(NULL ), global(global_)
163163 {
164- if (!global)
164+ if (!global)
165165 {
166- pthread_mutex_lock (&processIntanceMutex);
166+ if ( pthread_mutex_lock (&processIntanceMutex) != 0 ) std::cerr << " pthread_mutex_lock failed \n " ;
167167 return ;
168168 }
169169 umask (0 );
@@ -195,9 +195,9 @@ class InstanceLock
195195 }
196196 ~InstanceLock ()
197197 {
198- if (!global)
198+ if (!global)
199199 {
200- pthread_mutex_unlock (&processIntanceMutex);
200+ if ( pthread_mutex_unlock (&processIntanceMutex) != 0 ) std::cerr << " pthread_mutex_unlock failed \n " ;
201201 return ;
202202 }
203203 if (sem_post (globalSemaphore)) {
@@ -220,6 +220,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
220220public:
221221 TemporalThreadAffinity (uint32 core_id, bool checkStatus = true )
222222 {
223+ assert (core_id < 1024 );
223224 pthread_getaffinity_np (pthread_self (), sizeof (cpu_set_t ), &old_affinity);
224225
225226 cpu_set_t new_affinity;
@@ -247,6 +248,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
247248 TemporalThreadAffinity (const uint32 core_id, bool checkStatus = true )
248249 : set_size(CPU_ALLOC_SIZE(maxCPUs))
249250 {
251+ assert (core_id < maxCPUs);
250252 old_affinity = CPU_ALLOC (maxCPUs);
251253 assert (old_affinity);
252254 pthread_getaffinity_np (pthread_self (), set_size, old_affinity);
@@ -593,7 +595,7 @@ bool PCM::detectModel()
593595 auto tokens = split (line, ' :' );
594596 if (tokens.size () >= 2 && tokens[0 ].find (" flags" ) == 0 )
595597 {
596- for (auto curFlag : split (tokens[1 ], ' ' ))
598+ for (const auto & curFlag : split (tokens[1 ], ' ' ))
597599 {
598600 if (flag == curFlag)
599601 {
@@ -730,27 +732,27 @@ void PCM::initRDT()
730732 auto env = std::getenv (" PCM_USE_RESCTRL" );
731733 if (env != nullptr && std::string (env) == std::string (" 1" ))
732734 {
733- std::cout << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because environment variable PCM_USE_RESCTRL=1\n " ;
735+ std::cerr << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because environment variable PCM_USE_RESCTRL=1\n " ;
734736 resctrl.init ();
735737 useResctrl = true ;
736738 return ;
737739 }
738740 if (resctrl.isMounted ())
739741 {
740- std::cout << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because resctrl driver is mounted.\n " ;
742+ std::cerr << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because resctrl driver is mounted.\n " ;
741743 resctrl.init ();
742744 useResctrl = true ;
743745 return ;
744746 }
745747 if (isSecureBoot ())
746748 {
747- std::cout << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because Secure Boot mode is enabled.\n " ;
749+ std::cerr << " INFO: using Linux resctrl driver for RDT metrics (L3OCC, LMB, RMB) because Secure Boot mode is enabled.\n " ;
748750 resctrl.init ();
749751 useResctrl = true ;
750752 return ;
751753 }
752754#endif
753- std::cout << " Initializing RMIDs" << std::endl;
755+ std::cerr << " Initializing RMIDs" << std::endl;
754756 unsigned maxRMID;
755757 /* Calculate maximum number of RMID supported by socket */
756758 maxRMID = getMaxRMID ();
@@ -2105,6 +2107,7 @@ class CoreTaskQueue
21052107 std::thread worker;
21062108 CoreTaskQueue () = delete ;
21072109 CoreTaskQueue (CoreTaskQueue &) = delete ;
2110+ CoreTaskQueue & operator = (CoreTaskQueue &) = delete ;
21082111public:
21092112 CoreTaskQueue (int32 core) :
21102113 worker ([=]() {
@@ -3046,18 +3049,21 @@ PCM::ErrorCode PCM::programCoreCounters(const int i /* core */,
30463049 perf_event_attr e = PCM_init_perf_event_attr ();
30473050 e.type = PERF_TYPE_RAW;
30483051 e.config = (1ULL << 63ULL ) + event_select_reg.value ;
3049- if (event_select_reg.fields .event_select == getOCREventNr (0 , i).first && event_select_reg.fields .umask == getOCREventNr (0 , i).second )
3050- e.config1 = pExtDesc->OffcoreResponseMsrValue [0 ];
3051- if (event_select_reg.fields .event_select == getOCREventNr (1 , i).first && event_select_reg.fields .umask == getOCREventNr (1 , i).second )
3052- e.config1 = pExtDesc->OffcoreResponseMsrValue [1 ];
3053-
3054- if (event_select_reg.fields .event_select == LOAD_LATENCY_EVTNR && event_select_reg.fields .umask == LOAD_LATENCY_UMASK)
3055- {
3056- e.config1 = pExtDesc->LoadLatencyMsrValue ;
3057- }
3058- if (event_select_reg.fields .event_select == FRONTEND_EVTNR && event_select_reg.fields .umask == FRONTEND_UMASK)
3052+ if (pExtDesc != nullptr )
30593053 {
3060- e.config1 = pExtDesc->FrontendMsrValue ;
3054+ if (event_select_reg.fields .event_select == getOCREventNr (0 , i).first && event_select_reg.fields .umask == getOCREventNr (0 , i).second )
3055+ e.config1 = pExtDesc->OffcoreResponseMsrValue [0 ];
3056+ if (event_select_reg.fields .event_select == getOCREventNr (1 , i).first && event_select_reg.fields .umask == getOCREventNr (1 , i).second )
3057+ e.config1 = pExtDesc->OffcoreResponseMsrValue [1 ];
3058+
3059+ if (event_select_reg.fields .event_select == LOAD_LATENCY_EVTNR && event_select_reg.fields .umask == LOAD_LATENCY_UMASK)
3060+ {
3061+ e.config1 = pExtDesc->LoadLatencyMsrValue ;
3062+ }
3063+ if (event_select_reg.fields .event_select == FRONTEND_EVTNR && event_select_reg.fields .umask == FRONTEND_UMASK)
3064+ {
3065+ e.config1 = pExtDesc->FrontendMsrValue ;
3066+ }
30613067 }
30623068
30633069 if (programPerfEvent (e, PERF_GEN_EVENT_0_POS + j, std::string (" generic event #" ) + std::to_string (i)) == false )
@@ -3113,12 +3119,12 @@ PCM::ErrorCode PCM::programCoreCounters(const int i /* core */,
31133119 std::make_pair (perfRetiringPath, PERF_TOPDOWN_RETIRING_POS)};
31143120 int readPos = core_fixed_counter_num_used + core_gen_counter_num_used;
31153121 leader_counter = -1 ;
3116- for (auto event : topDownEvents)
3122+ for (const auto & event : topDownEvents)
31173123 {
31183124 uint64 eventSel = 0 , umask = 0 ;
31193125 const auto eventDesc = readSysFS (event.first );
31203126 const auto tokens = split (eventDesc, ' ,' );
3121- for (auto token : tokens)
3127+ for (const auto & token : tokens)
31223128 {
31233129 if (match (token, " event=" , &eventSel))
31243130 {
@@ -4605,9 +4611,9 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
46054611 else
46064612 {
46074613 fixedReg.value = 0 ;
4608- for (auto cfg : corePMUConfig.fixed )
4614+ for (const auto & cfg : corePMUConfig.fixed )
46094615 {
4610- fixedReg.value |= cfg.first [0 ];
4616+ fixedReg.value |= uint64 ( cfg.first [0 ]) ;
46114617 }
46124618 conf.fixedCfg = &fixedReg;
46134619 }
@@ -5428,6 +5434,7 @@ void print_mcfg(const char * path)
54285434 if (read_bytes == 0 )
54295435 {
54305436 std::cerr << " PCM Error: Cannot read " << path << " \n " ;
5437+ ::close (mcfg_handle);
54315438 throw std::exception ();
54325439 }
54335440
@@ -5442,6 +5449,7 @@ void print_mcfg(const char * path)
54425449 if (read_bytes == 0 )
54435450 {
54445451 std::cerr << " PCM Error: Cannot read " << path << " (2)\n " ;
5452+ ::close (mcfg_handle);
54455453 throw std::exception ();
54465454 }
54475455 std::cout << " Segment " << std::dec << i << " " ;
@@ -5640,16 +5648,21 @@ bool PCM::useLinuxPerfForUncore() const
56405648 bool secureBoot = isSecureBoot ();
56415649#ifdef PCM_USE_PERF
56425650 const auto imcIDs = enumeratePerfPMUs (" imc" , 100 );
5643- std::cout << " INFO: Linux perf interface to program uncore PMUs is " << (imcIDs.empty ()?" NOT " :" " ) << " present\n " ;
5651+ std::cerr << " INFO: Linux perf interface to program uncore PMUs is " << (imcIDs.empty ()?" NOT " :" " ) << " present\n " ;
5652+ if (imcIDs.empty ())
5653+ {
5654+ use = 0 ;
5655+ return 1 == use;
5656+ }
56445657 const char * perf_env = std::getenv (" PCM_USE_UNCORE_PERF" );
56455658 if (perf_env != NULL && std::string (perf_env) == std::string (" 1" ))
56465659 {
5647- std::cout << " INFO: using Linux perf interface to program uncore PMUs because env variable PCM_USE_UNCORE_PERF=1\n " ;
5660+ std::cerr << " INFO: using Linux perf interface to program uncore PMUs because env variable PCM_USE_UNCORE_PERF=1\n " ;
56485661 use = 1 ;
56495662 }
56505663 if (secureBoot)
56515664 {
5652- std::cout << " INFO: Secure Boot detected. Using Linux perf for uncore PMU programming.\n " ;
5665+ std::cerr << " INFO: Secure Boot detected. Using Linux perf for uncore PMU programming.\n " ;
56535666 use = 1 ;
56545667 }
56555668 else
@@ -7209,7 +7222,8 @@ void ServerPCICFGUncore::initMemTest(ServerPCICFGUncore::MemTestParam & param)
72097222 std::cerr << " ERROR: mmap failed\n " ;
72107223 return ;
72117224 }
7212- unsigned long long maxNode = (unsigned long long )(readMaxFromSysFS (" /sys/devices/system/node/online" ) + 1 );
7225+ const int64 onlineNodes = (int64)readMaxFromSysFS (" /sys/devices/system/node/online" );
7226+ unsigned long long maxNode = (unsigned long long )(onlineNodes + 1 );
72137227 if (maxNode == 0 )
72147228 {
72157229 std::cerr << " ERROR: max node is 0 \n " ;
@@ -7682,6 +7696,7 @@ void PCM::programCbo(const uint64 * events, const uint32 opCode, const uint32 nc
76827696
76837697 for (uint32 cbo = 0 ; cbo < getMaxNumOfCBoxes (); ++cbo)
76847698 {
7699+ assert (cbo < cboPMUs[i].size ());
76857700 cboPMUs[i][cbo].initFreeze (UNC_PMON_UNIT_CTL_FRZ_EN);
76867701
76877702 if (ICX != cpu_model && SNOWRIDGE != cpu_model)
@@ -7984,7 +7999,7 @@ void PCM::setupCustomCoreEventsForNuma(PCM::ExtendedCustomCoreEventDescription&
79847999 conf.OffcoreResponseMsrValue [1 ] = 0x3FC0008FFF | (1 << 27 ) | (1 << 28 ) | (1 << 29 );
79858000 break ;
79868001 case PCM::ICX:
7987- std::cout << " INFO: Monitored accesses include demand + L2 cache prefetcher, code read and RFO.\n " ;
8002+ std::cerr << " INFO: Monitored accesses include demand + L2 cache prefetcher, code read and RFO.\n " ;
79888003 // OCR.READS_TO_CORE.LOCAL_DRAM
79898004 conf.OffcoreResponseMsrValue [0 ] = 0x0104000477 ;
79908005 // OCR.READS_TO_CORE.REMOTE_DRAM
0 commit comments