Skip to content

Commit 68769a0

Browse files
committed
tools/power turbostat: Enhance perf probe
check_perf_access() will now check both IPC and LLC perf counters if they are enabled. If any fail, it now disables perf and all perf counters. Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 19476a5 commit 68769a0

1 file changed

Lines changed: 44 additions & 10 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,13 @@ static void bic_disable_msr_access(void)
24382438
free_sys_msr_counters();
24392439
}
24402440

2441+
static void bic_disable_perf_access(void)
2442+
{
2443+
CLR_BIC(BIC_IPC, &bic_enabled);
2444+
CLR_BIC(BIC_LLC_RPS, &bic_enabled);
2445+
CLR_BIC(BIC_LLC_HIT, &bic_enabled);
2446+
}
2447+
24412448
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
24422449
{
24432450
assert(!no_perf);
@@ -8327,26 +8334,23 @@ void print_dev_latency(void)
83278334
close(fd);
83288335
}
83298336

8330-
static int has_instr_count_access(void)
8337+
static int has_perf_instr_count_access(void)
83318338
{
83328339
int fd;
8333-
int has_access;
83348340

83358341
if (no_perf)
83368342
return 0;
83378343

83388344
fd = open_perf_counter(base_cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0);
8339-
has_access = fd != -1;
8340-
83418345
if (fd != -1)
83428346
close(fd);
83438347

8344-
if (!has_access)
8348+
if (fd == -1)
83458349
warnx("Failed to access %s. Some of the counters may not be available\n"
8346-
"\tRun as root to enable them or use %s to disable the access explicitly",
8347-
"instructions retired perf counter", "--no-perf");
8350+
"\tRun as root to enable them or use %s to disable the access explicitly", "perf instructions retired counter",
8351+
"'--hide IPC' or '--no-perf'");
83488352

8349-
return has_access;
8353+
return (fd != -1);
83508354
}
83518355

83528356
int add_rapl_perf_counter(int cpu, struct rapl_counter_info_t *rci, const struct rapl_counter_arch_info *cai,
@@ -9080,6 +9084,28 @@ void probe_pm_features(void)
90809084
decode_misc_feature_control();
90819085
}
90829086

9087+
/* perf_llc_probe
9088+
*
9089+
* return 1 on success, else 0
9090+
*/
9091+
int has_perf_llc_access(void)
9092+
{
9093+
int fd;
9094+
9095+
if (no_perf)
9096+
return 0;
9097+
9098+
fd = open_perf_counter(base_cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES, -1, PERF_FORMAT_GROUP);
9099+
if (fd != -1)
9100+
close(fd);
9101+
9102+
if (fd == -1)
9103+
warnx("Failed to access %s. Some of the counters may not be available\n"
9104+
"\tRun as root to enable them or use %s to disable the access explicitly", "perf LLC counters", "'--hide LLC' or '--no-perf'");
9105+
9106+
return (fd != -1);
9107+
}
9108+
90839109
void perf_llc_init(void)
90849110
{
90859111
int cpu;
@@ -9535,8 +9561,16 @@ void check_msr_access(void)
95359561

95369562
void check_perf_access(void)
95379563
{
9538-
if (no_perf || !BIC_IS_ENABLED(BIC_IPC) || !has_instr_count_access())
9539-
CLR_BIC(BIC_IPC, &bic_enabled);
9564+
if (BIC_IS_ENABLED(BIC_IPC))
9565+
if (!has_perf_instr_count_access())
9566+
no_perf = 1;
9567+
9568+
if (BIC_IS_ENABLED(BIC_LLC_RPS) || BIC_IS_ENABLED(BIC_LLC_HIT))
9569+
if (!has_perf_llc_access())
9570+
no_perf = 1;
9571+
9572+
if (no_perf)
9573+
bic_disable_perf_access();
95409574
}
95419575

95429576
bool perf_has_hybrid_devices(void)

0 commit comments

Comments
 (0)