linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Subhra Mazumdar <subhra.mazumdar@oracle.com>
Cc: Steven Sistare <steven.sistare@oracle.com>,
	linux-kernel@vger.kernel.org, mingo@redhat.com,
	dhaval.giani@oracle.com
Subject: Re: [RESEND RFC PATCH V3] sched: Improve scalability of select_idle_sibling using SMT balance
Date: Mon, 5 Feb 2018 13:19:47 +0100	[thread overview]
Message-ID: <20180205121947.GW2269@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <93db4b69-5ec6-732f-558e-5e64d9ba0cf9@oracle.com>

On Fri, Feb 02, 2018 at 09:37:02AM -0800, Subhra Mazumdar wrote:
> In the scheme of SMT balance, if the idle cpu search is done _not_ in the
> last run core, then we need a random cpu to start from. If the idle cpu
> search is done in the last run core we can start the search from last run
> cpu. Since we need the random index for the first case I just did it for
> both.

That shouldn't be too hard to fix. I think we can simply transpose the
CPU number. That is, something like:

  cpu' = core'_id + (cpu - core_id)

should work for most sane cases. We don't give any guarantees this will
in fact work, but (almost) all actual CPU enumeration schemes I've seen
this should work for.

And if it doesn't work, we're not worse of than we are now.

I just couldn't readily find a place where we need to do this for cores
with the current code. But I think we have one place between LLCs where
it can be done:

---
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7b6535987500..eb8b8d0a026c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6109,7 +6109,7 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t
 	if (!static_branch_likely(&sched_smt_present))
 		return -1;
 
-	for_each_cpu(cpu, cpu_smt_mask(target)) {
+	for_each_cpu_wrap(cpu, cpu_smt_mask(target), target) {
 		if (!cpumask_test_cpu(cpu, &p->cpus_allowed))
 			continue;
 		if (idle_cpu(cpu))
@@ -6357,8 +6357,17 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
 		if (cpu == prev_cpu)
 			goto pick_cpu;
 
-		if (wake_affine(affine_sd, p, prev_cpu, sync))
-			new_cpu = cpu;
+		if (wake_affine(affine_sd, p, prev_cpu, sync)) {
+			/*
+			 * Transpose prev_cpu's offset into this cpu's
+			 * LLC domain to retain the 'random' search offset
+			 * for for_each_cpu_wrap().
+			 */
+			new_cpu = per_cpu(sd_llc_id, cpu) +
+				  (prev_cpu - per_cpu(sd_llc_id, prev_cpu));
+			if (unlikely(!cpus_share_cache(new_cpu, cpu)))
+				new_cpu = cpu;
+		}
 	}
 
 	if (sd && !(sd_flag & SD_BALANCE_FORK)) {

  reply	other threads:[~2018-02-05 12:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 23:31 [RESEND RFC PATCH V3] sched: Improve scalability of select_idle_sibling using SMT balance subhra mazumdar
2018-02-01 12:33 ` Peter Zijlstra
2018-02-01 13:33   ` Peter Zijlstra
2018-02-02 16:53   ` Steven Sistare
2018-02-02 17:17     ` Peter Zijlstra
2018-02-02 17:36       ` Steven Sistare
2018-02-02 19:58         ` Peter Zijlstra
2018-02-02 20:51           ` Steven Sistare
2018-02-02 17:37       ` Subhra Mazumdar
2018-02-05 12:19         ` Peter Zijlstra [this message]
2018-02-05 22:09           ` Subhra Mazumdar
2018-02-06  9:12             ` Peter Zijlstra
2018-02-07  0:30               ` Subhra Mazumdar
2018-02-07  8:42                 ` Peter Zijlstra
2018-02-07 23:10                   ` Subhra Mazumdar
2018-02-02 17:21     ` Peter Zijlstra
2018-02-02 17:39       ` Steven Sistare
2018-02-02 18:34         ` Steven Sistare
2018-02-02 20:04           ` Peter Zijlstra
2018-02-02 21:17             ` Steven Sistare
2018-02-03  3:47           ` Mike Galbraith
2018-02-02 19:59     ` Peter Zijlstra
2018-02-02 21:06       ` Steven Sistare
2018-02-05 12:48         ` Peter Zijlstra
2018-02-05 13:54           ` Mike Galbraith
2018-02-05 17:03           ` Peter Zijlstra
2018-02-05 22:32             ` Subhra Mazumdar

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=20180205121947.GW2269@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dhaval.giani@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=steven.sistare@oracle.com \
    --cc=subhra.mazumdar@oracle.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;
as well as URLs for NNTP newsgroup(s).