From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Steve Muckle <steve.muckle@linaro.org>,
Ingo Molnar <mingo@redhat.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Vincent Guittot <vincent.guittot@linaro.org>,
Morten Rasmussen <morten.rasmussen@arm.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Juri Lelli <Juri.Lelli@arm.com>,
Patrick Bellasi <patrick.bellasi@arm.com>,
Michael Turquette <mturquette@baylibre.com>,
Ricky Liang <jcliang@chromium.org>
Subject: Re: [RFCv7 PATCH 03/10] sched: scheduler-driven cpu frequency selection
Date: Sat, 27 Feb 2016 01:08:02 +0100 [thread overview]
Message-ID: <1743951.Hhdov0yvNG@vostro.rjw.lan> (raw)
In-Reply-To: <20160226091843.GX6356@twins.programming.kicks-ass.net>
On Friday, February 26, 2016 10:18:43 AM Peter Zijlstra wrote:
> On Thu, Feb 25, 2016 at 10:08:48PM +0100, Rafael J. Wysocki wrote:
> > On Thursday, February 25, 2016 10:28:37 AM Peter Zijlstra wrote:
> > > Its vile though; one should not spray IPIs if one can avoid it. Such
> > > things are much better done with RCU. Sure sync_sched() takes a little
> > > longer, but this isn't a fast path by any measure.
> >
> > I see, thanks!
> >
> > BTW, when cpufreq_update_util() callbacks are removed, I use synchronize_rcu()
> > to wait for the running ones, but would it be better to use synchronize_sched()
> > in there instead?
>
> So I think we only call the callback with rq->lock held, in which case
> sync_sched() is good enough.
>
> It would allow you to get rid of the rcu_read_{,un}lock() calls as well.
>
> The down-side is that it all makes the code a little harder to get,
> because you're relying on caller context to DTRT.
OK, so what about the below (on top of linux-next)?
It has passed my cursory testing.
---
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH] cpufreq: Reduce cpufreq_update_util() overhead a bit
Use the observation that cpufreq_update_util() is only called
by the scheduler with rq->lock held, so the callers of
cpufreq_set_update_util_data() can use synchronize_sched()
instead of synchronize_rcu() to wait for cpufreq_update_util()
to complete. Moreover, if they are updated to do that,
rcu_read_(un)lock() calls in cpufreq_update_util() might be
replaced with rcu_read_(un)lock_sched(), respectively, but
those aren't really necessary, because the scheduler calls
that function from RCU-sched read-side critical sections
already.
In addition to that, if cpufreq_set_update_util_data() checks
the func field in the struct update_util_data before setting
the per-CPU pointer to it, the data->func check may be dropped
from cpufreq_update_util() as well.
Make the above changes to reduce the overhead from
cpufreq_update_util() in the scheduler paths invoking it
and to make the cleanup after removing its callbacks less
heavy-weight somewhat.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpufreq/cpufreq.c | 21 +++++++++++++--------
drivers/cpufreq/cpufreq_governor.c | 2 +-
drivers/cpufreq/intel_pstate.c | 4 ++--
3 files changed, 16 insertions(+), 11 deletions(-)
Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -77,12 +77,15 @@ static DEFINE_PER_CPU(struct update_util
* to call from cpufreq_update_util(). That function will be called from an RCU
* read-side critical section, so it must not sleep.
*
- * 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.
+ * 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()
+ * right after this function to avoid use-after-free.
*/
void cpufreq_set_update_util_data(int cpu, struct update_util_data *data)
{
+ if (WARN_ON(data && !data->func))
+ return;
+
rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);
}
EXPORT_SYMBOL_GPL(cpufreq_set_update_util_data);
@@ -95,18 +98,20 @@ EXPORT_SYMBOL_GPL(cpufreq_set_update_uti
*
* This function is called by the scheduler on every invocation of
* update_load_avg() on the CPU whose utilization is being updated.
+ *
+ * It can only be called from RCU-sched read-side critical sections.
*/
void cpufreq_update_util(u64 time, unsigned long util, unsigned long max)
{
struct update_util_data *data;
- rcu_read_lock();
-
data = rcu_dereference(*this_cpu_ptr(&cpufreq_update_util_data));
- if (data && data->func)
+ /*
+ * If this isn't inside of an RCU-sched read-side critical section, data
+ * may become NULL after the check below.
+ */
+ if (data)
data->func(data, time, util, max);
-
- rcu_read_unlock();
}
/* Flag to suspend/resume CPUFreq governors */
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -280,7 +280,7 @@ static inline void gov_clear_update_util
for_each_cpu(i, policy->cpus)
cpufreq_set_update_util_data(i, NULL);
- synchronize_rcu();
+ synchronize_sched();
}
static void gov_cancel_work(struct cpufreq_policy *policy)
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/intel_pstate.c
+++ linux-pm/drivers/cpufreq/intel_pstate.c
@@ -1171,7 +1171,7 @@ static void intel_pstate_stop_cpu(struct
pr_debug("intel_pstate: CPU %d exiting\n", cpu_num);
cpufreq_set_update_util_data(cpu_num, NULL);
- synchronize_rcu();
+ synchronize_sched();
if (hwp_active)
return;
@@ -1429,7 +1429,7 @@ out:
for_each_online_cpu(cpu) {
if (all_cpu_data[cpu]) {
cpufreq_set_update_util_data(cpu, NULL);
- synchronize_rcu();
+ synchronize_sched();
kfree(all_cpu_data[cpu]);
}
}
next prev parent reply other threads:[~2016-02-27 0:06 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-23 1:22 [RFCv7 PATCH 00/10] sched: scheduler-driven CPU " Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 01/10] sched: Compute cpu capacity available at current frequency Steve Muckle
2016-02-23 1:41 ` Rafael J. Wysocki
2016-02-23 9:19 ` Peter Zijlstra
2016-02-26 1:37 ` Rafael J. Wysocki
2016-02-26 9:14 ` Peter Zijlstra
2016-02-23 1:22 ` [RFCv7 PATCH 02/10] cpufreq: introduce cpufreq_driver_is_slow Steve Muckle
2016-02-23 1:31 ` Rafael J. Wysocki
2016-02-26 0:50 ` Michael Turquette
2016-02-26 1:07 ` Steve Muckle
2016-02-26 1:16 ` Rafael J. Wysocki
[not found] ` <20160226185503.2278.20479@quark.deferred.io>
2016-02-26 21:00 ` Rafael J. Wysocki
2016-02-23 1:22 ` [RFCv7 PATCH 03/10] sched: scheduler-driven cpu frequency selection Steve Muckle
2016-02-25 3:55 ` Rafael J. Wysocki
2016-02-25 9:21 ` Peter Zijlstra
2016-02-25 21:04 ` Rafael J. Wysocki
2016-02-25 9:28 ` Peter Zijlstra
2016-02-25 21:08 ` Rafael J. Wysocki
2016-02-26 9:18 ` Peter Zijlstra
2016-02-27 0:08 ` Rafael J. Wysocki [this message]
2016-03-01 12:57 ` Peter Zijlstra
2016-03-01 19:44 ` Rafael J. Wysocki
2016-02-25 11:04 ` Rafael J. Wysocki
2016-02-26 0:34 ` Steve Muckle
2016-02-27 2:39 ` Rafael J. Wysocki
2016-02-27 4:17 ` Steve Muckle
2016-02-28 2:26 ` Rafael J. Wysocki
2016-03-01 14:31 ` Peter Zijlstra
2016-03-01 20:32 ` Rafael J. Wysocki
2016-03-01 13:26 ` Peter Zijlstra
2016-03-01 13:17 ` Peter Zijlstra
2016-03-02 7:49 ` Michael Turquette
2016-03-03 2:49 ` Rafael J. Wysocki
2016-03-03 3:50 ` Steve Muckle
2016-03-03 9:34 ` Juri Lelli
2016-03-03 13:03 ` Peter Zijlstra
2016-03-03 14:21 ` Ingo Molnar
2016-02-23 1:22 ` [RFCv7 PATCH 04/10] sched/fair: add triggers for OPP change requests Steve Muckle
2016-03-01 6:51 ` Ricky Liang
2016-03-03 3:55 ` Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 05/10] sched/{core,fair}: trigger OPP change request on fork() Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 06/10] sched/fair: cpufreq_sched triggers for load balancing Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 07/10] sched/fair: jump to max OPP when crossing UP threshold Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 08/10] sched: remove call of sched_avg_update from sched_rt_avg_update Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 09/10] sched/deadline: split rt_avg in 2 distincts metrics Steve Muckle
2016-02-23 1:22 ` [RFCv7 PATCH 10/10] sched: rt scheduler sets capacity requirement Steve Muckle
2016-02-23 1:33 ` [RFCv7 PATCH 00/10] sched: scheduler-driven CPU frequency selection Steve Muckle
2016-03-30 0:45 ` Yuyang Du
2016-03-31 1:35 ` Steve Muckle
2016-03-30 20:22 ` Yuyang Du
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=1743951.Hhdov0yvNG@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=Juri.Lelli@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=jcliang@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=mturquette@baylibre.com \
--cc=patrick.bellasi@arm.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=steve.muckle@linaro.org \
--cc=vincent.guittot@linaro.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
all inboxes | Powered by JetHome®