@@ -267,6 +267,7 @@ unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */
267267unsigned int first_counter_read = 1 ;
268268int ignore_stdin ;
269269bool no_msr ;
270+ bool no_perf ;
270271
271272int get_msr (int cpu , off_t offset , unsigned long long * msr );
272273
@@ -1314,8 +1315,17 @@ static void bic_disable_msr_access(void)
13141315 bic_enabled &= ~bic_msrs ;
13151316}
13161317
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+
13171325static long perf_event_open (struct perf_event_attr * hw_event , pid_t pid , int cpu , int group_fd , unsigned long flags )
13181326{
1327+ assert (!no_perf );
1328+
13191329 return syscall (__NR_perf_event_open , hw_event , pid , cpu , group_fd , flags );
13201330}
13211331
@@ -1332,8 +1342,8 @@ static int perf_instr_count_open(int cpu_num)
13321342 /* counter for cpu_num, including user + kernel and all processes */
13331343 fd = perf_event_open (& pea , -1 , cpu_num , -1 , 0 );
13341344 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 ( );
13371347 }
13381348
13391349 return fd ;
@@ -1399,6 +1409,7 @@ void help(void)
13991409 " -J, --Joules displays energy in Joules instead of Watts\n"
14001410 " -l, --list list column headers only\n"
14011411 " -M, --no-msr Disable all uses of the MSR driver\n"
1412+ " -P, --no-perf Disable all uses of the perf API\n"
14021413 " -n, --num_iterations num\n"
14031414 " number of the measurement iterations\n"
14041415 " -N, --header_iterations num\n"
@@ -6745,6 +6756,7 @@ void cmdline(int argc, char **argv)
67456756 { "out" , required_argument , 0 , 'o' },
67466757 { "quiet" , no_argument , 0 , 'q' },
67476758 { "no-msr" , no_argument , 0 , 'M' },
6759+ { "no-perf" , no_argument , 0 , 'P' },
67486760 { "show" , required_argument , 0 , 's' },
67496761 { "Summary" , no_argument , 0 , 'S' },
67506762 { "TCC" , required_argument , 0 , 'T' },
@@ -6758,11 +6770,14 @@ void cmdline(int argc, char **argv)
67586770 * Parse some options early, because they may make other options invalid,
67596771 * like adding the MSR counter with --add and at the same time using --no-msr.
67606772 */
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 ) {
67626774 switch (opt ) {
67636775 case 'M' :
67646776 no_msr = 1 ;
67656777 break ;
6778+ case 'P' :
6779+ no_perf = 1 ;
6780+ break ;
67666781 default :
67676782 break ;
67686783 }
@@ -6828,6 +6843,7 @@ void cmdline(int argc, char **argv)
68286843 quiet = 1 ;
68296844 break ;
68306845 case 'M' :
6846+ case 'P' :
68316847 /* Parsed earlier */
68326848 break ;
68336849 case 'n' :
@@ -6909,6 +6925,9 @@ int main(int argc, char **argv)
69096925 if (no_msr )
69106926 bic_disable_msr_access ();
69116927
6928+ if (no_perf )
6929+ bic_disable_perf_access ();
6930+
69126931 if (!quiet ) {
69136932 print_version ();
69146933 print_bootcmd ();
0 commit comments