Skip to content

Commit 1b0e45e

Browse files
authored
Merge pull request #254 from opcm/opcm-push-202011
Opcm push 202011
2 parents b940626 + bd29929 commit 1b0e45e

File tree

13 files changed

+155
-332
lines changed

13 files changed

+155
-332
lines changed

cpucounters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ bool PCM::checkModel()
20612061
if (cpu_model == BROADWELL_XEON_E3) cpu_model = BROADWELL;
20622062
if (cpu_model == SKL_UY) cpu_model = SKL;
20632063
if (cpu_model == KBL_1) cpu_model = KBL;
2064+
if (cpu_model == CML) cpu_model = KBL;
20642065

20652066
if(!isCPUModelSupported((int)cpu_model))
20662067
{

cpucounters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ class PCM_API PCM
12431243
SKL_UY = 78,
12441244
KBL = 158,
12451245
KBL_1 = 142,
1246+
CML = 166,
12461247
ICL = 126,
12471248
BDX = 79,
12481249
KNL = 87,

pcm-core.cpp

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <vector>
4444
#define PCM_DELAY_DEFAULT 1.0 // in seconds
4545
#define PCM_DELAY_MIN 0.015 // 15 milliseconds is practical on most modern CPUs
46-
#define PCM_CALIBRATION_INTERVAL 50 // calibrate clock only every 50th iteration
4746
#define MAX_CORES 4096
4847

4948
using namespace std;
@@ -136,6 +135,7 @@ void print_usage(const string progname)
136135
cerr << " [-e event1] [-e event2] [-e event3] .. => optional list of custom events to monitor\n";
137136
cerr << " event description example: cpu/umask=0x01,event=0x05,name=MISALIGN_MEM_REF.LOADS/ \n";
138137
cerr << " -yc | --yescores | /yc => enable specific cores to output\n";
138+
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
139139
print_help_force_rtm_abort_mode(41);
140140
cerr << " Examples:\n";
141141
cerr << " " << progname << " 1 => print counters every second without core and socket output\n";
@@ -292,10 +292,8 @@ int main(int argc, char * argv[])
292292
char **sysArgv = NULL;
293293
uint32 cur_event = 0;
294294
bool csv = false;
295-
long diff_usec = 0; // deviation of clock is useconds between measurements
296295
uint64 txn_rate = 1;
297-
int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
298-
unsigned int numberOfIterations = 0; // number of iterations
296+
MainLoop mainLoop;
299297
string program = string(argv[0]);
300298
EventSelectRegister regs[PERF_MAX_COUNTERS];
301299
PCM::ExtendedCustomCoreEventDescription conf;
@@ -335,17 +333,8 @@ int main(int argc, char * argv[])
335333
continue;
336334
}
337335
else
338-
if (strncmp(*argv, "-i", 2) == 0 ||
339-
strncmp(*argv, "/i", 2) == 0)
336+
if (mainLoop.parseArg(*argv))
340337
{
341-
string cmd = string(*argv);
342-
size_t found = cmd.find('=', 2);
343-
if (found != string::npos) {
344-
string tmp = cmd.substr(found + 1);
345-
if (!tmp.empty()) {
346-
numberOfIterations = (unsigned int)atoi(tmp.c_str());
347-
}
348-
}
349338
continue;
350339
}
351340
else if (strncmp(*argv, "-c",2) == 0 ||
@@ -515,38 +504,12 @@ int main(int argc, char * argv[])
515504
}
516505

517506

