[PATCH v1 08/13] perf/x86/core: add idle hooks

From: Stephane Eranian
Date: Thu Sep 09 2021 - 03:59:14 EST


This patch adds the perf idle hooks x86 idle routines.

Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
---
arch/x86/include/asm/mwait.h | 6 +++++-
kernel/sched/idle.c | 12 ++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 29dd27b5a339..92080fdc1d2a 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -4,6 +4,7 @@

#include <linux/sched.h>
#include <linux/sched/idle.h>
+#include <linux/perf_event.h>

#include <asm/cpufeature.h>
#include <asm/nospec-branch.h>
@@ -114,8 +115,11 @@ static inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
}

__monitor((void *)&current_thread_info()->flags, 0, 0);
- if (!need_resched())
+ if (!need_resched()) {
+ perf_lopwr_cb(true);
__mwait(eax, ecx);
+ perf_lopwr_cb(false);
+ }
}
current_clr_polling();
}
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 14ce130aee1b..c0ddc3c32a33 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -179,7 +179,6 @@ static void cpuidle_idle_call(void)
*/
if (need_resched()) {
local_irq_enable();
- perf_lopwr_cb(false);
return;
}

@@ -230,6 +229,9 @@ static void cpuidle_idle_call(void)
tick_nohz_idle_stop_tick();

next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns);
+ if (!cpu_idle_force_poll)
+ perf_lopwr_cb(true);
+
call_cpuidle(drv, dev, next_state);
} else {
bool stop_tick = true;
@@ -244,12 +246,17 @@ static void cpuidle_idle_call(void)
else
tick_nohz_idle_retain_tick();

+ if (!cpu_idle_force_poll)
+ perf_lopwr_cb(true);
+
entered_state = call_cpuidle(drv, dev, next_state);
/*
* Give the governor an opportunity to reflect on the outcome
*/
cpuidle_reflect(dev, entered_state);
}
+ if (!cpu_idle_force_poll)
+ perf_lopwr_cb(false);

exit_idle:
__current_set_polling();
@@ -259,7 +266,6 @@ static void cpuidle_idle_call(void)
*/
if (WARN_ON_ONCE(irqs_disabled())) {
local_irq_enable();
- perf_lopwr_cb(false);
}
}

@@ -293,8 +299,6 @@ static void do_idle(void)
while (!need_resched()) {
rmb();

- perf_lopwr_cb(true);
-
local_irq_disable();

if (cpu_is_offline(cpu)) {
--
2.33.0.153.gba50c8fa24-goog