The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Madadi Vineeth Reddy <vineethr@linux.ibm.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <sh@gentwo.org>
Subject: Re: [PATCH] sched/fair: Let sync wakeups target the waker's core
Date: Tue, 4 Aug 2026 10:19:13 +0530	[thread overview]
Message-ID: <492e6bb3-504d-486a-ad9d-226e9d7235a3@amd.com> (raw)
In-Reply-To: <20260801035532.260625-1-vineethr@linux.ibm.com>

Hello Vineeth,

On 8/1/2026 9:25 AM, Madadi Vineeth Reddy wrote:
> -static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpus, int *idle_cpu)
> +static int select_idle_core(struct task_struct *p, int core, struct cpumask *cpus,
> +				int *idle_cpu, int sync_cpu)
>  {
>  	bool idle = true;
>  	int cpu;
>  
>  	for_each_cpu(cpu, cpu_smt_mask(core)) {
> -		if (!available_idle_cpu(cpu)) {
> +		bool sync_waker = (cpu == sync_cpu);
> +
> +		/*
> +		 * @sync_cpu, if set, is running a waker that is about to
> +		 * block with nothing else runnable behind it. Treat it as
> +		 * idle so this core stays an idle-core candidate: placing
> +		 * the wakee on a sibling keeps the cache sharing that
> +		 * stacking on the waker's rq would get, without serialising
> +		 * the wakee behind the waker's remaining work.
> +		 */
> +		if (!available_idle_cpu(cpu) && !sync_waker) {

If I'm not wrong, all you want to make is the sync_waker appear idle and
then see if you can then consider that core as idle core or not right?

Why can't this be done in select_idle_sibling() extending that early
check for (!has_idle_core && cpus_share_cache(prev, target)) condition
and then initializing "idle_cpu" in select_idle_cpu() accordingly?

Something along the lines of:

  (Only build tested)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index df8c9c2c7918..dd62bceb3838 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1301,7 +1301,6 @@ static bool update_deadline(struct cfs_rq *cfs_rq, struct sched_entity *se)
 
 #include "pelt.h"
 
-static int select_idle_sibling(struct task_struct *p, int prev_cpu, int cpu);
 static unsigned long task_h_load(struct task_struct *p);
 static unsigned long capacity_of(int cpu);
 
@@ -8661,10 +8660,11 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t
  * comparing the average scan cost (tracked in sd->avg_scan_cost) against the
  * average idle time for this rq (as found in rq->avg_idle).
  */
-static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool has_idle_core, int target)
+static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool has_idle_core,
+			   int target, int idle_cpu)
 {
 	struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
-	int i, cpu, idle_cpu = -1, nr = INT_MAX;
+	int i, cpu, nr = INT_MAX;
 
 	if (sched_feat(SIS_UTIL) && sd->shared) {
 		/*
@@ -8928,7 +8928,7 @@ static inline bool asym_fits_cpu(unsigned long util,
 /*
  * Try and locate an idle core/thread in the LLC cache domain.
  */
-static int select_idle_sibling(struct task_struct *p, int prev, int target)
+static int select_idle_sibling(struct task_struct *p, int prev, int target, int sync_cpu)
 {
 	bool has_idle_core = false;
 	struct sched_domain *sd;
@@ -9028,16 +9028,19 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
 		return target;
 
 	if (sched_smt_active()) {
+		int cpu = ((unsigned)sync_cpu < nr_cpumask_bits) ? sync_cpu : prev;
+
 		has_idle_core = test_idle_cores(target);
 
-		if (!has_idle_core && cpus_share_cache(prev, target)) {
-			i = select_idle_smt(p, sd, prev);
-			if ((unsigned int)i < nr_cpumask_bits)
+		if (sync_cpu == target || (!has_idle_core && cpus_share_cache(prev, target))) {
+			i = select_idle_smt(p, sd, cpu);
+
+			if (!has_idle_core && ((unsigned int)i < nr_cpumask_bits))
 				return i;
 		}
 	}
 
-	i = select_idle_cpu(p, sd, has_idle_core, target);
+	i = select_idle_cpu(p, sd, has_idle_core, target, i);
 	if ((unsigned)i < nr_cpumask_bits)
 		return i;
 
@@ -9733,8 +9736,18 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
 		return sched_balance_find_dst_cpu(sd, p, cpu, prev_cpu, sd_flag);
 
 	/* Fast path */
-	if (wake_flags & WF_TTWU)
-		return select_idle_sibling(p, prev_cpu, new_cpu);
+	if (wake_flags & WF_TTWU) {
+		int sync_cpu = -1;
+
+		if (want_affine && sync && new_cpu == cpu) {
+			struct rq *rq = cpu_rq(cpu);
+
+			if ((rq->nr_running - cfs_h_nr_delayed(rq)) == 1)
+				sync_cpu = cpu;
+		}
+
+		return select_idle_sibling(p, prev_cpu, new_cpu, sync_cpu);
+	}
 
 	return new_cpu;
 }
---

You can probably infer sync hint by checking
"target == smp_preocessor_id()" too in select_idle_sibling() instead of
passing it on.

>  			idle = false;
>  			if (*idle_cpu == -1) {
>  				if (choose_sched_idle_rq(cpu_rq(cpu), p) &&
-- 
Thanks and Regards,
Prateek


  parent reply	other threads:[~2026-08-04  4:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01  3:55 [PATCH] sched/fair: Let sync wakeups target the waker's core Madadi Vineeth Reddy
2026-08-01  6:43 ` Zhan Xusheng
2026-08-04  4:49 ` K Prateek Nayak [this message]
2026-08-04 12:13   ` Madadi Vineeth Reddy
2026-08-05  3:30     ` K Prateek Nayak
2026-08-06  4:50       ` Madadi Vineeth Reddy
2026-08-06 14:22         ` Chen Yu
2026-08-06 13:03 ` Kayra Cizmeci

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=492e6bb3-504d-486a-ad9d-226e9d7235a3@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sh@gentwo.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vineethr@linux.ibm.com \
    --cc=vschneid@redhat.com \
    /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