]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/power turbostat: Add idle governor statistics reporting
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Sat, 8 Feb 2025 11:53:19 +0000 (13:53 +0200)
committerLen Brown <len.brown@intel.com>
Thu, 20 Feb 2025 06:03:34 +0000 (01:03 -0500)
The idle governor provides the following per-idle state sysfs files:
  * above - Indicates overshoots, where a more shallow state should have
            been requested (if avaliale and enabled).
  * below - Indicates undershoots, where a deeper state should have been
            requested (if available and enabled).

These files offer valuable insights into how effectively the Linux kernel
idle governor selects idle states for a given workload. This commit adds
support for these files in turbostat.

Expose the contents of these files with the following naming convention:
* C1: The number of times the C1 state was requested (existing counter).
* C1+: The number of times the idle governor selected C1, but a deeper
  idle state should have been selected instead.
* C1-: The number of times the idle governor selected C1, but a shallower
  idle state should have been selected instead.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
tools/power/x86/turbostat/turbostat.8
tools/power/x86/turbostat/turbostat.c

index ed258f24815239ef586e03cd77826c78263c35f8..52d727e29ea72f383052557f87b0255f7584c146 100644 (file)
@@ -160,6 +160,10 @@ The system configuration dump (if --quiet is not used) is followed by statistics
 .PP
 \fBC1, C2, C3...\fP The number times Linux requested the C1, C2, C3 idle state during the measurement interval.  The system summary line shows the sum for all CPUs.  These are C-state names as exported in /sys/devices/system/cpu/cpu*/cpuidle/state*/name.  While their names are generic, their attributes are processor specific. They the system description section of output shows what MWAIT sub-states they are mapped to on each system.
 .PP
+\fBC1+, C2+, C3+...\fP The idle governor idle state misprediction statistics. Inidcates the number times Linux requested the C1, C2, C3 idle state during the measurement interval, but should have requested a deeper idle state (if it exists and enabled). These statistics come from the /sys/devices/system/cpu/cpu*/cpuidle/state*/below file.
+.PP
+\fBC1-, C2-, C3-...\fP The idle governor idle state misprediction statistics. Inidcates the number times Linux requested the C1, C2, C3 idle state during the measurement interval, but should have requested a shallower idle state (if it exists and enabled). These statistics come from the /sys/devices/system/cpu/cpu*/cpuidle/state*/above file.
+.PP
 \fBC1%, C2%, C3%\fP The residency percentage that Linux requested C1, C2, C3....  The system summary is the average of all CPUs in the system.  Note that these are software, reflecting what was requested.  The hardware counters reflect what was actually achieved.
 .PP
 \fBCPU%c1, CPU%c3, CPU%c6, CPU%c7\fP show the percentage residency in hardware core idle states.  These numbers are from hardware residency counters.
index d3af2bf307e17dc76e33fcbd84e396fd30491953..f29e47fe424948414379badd51925e6ff8d8357b 100644 (file)
@@ -10265,6 +10265,7 @@ void probe_sysfs(void)
        char name_buf[16];
        FILE *input;
        int state;
+       int min_state = 1024, max_state = 0;
        char *sp;
 
        for (state = 10; state >= 0; --state) {
@@ -10296,6 +10297,11 @@ void probe_sysfs(void)
                        continue;
 
                add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, FORMAT_PERCENT, SYSFS_PERCPU, 0);
+
+               if (state > max_state)
+                       max_state = state;
+               if (state < min_state)
+                       min_state = state;
        }
 
        for (state = 10; state >= 0; --state) {
@@ -10306,26 +10312,52 @@ void probe_sysfs(void)
                        continue;
                if (!fgets(name_buf, sizeof(name_buf), input))
                        err(1, "%s: failed to read file", path);
-               /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */
-               sp = strchr(name_buf, '-');
-               if (!sp)
-                       sp = strchrnul(name_buf, '\n');
-               *sp = '\0';
                fclose(input);
 
                remove_underbar(name_buf);
 
-               sprintf(path, "cpuidle/state%d/usage", state);
-
                if (!DO_BIC(BIC_sysfs) && !is_deferred_add(name_buf))
                        continue;
 
                if (is_deferred_skip(name_buf))
                        continue;
 
+               /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */
+               sp = strchr(name_buf, '-');
+               if (!sp)
+                       sp = strchrnul(name_buf, '\n');
+
+               /*
+                * The 'below' sysfs file always contains 0 for the deepest state (largest index),
+                * do not add it.
+                */
+               if (state != max_state) {
+                       /*
+                        * Add 'C1+' for C1, and so on. The 'below' sysfs file always contains 0 for
+                        * the last state, so do not add it.
+                        */
+
+                       *sp = '+';
+                       *(sp + 1) = '\0';
+                       sprintf(path, "cpuidle/state%d/below", state);
+                       add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
+               }
+
+               *sp = '\0';
+               sprintf(path, "cpuidle/state%d/usage", state);
                add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
-       }
 
+               /*
+                * The 'above' sysfs file always contains 0 for the shallowest state (smallest
+                * index), do not add it.
+                */
+               if (state != min_state) {
+                       *sp = '-';
+                       *(sp + 1) = '\0';
+                       sprintf(path, "cpuidle/state%d/above", state);
+                       add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, FORMAT_DELTA, SYSFS_PERCPU, 0);
+               }
+       }
 }
 
 /*