From: Saravana Kannan <skannan@codeaurora.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: Linux PM mailing list <linux-pm@vger.kernel.org>
Subject: Bug in cpufreq_update_util hook handling?
Date: Wed, 21 Jun 2017 17:24:51 -0700 [thread overview]
Message-ID: <594B0E53.7020208@codeaurora.org> (raw)
cpufreq_add_update_util_hook() registers the "data" and we are using
RCUs to store "data".
When we need to send util updates, scheduler calls cpufreq_update_util()
that just uses a rcu_dereference_sched() to access the data pointer.
When the governor is stopped, to unregister the hook, it calls
cpufreq_remove_update_util_hook() and calls synchronize_sched(). The
assumption that the governor is making (and is allowed to make) is that
after synchronize_sched() all references to "data" and "func" are no
longer used (since cpufreq_remove_update_util_hook is supposed to
replace data with NULL).
I'm no RCU, expert, if I understand it right, if we don't use
"rcu_read_lock()" and "rcu_read_unlock()" in cpufreq_update_util(), then
the scheduler can continue calling into the governor hooks after the
governor has stopped.
rcu_read_lock();
data = rcu_dereference_sched(*per_cpu_ptr(&cpufreq_update_util_data,
cpu_of(rq)));
if (data)
data->func(data, sched_clock(), flags);
rcu_read_unlock();
Is my understanding right? Is my suggest fix acceptable? I can send a
patch for it if it's acceptable.
On a separate note, I think the synchronize_sched() should be inside
cpufreq_remove_update_util_hook(). I can't think of any reason any
caller (governor) would want to allow access to the old "data" pointer
after unregistering the hooks. Also, the user of the hooks shouldn't
have to know whether the we use RCU or spinlock or whatever locking to
protect the data we pass into the add/remove functions. That doesn't
seem like a good abstractions -- especially for simple add/remove functions.
Thanks,
Saravana
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
next reply other threads:[~2017-06-22 0:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 0:24 Saravana Kannan [this message]
2017-06-22 0:36 ` Bug in cpufreq_update_util hook handling? Rafael J. Wysocki
2017-06-22 1:59 ` Saravana Kannan
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=594B0E53.7020208@codeaurora.org \
--to=skannan@codeaurora.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=viresh.kumar@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;
as well as URLs for NNTP newsgroup(s).