Commit a0e86c90 authored by Patryk Wlazlyn's avatar Patryk Wlazlyn Committed by Len Brown

tools/power turbostat: Add --no-perf option

Add the --no-perf option to allow users to run turbostat without
accessing perf.
Signed-off-by: default avatarPatryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Reviewed-by: default avatarLen Brown <len.brown@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 3e404846
...@@ -69,6 +69,8 @@ The column name "all" can be used to enable all disabled-by-default built-in cou ...@@ -69,6 +69,8 @@ The column name "all" can be used to enable all disabled-by-default built-in cou
.PP .PP
+\fB--no-msr\fP Disable all the uses of the MSR driver. +\fB--no-msr\fP Disable all the uses of the MSR driver.
+.PP +.PP
+\fB--no-perf\fP Disable all the uses of the perf API.
+.PP
\fB--interval seconds\fP overrides the default 5.0 second measurement interval. \fB--interval seconds\fP overrides the default 5.0 second measurement interval.
.PP .PP
\fB--num_iterations num\fP number of the measurement iterations. \fB--num_iterations num\fP number of the measurement iterations.
......
...@@ -267,6 +267,7 @@ unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ ...@@ -267,6 +267,7 @@ unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */
unsigned int first_counter_read = 1; unsigned int first_counter_read = 1;
int ignore_stdin; int ignore_stdin;
bool no_msr; bool no_msr;
bool no_perf;
int get_msr(int cpu, off_t offset, unsigned long long *msr); int get_msr(int cpu, off_t offset, unsigned long long *msr);
...@@ -1314,8 +1315,17 @@ static void bic_disable_msr_access(void) ...@@ -1314,8 +1315,17 @@ static void bic_disable_msr_access(void)
bic_enabled &= ~bic_msrs; bic_enabled &= ~bic_msrs;
} }
static void bic_disable_perf_access(void)
{
const unsigned long bic_perf = BIC_IPC;
bic_enabled &= ~bic_perf;
}
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags) static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
{ {
assert(!no_perf);
return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags); return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
} }
...@@ -1332,8 +1342,8 @@ static int perf_instr_count_open(int cpu_num) ...@@ -1332,8 +1342,8 @@ static int perf_instr_count_open(int cpu_num)
/* counter for cpu_num, including user + kernel and all processes */ /* counter for cpu_num, including user + kernel and all processes */
fd = perf_event_open(&pea, -1, cpu_num, -1, 0); fd = perf_event_open(&pea, -1, cpu_num, -1, 0);
if (fd == -1) { if (fd == -1) {
warnx("capget(CAP_PERFMON) failed, try \"# setcap cap_sys_admin=ep %s\"", progname); warnx("capget(CAP_PERFMON) failed, try \"# setcap cap_sys_admin=ep %s\" or use --no-perf", progname);
BIC_NOT_PRESENT(BIC_IPC); bic_disable_perf_access();
} }
return fd; return fd;
...@@ -1399,6 +1409,7 @@ void help(void) ...@@ -1399,6 +1409,7 @@ void help(void)
" -J, --Joules displays energy in Joules instead of Watts\n" " -J, --Joules displays energy in Joules instead of Watts\n"
" -l, --list list column headers only\n" " -l, --list list column headers only\n"
" -M, --no-msr Disable all uses of the MSR driver\n" " -M, --no-msr Disable all uses of the MSR driver\n"
" -P, --no-perf Disable all uses of the perf API\n"
" -n, --num_iterations num\n" " -n, --num_iterations num\n"
" number of the measurement iterations\n" " number of the measurement iterations\n"
" -N, --header_iterations num\n" " -N, --header_iterations num\n"
...@@ -6745,6 +6756,7 @@ void cmdline(int argc, char **argv) ...@@ -6745,6 +6756,7 @@ void cmdline(int argc, char **argv)
{ "out", required_argument, 0, 'o' }, { "out", required_argument, 0, 'o' },
{ "quiet", no_argument, 0, 'q' }, { "quiet", no_argument, 0, 'q' },
{ "no-msr", no_argument, 0, 'M' }, { "no-msr", no_argument, 0, 'M' },
{ "no-perf", no_argument, 0, 'P' },
{ "show", required_argument, 0, 's' }, { "show", required_argument, 0, 's' },
{ "Summary", no_argument, 0, 'S' }, { "Summary", no_argument, 0, 'S' },
{ "TCC", required_argument, 0, 'T' }, { "TCC", required_argument, 0, 'T' },
...@@ -6758,11 +6770,14 @@ void cmdline(int argc, char **argv) ...@@ -6758,11 +6770,14 @@ void cmdline(int argc, char **argv)
* Parse some options early, because they may make other options invalid, * Parse some options early, because they may make other options invalid,
* like adding the MSR counter with --add and at the same time using --no-msr. * like adding the MSR counter with --add and at the same time using --no-msr.
*/ */
while ((opt = getopt_long_only(argc, argv, "M", long_options, &option_index)) != -1) { while ((opt = getopt_long_only(argc, argv, "MP", long_options, &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'M': case 'M':
no_msr = 1; no_msr = 1;
break; break;
case 'P':
no_perf = 1;
break;
default: default:
break; break;
} }
...@@ -6828,6 +6843,7 @@ void cmdline(int argc, char **argv) ...@@ -6828,6 +6843,7 @@ void cmdline(int argc, char **argv)
quiet = 1; quiet = 1;
break; break;
case 'M': case 'M':
case 'P':
/* Parsed earlier */ /* Parsed earlier */
break; break;
case 'n': case 'n':
...@@ -6909,6 +6925,9 @@ int main(int argc, char **argv) ...@@ -6909,6 +6925,9 @@ int main(int argc, char **argv)
if (no_msr) if (no_msr)
bic_disable_msr_access(); bic_disable_msr_access();
if (no_perf)
bic_disable_perf_access();
if (!quiet) { if (!quiet) {
print_version(); print_version();
print_bootcmd(); print_bootcmd();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment