From: Viresh Kumar <viresh.kumar@linaro.org>
To: Rafael Wysocki <rjw@rjwysocki.net>
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org,
Srivatsa Bhat <srivatsa@mit.edu>,
Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH V4 05/14] cpufreq: Manage governor usage history with 'policy->last_governor'
Date: Tue, 12 May 2015 12:22:34 +0530 [thread overview]
Message-ID: <4eec433110f00e1446ad46ecdfd084ee812efcc2.1431412012.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <b28aac5f8ece928d59aee85316aa6e04f8d2885b.1431065963.git.viresh.kumar@linaro.org>
History of which governor was used last is common to all CPUs within a
policy and maintaining it per-cpu isn't the best approach for sure.
Apart from wasting memory, this also increases the complexity of
managing this data structure as it has to be updated for all CPUs.
To make that somewhat simpler, lets store this information in a new
field 'last_governor' in struct cpufreq_policy and update it on removal
of last cpu of a policy.
As a side-effect it also solves an old problem, consider a system with
two clusters 0 & 1. And there is one policy per cluster.
Cluster 0: CPU0 and 1.
Cluster 1: CPU2 and 3.
- CPU2 is first brought online, and governor is set to performance
(default as cpufreq_cpu_governor wasn't set).
- Governor is changed to ondemand.
- CPU2 is taken offline and cpufreq_cpu_governor is updated for CPU2.
- CPU3 is brought online.
- Because cpufreq_cpu_governor wasn't set for CPU3, the default governor
performance is picked for CPU3.
This patch fixes the bug as we now have a single variable to update for
policy.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V4->V5:
- Rebased on top of [V4 1/14]
drivers/cpufreq/cpufreq.c | 30 +++++++++++++++---------------
include/linux/cpufreq.h | 1 +
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e6a63d6ba6f1..16275ba6428e 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -104,9 +104,6 @@ static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
static DEFINE_RWLOCK(cpufreq_driver_lock);
DEFINE_MUTEX(cpufreq_governor_lock);
-/* This one keeps track of the previously set governor of a removed CPU */
-static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
-
/* Flag to suspend/resume CPUFreq governors */
static bool cpufreq_suspended;
@@ -1017,7 +1014,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy)
memcpy(&new_policy, policy, sizeof(*policy));
/* Update governor of new_policy to the governor used before hotplug */
- gov = find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu));
+ gov = find_governor(policy->last_governor);
if (gov)
pr_debug("Restoring governor %s for cpu %d\n",
policy->governor->name, policy->cpu);
@@ -1411,14 +1408,15 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
pr_err("%s: Failed to stop governor\n", __func__);
return ret;
}
-
- strncpy(per_cpu(cpufreq_cpu_governor, cpu),
- policy->governor->name, CPUFREQ_NAME_LEN);
}
- down_read(&policy->rwsem);
+ down_write(&policy->rwsem);
cpus = cpumask_weight(policy->cpus);
- up_read(&policy->rwsem);
+
+ if (has_target() && cpus == 1)
+ strncpy(policy->last_governor, policy->governor->name,
+ CPUFREQ_NAME_LEN);
+ up_write(&policy->rwsem);
if (cpu != policy->cpu) {
sysfs_remove_link(&dev->kobj, "cpufreq");
@@ -2135,7 +2133,8 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor);
void cpufreq_unregister_governor(struct cpufreq_governor *governor)
{
- int cpu;
+ struct cpufreq_policy *policy;
+ unsigned long flags;
if (!governor)
return;
@@ -2143,12 +2142,13 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
if (cpufreq_disabled())
return;
- for_each_present_cpu(cpu) {
- if (cpu_online(cpu))
- continue;
- if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
- strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
+ /* clear last_governor for all inactive policies */
+ read_lock_irqsave(&cpufreq_driver_lock, flags);
+ for_each_inactive_policy(policy) {
+ if (!strcmp(policy->last_governor, governor->name))
+ strcpy(policy->last_governor, "\0");
}
+ read_unlock_irqrestore(&cpufreq_driver_lock, flags);
mutex_lock(&cpufreq_governor_mutex);
list_del(&governor->governor_list);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 2ee4888c1f47..48e37c07eb84 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -80,6 +80,7 @@ struct cpufreq_policy {
struct cpufreq_governor *governor; /* see below */
void *governor_data;
bool governor_enabled; /* governor start/stop flag */
+ char last_governor[CPUFREQ_NAME_LEN]; /* last governor used */
struct work_struct update; /* if update_policy() needs to be
* called, but you're in IRQ context */
--
2.4.0
next prev parent reply other threads:[~2015-05-12 6:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 6:23 [PATCH V3 00/14] cpufreq: Don't loose cpufreq history on CPU hotplug Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 01/14] cpufreq: Create for_each_{in}active_policy() Viresh Kumar
2015-05-08 21:46 ` Rafael J. Wysocki
2015-05-09 2:27 ` Viresh Kumar
2015-05-12 6:04 ` Viresh Kumar
2015-05-12 6:50 ` [PATCH V4 " Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 02/14] cpufreq: Don't clear cpufreq_cpu_data and policy list for inactive policies Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 03/14] cpufreq: Get rid of cpufreq_cpu_data_fallback Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 04/14] cpufreq: Don't traverse all active policies to find policy for a cpu Viresh Kumar
2015-05-12 6:52 ` [PATCH V4 " Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 05/14] cpufreq: Manage governor usage history with 'policy->last_governor' Viresh Kumar
2015-05-12 6:52 ` Viresh Kumar [this message]
2015-05-08 6:23 ` [PATCH V3 06/14] cpufreq: Mark policy->governor = NULL for inactive policies Viresh Kumar
2015-05-12 6:52 ` [PATCH V4 " Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 07/14] cpufreq: Don't allow updating inactive-policies from sysfs Viresh Kumar
2015-05-16 1:10 ` Rafael J. Wysocki
2015-05-16 2:01 ` Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 08/14] cpufreq: Track cpu managing sysfs kobjects separately Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 09/14] cpufreq: Stop migrating sysfs files on hotplug Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 10/14] cpufreq: Remove cpufreq_update_policy() Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 11/14] cpufreq: Initialize policy->kobj while allocating policy Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 12/14] cpufreq: Call cpufreq_policy_put_kobj() from cpufreq_policy_free() Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 13/14] cpufreq: Restart governor as soon as possible Viresh Kumar
2015-05-08 6:23 ` [PATCH V3 14/14] cpufreq: Add support for physical hoplug of CPUs Viresh Kumar
2015-05-16 1:18 ` Rafael J. Wysocki
2015-05-16 2:13 ` Viresh Kumar
2015-05-18 0:30 ` Rafael J. Wysocki
2015-05-18 2:11 ` Viresh Kumar
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=4eec433110f00e1446ad46ecdfd084ee812efcc2.1431412012.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=prarit@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=sboyd@codeaurora.org \
--cc=skannan@codeaurora.org \
--cc=srivatsa@mit.edu \
/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).