All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florent Carli <fcarli@gmail.com>
To: stable@vger.kernel.org
Cc: Juri Lelli <juri.lelli@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Gabriele Monaco <gmonaco@redhat.com>,
	linux-rt-users@vger.kernel.org
Subject: [PATCH 6.12.y 3/4] sched: Provide idle_rq() helper
Date: Fri, 20 Nov 2026 19:19:48 +0100	[thread overview]
Message-ID: <20261120181949.7528-4-fcarli@gmail.com> (raw)
In-Reply-To: <20261120181949.7528-1-fcarli@gmail.com>

From: Peter Zijlstra <peterz@infradead.org>

commit 1e0a2ba7afb1b60f02599093d84b72ce62ad11c0 upstream.

A fix for the dl_server 'requires' idle_cpu() usage, which made me
note that it and available_idle_cpu() are extern function calls.

And while idle_cpu() is used outside of kernel/sched/,
available_idle_cpu() is not.

This makes it hard to make idle_cpu() an inline helper, so provide
idle_rq() and implement idle_cpu() and available_idle_cpu() using
that.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
[ Florent: rq->ttwu_pending only exists with CONFIG_SMP in 6.12 ]
Signed-off-by: Florent Carli <fcarli@gmail.com>
---
 include/linux/sched.h   |  1 -
 kernel/sched/sched.h    | 28 ++++++++++++++++++++++++++++
 kernel/sched/syscalls.c | 32 +-------------------------------
 3 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7f0fb62df..efee6139c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1895,7 +1895,6 @@ static inline int task_nice(const struct task_struct *p)
 extern int can_nice(const struct task_struct *p, const int nice);
 extern int task_curr(const struct task_struct *p);
 extern int idle_cpu(int cpu);
-extern int available_idle_cpu(int cpu);
 extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
 extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
 extern void sched_set_fifo(struct task_struct *p);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 598dd26fe..27de92902 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1390,6 +1390,34 @@ static inline u32 sched_rng(void)
 #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
 #define raw_rq()		raw_cpu_ptr(&runqueues)
 
+static inline bool idle_rq(struct rq *rq)
+{
+	if (rq->curr != rq->idle || rq->nr_running)
+		return false;
+#ifdef CONFIG_SMP
+	if (rq->ttwu_pending)
+		return false;
+#endif
+	return true;
+}
+
+/**
+ * available_idle_cpu - is a given CPU idle for enqueuing work.
+ * @cpu: the CPU in question.
+ *
+ * Return: 1 if the CPU is currently idle. 0 otherwise.
+ */
+static inline bool available_idle_cpu(int cpu)
+{
+	if (!idle_rq(cpu_rq(cpu)))
+		return 0;
+
+	if (vcpu_is_preempted(cpu))
+		return 0;
+
+	return 1;
+}
+
 #ifdef CONFIG_SCHED_CORE
 static inline struct cpumask *sched_group_span(struct sched_group *sg);
 
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index b51b39a10..f31fcdcfe 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -201,37 +201,7 @@ int task_prio(const struct task_struct *p)
  */
 int idle_cpu(int cpu)
 {
-	struct rq *rq = cpu_rq(cpu);
-
-	if (rq->curr != rq->idle)
-		return 0;
-
-	if (rq->nr_running)
-		return 0;
-
-#ifdef CONFIG_SMP
-	if (rq->ttwu_pending)
-		return 0;
-#endif
-
-	return 1;
-}
-
-/**
- * available_idle_cpu - is a given CPU idle for enqueuing work.
- * @cpu: the CPU in question.
- *
- * Return: 1 if the CPU is currently idle. 0 otherwise.
- */
-int available_idle_cpu(int cpu)
-{
-	if (!idle_cpu(cpu))
-		return 0;
-
-	if (vcpu_is_preempted(cpu))
-		return 0;
-
-	return 1;
+	return idle_rq(cpu_rq(cpu));
 }
 
 /**
-- 
2.39.3 (Apple Git-146)


  parent reply	other threads:[~2026-11-20 18:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:09 [REGRESSION] 6.12.y, 6.18.y: fair server runs SCHED_OTHER ahead of SCHED_FIFO on an idle CPU (fixed in 6.19) Florent Carli
2026-11-20 17:09 ` Juri Lelli
2026-11-20 18:19   ` Florent Carli
2026-11-21 15:27     ` Sasha Levin
2026-11-20 18:19   ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Florent Carli
2026-11-20 18:19     ` [PATCH 6.12.y 1/4] sched/deadline: Fix dl_server time accounting Florent Carli
2026-11-20 18:19     ` [PATCH 6.12.y 2/4] sched/deadline: Fix dl_server stop condition Florent Carli
2026-11-20 18:19     ` Florent Carli [this message]
2026-11-20 18:19     ` [PATCH 6.12.y 4/4] sched/deadline: Fix server stopping with runnable tasks Florent Carli
2026-11-21 15:27     ` [PATCH 6.12.y 0/4] sched/deadline: dl_server fixes from 6.19 Sasha Levin

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=20261120181949.7528-4-fcarli@gmail.com \
    --to=fcarli@gmail.com \
    --cc=gmonaco@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.