Skip to content

Commit 416fce0

Browse files
committed
Merge tag '2022-08-01' into push-2022-08-01
Change-Id: I2064072c7a059d2e882e1e2bcfb442a96cc34c8a
2 parents 75fc2ee + efeccd5 commit 416fce0

16 files changed

+791
-762
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"core" : {
3+
"programmable" : {
4+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
5+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
6+
"User": {"Config": 0, "Position": 16, "Width": 1, "DefaultValue": 1},
7+
"OS": {"Config": 0, "Position": 17, "Width": 1, "DefaultValue": 1},
8+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1},
9+
"PinControl": {"Config": 0, "Position": 19, "Width": 1, "DefaultValue": 0},
10+
"APICInt": {"Config": 0, "Position": 20, "Width": 1, "DefaultValue": 0},
11+
"Enable": {"Config": 0, "Position": 22, "Width": 1, "DefaultValue": 1},
12+
"Invert": {"Config": 0, "Position": 23, "Width": 1},
13+
"CounterMask": {"Config": 0, "Position": 24, "Width": 8},
14+
"MSRIndex": {
15+
"0x1a6" : {"Config": 1, "Position": 0, "Width": 64},
16+
"0x1a7" : {"Config": 2, "Position": 0, "Width": 64},
17+
"0x3f6" : {"Config": 3, "Position": 0, "Width": 64},
18+
"0x3f7" : {"Config": 4, "Position": 0, "Width": 64}
19+
}
20+
},
21+
"fixed0" : {
22+
"OS": {"Config": 0, "Position": 0, "Width": 1, "DefaultValue": 1},
23+
"User": {"Config": 0, "Position": 1, "Width": 1, "DefaultValue": 1},
24+
"EnablePMI": {"Config": 0, "Position": 3, "Width": 1, "DefaultValue": 0},
25+
"EventCode": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
26+
"UMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
27+
"EdgeDetect": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
28+
"Invert": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
29+
"CounterMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"}
30+
},
31+
"fixed1" : {
32+
"OS": {"Config": 0, "Position": 4, "Width": 1, "DefaultValue": 1},
33+
"User": {"Config": 0, "Position": 5, "Width": 1, "DefaultValue": 1},
34+
"EnablePMI": {"Config": 0, "Position": 7, "Width": 1, "DefaultValue": 0},
35+
"EventCode": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
36+
"UMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
37+
"EdgeDetect": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
38+
"Invert": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
39+
"CounterMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"}
40+
},
41+
"fixed2" : {
42+
"OS": {"Config": 0, "Position": 8, "Width": 1, "DefaultValue": 1},
43+
"User": {"Config": 0, "Position": 9, "Width": 1, "DefaultValue": 1},
44+
"EnablePMI": {"Config": 0, "Position": 11, "Width": 1, "DefaultValue": 0},
45+
"EventCode": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
46+
"UMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
47+
"EdgeDetect": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
48+
"Invert": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"},
49+
"CounterMask": {"Config": 0, "Position": -1, "__comment": "position=-1 means field ignored"}
50+
}
51+
},
52+
"cha" : {
53+
"programmable" : {
54+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
55+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
56+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0},
57+
"Threshold": {"Config": 0, "Position": 24, "Width": 8, "DefaultValue": 0},
58+
"UMaskExt": {"Config": 0, "Position": 32, "Width": 26}
59+
}
60+
},
61+
"imc" : {
62+
"programmable" : {
63+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
64+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
65+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0},
66+
"Threshold": {"Config": 0, "Position": 24, "Width": 8, "DefaultValue": 0}
67+
}
68+
},
69+
"m2m" : {
70+
"programmable" : {
71+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
72+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
73+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0},
74+
"Threshold": {"Config": 0, "Position": 24, "Width": 8, "DefaultValue": 0},
75+
"UMaskExt": {"Config": 0, "Position": 32, "Width": 8}
76+
}
77+
},
78+
"irp" : {
79+
"programmable" : {
80+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
81+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
82+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0},
83+
"Threshold": {"Config": 0, "Position": 24, "Width": 8, "DefaultValue": 0}
84+
}
85+
},
86+
"pcu" : {
87+
"programmable" : {
88+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
89+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
90+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0}
91+
}
92+
},
93+
"iio" : {
94+
"programmable" : {
95+
"EventCode": {"Config": 0, "Position": 0, "Width": 8},
96+
"UMask": {"Config": 0, "Position": 8, "Width": 8},
97+
"EdgeDetect": {"Config": 0, "Position": 18, "Width": 1, "DefaultValue": 0},
98+
"Threshold": {"Config": 0, "Position": 24, "Width": 12, "DefaultValue": 0},
99+
"PortMask": {"Config": 0, "Position": 36, "Width": 12},
100+
"FCMask": {"Config": 0, "Position": 48, "Width": 3}
101+
}
102+
}
103+
}