518-
unsigned int ic = 1;
519-
520-
while ((ic <= numberOfIterations) || (numberOfIterations == 0))
507+
mainLoop([&]()
521508
{
522509
if(!csv) cout << std::flush;
523-
int delay_ms = int(delay * 1000);
524-
int calibrated_delay_ms = delay_ms;
525-
#ifdef _MSC_VER
526-
// compensate slow Windows console output
527-
if(AfterTime) delay_ms -= (int)(m->getTickCount() - BeforeTime);
528-
if(delay_ms < 0) delay_ms = 0;
529-
#else
530-
// compensation of delay on Linux/UNIX
531-
// to make the samling interval as monotone as possible
532-
struct timeval start_ts, end_ts;
533-
if(calibrated == 0) {
534-
gettimeofday(&end_ts, NULL);
535-
diff_usec = (end_ts.tv_sec-start_ts.tv_sec)*1000000.0+(end_ts.tv_usec-start_ts.tv_usec);
536-
calibrated_delay_ms = delay_ms - diff_usec/1000.0;
537-
}
538-
#endif
539-
if (sysCmd == NULL || numberOfIterations != 0 || m->isBlocked() == false)
540-
{
541-
MySleepMs(calibrated_delay_ms);
542-
}
543510

544-
#ifndef _MSC_VER
545-
calibrated = (calibrated + 1) % PCM_CALIBRATION_INTERVAL;
546-
if(calibrated == 0) {
547-
gettimeofday(&start_ts, NULL);
548-
}
549-
#endif
511+
calibratedSleep(delay, sysCmd, mainLoop, m);
512+
550513
AfterTime = m->getTickCount();
551514
m->getAllCounterStates(SysAfterState, DummySocketStates, AfterState);
552515

@@ -611,9 +574,9 @@ int main(int argc, char * argv[])
611574

612575
if ( m->isBlocked() ) {
613576
// in case PCM was blocked after spawning child application: break monitoring loop here
614-
break;
577+
return false;
615578
}
616-
++ic;
617-
}
579+
return true;
580+
});
618581
exit(EXIT_SUCCESS);
619582
}

pcm-latency.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ void build_registers(PCM *m, PCM::ExtendedCustomCoreEventDescription conf, bool
449449
m->programServerUncoreLatencyMetrics(enable_pmm);
450450
}
451451

452-
void collect_data(PCM *m, bool enable_pmm, bool enable_verbose, int delay_ms)
452+
void collect_data(PCM *m, bool enable_pmm, bool enable_verbose, int delay_ms, MainLoop & mainLoop)
453453
{
454454

455455
BeforeState = new ServerUncoreCounterState[m->getNumSockets()];
456456
AfterState = new ServerUncoreCounterState[m->getNumSockets()];
457457

458-
while (1)
458+
mainLoop([&]()
459459
{
460460
collect_beforestate_uncore(m);
461461
collect_beforestate_core(m);
@@ -470,7 +470,8 @@ void collect_data(PCM *m, bool enable_pmm, bool enable_verbose, int delay_ms)
470470

471471
print_all_stats(m, enable_pmm, enable_verbose);
472472
std::cout << std::flush;
473-
}
473+
return true;
474+
});
474475

475476
delete[] BeforeState;
476477
delete[] AfterState;
@@ -479,9 +480,10 @@ void collect_data(PCM *m, bool enable_pmm, bool enable_verbose, int delay_ms)
479480
void print_usage()
480481
{
481482
cerr << "\nUsage: \n";
482-
cerr << " -h | --help | /h => Print this help and exit\n";
483-
cerr << " --PMM | -pmm => to enable PMM (Default DDR uncore latency)\n";
484-
cerr << " -v | --verbose => Verbose Output\n";
483+
cerr << " -h | --help | /h => print this help and exit\n";
484+
cerr << " --PMM | -pmm => to enable PMM (Default DDR uncore latency)\n";
485+
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
486+
cerr << " -v | --verbose => verbose Output\n";
485487
cerr << "\n";
486488
}
487489

@@ -493,6 +495,7 @@ int main(int argc, char * argv[])
493495
bool enable_pmm = false;
494496
bool enable_verbose = false;
495497
int delay_ms = 1000;
498+
MainLoop mainLoop;
496499
if(argc > 1) do
497500
{
498501
argv++;
@@ -505,6 +508,10 @@ int main(int argc, char * argv[])
505508
print_usage();
506509
exit(EXIT_FAILURE);
507510
}
511+
else if (mainLoop.parseArg(*argv))
512+
{
513+
continue;
514+
}
508515
else if (strncmp(*argv, "--PMM",6) == 0 || strncmp(*argv, "-pmm", 5) == 0)
509516
{
510517
argv++;
@@ -528,7 +535,7 @@ int main(int argc, char * argv[])
528535
PCM * m = PCM::getInstance();
529536

530537
build_registers(m, conf, enable_pmm, enable_verbose);
531-
collect_data(m, enable_pmm, enable_verbose, delay_ms);
538+
collect_data(m, enable_pmm, enable_verbose, delay_ms, mainLoop);
532539

533540
exit(EXIT_SUCCESS);
534541
}

