From: Peter Zijlstra <peterz@infradead.org>
To: Ankit Jain <ankitja@vmware.com>
Cc: yury.norov@gmail.com, andriy.shevchenko@linux.intel.com,
linux@rasmusvillemoes.dk, qyousef@layalina.io, pjt@google.com,
joshdon@google.com, bristot@redhat.com, vschneid@redhat.com,
linux-kernel@vger.kernel.org, namit@vmware.com,
amakhalov@vmware.com, srinidhir@vmware.com,
vsirnapalli@vmware.com, vbrahmajosyula@vmware.com,
akaher@vmware.com, srivatsa@csail.mit.edu
Subject: Re: [PATCH RFC] cpumask: Randomly distribute the tasks within affinity mask
Date: Wed, 11 Oct 2023 15:52:38 +0200 [thread overview]
Message-ID: <20231011135238.GG6337@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231011114642.GA36521@noisy.programming.kicks-ass.net>
On Wed, Oct 11, 2023 at 01:46:42PM +0200, Peter Zijlstra wrote:
> Now, looking at the code, I don't think the current code actually
> behaves correct in this case :-(, somewhere along the line we should
> truncate cpu_valid_mask to a single bit. Let me see where the sane place
> is to do that.
Something like so I suppose, that limits newmask to the first
root_domain, which should be a superset of the cpuset if there is such a
thing.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 23f638d431d6..334c5bc59160 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3081,6 +3081,29 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag
return 0;
}
+static struct cpumask *root_domain_allowed(struct cpumask *newmask,
+ struct cpumask *scratch,
+ struct cpumask *valid)
+{
+ struct root_domain *rd;
+ struct cpumask *mask;
+ struct rq *rq;
+
+ int first = cpumask_first_and(newmask, valid);
+ if (first >= nr_cpu_ids)
+ return NULL;
+
+ mask = cpumask_of(first);
+ rd = cpu_rq(first)->rd;
+ if (rd)
+ mask = rd->span;
+
+ if (!cpumask_and(scratch, newmask, mask))
+ return NULL;
+
+ return scratch;
+}
+
/*
* Called with both p->pi_lock and rq->lock held; drops both before returning.
*/
@@ -3113,6 +3136,13 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
cpu_valid_mask = cpu_online_mask;
}
+ ctx->new_mask = root_domain_allowed(ctx->new_mask,
+ rq->scratch_mask, cpu_valid_mask);
+ if (!ctx->new_mask) {
+ ret = -EINVAL;
+ goto out;
+ }
+
if (!kthread && !cpumask_subset(ctx->new_mask, cpu_allowed_mask)) {
ret = -EINVAL;
goto out;
next prev parent reply other threads:[~2023-10-11 13:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 7:19 [PATCH RFC] cpumask: Randomly distribute the tasks within affinity mask Ankit Jain
2023-10-11 10:39 ` Andy Shevchenko
2023-10-11 10:53 ` Peter Zijlstra
2023-10-11 11:46 ` Peter Zijlstra
2023-10-11 13:52 ` Peter Zijlstra [this message]
2023-10-11 23:55 ` Josh Don
2023-10-12 8:05 ` Peter Zijlstra
2023-10-12 15:43 ` Ankit Jain
2023-10-12 0:16 ` Yury Norov
2023-10-12 15:52 ` Ankit Jain
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=20231011135238.GG6337@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akaher@vmware.com \
--cc=amakhalov@vmware.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ankitja@vmware.com \
--cc=bristot@redhat.com \
--cc=joshdon@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=namit@vmware.com \
--cc=pjt@google.com \
--cc=qyousef@layalina.io \
--cc=srinidhir@vmware.com \
--cc=srivatsa@csail.mit.edu \
--cc=vbrahmajosyula@vmware.com \
--cc=vschneid@redhat.com \
--cc=vsirnapalli@vmware.com \
--cc=yury.norov@gmail.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