Re: [PATCH tip/core/rcu 23/41] sched: Replace synchronize_sched() with synchronize_rcu()

Paul E. McKenney
2018-11-26T20:00:02Z

On Mon, Nov 12, 2018 at 02:21:12PM -0800, Paul E. McKenney wrote:
> On Mon, Nov 12, 2018 at 07:17:41PM +0100, Peter Zijlstra wrote:
> > On Mon, Nov 12, 2018 at 05:28:52AM -0800, Paul E. McKenney wrote:
> > > On Mon, Nov 12, 2018 at 10:00:47AM +0100, Peter Zijlstra wrote:
> >
> > > > Still, better safe than sorry. It was a rather big change in behaviour,
> > > > so it wouldn't have been strange to call that out.
> > >
> > > This guy:
> > >
> > > 45975c7d21a1 ("rcu: Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds")
> > >
> > > Has a commit log that says:
> > >
> > > Now that RCU-preempt knows about preemption disabling, its
> > > implementation of synchronize_rcu() works for synchronize_sched(),
> > > and likewise for the other RCU-sched update-side API members.
> > > This commit therefore confines the RCU-sched update-side code
> > > to CONFIG_PREEMPT=n builds, and defines RCU-sched's update-side
> > > API members in terms of those of RCU-preempt.
> > >
> > > That last phrase seems pretty explicit. What am I missing here?
> >
> > That does not explicitly state that because RCU-preempt
> > synchornize_rcu() can take _much_ longer, the new synchronize_sched()
> > can now take _much_ longer too.
> >
> > So when someone bisects a problem to this commit; and he reads the
> > Changelog, he might get the impression that was unexpected.
>
> Of course, a preempt_disable() section of code can still be preempted
> by the underlying hypervisor, so in a surprisingly large fraction of
> the installed base, there really isn't that much difference.
>
> > > Not that it matters, given that I know of no way to change a mainlined
> > > commit log. I suppose I could ask Jon if he would be willing to take
> > > a 2018 RCU API LWN article, if that would help.
> >
> > Yes, it is water under the bridge; but Changelogs should be explicit
> > about behavioural changes.
> >
> > And while the merged RCU has the semantic behaviour required, the timing
> > behaviour did change significantly.
>
> When running on bare metal, potentially. From what I see, preemption
> of RCU read-side critical sections is the exception rather than the rule.
> And again, when running on hypervisors, even irq-disable regions of code
> can be preempted. (And yes, there is work in flight to allow RCU to deal
> with this.)
>
> > > > > > Again, the patch didn't say that.
> > > > > >
> > > > > > If the Changelog would've read something like:
> > > > > >
> > > > > > "Since synchronize_sched() is now equivalent to synchronize_rcu(),
> > > > > > replace the synchronize_sched() usage such that we can eventually remove
> > > > > > the interface."
> > > > > >
> > > > > > It would've been clear that the patch is a nop and what the purpose
> > > > > > was.
> > > > >
> > > > > I can easily make that change.
> > > >
> > > > Please, sufficient doesn't imply necessary etc.. A changelog should
> > > > always clarify why we do the patch.
> > >
> > > ??? Did you mean to say "necessary doesn't imply sufficient"? If so,
> > > what else do you feel is missing?
> >
> > No, I meant to say that your original Changelog only states that
> > sync_rcu now covers rcu-sched behaviour. Which means that the change is
> > sufficient.
> >
> > It completely and utterly fails to explain _why_ you're doing the
> > change. Ie. you do not address why it is necessary.
> >
> > A Changelog should always explain why the change is needed.
> >
> > In this case because you want to get rid of the sync_sched() api.
>
> Right, which is stated in your suggested wording above. So I am still
> not seeing what you want added to this:
>
> "Since synchronize_sched() is now equivalent to synchronize_rcu(),
> replace the synchronize_sched() usage such that we can eventually
> remove the interface."

Finally getting back to this. I removed this commit from the group that
I intend to send in next week's -tip pull request, and updated its commit
log as shown below. Does this work for you?

Thanx, Paul

------------------------------------------------------------------------

commit 52ffe7fbe615e8989f054432c76a7e43b8c35607
Author: Paul E. McKenney <paulmck@linux.ibm.com>
Date: Tue Nov 6 19:13:54 2018 -0800

sched: Replace synchronize_sched() with synchronize_rcu()

Now that synchronize_rcu() waits for preempt-disable regions of
code as well as RCU read-side critical sections, synchronize_sched()
can be replaced by synchronize_rcu(), in fact, synchronize_sched()
is now completely equivalent to synchronize_rcu(). This commit
therefore replaces synchronize_sched() with synchronize_rcu() so that
synchronize_sched() can eventually be removed entirely.

Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>

diff --git a/kernel/sched/cpufreq.c b/kernel/sched/cpufreq.c
index 5e54cbcae673..90fee8e01280 100644
--- a/kernel/sched/cpufreq.c
+++ b/kernel/sched/cpufreq.c
@@ -51,8 +51,8 @@ EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook);
*
* Clear the update_util_data pointer for the given CPU.
*
- * Callers must use RCU-sched callbacks to free any memory that might be
- * accessed via the old update_util_data pointer or invoke synchronize_sched()
+ * Callers must use RCU callbacks to free any memory that might be
+ * accessed via the old update_util_data pointer or invoke synchronize_rcu()
* right after this function to avoid use-after-free.
*/
void cpufreq_remove_update_util_hook(int cpu)
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 3fffad3bc8a8..6a1bb76afbd1 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -839,7 +839,7 @@ static void sugov_stop(struct cpufreq_policy *policy)
for_each_cpu(cpu, policy->cpus)
cpufreq_remove_update_util_hook(cpu);

- synchronize_sched();
+ synchronize_rcu();

if (!policy->fast_switch_enabled) {
irq_work_sync(&sg_policy->irq_work);