pcm-memory.cpp

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
#define PCM_DELAY_DEFAULT 1.0 // in seconds
4141
#define PCM_DELAY_MIN 0.015 // 15 milliseconds is practical on most modern CPUs
42-
#define PCM_CALIBRATION_INTERVAL 50 // calibrate clock only every 50th iteration
4342

4443
#define DEFAULT_DISPLAY_COLUMNS 2
4544

@@ -91,6 +90,7 @@ void print_help(const string prog_name)
9190
<< " to a file, in case filename is provided\n";
9291
cerr << " -columns=X | /columns=X => Number of columns to display the NUMA Nodes, defaults to 2.\n";
9392
cerr << " -all | /all => Display all channels (even with no traffic)\n";
93+
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
9494
#ifdef _MSC_VER
9595
cerr << " --uninstallDriver | --installDriver=> (un)install driver\n";
9696
#endif
@@ -826,12 +826,8 @@ int main(int argc, char * argv[])
826826
uint32 no_columns = DEFAULT_DISPLAY_COLUMNS; // Default number of columns is 2
827827
char * sysCmd = NULL;
828828
char ** sysArgv = NULL;
829-
#ifndef _MSC_VER
830-
long diff_usec = 0; // deviation of clock is useconds between measurements
831-
int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
832-
#endif
833829
int rankA = -1, rankB = -1;
834-
unsigned int numberOfIterations = 0; // number of iterations
830+
MainLoop mainLoop;
835831

836832
string program = string(argv[0]);
837833

@@ -867,17 +863,8 @@ int main(int argc, char * argv[])
867863
continue;
868864
}
869865
else
870-
if (strncmp(*argv, "-i", 2) == 0 ||
871-
strncmp(*argv, "/i", 2) == 0)
866+
if (mainLoop.parseArg(*argv))
872867
{
873-
string cmd = string(*argv);
874-
size_t found = cmd.find('=', 2);
875-
if (found != string::npos) {
876-
string tmp = cmd.substr(found + 1);
877-
if (!tmp.empty()) {
878-
numberOfIterations = (unsigned int)atoi(tmp.c_str());
879-
}
880-
}
881868
continue;
882869
}
883870
else
@@ -1097,39 +1084,11 @@ int main(int argc, char * argv[])
10971084
MySystem(sysCmd, sysArgv);
10981085
}
10991086

1100-
unsigned int i = 1;
1101-
1102-
while ((i <= numberOfIterations) || (numberOfIterations == 0))
1087+
mainLoop([&]()
11031088
{
11041089
if(!csv) cout << flush;
1105-
int delay_ms = int(delay * 1000);
1106-
int calibrated_delay_ms = delay_ms;
1107-
#ifdef _MSC_VER
1108-
// compensate slow Windows console output
1109-
if(AfterTime) delay_ms -= (int)(m->getTickCount() - BeforeTime);
1110-
if(delay_ms < 0) delay_ms = 0;
1111-
#else
1112-
// compensation of delay on Linux/UNIX
1113-
// to make the samling interval as monotone as possible
1114-
struct timeval start_ts, end_ts;
1115-
if(calibrated == 0) {
1116-
gettimeofday(&end_ts, NULL);
1117-
diff_usec = (end_ts.tv_sec-start_ts.tv_sec)*1000000.0+(end_ts.tv_usec-start_ts.tv_usec);
1118-
calibrated_delay_ms = delay_ms - diff_usec/1000.0;
1119-
}
1120-
#endif
1121-
1122-
if (sysCmd == NULL || numberOfIterations != 0 || m->isBlocked() == false)
1123-
{
1124-
MySleepMs(calibrated_delay_ms);
1125-
}
11261090

1127-
#ifndef _MSC_VER
1128-
calibrated = (calibrated + 1) % PCM_CALIBRATION_INTERVAL;
1129-
if(calibrated == 0) {
1130-
gettimeofday(&start_ts, NULL);
1131-
}
1132-
#endif
1091+
calibratedSleep(delay, sysCmd, mainLoop, m);
11331092

11341093
AfterTime = m->getTickCount();
11351094
for(uint32 i=0; i<m->getNumSockets(); ++i)
@@ -1150,10 +1109,10 @@ int main(int argc, char * argv[])
11501109

11511110
if ( m->isBlocked() ) {
11521111
// in case PCM was blocked after spawning child application: break monitoring loop here
1153-
break;
1112+
return false;
11541113
}
1155-
++i;
1156-
}
1114+
return true;
1115+
});
11571116

