@@ -112,7 +112,7 @@ bool PCM::initWinRing0Lib()
112
112
113
113
if (result == FALSE )
114
114
{
115
- CloseHandle ( hOpenLibSys);
115
+ DeinitOpenLibSys (& hOpenLibSys);
116
116
hOpenLibSys = NULL ;
117
117
return false ;
118
118
}
@@ -161,9 +161,9 @@ class InstanceLock
161
161
public:
162
162
InstanceLock (const bool global_) : globalSemaphoreName(PCM_INSTANCE_LOCK_SEMAPHORE_NAME), globalSemaphore(NULL ), global(global_)
163
163
{
164
- if (!global)
164
+ if (!global)
165
165
{
166
- pthread_mutex_lock (&processIntanceMutex);
166
+ if ( pthread_mutex_lock (&processIntanceMutex) != 0 ) std::cerr << " pthread_mutex_lock failed \n " ;
167
167
return ;
168
168
}
169
169
umask (0 );
@@ -195,9 +195,9 @@ class InstanceLock
195
195
}
196
196
~InstanceLock ()
197
197
{
198
- if (!global)
198
+ if (!global)
199
199
{
200
- pthread_mutex_unlock (&processIntanceMutex);
200
+ if ( pthread_mutex_unlock (&processIntanceMutex) != 0 ) std::cerr << " pthread_mutex_unlock failed \n " ;
201
201
return ;
202
202
}
203
203
if (sem_post (globalSemaphore)) {
@@ -220,6 +220,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
220
220
public:
221
221
TemporalThreadAffinity (uint32 core_id, bool checkStatus = true )
222
222
{
223
+ assert (core_id < 1024 );
223
224
pthread_getaffinity_np (pthread_self (), sizeof (cpu_set_t ), &old_affinity);
224
225
225
226
cpu_set_t new_affinity;
@@ -247,6 +248,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
247
248
TemporalThreadAffinity (const uint32 core_id, bool checkStatus = true )
248
249
: set_size(CPU_ALLOC_SIZE(maxCPUs))
249
250
{
251
+ assert (core_id < maxCPUs);
250
252
old_affinity = CPU_ALLOC (maxCPUs);
251
253
assert (old_affinity);
252
254
pthread_getaffinity_np (pthread_self (), set_size, old_affinity);
@@ -593,7 +595,7 @@ bool PCM::detectModel()
593
595
auto tokens = split (line, ' :' );
594
596
if (tokens.size () >= 2 && tokens[0 ].find (" flags" ) == 0 )
595
597
{
596
- for (auto curFlag : split (tokens[1 ], ' ' ))
598
+ for (const auto & curFlag : split (tokens[1 ], ' ' ))
597
599
{
598
600
if (flag == curFlag)
599
601
{
@@ -730,27 +732,27 @@ void PCM::initRDT()
730
732
auto env = std::getenv (" PCM_USE_RESCTRL" );
731
733
if (env != nullptr && std::string (env) == std::string (" 1" ))
732
734
{
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 " ;
734
736
resctrl.init ();
735
737
useResctrl = true ;
736
738
return ;
737
739
}
738
740
if (resctrl.isMounted ())
739
741
{
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 " ;
741
743
resctrl.init ();
742
744
useResctrl = true ;
743
745
return ;
744
746
}
745
747
if (isSecureBoot ())
746
748
{
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 " ;
748
750
resctrl.init ();
749
751
useResctrl = true ;
750
752
return ;
751
753
}
752
754
#endif
753
- std::cout << " Initializing RMIDs" << std::endl;
755
+ std::cerr << " Initializing RMIDs" << std::endl;
754
756
unsigned maxRMID;
755
757
/* Calculate maximum number of RMID supported by socket */
756
758
maxRMID = getMaxRMID ();
@@ -2105,6 +2107,7 @@ class CoreTaskQueue
2105
2107
std::thread worker;
2106
2108
CoreTaskQueue () = delete ;
2107
2109
CoreTaskQueue (CoreTaskQueue &) = delete ;
2110
+ CoreTaskQueue & operator = (CoreTaskQueue &) = delete ;
2108
2111
public:
2109
2112
CoreTaskQueue (int32 core) :
2110
2113
worker ([=]() {
@@ -3046,18 +3049,21 @@ PCM::ErrorCode PCM::programCoreCounters(const int i /* core */,
3046
3049
perf_event_attr e = PCM_init_perf_event_attr ();
3047
3050
e.type = PERF_TYPE_RAW;
3048
3051
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 )
3059
3053
{
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
+ }
3061
3067
}
3062
3068
3063
3069
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 */,
3113
3119
std::make_pair (perfRetiringPath, PERF_TOPDOWN_RETIRING_POS)};
3114
3120
int readPos = core_fixed_counter_num_used + core_gen_counter_num_used;
3115
3121
leader_counter = -1 ;
3116
- for (auto event : topDownEvents)
3122
+ for (const auto & event : topDownEvents)
3117
3123
{
3118
3124
uint64 eventSel = 0 , umask = 0 ;
3119
3125
const auto eventDesc = readSysFS (event.first );
3120
3126
const auto tokens = split (eventDesc, ' ,' );
3121
- for (auto token : tokens)
3127
+ for (const auto & token : tokens)
3122
3128
{
3123
3129
if (match (token, " event=" , &eventSel))
3124
3130
{
@@ -4605,9 +4611,9 @@ PCM::ErrorCode PCM::program(const RawPMUConfigs& curPMUConfigs_, const bool sile
4605
4611
else
4606
4612
{
4607
4613
fixedReg.value = 0 ;
4608
- for (auto cfg : corePMUConfig.fixed )
4614
+ for (const auto & cfg : corePMUConfig.fixed )
4609
4615
{
4610
- fixedReg.value |= cfg.first [0 ];
4616
+ fixedReg.value |= uint64 ( cfg.first [0 ]) ;
4611
4617
}
4612
4618
conf.fixedCfg = &fixedReg;
4613
4619
}
@@ -5428,6 +5434,7 @@ void print_mcfg(const char * path)
5428
5434
if (read_bytes == 0 )
5429
5435
{
5430
5436
std::cerr << " PCM Error: Cannot read " << path << " \n " ;
5437
+ ::close (mcfg_handle);
5431
5438
throw std::exception ();
5432
5439
}
5433
5440
@@ -5442,6 +5449,7 @@ void print_mcfg(const char * path)
5442
5449
if (read_bytes == 0 )
5443
5450
{
5444
5451
std::cerr << " PCM Error: Cannot read " << path << " (2)\n " ;
5452
+ ::close (mcfg_handle);
5445
5453
throw std::exception ();
5446
5454
}
5447
5455
std::cout << " Segment " << std::dec << i << " " ;
@@ -5640,16 +5648,21 @@ bool PCM::useLinuxPerfForUncore() const
5640
5648
bool secureBoot = isSecureBoot ();
5641
5649
#ifdef PCM_USE_PERF
5642
5650
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
+ }
5644
5657
const char * perf_env = std::getenv (" PCM_USE_UNCORE_PERF" );
5645
5658
if (perf_env != NULL && std::string (perf_env) == std::string (" 1" ))
5646
5659
{
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 " ;
5648
5661
use = 1 ;
5649
5662
}
5650
5663
if (secureBoot)
5651
5664
{
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 " ;
5653
5666
use = 1 ;
5654
5667
}
5655
5668
else
@@ -7209,7 +7222,8 @@ void ServerPCICFGUncore::initMemTest(ServerPCICFGUncore::MemTestParam & param)
7209
7222
std::cerr << " ERROR: mmap failed\n " ;
7210
7223
return ;
7211
7224
}
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 );
7213
7227
if (maxNode == 0 )
7214
7228
{
7215
7229
std::cerr << " ERROR: max node is 0 \n " ;
@@ -7682,6 +7696,7 @@ void PCM::programCbo(const uint64 * events, const uint32 opCode, const uint32 nc
7682
7696
7683
7697
for (uint32 cbo = 0 ; cbo < getMaxNumOfCBoxes (); ++cbo)
7684
7698
{
7699
+ assert (cbo < cboPMUs[i].size ());
7685
7700
cboPMUs[i][cbo].initFreeze (UNC_PMON_UNIT_CTL_FRZ_EN);
7686
7701
7687
7702
if (ICX != cpu_model && SNOWRIDGE != cpu_model)
@@ -7984,7 +7999,7 @@ void PCM::setupCustomCoreEventsForNuma(PCM::ExtendedCustomCoreEventDescription&
7984
7999
conf.OffcoreResponseMsrValue [1 ] = 0x3FC0008FFF | (1 << 27 ) | (1 << 28 ) | (1 << 29 );
7985
8000
break ;
7986
8001
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 " ;
7988
8003
// OCR.READS_TO_CORE.LOCAL_DRAM
7989
8004
conf.OffcoreResponseMsrValue [0 ] = 0x0104000477 ;
7990
8005
// OCR.READS_TO_CORE.REMOTE_DRAM
0 commit comments