Skip to content

Commit 6ab4b19

Browse files
mrkajetanprafaeljw
authored andcommitted
cpuidle: Add cpu_idle_miss trace event
Add a trace event for cpuidle to track missed (too deep or too shallow) wakeups. After each wakeup, CPUIdle already computes whether the entered state was optimal, above or below the desired one and updates the relevant counters. This patch makes it possible to trace those events in addition to just reading the counters. The patterns of types and percentages of misses across different workloads appear to be very consistent. This makes the trace event very useful for comparing the relative correctness of different CPUIdle governors for different types of workloads, or for finding the optimal governor for a given device. Signed-off-by: Kajetan Puchalski <[email protected]> Reviewed-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent a771ea6 commit 6ab4b19

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

drivers/cpuidle/cpuidle.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* This code is licenced under the GPL.
99
*/
1010

11+
#include "linux/percpu-defs.h"
1112
#include <linux/clockchips.h>
1213
#include <linux/kernel.h>
1314
#include <linux/mutex.h>
@@ -278,6 +279,7 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
278279

279280
/* Shallower states are enabled, so update. */
280281
dev->states_usage[entered_state].above++;
282+
trace_cpu_idle_miss(dev->cpu, entered_state, false);
281283
break;
282284
}
283285
} else if (diff > delay) {
@@ -289,8 +291,10 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
289291
* Update if a deeper state would have been a
290292
* better match for the observed idle duration.
291293
*/
292-
if (diff - delay >= drv->states[i].target_residency_ns)
294+
if (diff - delay >= drv->states[i].target_residency_ns) {
293295
dev->states_usage[entered_state].below++;
296+
trace_cpu_idle_miss(dev->cpu, entered_state, true);
297+
}
294298

295299
break;
296300
}

include/trace/events/power.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ DEFINE_EVENT(cpu, cpu_idle,
4040
TP_ARGS(state, cpu_id)
4141
);
4242

43+
TRACE_EVENT(cpu_idle_miss,
44+
45+
TP_PROTO(unsigned int cpu_id, unsigned int state, bool below),
46+
47+
TP_ARGS(cpu_id, state, below),
48+
49+
TP_STRUCT__entry(
50+
__field(u32, cpu_id)
51+
__field(u32, state)
52+
__field(bool, below)
53+
),
54+
55+
TP_fast_assign(
56+
__entry->cpu_id = cpu_id;
57+
__entry->state = state;
58+
__entry->below = below;
59+
),
60+
61+
TP_printk("cpu_id=%lu state=%lu type=%s", (unsigned long)__entry->cpu_id,
62+
(unsigned long)__entry->state, (__entry->below)?"below":"above")
63+
);
64+
4365
TRACE_EVENT(powernv_throttle,
4466

4567
TP_PROTO(int chip_id, const char *reason, int pmax),

0 commit comments

Comments
 (0)