src/cpucounters.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void pcm_cpuid_bsd(int leaf, PCM_CPUID_INFO& info, int core)
329329
{
330330
info.array[i] = cpuid_args_freebsd.data[i];
331331
}
332+
::close(fd);
332333
}
333334
#endif
334335

src/pci.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ bool PciHandle::exists(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 func
257257
struct pci_match_conf pattern;
258258
struct pci_conf conf[4];
259259
int fd;
260+
int ret;
260261

261262
fd = ::open("/dev/pci", O_RDWR, 0);
262263
if (fd < 0) return false;
@@ -274,7 +275,10 @@ bool PciHandle::exists(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 func
274275
pc.match_buf_len = sizeof(conf);
275276
pc.matches = conf;
276277

277-
if (ioctl(fd, PCIOCGETCONF, &pc)) return false;
278+
ret = ioctl(fd, PCIOCGETCONF, &pc);
279+
::close(fd);
280+
281+
if (ret) return false;
278282

279283
if (pc.status != PCI_GETCONF_LAST_DEVICE) return false;
280284

src/pcm-core.cpp

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,29 @@ extern "C" {
110110
}
111111
}
112112

113-
void print_usage(const string progname)
113+
void print_usage(const string & progname)
114114
{
115-
cerr << "\n Usage: \n " << progname
116-
<< " --help | [delay] [options] [-- external_program [external_program_options]]\n";
117-
cerr << " <delay> => time interval to sample performance counters.\n";
118-
cerr << " If not specified, or 0, with external program given\n";
119-
cerr << " will read counters only after external program finishes\n";
120-
cerr << " Supported <options> are: \n";
121-
cerr << " -h | --help | /h => print this help and exit\n";
122-
cerr << " -c | /c => print CPU Model name and exit (used for pmu-query.py)\n";
123-
cerr << " -csv[=file.csv] | /csv[=file.csv] => output compact CSV format to screen or\n"
115+
cout << "\n Usage: \n " << progname
116+
<< " --help | [delay] [options] [-- external_program [external_program_options]]\n";
117+
cout << " <delay> => time interval to sample performance counters.\n";
118+
cout << " If not specified, or 0, with external program given\n";
119+
cout << " will read counters only after external program finishes\n";
120+
cout << " Supported <options> are: \n";
121+
cout << " -h | --help | /h => print this help and exit\n";
122+
cout << " -silent => silence information output and print only measurements\n";
123+
cout << " -c | /c => print CPU Model name and exit (used for pmu-query.py)\n";
124+
cout << " -csv[=file.csv] | /csv[=file.csv] => output compact CSV format to screen or\n"
124125
<< " to a file, in case filename is provided\n";
125-
cerr << " [-e event1] [-e event2] [-e event3] .. => optional list of custom events to monitor\n";
126-
cerr << " event description example: cpu/umask=0x01,event=0x05,name=MISALIGN_MEM_REF.LOADS/ \n";
127-
cerr << " -yc | --yescores | /yc => enable specific cores to output\n";
128-
cerr << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
126+
cout << " [-e event1] [-e event2] [-e event3] .. => optional list of custom events to monitor\n";
127+
cout << " event description example: cpu/umask=0x01,event=0x05,name=MISALIGN_MEM_REF.LOADS/ \n";
128+
cout << " -yc | --yescores | /yc => enable specific cores to output\n";
129+
cout << " -i[=number] | /i[=number] => allow to determine number of iterations\n";
129130
print_help_force_rtm_abort_mode(41);
130-
cerr << " Examples:\n";
131-
cerr << " " << progname << " 1 => print counters every second without core and socket output\n";
132-
cerr << " " << progname << " 0.5 -csv=test.log => twice a second save counter values to test.log in CSV format\n";
133-
cerr << " " << progname << " /csv 5 2>/dev/null => one sampe every 5 seconds, and discard all diagnostic output\n";
134-
cerr << "\n";
131+
cout << " Examples:\n";
132+
cout << " " << progname << " 1 => print counters every second without core and socket output\n";
133+
cout << " " << progname << " 0.5 -csv=test.log => twice a second save counter values to test.log in CSV format\n";
134+
cout << " " << progname << " /csv 5 2>/dev/null => one sampe every 5 seconds, and discard all diagnostic output\n";
135+
cout << "\n";
135136
}
136137

137138
template <class StateType>
@@ -258,14 +259,17 @@ void build_event(const char * argv, EventSelectRegister *reg, int idx)
258259

259260
int main(int argc, char * argv[])
260261
{
261-
set_signal_handlers();
262-
262+
null_stream nullStream2;
263263
#ifdef PCM_FORCE_SILENT
264-
null_stream nullStream1, nullStream2;
264+
null_stream nullStream1;
265265
std::cout.rdbuf(&nullStream1);
266266
std::cerr.rdbuf(&nullStream2);
267+
#else
268+
check_and_set_silent(argc, argv, nullStream2);
267269
#endif
268270

271+
set_signal_handlers();
272+
269273
cerr << "\n";
270274
cerr << " Processor Counter Monitor: Core Monitoring Utility \n";
271275
cerr << "\n";
@@ -294,50 +298,48 @@ int main(int argc, char * argv[])
294298
{
295299
argv++;
296300
argc--;
297-
if (strncmp(*argv, "--help", 6) == 0 ||
298-
strncmp(*argv, "-h", 2) == 0 ||
299-
strncmp(*argv, "/h", 2) == 0)
301+
string arg_value;
302+
303+
if (check_argument_equals(*argv, {"--help", "-h", "/h"}))
300304
{
301305
print_usage(program);
302306
exit(EXIT_FAILURE);
303307
}
304-
else if (strncmp(*argv, "-csv",4) == 0 ||
305-
strncmp(*argv, "/csv",4) == 0)
308+
else if (check_argument_equals(*argv, {"-silent", "/silent"}))
309+
{
310+
// handled in check_and_set_silent
311+
continue;
312+
}
313+
else if (check_argument_equals(*argv, {"-csv", "/csv"}))
306314
{
307315
csv = true;
308-
string cmd = string(*argv);
309-
size_t found = cmd.find('=',4);
310-
if (found != string::npos) {
311-
string filename = cmd.substr(found+1);
312-
if (!filename.empty()) {
313-
m->setOutput(filename);
314-
}
316+
}
317+
else if (extract_argument_value(*argv, {"-csv", "/csv"}, arg_value))
318+
{
319+
csv = true;
320+
if (!arg_value.empty()) {
321+
m->setOutput(arg_value);
315322
}
316323
continue;
317324
}
318-
else
319-
if (mainLoop.parseArg(*argv))
325+
else if (mainLoop.parseArg(*argv))
320326
{
321327
continue;
322328
}
323-
else if (strncmp(*argv, "-c",2) == 0 ||
324-
strncmp(*argv, "/c",2) == 0)
329+
else if (check_argument_equals(*argv, {"-c", "/c"}))
325330
{
326331
cout << m->getCPUFamilyModelString() << "\n";
327332
exit(EXIT_SUCCESS);
328333
}
329-
else if (strncmp(*argv, "-txn",4) == 0 ||
330-
strncmp(*argv, "/txn",4) == 0)
334+
else if (check_argument_equals(*argv, {"-txn", "/txn"}))
331335
{
332336
argv++;
333337
argc--;
334338
txn_rate = strtoull(*argv,NULL,10);
335339
cout << "txn_rate set to " << txn_rate << "\n";
336340
continue;
337341
}
338-
if (strncmp(*argv, "--yescores", 10) == 0 ||
339-
strncmp(*argv, "-yc", 3) == 0 ||
340-
strncmp(*argv, "/yc", 3) == 0)
342+
else if (check_argument_equals(*argv, {"--yescores", "-yc", "/yc"}))
341343
{
342344
argv++;
343345
argc--;
@@ -372,10 +374,11 @@ int main(int argc, char * argv[])
372374
}
373375
continue;
374376
}
375-
else if (strncmp(*argv, "-e",2) == 0)
377+
else if (check_argument_equals(*argv, {"-e"}))
376378
{
377379
argv++;
378380
argc--;
381+
379382
if(cur_event >= conf.nGPCounters) {
380383
cerr << "At most " << conf.nGPCounters << " events are allowed\n";
381384
exit(EXIT_FAILURE);
@@ -386,15 +389,13 @@ int main(int argc, char * argv[])
386389
} catch (...) {
387390
exit(EXIT_FAILURE);
388391
}
389-
390392
continue;
391393
}
392-
else
393-
if (CheckAndForceRTMAbortMode(*argv, m))
394-
{
395-
continue;
396-
}
397-
else if (strncmp(*argv, "--", 2) == 0)
394+
else if (CheckAndForceRTMAbortMode(*argv, m))
395+
{
396+
continue;
397+
}
398+
else if (check_argument_equals(*argv, {"--"}))
398399
{
399400
argv++;
400401
sysCmd = *argv;
@@ -403,18 +404,7 @@ int main(int argc, char * argv[])
403404
}
404405
else
405406
{
406-
// any other options positional that is a floating point number is treated as <delay>,
407-
// while the other options are ignored with a warning issues to stderr
408-
double delay_input = 0.0;
409-
std::istringstream is_str_stream(*argv);
410-
is_str_stream >> noskipws >> delay_input;
411-
if(is_str_stream.eof() && !is_str_stream.fail()) {
412-
delay = delay_input;
413-
} else {
414-
cerr << "WARNING: unknown command-line option: \"" << *argv << "\". Ignoring it.\n";
415-
print_usage(program);
416-
exit(EXIT_FAILURE);
417-
}
407+
delay = parse_delay(*argv, program, (print_usage_func)print_usage);
418408
continue;
419409
}
420410
} while(argc > 1); // end of command line parsing loop

0 commit comments

Comments
 (0)