11581117
delete[] BeforeState;
11591118
delete[] AfterState;

pcm-numa.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include <vector>
4242
#define PCM_DELAY_DEFAULT 1.0 // in seconds
4343
#define PCM_DELAY_MIN 0.015 // 15 milliseconds is practical on most modern CPUs
44-
#define PCM_CALIBRATION_INTERVAL 50 // calibrate clock only every 50th iteration
4544

4645
using namespace std;
4746
using namespace pcm;
@@ -57,6 +56,7 @@ void print_usage(const string progname)
5756
cerr << " -h | --help | /h => print this help and exit\n";
5857
cerr << " -csv[=file.csv] | /csv[=file.csv] => output compact CSV format to screen or\n"
5958
<< " to a file, in case filename is provided\n";
59+
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
6060
cerr << " Examples:\n";
6161
cerr << " " << progname << " 1 => print counters every second without core and socket output\n";
6262
cerr << " " << progname << " 0.5 -csv=test.log => twice a second save counter values to test.log in CSV format\n";
@@ -111,8 +111,7 @@ int main(int argc, char * argv[])
111111
char * sysCmd = NULL;
112112
char ** sysArgv = NULL;
113113
bool csv = false;
114-
long diff_usec = 0; // deviation of clock is useconds between measurements
115-
int calibrated = PCM_CALIBRATION_INTERVAL - 2; // keeps track is the clock calibration needed
114+
MainLoop mainLoop;
116115
string program = string(argv[0]);
117116

118117
PCM * m = PCM::getInstance();
@@ -142,6 +141,10 @@ int main(int argc, char * argv[])
142141
}
143142
continue;
144143
}
144+
else if (mainLoop.parseArg(*argv))
145+
{
146+
continue;
147+
}
145148
else if (strncmp(*argv, "--", 2) == 0)
146149
{
147150
argv++;
@@ -256,36 +259,12 @@ int main(int argc, char * argv[])
256259
MySystem(sysCmd, sysArgv);
257260
}
258261

259-
while (1)
262+
mainLoop([&]()
260263
{
261264
if (!csv) cout << flush;
262-
int delay_ms = int(delay * 1000);
263-
int calibrated_delay_ms = delay_ms;
264-
#ifdef _MSC_VER
265-
// compensate slow Windows console output
266-
if (AfterTime) delay_ms -= (int)(m->getTickCount() - BeforeTime);
267-
if (delay_ms < 0) delay_ms = 0;
268-
#else
269-
// compensation of delay on Linux/UNIX
270-
// to make the samling interval as monotone as possible
271-
struct timeval start_ts, end_ts;
272-
if (calibrated == 0) {
273-
gettimeofday(&end_ts, NULL);
274-
diff_usec = (end_ts.tv_sec - start_ts.tv_sec) * 1000000.0 + (end_ts.tv_usec - start_ts.tv_usec);
275-
calibrated_delay_ms = delay_ms - diff_usec / 1000.0;
276-
}
277-
#endif
278-
if (sysCmd == NULL || m->isBlocked() == false)
279-
{
280-
MySleepMs(calibrated_delay_ms);
281-
}
282265

283-
#ifndef _MSC_VER
284-
calibrated = (calibrated + 1) % PCM_CALIBRATION_INTERVAL;
285-
if (calibrated == 0) {
286-
gettimeofday(&start_ts, NULL);
287-
}
288-
#endif
266+
calibratedSleep(delay, sysCmd, mainLoop, m);
267+
289268
AfterTime = m->getTickCount();
290269
m->getAllCounterStates(SysAfterState, DummySocketStates, AfterState);
291270

@@ -326,9 +305,10 @@ int main(int argc, char * argv[])
326305

327306
if (m->isBlocked()) {
328307
// in case PCM was blocked after spawning child application: break monitoring loop here
329-
break;
308+
return false;
330309
}
331-
}
310+
return true;
311+
});
332312

333313
exit(EXIT_SUCCESS);
334314
}

0 commit comments

Comments
 (0)