From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
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>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Will Deacon <will@kernel.org>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v3 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask
Date: Mon, 15 Aug 2022 09:37:02 -0400 [thread overview]
Message-ID: <a7eb96cd-1d4b-65a5-6213-a2f0df2d9ccc@redhat.com> (raw)
In-Reply-To: <YvoKy6OdJIkNXbtq@worktop.programming.kicks-ass.net>
On 8/15/22 04:58, Peter Zijlstra wrote:
> On Fri, Aug 12, 2022 at 04:39:28PM -0400, Waiman Long wrote:
>> Since accessing the content of the user_cpus_ptr requires lock protection
>> to ensure its validity, provide a helper function copy_user_cpus_mask()
>> to facilitate its reading.
> Sure, but this is atrocious.
>
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -2619,6 +2619,24 @@ void release_user_cpus_ptr(struct task_struct *p)
>> kfree(clear_user_cpus_ptr(p));
>> }
>>
>> +/*
>> + * Return the copied mask pointer or NULL if user mask not available.
>> + */
>> +struct cpumask *copy_user_cpus_mask(struct task_struct *p,
>> + struct cpumask *user_mask)
>> +{
>> + struct rq_flags rf;
>> + struct rq *rq = task_rq_lock(p, &rf);
>> + struct cpumask *mask = NULL;
>> +
>> + if (p->user_cpus_ptr) {
>> + cpumask_copy(user_mask, p->user_cpus_ptr);
>> + mask = user_mask;
>> + }
>> + task_rq_unlock(rq, p, &rf);
>> + return mask;
>> +}
> For reading the mask you only need one of those locks, and I would
> suggest p->pi_lock is much less contended than rq->lock.
>
Right. pi_lock should be enough for read access. Will make the change.
Thanks,
Longman
next prev parent reply other threads:[~2022-08-15 13:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 20:39 [PATCH v3 0/3] sched, cgroup/cpuset: Keep user set cpus affinity Waiman Long
2022-08-12 20:39 ` [PATCH v3 1/3] sched: Use user_cpus_ptr for saving user provided cpumask in sched_setaffinity() Waiman Long
2022-08-15 8:57 ` Peter Zijlstra
2022-08-15 13:52 ` Waiman Long
2022-08-15 14:25 ` Peter Zijlstra
2022-08-15 15:23 ` Waiman Long
2022-08-12 20:39 ` [PATCH v3 2/3] sched: Provide copy_user_cpus_mask() to copy out user mask Waiman Long
2022-08-15 8:58 ` Peter Zijlstra
2022-08-15 13:37 ` Waiman Long [this message]
2022-08-12 20:39 ` [PATCH v3 3/3] cgroup/cpuset: Keep user set cpus affinity Waiman Long
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=a7eb96cd-1d4b-65a5-6213-a2f0df2d9ccc@redhat.com \
--to=longman@redhat.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@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 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).