From: Ulf Hansson <ulf.hansson@linaro.org>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Mark Rutland <mark.rutland@arm.com>,
Marc Zyngier <maz@kernel.org>,
Maulik Shah <quic_mkshah@quicinc.com>,
Sudeep Holla <sudeep.holla@arm.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Ben Horgan <ben.horgan@arm.com>,
linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Ulf Hansson <ulf.hansson@linaro.org>
Subject: [PATCH v3 1/2] smp: Introduce a helper function to check for pending IPIs
Date: Fri, 31 Oct 2025 12:00:57 +0100 [thread overview]
Message-ID: <20251031110106.62394-2-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20251031110106.62394-1-ulf.hansson@linaro.org>
When governors used during cpuidle try to find the most optimal idle state
for a CPU or a group of CPUs, they are known to quite often fail. One
reason for this is, that they are not taking into account whether there has
been an IPI scheduled for any of the CPUs that are affected by the selected
idle state.
To enable pending IPIs to be taken into account for cpuidle decisions,
introduce a new helper function, cpus_peek_for_pending_ipi().
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- Renamed the helper function and updated its description.
- Updated the commit message.
Changes in v2:
- Implemented a common function, rather than making it arch-specific. As
suggested by Thomas and Marc.
- Renamed the function to indicate that it doesn't provide correctness.
- Clarified function description and commit message.
---
include/linux/smp.h | 5 +++++
kernel/smp.c | 24 ++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/linux/smp.h b/include/linux/smp.h
index 18e9c918325e..91d0ecf3b8d3 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -168,6 +168,7 @@ int smp_call_function_any(const struct cpumask *mask,
void kick_all_cpus_sync(void);
void wake_up_all_idle_cpus(void);
+bool cpus_peek_for_pending_ipi(const struct cpumask *mask);
/*
* Generic and arch helpers
@@ -216,6 +217,10 @@ smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
static inline void kick_all_cpus_sync(void) { }
static inline void wake_up_all_idle_cpus(void) { }
+static inline bool cpus_peek_for_pending_ipi(const struct cpumask *mask)
+{
+ return false;
+}
#define setup_max_cpus 0
diff --git a/kernel/smp.c b/kernel/smp.c
index 02f52291fae4..4533e666152c 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -1087,6 +1087,30 @@ void wake_up_all_idle_cpus(void)
}
EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus);
+/**
+ * cpus_peek_for_pending_ipi - Check for pending IPI for CPUs
+ * @mask: The CPU mask for the CPUs to check.
+ *
+ * This function walks through the @mask to check if there are any pending IPIs
+ * scheduled, for any of the CPUs in the @mask.
+ *
+ * It's important for the caller to know that this function does not guarantee
+ * correctness. It provides a snapshot, while being as lightweight as possible.
+ *
+ * Returns true if there is a pending IPI scheduled and false otherwise.
+ */
+bool cpus_peek_for_pending_ipi(const struct cpumask *mask)
+{
+ unsigned int cpu;
+
+ for_each_cpu(cpu, mask) {
+ if (!llist_empty(per_cpu_ptr(&call_single_queue, cpu)))
+ return true;
+ }
+
+ return false;
+}
+
/**
* struct smp_call_on_cpu_struct - Call a function on a specific CPU
* @work: &work_struct
--
2.43.0
next prev parent reply other threads:[~2025-10-31 11:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 11:00 [PATCH v3 0/2] pmdomain: Improve idle state selection for CPUs Ulf Hansson
2025-10-31 11:00 ` Ulf Hansson [this message]
2025-11-01 19:59 ` [PATCH v3 1/2] smp: Introduce a helper function to check for pending IPIs Thomas Gleixner
2025-10-31 11:00 ` [PATCH v3 2/2] pmdomain: Extend the genpd governor for CPUs to account for IPIs Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251031110106.62394-2-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=ben.horgan@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=quic_mkshah@quicinc.com \
--cc=rafael@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®