When governors used during cpuidle, tries to find the most optimal
idlestate for a CPU or a group of CPUs, they are known to quite often fail.
One reason for this, is that we are not taking into account whether there
has been an IPI scheduled for any of the CPUs that are affected by the
selected idlestate.
To enable pending IPIs to be taken into account for cpuidle decisions,
let's introduce a new helper function, cpus_may_have_pending_ipi().
Note that, the implementation is intentionally as lightweight as possible,
in favor of always providing the correct information. For cpuidle decisions
this is good enough.
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
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..093e5458493e 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_may_have_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_may_have_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..775f90790935 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_may_have_pending_ipi - Check for pending IPIs 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, as the intent is to be as lightweight as possible.
+ *
+ * Returns true if there is a pending IPI scheduled and false otherwise.
+ */
+bool cpus_may_have_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
On Mon, Oct 20 2025 at 16:17, Ulf Hansson wrote:
> When governors used during cpuidle, tries to find the most optimal
When governors used during cpuidle trie to ...
Both plural and no comma.
> idlestate for a CPU or a group of CPUs, they are known to quite often fail.
idle state
> One reason for this, is that we are not taking into account whether there
...for this is, that they are not taking into account
> has been an IPI scheduled for any of the CPUs that are affected by the
> selected idlestate.
>
> To enable pending IPIs to be taken into account for cpuidle decisions,
> let's introduce a new helper function, cpus_may_have_pending_ipi().
s/let's//
> Note that, the implementation is intentionally as lightweight as possible,
> in favor of always providing the correct information.
That sentence doesn't make sense. It's a snapshot and therefore can't
provide the correct information.
> For cpuidle decisions this is good enough.
Thanks,
tglx
Hi Ulf, Only a comment on the naming rather than a full review. On 10/20/25 15:17, Ulf Hansson wrote: > When governors used during cpuidle, tries to find the most optimal > idlestate for a CPU or a group of CPUs, they are known to quite often fail. > One reason for this, is that we are not taking into account whether there > has been an IPI scheduled for any of the CPUs that are affected by the > selected idlestate. > > To enable pending IPIs to be taken into account for cpuidle decisions, > let's introduce a new helper function, cpus_may_have_pending_ipi(). To me, "may" indicates permission, i.e. is allowed, rather than correctness. Would "likely" be better here, cpus_likely_have_pending_ipi()? > > Note that, the implementation is intentionally as lightweight as possible, > in favor of always providing the correct information. For cpuidle decisions > this is good enough. > > Suggested-by: Thomas Gleixner <tglx@linutronix.de> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> > --- > > 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. > -- Thanks, Ben
On Mon, 20 Oct 2025 at 21:11, Ben Horgan <ben.horgan@arm.com> wrote: > > Hi Ulf, > > Only a comment on the naming rather than a full review. > > On 10/20/25 15:17, Ulf Hansson wrote: > > When governors used during cpuidle, tries to find the most optimal > > idlestate for a CPU or a group of CPUs, they are known to quite often fail. > > One reason for this, is that we are not taking into account whether there > > has been an IPI scheduled for any of the CPUs that are affected by the > > selected idlestate. > > > > To enable pending IPIs to be taken into account for cpuidle decisions, > > let's introduce a new helper function, cpus_may_have_pending_ipi(). > > To me, "may" indicates permission, i.e. is allowed, rather than > correctness. Would "likely" be better here, cpus_likely_have_pending_ipi()? Sure, that sounds better to me too. I leave it a few days to allow people to provide their additional input, before posting a new version with the new name of the function. > > > > > Note that, the implementation is intentionally as lightweight as possible, > > in favor of always providing the correct information. For cpuidle decisions > > this is good enough. > > > > Suggested-by: Thomas Gleixner <tglx@linutronix.de> > > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> > > --- > > > > 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. > > > -- > Thanks, > > Ben > Kind regards Uffe
On Tue, Oct 21 2025 at 12:08, Ulf Hansson wrote: > On Mon, 20 Oct 2025 at 21:11, Ben Horgan <ben.horgan@arm.com> wrote: >> >> Hi Ulf, >> >> Only a comment on the naming rather than a full review. >> >> On 10/20/25 15:17, Ulf Hansson wrote: >> > When governors used during cpuidle, tries to find the most optimal >> > idlestate for a CPU or a group of CPUs, they are known to quite often fail. >> > One reason for this, is that we are not taking into account whether there >> > has been an IPI scheduled for any of the CPUs that are affected by the >> > selected idlestate. >> > >> > To enable pending IPIs to be taken into account for cpuidle decisions, >> > let's introduce a new helper function, cpus_may_have_pending_ipi(). >> >> To me, "may" indicates permission, i.e. is allowed, rather than >> correctness. Would "likely" be better here, cpus_likely_have_pending_ipi()? > > Sure, that sounds better to me too. cpus_peek_for_pending_ipis() perhaps?
© 2016 - 2025 Red Hat, Inc.