Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Qais Yousef <qais.yousef@arm.com>
To: Valentin Schneider <valentin.schneider@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Doug Anderson <dianders@chromium.org>,
	Jonathan Corbet <corbet@lwn.net>,
	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>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>,
	Quentin Perret <qperret@google.com>,
	Patrick Bellasi <patrick.bellasi@matbug.net>,
	Pavan Kondeti <pkondeti@codeaurora.org>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v6 1/2] sched/uclamp: Add a new sysctl to control RT default boost value
Date: Tue, 7 Jul 2020 10:34:47 +0100	[thread overview]
Message-ID: <20200707093447.4t6eqjy4fkt747fo@e107158-lin.cambridge.arm.com> (raw)
In-Reply-To: <jhj8sfw8wzk.mognet@arm.com>

On 07/06/20 16:49, Valentin Schneider wrote:
> 
> On 06/07/20 15:28, Qais Yousef wrote:
> > CC: linux-fsdevel@vger.kernel.org
> > ---
> >
> > Peter
> >
> > I didn't do the
> >
> >       read_lock(&taslist_lock);
> >       smp_mb__after_spinlock();
> >       read_unlock(&tasklist_lock);
> >
> > dance you suggested on IRC as it didn't seem necessary. But maybe I missed
> > something.
> >
> 
> So the annoying bit with just uclamp_fork() is that it happens *before* the
> task is appended to the tasklist. This means without too much care we
> would have (if we'd do a sync at uclamp_fork()):
> 
>   CPU0 (sysctl write)                                CPU1 (concurrent forker)
> 
>                                                        copy_process()
>                                                          uclamp_fork()
>                                                            p.uclamp_min = state
>     state = foo
> 
>     for_each_process_thread(p, t)
>       update_state(t);
>                                                          list_add(p)
> 
> i.e. that newly forked process would entirely sidestep the update. Now,
> with Peter's suggested approach we can be in a much better situation. If we
> have this in the sysctl update:
> 
>   state = foo;
> 
>   read_lock(&taslist_lock);
>   smp_mb__after_spinlock();
>   read_unlock(&tasklist_lock);
> 
>   for_each_process_thread(p, t)
>     update_state(t);
> 
> While having this in the fork:
> 
>   write_lock(&tasklist_lock);
>   list_add(p);
>   write_unlock(&tasklist_lock);
> 
>   sched_post_fork(p); // state re-read here; probably wants an mb first
> 
> Then we can no longer miss an update. If the forked p doesn't see the new
> value, it *must* have been added to the tasklist before the updater loops
> over it, so the loop will catch it. If it sees the new value, we're done.

uclamp_fork() has nothing to do with the race. If copy_process() duplicates the
task_struct of an RT task, it'll copy the old value.

I'd expect the newly introduced sched_post_fork() (also in copy_process() after
the list update) to prevent this race altogether.

Now we could end up with a problem if for_each_process_thread() doesn't see the
newly forked task _after_ sched_post_fork(). Hence my question to Peter.

> 
> AIUI, the above strategy doesn't require any use of RCU. The update_state()
> and sched_post_fork() can race, but as per the above they should both be
> writing the same value.

for_each_process_thread() must be protected by either tasklist_lock or
rcu_read_lock().

The other RCU logic I added is not to protect against the race above. I
describe the other race condition in a comment. Basically another updater on a
different cpu via fork() and sched_setattr() might read an old value and get
preempted. The rcu synchronization will ensure concurrent updaters have
finished before iterating the list.

Thanks

--
Qais Yousef

  reply	other threads:[~2020-07-07  9:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 14:28 [PATCH v6 0/2] sched/uclamp: new sysctl for default RT boost value Qais Yousef
2020-07-06 14:28 ` [PATCH v6 1/2] sched/uclamp: Add a new sysctl to control RT default " Qais Yousef
2020-07-06 15:49   ` Valentin Schneider
2020-07-07  9:34     ` Qais Yousef [this message]
2020-07-07 11:30       ` Valentin Schneider
2020-07-07 12:36         ` Qais Yousef
2020-07-08 11:05           ` Valentin Schneider
2020-07-08 13:08             ` Qais Yousef
2020-07-08 21:45               ` Valentin Schneider
2020-07-07 11:39   ` Valentin Schneider
2020-07-07 12:58     ` Qais Yousef
2020-07-13 11:21   ` Peter Zijlstra
2020-07-13 11:36     ` peterz
2020-07-13 12:12     ` Qais Yousef
2020-07-13 13:35       ` Peter Zijlstra
2020-07-13 14:27         ` Qais Yousef
2020-07-13 16:54           ` Peter Zijlstra
2020-07-13 18:09             ` Qais Yousef
2020-07-06 14:28 ` [PATCH v6 2/2] Documentation/sysctl: Document uclamp sysctl knobs Qais Yousef

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=20200707093447.4t6eqjy4fkt747fo@e107158-lin.cambridge.arm.com \
    --to=qais.yousef@arm.com \
    --cc=bsegall@google.com \
    --cc=corbet@lwn.net \
    --cc=dianders@chromium.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=patrick.bellasi@matbug.net \
    --cc=peterz@infradead.org \
    --cc=pkondeti@codeaurora.org \
    --cc=qperret@google.com \
    --cc=rostedt@goodmis.org \
    --cc=valentin.schneider@arm.com \
    --cc=vincent.guittot@linaro.org \
    --cc=yzaikin@google.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).