Commit 0e39702f authored by Patryk Wlazlyn's avatar Patryk Wlazlyn Committed by Len Brown

tools/power turbostat: Enable non-privileged users to read sysfs counters

A group of counters called "sysfs" displays software
C-state request counts and resulting perceived C-state residency.

They are not built-in counters that turbostat knows about ahead of time,
rather they are discovered in sysfs when turbostat starts.

Thus, they are added dynamically, using the same interface
as user-added MSR counters.

When turbostat enters "no-msr" mode, such as when running as a
non-privileged user, it clears all added counters.

Updating that to clear only actual MSR added counters
allows regular users to see the sysfs counters.

[lenb: commit message]
Signed-off-by: default avatarPatryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent d3e6f625
...@@ -1377,36 +1377,42 @@ struct sys_counters { ...@@ -1377,36 +1377,42 @@ struct sys_counters {
struct msr_counter *pp; struct msr_counter *pp;
} sys; } sys;
void free_sys_counters(void) static size_t free_msr_counters_(struct msr_counter **pp)
{ {
struct msr_counter *p = sys.tp, *pnext = NULL; struct msr_counter *p = NULL;
size_t num_freed = 0;
while (p) { while (*pp) {
pnext = p->next; p = *pp;
free(p);
p = pnext;
}
p = sys.cp, pnext = NULL; if (p->msr_num != 0) {
while (p) { *pp = p->next;
pnext = p->next;
free(p);
p = pnext;
}
p = sys.pp, pnext = NULL; free(p);
while (p) { ++num_freed;
pnext = p->next;
free(p); continue;
p = pnext; }
pp = &p->next;
} }
sys.added_thread_counters = 0; return num_freed;
sys.added_core_counters = 0; }
sys.added_package_counters = 0;
sys.tp = NULL; /*
sys.cp = NULL; * Free all added counters accessed via msr.
sys.pp = NULL; */
static void free_sys_msr_counters(void)
{
/* Thread counters */
sys.added_thread_counters -= free_msr_counters_(&sys.tp);
/* Core counters */
sys.added_core_counters -= free_msr_counters_(&sys.cp);
/* Package counters */
sys.added_package_counters -= free_msr_counters_(&sys.pp);
} }
struct system_summary { struct system_summary {
...@@ -1566,7 +1572,7 @@ static void bic_disable_msr_access(void) ...@@ -1566,7 +1572,7 @@ static void bic_disable_msr_access(void)
bic_enabled &= ~bic_msrs; bic_enabled &= ~bic_msrs;
free_sys_counters(); free_sys_msr_counters();
} }
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)
......
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