@@ -267,6 +267,7 @@ unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */
267
267
unsigned int first_counter_read = 1 ;
268
268
int ignore_stdin ;
269
269
bool no_msr ;
270
+ bool no_perf ;
270
271
271
272
int get_msr (int cpu , off_t offset , unsigned long long * msr );
272
273
@@ -1314,8 +1315,17 @@ static void bic_disable_msr_access(void)
1314
1315
bic_enabled &= ~bic_msrs ;
1315
1316
}
1316
1317
1318
+ static void bic_disable_perf_access (void )
1319
+ {
1320
+ const unsigned long bic_perf = BIC_IPC ;
1321
+
1322
+ bic_enabled &= ~bic_perf ;
1323
+ }
1324
+
1317
1325
static long perf_event_open (struct perf_event_attr * hw_event , pid_t pid , int cpu , int group_fd , unsigned long flags )
1318
1326
{
1327
+ assert (!no_perf );
1328
+
1319
1329
return syscall (__NR_perf_event_open , hw_event , pid , cpu , group_fd , flags );
1320
1330
}
1321
1331
@@ -1332,8 +1342,8 @@ static int perf_instr_count_open(int cpu_num)
1332
1342
/* counter for cpu_num, including user + kernel and all processes */
1333
1343
fd = perf_event_open (& pea , -1 , cpu_num , -1 , 0 );
1334
1344
if (fd == -1 ) {
1335
- warnx ("capget(CAP_PERFMON) failed, try \"# setcap cap_sys_admin=ep %s\"" , progname );
1336
- BIC_NOT_PRESENT ( BIC_IPC );
1345
+ warnx ("capget(CAP_PERFMON) failed, try \"# setcap cap_sys_admin=ep %s\" or use --no-perf " , progname );
1346
+ bic_disable_perf_access ( );
1337
1347
}
1338
1348
1339
1349
return fd ;
@@ -1399,6 +1409,7 @@ void help(void)
1399
1409
" -J, --Joules displays energy in Joules instead of Watts\n"
1400
1410
" -l, --list list column headers only\n"
1401
1411
" -M, --no-msr Disable all uses of the MSR driver\n"
1412
+ " -P, --no-perf Disable all uses of the perf API\n"
1402
1413
" -n, --num_iterations num\n"
1403
1414
" number of the measurement iterations\n"
1404
1415
" -N, --header_iterations num\n"
@@ -6745,6 +6756,7 @@ void cmdline(int argc, char **argv)
6745
6756
{ "out" , required_argument , 0 , 'o' },
6746
6757
{ "quiet" , no_argument , 0 , 'q' },
6747
6758
{ "no-msr" , no_argument , 0 , 'M' },
6759
+ { "no-perf" , no_argument , 0 , 'P' },
6748
6760
{ "show" , required_argument , 0 , 's' },
6749
6761
{ "Summary" , no_argument , 0 , 'S' },
6750
6762
{ "TCC" , required_argument , 0 , 'T' },
@@ -6758,11 +6770,14 @@ void cmdline(int argc, char **argv)
6758
6770
* Parse some options early, because they may make other options invalid,
6759
6771
* like adding the MSR counter with --add and at the same time using --no-msr.
6760
6772
*/
6761
- while ((opt = getopt_long_only (argc , argv , "M " , long_options , & option_index )) != -1 ) {
6773
+ while ((opt = getopt_long_only (argc , argv , "MP " , long_options , & option_index )) != -1 ) {
6762
6774
switch (opt ) {
6763
6775
case 'M' :
6764
6776
no_msr = 1 ;
6765
6777
break ;
6778
+ case 'P' :
6779
+ no_perf = 1 ;
6780
+ break ;
6766
6781
default :
6767
6782
break ;
6768
6783
}
@@ -6828,6 +6843,7 @@ void cmdline(int argc, char **argv)
6828
6843
quiet = 1 ;
6829
6844
break ;
6830
6845
case 'M' :
6846
+ case 'P' :
6831
6847
/* Parsed earlier */
6832
6848
break ;
6833
6849
case 'n' :
@@ -6909,6 +6925,9 @@ int main(int argc, char **argv)
6909
6925
if (no_msr )
6910
6926
bic_disable_msr_access ();
6911
6927
6928
+ if (no_perf )
6929
+ bic_disable_perf_access ();
6930
+
6912
6931
if (!quiet ) {
6913
6932
print_version ();
6914
6933
print_bootcmd ();
0 commit comments