Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1328955 > unrolled thread
| Started by | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| First post | 2016-02-08 12:50 +0100 |
| Last post | 2016-02-08 22:50 +0100 |
| Articles | 18 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 07/13] cpufreq: Call __cpufreq_governor() with policy->rwsem held Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 02/13] cpufreq: governor: Move common tunables to 'struct dbs_data' Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 05/13] Revert "cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT" Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 13/13] cpufreq: conservative: Update sample_delay_ns immediately Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 10/13] cpufreq: governor: No need to manage state machine now Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 04/13] cpufreq: governor: Drop unused macros for creating governor tunable attributes Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
[PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c "Rafael J. Wysocki" <rafael@kernel.org> - 2016-02-08 14:00 +0100
Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 14:10 +0100
Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c "Rafael J. Wysocki" <rafael@kernel.org> - 2016-02-08 14:30 +0100
[PATCH V3 01/13] cpufreq: governor: Create generic macro for global tuners Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 12:50 +0100
Re: [PATCH V3 01/13] cpufreq: governor: Create generic macro for global tuners "Rafael J. Wysocki" <rafael@kernel.org> - 2016-02-08 17:40 +0100
Re: [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> - 2016-02-08 14:00 +0100
Re: [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 14:00 +0100
Re: [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups Juri Lelli <juri.lelli@arm.com> - 2016-02-08 17:40 +0100
Re: [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-08 18:00 +0100
Re: [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups "Rafael J. Wysocki" <rafael@kernel.org> - 2016-02-08 22:50 +0100
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 00/13] cpufreq: governors: Fix ABBA lockups |
| Message-ID | <qZSul-4Ei-3@gated-at.bofh.it> |
Hi Rafael,
Things look much much better now. I have rebased this series over
pm/bleeding-edge, that has all your patches.
I have moved ahead and done few more changes in this series, that should
get rid of all the lockdeps we were getting earlier, that includes
fixing lockdep issue in update_sampling_rate() that we were chasing.
These are pushed here again:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject
@Juri/Shilpa: Can you please confirm if all the issues got resolved now
?
V2->V3:
- The first patch from V2, that was moving min_sampling_rate to
per governor structure was dropped, as you suggested.
- Also, I have moved common tunables to struct dbs_data now, which you
also suggested sometime back.
- Last 5 patches are all new and fix rest of the issues we were facing.
--
viresh
Viresh Kumar (13):
cpufreq: governor: Create generic macro for global tuners
cpufreq: governor: Move common tunables to 'struct dbs_data'
cpufreq: governor: New sysfs show/store callbacks for governor
tunables
cpufreq: governor: Drop unused macros for creating governor tunable
attributes
Revert "cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT"
cpufreq: Merge cpufreq_offline_prepare/finish routines
cpufreq: Call __cpufreq_governor() with policy->rwsem held
cpufreq: Remove cpufreq_governor_lock
cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c
cpufreq: governor: No need to manage state machine now
cpufreq: governor: Keep list of policy_dbs within dbs_data
cpufreq: ondemand: Traverse list of policy_dbs in
update_sampling_rate()
cpufreq: conservative: Update sample_delay_ns immediately
drivers/cpufreq/cpufreq.c | 98 ++++++------
drivers/cpufreq/cpufreq_conservative.c | 143 ++++--------------
drivers/cpufreq/cpufreq_governor.c | 266 +++++++++++++++++++++++++--------
drivers/cpufreq/cpufreq_governor.h | 156 ++++++++-----------
drivers/cpufreq/cpufreq_ondemand.c | 241 +++++------------------------
include/linux/cpufreq.h | 4 -
6 files changed, 381 insertions(+), 527 deletions(-)
--
2.7.1.370.gb2aa7f8
[toc] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 07/13] cpufreq: Call __cpufreq_governor() with policy->rwsem held |
| Message-ID | <qZSum-4Ei-19@gated-at.bofh.it> |
| In reply to | #1328955 |
This isn't followed properly by all parts of the core code, some follow
it, whereas others don't.
Enforcing it will also enable us to remove cpufreq_governor_lock, that
is used today because we can't guarantee that __cpufreq_governor() isn't
executed in parallel.
We should also ensure that the lock is held across state changes to the
governors.
For example, while adding a CPU to the policy on cpu-online path, we
need to stop the governor, change policy->cpus, start the governor and
then refresh its limits. The complete sequence must be guaranteed to
execute without any concurrent races. And that can be achieved using
policy->rwsem around these use cases.
Also note that cpufreq_driver->stop_cpu() and ->exit() can get called
while policy->rwsem is held. That shouldn't have any side effects
though.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 49 +++++++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 863ac26c4ecf..51fb47cd38a0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1048,30 +1048,29 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
if (cpumask_test_cpu(cpu, policy->cpus))
return 0;
+ down_write(&policy->rwsem);
if (has_target()) {
ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
if (ret) {
pr_err("%s: Failed to stop governor\n", __func__);
- return ret;
+ goto unlock;
}
}
- down_write(&policy->rwsem);
cpumask_set_cpu(cpu, policy->cpus);
- up_write(&policy->rwsem);
if (has_target()) {
ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
if (!ret)
ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
- if (ret) {
+ if (ret)
pr_err("%s: Failed to start governor\n", __func__);
- return ret;
- }
}
- return 0;
+unlock:
+ up_write(&policy->rwsem);
+ return ret;
}
static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
@@ -1374,13 +1373,13 @@ static void cpufreq_offline(unsigned int cpu)
return;
}
+ down_write(&policy->rwsem);
if (has_target()) {
ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
if (ret)
pr_err("%s: Failed to stop governor\n", __func__);
}
- down_write(&policy->rwsem);
cpumask_clear_cpu(cpu, policy->cpus);
if (policy_is_inactive(policy)) {
@@ -1393,7 +1392,6 @@ static void cpufreq_offline(unsigned int cpu)
/* Nominate new CPU */
policy->cpu = cpumask_any(policy->cpus);
}
- up_write(&policy->rwsem);
/* Start governor again for active policy */
if (!policy_is_inactive(policy)) {
@@ -1406,7 +1404,7 @@ static void cpufreq_offline(unsigned int cpu)
pr_err("%s: Failed to start governor\n", __func__);
}
- return;
+ goto unlock;
}
if (cpufreq_driver->stop_cpu)
@@ -1428,6 +1426,9 @@ static void cpufreq_offline(unsigned int cpu)
cpufreq_driver->exit(policy);
policy->freq_table = NULL;
}
+
+unlock:
+ up_write(&policy->rwsem);
}
/**
@@ -1624,6 +1625,7 @@ EXPORT_SYMBOL(cpufreq_generic_suspend);
void cpufreq_suspend(void)
{
struct cpufreq_policy *policy;
+ int ret;
if (!cpufreq_driver)
return;
@@ -1634,7 +1636,11 @@ void cpufreq_suspend(void)
pr_debug("%s: Suspending Governors\n", __func__);
for_each_active_policy(policy) {
- if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP))
+ down_write(&policy->rwsem);
+ ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
+ up_write(&policy->rwsem);
+
+ if (ret)
pr_err("%s: Failed to stop governor for policy: %p\n",
__func__, policy);
else if (cpufreq_driver->suspend
@@ -1656,6 +1662,7 @@ void cpufreq_suspend(void)
void cpufreq_resume(void)
{
struct cpufreq_policy *policy;
+ int ret;
if (!cpufreq_driver)
return;
@@ -1668,13 +1675,20 @@ void cpufreq_resume(void)
pr_debug("%s: Resuming Governors\n", __func__);
for_each_active_policy(policy) {
- if (cpufreq_driver->resume && cpufreq_driver->resume(policy))
+ if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
pr_err("%s: Failed to resume driver: %p\n", __func__,
policy);
- else if (__cpufreq_governor(policy, CPUFREQ_GOV_START)
- || __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))
- pr_err("%s: Failed to start governor for policy: %p\n",
- __func__, policy);
+ } else {
+ down_write(&policy->rwsem);
+ ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
+ if (!ret)
+ __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ up_write(&policy->rwsem);
+
+ if (ret)
+ pr_err("%s: Failed to start governor for policy: %p\n",
+ __func__, policy);
+ }
}
/*
@@ -2325,8 +2339,11 @@ static int cpufreq_boost_set_sw(int state)
__func__);
break;
}
+
+ down_write(&policy->rwsem);
policy->user_policy.max = policy->max;
__cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+ up_write(&policy->rwsem);
}
}
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 02/13] cpufreq: governor: Move common tunables to 'struct dbs_data' |
| Message-ID | <qZSum-4Ei-17@gated-at.bofh.it> |
| In reply to | #1328955 |
There are few more common tunables shared across ondemand and
conservative governors. Move them to 'struct dbs_data' to simplify code.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_conservative.c | 38 ++++++++++++++-----------------
drivers/cpufreq/cpufreq_governor.c | 37 ++++++------------------------
drivers/cpufreq/cpufreq_governor.h | 14 +++++-------
drivers/cpufreq/cpufreq_ondemand.c | 41 +++++++++++++++-------------------
4 files changed, 47 insertions(+), 83 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 8aaa8a4c2fca..ee4937ab6a8b 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -60,7 +60,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
return;
/* Check for frequency increase */
- if (load > cs_tuners->up_threshold) {
+ if (load > dbs_data->up_threshold) {
dbs_info->down_skip = 0;
/* if we are already at full speed then break out early */
@@ -78,7 +78,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
}
/* if sampling_down_factor is active break out early */
- if (++dbs_info->down_skip < cs_tuners->sampling_down_factor)
+ if (++dbs_info->down_skip < dbs_data->sampling_down_factor)
return;
dbs_info->down_skip = 0;
@@ -107,10 +107,9 @@ static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
{
struct policy_dbs_info *policy_dbs = policy->governor_data;
struct dbs_data *dbs_data = policy_dbs->dbs_data;
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
dbs_check_cpu(policy);
- return delay_for_sampling_rate(cs_tuners->sampling_rate);
+ return delay_for_sampling_rate(dbs_data->sampling_rate);
}
static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
@@ -126,7 +125,6 @@ static struct dbs_governor cs_dbs_gov;
static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
const char *buf, size_t count)
{
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
unsigned int input;
int ret;
ret = sscanf(buf, "%u", &input);
@@ -134,14 +132,13 @@ static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
return -EINVAL;
- cs_tuners->sampling_down_factor = input;
+ dbs_data->sampling_down_factor = input;
return count;
}
static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
size_t count)
{
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
unsigned int input;
int ret;
ret = sscanf(buf, "%u", &input);
@@ -149,7 +146,7 @@ static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
if (ret != 1)
return -EINVAL;
- cs_tuners->sampling_rate = max(input, dbs_data->min_sampling_rate);
+ dbs_data->sampling_rate = max(input, dbs_data->min_sampling_rate);
return count;
}
@@ -164,7 +161,7 @@ static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
if (ret != 1 || input > 100 || input <= cs_tuners->down_threshold)
return -EINVAL;
- cs_tuners->up_threshold = input;
+ dbs_data->up_threshold = input;
return count;
}
@@ -178,7 +175,7 @@ static ssize_t store_down_threshold(struct dbs_data *dbs_data, const char *buf,
/* cannot be lower than 11 otherwise freq will not fall */
if (ret != 1 || input < 11 || input > 100 ||
- input >= cs_tuners->up_threshold)
+ input >= dbs_data->up_threshold)
return -EINVAL;
cs_tuners->down_threshold = input;
@@ -188,7 +185,6 @@ static ssize_t store_down_threshold(struct dbs_data *dbs_data, const char *buf,
static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
const char *buf, size_t count)
{
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
unsigned int input, j;
int ret;
@@ -199,10 +195,10 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
if (input > 1)
input = 1;
- if (input == cs_tuners->ignore_nice_load) /* nothing to do */
+ if (input == dbs_data->ignore_nice_load) /* nothing to do */
return count;
- cs_tuners->ignore_nice_load = input;
+ dbs_data->ignore_nice_load = input;
/* we need to re-evaluate prev_cpu_idle */
for_each_online_cpu(j) {
@@ -210,7 +206,7 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
dbs_info = &per_cpu(cs_cpu_dbs_info, j);
dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
&dbs_info->cdbs.prev_cpu_wall, 0);
- if (cs_tuners->ignore_nice_load)
+ if (dbs_data->ignore_nice_load)
dbs_info->cdbs.prev_cpu_nice =
kcpustat_cpu(j).cpustat[CPUTIME_NICE];
}
@@ -239,12 +235,12 @@ static ssize_t store_freq_step(struct dbs_data *dbs_data, const char *buf,
return count;
}
-show_store_one(cs, sampling_rate);
-show_store_one(cs, sampling_down_factor);
-show_store_one(cs, up_threshold);
show_store_one(cs, down_threshold);
-show_store_one(cs, ignore_nice_load);
show_store_one(cs, freq_step);
+show_store_one_global(cs, sampling_rate);
+show_store_one_global(cs, sampling_down_factor);
+show_store_one_global(cs, up_threshold);
+show_store_one_global(cs, ignore_nice_load);
show_one_global(cs, min_sampling_rate);
gov_sys_pol_attr_rw(sampling_rate);
@@ -299,11 +295,11 @@ static int cs_init(struct dbs_data *dbs_data, bool notify)
return -ENOMEM;
}
- tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
tuners->down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD;
- tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
- tuners->ignore_nice_load = 0;
tuners->freq_step = DEF_FREQUENCY_STEP;
+ dbs_data->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
+ dbs_data->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
+ dbs_data->ignore_nice_load = 0;
dbs_data->tuners = tuners;
dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 9c1dfcee0d57..b168a32cc8f0 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -38,10 +38,9 @@ void dbs_check_cpu(struct cpufreq_policy *policy)
struct policy_dbs_info *policy_dbs = policy->governor_data;
struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
- unsigned int sampling_rate;
+ unsigned int sampling_rate = dbs_data->sampling_rate;
+ unsigned int ignore_nice = dbs_data->ignore_nice_load;
unsigned int max_load = 0;
- unsigned int ignore_nice;
unsigned int j;
if (gov->governor == GOV_ONDEMAND) {
@@ -54,13 +53,8 @@ void dbs_check_cpu(struct cpufreq_policy *policy)
* the 'sampling_rate', so as to keep the wake-up-from-idle
* detection logic a bit conservative.
*/
- sampling_rate = od_tuners->sampling_rate;
sampling_rate *= od_dbs_info->rate_mult;
- ignore_nice = od_tuners->ignore_nice_load;
- } else {
- sampling_rate = cs_tuners->sampling_rate;
- ignore_nice = cs_tuners->ignore_nice_load;
}
/* Get Absolute Load */
@@ -279,19 +273,6 @@ static void dbs_update_util_handler(struct update_util_data *data, u64 time,
atomic_dec(&policy_dbs->skip_work);
}
-static void set_sampling_rate(struct dbs_data *dbs_data,
- struct dbs_governor *gov,
- unsigned int sampling_rate)
-{
- if (gov->governor == GOV_CONSERVATIVE) {
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
- cs_tuners->sampling_rate = sampling_rate;
- } else {
- struct od_dbs_tuners *od_tuners = dbs_data->tuners;
- od_tuners->sampling_rate = sampling_rate;
- }
-}
-
static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
struct dbs_governor *gov)
{
@@ -383,8 +364,8 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy)
/* Bring kernel and HW constraints together */
dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate,
MIN_LATENCY_MULTIPLIER * latency);
- set_sampling_rate(dbs_data, gov, max(dbs_data->min_sampling_rate,
- latency * LATENCY_MULTIPLIER));
+ dbs_data->sampling_rate = max(dbs_data->min_sampling_rate,
+ LATENCY_MULTIPLIER * latency);
if (!have_governor_per_policy())
gov->gdbs_data = dbs_data;
@@ -456,16 +437,12 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
if (policy_dbs->policy)
return -EBUSY;
- if (gov->governor == GOV_CONSERVATIVE) {
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
+ sampling_rate = dbs_data->sampling_rate;
+ ignore_nice = dbs_data->ignore_nice_load;
- sampling_rate = cs_tuners->sampling_rate;
- ignore_nice = cs_tuners->ignore_nice_load;
- } else {
+ if (gov->governor == GOV_ONDEMAND) {
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
- sampling_rate = od_tuners->sampling_rate;
- ignore_nice = od_tuners->ignore_nice_load;
io_busy = od_tuners->io_is_busy;
}
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index cc9a373b9736..5c5d7936087c 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -153,9 +153,13 @@ static void *get_cpu_dbs_info_s(int cpu) \
/* Governor demand based switching data (per-policy or global). */
struct dbs_data {
- unsigned int min_sampling_rate;
int usage_count;
void *tuners;
+ unsigned int min_sampling_rate;
+ unsigned int ignore_nice_load;
+ unsigned int sampling_rate;
+ unsigned int sampling_down_factor;
+ unsigned int up_threshold;
};
/* Common to all CPUs of a policy */
@@ -216,19 +220,11 @@ struct cs_cpu_dbs_info_s {
/* Per policy Governors sysfs tunables */
struct od_dbs_tuners {
- unsigned int ignore_nice_load;
- unsigned int sampling_rate;
- unsigned int sampling_down_factor;
- unsigned int up_threshold;
unsigned int powersave_bias;
unsigned int io_is_busy;
};
struct cs_dbs_tuners {
- unsigned int ignore_nice_load;
- unsigned int sampling_rate;
- unsigned int sampling_down_factor;
- unsigned int up_threshold;
unsigned int down_threshold;
unsigned int freq_step;
};
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 2a71a6755998..cb0d6ff1ced5 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -110,7 +110,7 @@ static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy,
dbs_info->freq_lo_jiffies = 0;
return freq_lo;
}
- jiffies_total = usecs_to_jiffies(od_tuners->sampling_rate);
+ jiffies_total = usecs_to_jiffies(dbs_data->sampling_rate);
jiffies_hi = (freq_avg - freq_lo) * jiffies_total;
jiffies_hi += ((freq_hi - freq_lo) / 2);
jiffies_hi /= (freq_hi - freq_lo);
@@ -161,11 +161,10 @@ static void od_check_cpu(int cpu, unsigned int load)
dbs_info->freq_lo = 0;
/* Check for frequency increase */
- if (load > od_tuners->up_threshold) {
+ if (load > dbs_data->up_threshold) {
/* If switching to max speed, apply sampling_down_factor */
if (policy->cur < policy->max)
- dbs_info->rate_mult =
- od_tuners->sampling_down_factor;
+ dbs_info->rate_mult = dbs_data->sampling_down_factor;
dbs_freq_increase(policy, policy->max);
} else {
/* Calculate the next frequency proportional to load */
@@ -195,7 +194,6 @@ static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
struct policy_dbs_info *policy_dbs = policy->governor_data;
struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
- struct od_dbs_tuners *od_tuners = dbs_data->tuners;
int delay = 0, sample_type = dbs_info->sample_type;
/* Common NORMAL_SAMPLE setup */
@@ -214,7 +212,7 @@ static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
}
if (!delay)
- delay = delay_for_sampling_rate(od_tuners->sampling_rate
+ delay = delay_for_sampling_rate(dbs_data->sampling_rate
* dbs_info->rate_mult);
return delay;
@@ -239,11 +237,10 @@ static struct dbs_governor od_dbs_gov;
static void update_sampling_rate(struct dbs_data *dbs_data,
unsigned int new_rate)
{
- struct od_dbs_tuners *od_tuners = dbs_data->tuners;
struct cpumask cpumask;
int cpu;
- od_tuners->sampling_rate = new_rate = max(new_rate,
+ dbs_data->sampling_rate = new_rate = max(new_rate,
dbs_data->min_sampling_rate);
/*
@@ -348,7 +345,6 @@ static ssize_t store_io_is_busy(struct dbs_data *dbs_data, const char *buf,
static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
size_t count)
{
- struct od_dbs_tuners *od_tuners = dbs_data->tuners;
unsigned int input;
int ret;
ret = sscanf(buf, "%u", &input);
@@ -358,21 +354,20 @@ static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
return -EINVAL;
}
- od_tuners->up_threshold = input;
+ dbs_data->up_threshold = input;
return count;
}
static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
const char *buf, size_t count)
{
- struct od_dbs_tuners *od_tuners = dbs_data->tuners;
unsigned int input, j;
int ret;
ret = sscanf(buf, "%u", &input);
if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
return -EINVAL;
- od_tuners->sampling_down_factor = input;
+ dbs_data->sampling_down_factor = input;
/* Reset down sampling multiplier in case it was active */
for_each_online_cpu(j) {
@@ -399,10 +394,10 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
if (input > 1)
input = 1;
- if (input == od_tuners->ignore_nice_load) { /* nothing to do */
+ if (input == dbs_data->ignore_nice_load) { /* nothing to do */
return count;
}
- od_tuners->ignore_nice_load = input;
+ dbs_data->ignore_nice_load = input;
/* we need to re-evaluate prev_cpu_idle */
for_each_online_cpu(j) {
@@ -410,7 +405,7 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
dbs_info = &per_cpu(od_cpu_dbs_info, j);
dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
&dbs_info->cdbs.prev_cpu_wall, od_tuners->io_is_busy);
- if (od_tuners->ignore_nice_load)
+ if (dbs_data->ignore_nice_load)
dbs_info->cdbs.prev_cpu_nice =
kcpustat_cpu(j).cpustat[CPUTIME_NICE];
@@ -437,12 +432,12 @@ static ssize_t store_powersave_bias(struct dbs_data *dbs_data, const char *buf,
return count;
}
-show_store_one(od, sampling_rate);
show_store_one(od, io_is_busy);
-show_store_one(od, up_threshold);
-show_store_one(od, sampling_down_factor);
-show_store_one(od, ignore_nice_load);
show_store_one(od, powersave_bias);
+show_store_one_global(od, sampling_rate);
+show_store_one_global(od, up_threshold);
+show_store_one_global(od, sampling_down_factor);
+show_store_one_global(od, ignore_nice_load);
show_one_global(od, min_sampling_rate);
gov_sys_pol_attr_rw(sampling_rate);
@@ -504,7 +499,7 @@ static int od_init(struct dbs_data *dbs_data, bool notify)
put_cpu();
if (idle_time != -1ULL) {
/* Idle micro accounting is supported. Use finer thresholds */
- tuners->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
+ dbs_data->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
/*
* In nohz/micro accounting case we set the minimum frequency
* not depending on HZ, but fixed (very low). The deferred
@@ -512,15 +507,15 @@ static int od_init(struct dbs_data *dbs_data, bool notify)
*/
dbs_data->min_sampling_rate = MICRO_FREQUENCY_MIN_SAMPLE_RATE;
} else {
- tuners->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
+ dbs_data->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
/* For correct statistics, we need 10 ticks for each measure */
dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
jiffies_to_usecs(10);
}
- tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
- tuners->ignore_nice_load = 0;
+ dbs_data->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
+ dbs_data->ignore_nice_load = 0;
tuners->powersave_bias = default_powersave_bias;
tuners->io_is_busy = should_io_be_busy();
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 05/13] Revert "cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT" |
| Message-ID | <qZSum-4Ei-21@gated-at.bofh.it> |
| In reply to | #1328955 |
Earlier, when the struct freq-attr was used to represent governor
attributes, the standard cpufreq show/store sysfs attribute callbacks
were applied to the governor tunable attributes and they always acquire
the policy->rwsem lock before carrying out the operation. That could
have resulted in an ABBA deadlock if governor tunable attributes are
removed under policy->rwsem while one of them is being accessed
concurrently (if sysfs attributes removal wins the race, it will wait
for the access to complete with policy->rwsem held while the attribute
callback will block on policy->rwsem indefinitely).
We attempted to address this issue by dropping policy->rwsem around
governor tunable attributes removal (that is, around invocations of the
->governor callback with the event arg equal to CPUFREQ_GOV_POLICY_EXIT)
in cpufreq_set_policy(), but that opened up race conditions that had not
been possible with policy->rwsem held all the time.
The previous commit, "cpufreq: governor: New sysfs show/store callbacks
for governor tunables", fixed the original ABBA deadlock by adding new
governor specific show/store callbacks.
We don't have to drop rwsem around invocations of governor event
CPUFREQ_GOV_POLICY_EXIT anymore, and original fix can be reverted now.
Fixes: 955ef4833574 ("cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT")
Reported-by: Juri Lelli <juri.lelli@arm.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 5 -----
include/linux/cpufreq.h | 4 ----
2 files changed, 9 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 29755fcbf200..9c62bf35b9dc 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2204,10 +2204,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
return ret;
}
- up_write(&policy->rwsem);
ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
- down_write(&policy->rwsem);
-
if (ret) {
pr_err("%s: Failed to Exit Governor: %s (%d)\n",
__func__, old_gov->name, ret);
@@ -2223,9 +2220,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
if (!ret)
goto out;
- up_write(&policy->rwsem);
__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
- down_write(&policy->rwsem);
}
/* new governor failed, so re-start old one */
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 11aa93134493..2a029c587975 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -100,10 +100,6 @@ struct cpufreq_policy {
* - Any routine that will write to the policy structure and/or may take away
* the policy altogether (eg. CPU hotplug), will hold this lock in write
* mode before doing so.
- *
- * Additional rules:
- * - Lock should not be held across
- * __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT);
*/
struct rw_semaphore rwsem;
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 13/13] cpufreq: conservative: Update sample_delay_ns immediately |
| Message-ID | <qZSum-4Ei-27@gated-at.bofh.it> |
| In reply to | #1328955 |
Ondemand governor already updates sample_delay_ns immediately on updates
to sampling rate, but conservative isn't doing that.
It was left out earlier as the code has been really complex to get that
done easily. But now things are sorted out very well, and we can follow
the same for conservative governor as well.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_governor.c | 30 +++++++++++++++++++++++++++---
drivers/cpufreq/cpufreq_governor.h | 1 -
drivers/cpufreq/cpufreq_ondemand.c | 38 --------------------------------------
3 files changed, 27 insertions(+), 42 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index e267acc67067..3f4338bdb3aa 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -29,7 +29,7 @@ EXPORT_SYMBOL_GPL(dbs_data_mutex);
static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
size_t count)
{
- struct dbs_governor *gov = dbs_data->gov;
+ struct policy_dbs_info *policy_dbs;
unsigned int rate;
int ret;
ret = sscanf(buf, "%u", &rate);
@@ -38,8 +38,32 @@ static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
dbs_data->sampling_rate = max(rate, dbs_data->min_sampling_rate);
- if (gov->update_sampling_rate)
- gov->update_sampling_rate(dbs_data);
+ /*
+ * We are operating under dbs_data->mutex and so the list and its
+ * entries can't be freed concurrently.
+ */
+ list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list) {
+ mutex_lock(&policy_dbs->timer_mutex);
+ /*
+ * On 32-bit architectures this may race with the
+ * sample_delay_ns read in dbs_update_util_handler(), but that
+ * really doesn't matter. If the read returns a value that's
+ * too big, the sample will be skipped, but the next invocation
+ * of dbs_update_util_handler() (when the update has been
+ * completed) will take a sample. If the returned value is too
+ * small, the sample will be taken immediately, but that isn't a
+ * problem, as we want the new rate to take effect immediately
+ * anyway.
+ *
+ * If this runs in parallel with dbs_work_handler(), we may end
+ * up overwriting the sample_delay_ns value that it has just
+ * written, but the difference should not be too big and it will
+ * be corrected next time a sample is taken, so it shouldn't be
+ * significant.
+ */
+ gov_update_sample_delay(policy_dbs, dbs_data->sampling_rate);
+ mutex_unlock(&policy_dbs->timer_mutex);
+ }
return count;
}
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index b740633c2fbe..127982f6d869 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -212,7 +212,6 @@ struct dbs_governor {
void (*exit)(struct dbs_data *dbs_data, bool notify);
bool (*invalid_up_threshold)(struct dbs_data *dbs_data, unsigned int threshold);
bool (*invalid_sampling_down_factor)(unsigned int factor);
- void (*update_sampling_rate)(struct dbs_data *dbs_data);
void (*update_sampling_down_factor)(struct dbs_data *dbs_data);
void (*update_ignore_nice_load)(struct dbs_data *dbs_data);
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index f72087bc8302..1e17f6ffdf42 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -221,43 +221,6 @@ static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
/************************** sysfs interface ************************/
static struct dbs_governor od_dbs_gov;
-/**
- * update_sampling_rate - update sampling rate effective immediately if needed.
- * @new_rate: new sampling rate
- */
-static void update_sampling_rate(struct dbs_data *dbs_data)
-{
- struct policy_dbs_info *policy_dbs;
- unsigned int new_rate = dbs_data->sampling_rate;
-
- /*
- * We are operating under dbs_data->mutex and so the list and its
- * entries can't be freed concurrently.
- */
- list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list) {
- mutex_lock(&policy_dbs->timer_mutex);
- /*
- * On 32-bit architectures this may race with the
- * sample_delay_ns read in dbs_update_util_handler(), but that
- * really doesn't matter. If the read returns a value that's
- * too big, the sample will be skipped, but the next invocation
- * of dbs_update_util_handler() (when the update has been
- * completed) will take a sample. If the returned value is too
- * small, the sample will be taken immediately, but that isn't a
- * problem, as we want the new rate to take effect immediately
- * anyway.
- *
- * If this runs in parallel with dbs_work_handler(), we may end
- * up overwriting the sample_delay_ns value that it has just
- * written, but the difference should not be too big and it will
- * be corrected next time a sample is taken, so it shouldn't be
- * significant.
- */
- gov_update_sample_delay(policy_dbs, new_rate);
- mutex_unlock(&policy_dbs->timer_mutex);
- }
-}
-
static bool invalid_up_threshold(struct dbs_data *dbs_data,
unsigned int threshold)
{
@@ -425,7 +388,6 @@ static struct dbs_governor od_dbs_gov = {
.get_cpu_dbs_info_s = get_cpu_dbs_info_s,
.gov_dbs_timer = od_dbs_timer,
.gov_check_cpu = od_check_cpu,
- .update_sampling_rate = update_sampling_rate,
.invalid_up_threshold = invalid_up_threshold,
.invalid_sampling_down_factor = invalid_sampling_down_factor,
.update_sampling_down_factor = update_sampling_down_factor,
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 10/13] cpufreq: governor: No need to manage state machine now |
| Message-ID | <qZSum-4Ei-29@gated-at.bofh.it> |
| In reply to | #1328955 |
cpufreq core now guarantees that policy->rwsem wouldn't get dropped
while calling CPUFREQ_GOV_POLICY_EXIT governor event and will be kept
acquired until the complete sequence of governor state changes has
finished.
And so we can remove the state machine checks that were put in place
earlier.
This also means that policy_dbs->policy can be initialized while
policy_dbs is allocated, to move all initialization together.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_governor.c | 27 +++++----------------------
drivers/cpufreq/cpufreq_ondemand.c | 6 +++---
2 files changed, 8 insertions(+), 25 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 5403f863b14d..ee3c2d92da53 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -332,8 +332,10 @@ static inline void gov_clear_update_util(struct cpufreq_policy *policy)
synchronize_rcu();
}
-static void gov_cancel_work(struct policy_dbs_info *policy_dbs)
+static void gov_cancel_work(struct cpufreq_policy *policy)
{
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+
/* Tell dbs_update_util_handler() to skip queuing up work items. */
atomic_inc(&policy_dbs->skip_work);
/*
@@ -429,6 +431,7 @@ static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *poli
if (!policy_dbs)
return NULL;
+ policy_dbs->policy = policy;
mutex_init(&policy_dbs->timer_mutex);
atomic_set(&policy_dbs->skip_work, 0);
init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
@@ -551,10 +554,6 @@ static int cpufreq_governor_exit(struct cpufreq_policy *policy)
struct policy_dbs_info *policy_dbs = policy->governor_data;
struct dbs_data *dbs_data = policy_dbs->dbs_data;
- /* State should be equivalent to INIT */
- if (policy_dbs->policy)
- return -EBUSY;
-
if (!--dbs_data->usage_count) {
kobject_put(&dbs_data->kobj);
@@ -585,10 +584,6 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
if (!policy->cur)
return -EINVAL;
- /* State should be equivalent to INIT */
- if (policy_dbs->policy)
- return -EBUSY;
-
sampling_rate = dbs_data->sampling_rate;
ignore_nice = dbs_data->ignore_nice_load;
@@ -613,7 +608,6 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
if (ignore_nice)
j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
}
- policy_dbs->policy = policy;
if (gov->governor == GOV_CONSERVATIVE) {
struct cs_cpu_dbs_info_s *cs_dbs_info =
@@ -636,14 +630,7 @@ static int cpufreq_governor_start(struct cpufreq_policy *policy)
static int cpufreq_governor_stop(struct cpufreq_policy *policy)
{
- struct policy_dbs_info *policy_dbs = policy->governor_data;
-
- /* State should be equivalent to START */
- if (!policy_dbs->policy)
- return -EBUSY;
-
- gov_cancel_work(policy_dbs);
- policy_dbs->policy = NULL;
+ gov_cancel_work(policy);
return 0;
}
@@ -652,10 +639,6 @@ static int cpufreq_governor_limits(struct cpufreq_policy *policy)
{
struct policy_dbs_info *policy_dbs = policy->governor_data;
- /* State should be equivalent to START */
- if (!policy_dbs->policy)
- return -EBUSY;
-
mutex_lock(&policy_dbs->timer_mutex);
if (policy->max < policy->cur)
__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index ccc3419d43f3..745290d7f6a2 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -258,10 +258,10 @@ static void update_sampling_rate(struct dbs_data *dbs_data)
policy_dbs = cdbs->policy_dbs;
/*
- * A valid policy_dbs and policy_dbs->policy means governor
- * hasn't stopped or exited yet.
+ * A valid policy_dbs means governor hasn't stopped or exited
+ * yet.
*/
- if (!policy_dbs || !policy_dbs->policy)
+ if (!policy_dbs)
continue;
policy = policy_dbs->policy;
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 04/13] cpufreq: governor: Drop unused macros for creating governor tunable attributes |
| Message-ID | <qZSum-4Ei-25@gated-at.bofh.it> |
| In reply to | #1328955 |
"The previous commit introduced a new set of macros for creating sysfs
attributes that represent governor tunables and the old macros used for
this purpose are not needed any more, so drop them."
[ Rafael: Written changelog ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_governor.h | 89 --------------------------------------
1 file changed, 89 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index a3afac5d8ab2..f164437f235e 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -41,95 +41,6 @@
/* Ondemand Sampling types */
enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};
-/*
- * Macro for creating governors sysfs routines
- *
- * - gov_sys: One governor instance per whole system
- * - gov_pol: One governor instance per policy
- */
-
-/* Create attributes */
-#define gov_sys_attr_ro(_name) \
-static struct global_attr _name##_gov_sys = \
-__ATTR(_name, 0444, show_##_name##_gov_sys, NULL)
-
-#define gov_sys_attr_rw(_name) \
-static struct global_attr _name##_gov_sys = \
-__ATTR(_name, 0644, show_##_name##_gov_sys, store_##_name##_gov_sys)
-
-#define gov_pol_attr_ro(_name) \
-static struct freq_attr _name##_gov_pol = \
-__ATTR(_name, 0444, show_##_name##_gov_pol, NULL)
-
-#define gov_pol_attr_rw(_name) \
-static struct freq_attr _name##_gov_pol = \
-__ATTR(_name, 0644, show_##_name##_gov_pol, store_##_name##_gov_pol)
-
-#define gov_sys_pol_attr_rw(_name) \
- gov_sys_attr_rw(_name); \
- gov_pol_attr_rw(_name)
-
-#define gov_sys_pol_attr_ro(_name) \
- gov_sys_attr_ro(_name); \
- gov_pol_attr_ro(_name)
-
-/* Create show/store routines */
-#define show_one(_gov, file_name) \
-static ssize_t show_##file_name##_gov_sys \
-(struct kobject *kobj, struct attribute *attr, char *buf) \
-{ \
- struct _gov##_dbs_tuners *tuners = _gov##_dbs_gov.gdbs_data->tuners; \
- return sprintf(buf, "%u\n", tuners->file_name); \
-} \
- \
-static ssize_t show_##file_name##_gov_pol \
-(struct cpufreq_policy *policy, char *buf) \
-{ \
- struct policy_dbs_info *policy_dbs = policy->governor_data; \
- struct dbs_data *dbs_data = policy_dbs->dbs_data; \
- struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \
- return sprintf(buf, "%u\n", tuners->file_name); \
-}
-
-#define store_one(_gov, file_name) \
-static ssize_t store_##file_name##_gov_sys \
-(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) \
-{ \
- struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \
- return store_##file_name(dbs_data, buf, count); \
-} \
- \
-static ssize_t store_##file_name##_gov_pol \
-(struct cpufreq_policy *policy, const char *buf, size_t count) \
-{ \
- struct policy_dbs_info *policy_dbs = policy->governor_data; \
- return store_##file_name(policy_dbs->dbs_data, buf, count); \
-}
-
-#define show_store_one(_gov, file_name) \
-show_one(_gov, file_name); \
-store_one(_gov, file_name)
-
-#define show_one_global(_gov, file_name) \
-static ssize_t show_##file_name##_gov_sys \
-(struct kobject *kobj, struct attribute *attr, char *buf) \
-{ \
- struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \
- return sprintf(buf, "%u\n", dbs_data->file_name); \
-} \
- \
-static ssize_t show_##file_name##_gov_pol \
-(struct cpufreq_policy *policy, char *buf) \
-{ \
- struct policy_dbs_info *policy_dbs = policy->governor_data; \
- struct dbs_data *dbs_data = policy_dbs->dbs_data; \
- return sprintf(buf, "%u\n", dbs_data->file_name); \
-}
-
-#define show_store_one_global(_gov, file_name) \
-show_one_global(_gov, file_name); \
-store_one(_gov, file_name)
-
/* create helper routines */
#define define_get_cpu_dbs_routines(_dbs_info) \
static struct cpu_dbs_info *get_cpu_cdbs(int cpu) \
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c |
| Message-ID | <qZSum-4Ei-31@gated-at.bofh.it> |
| In reply to | #1328955 |
We have got five common sysfs tunables between ondemand and conservative
governors, move their callbacks to cpufreq_governor.c to get rid of
redundant code.
Because of minor differences in the implementation of the callbacks,
some more per-governor callbacks are introduced in order to not
introduce any more "governor == ONDEMAND/CONSERVATIVE" like checks.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_conservative.c | 80 +++++---------------------
drivers/cpufreq/cpufreq_governor.c | 100 +++++++++++++++++++++++++++++++++
drivers/cpufreq/cpufreq_governor.h | 16 +++++-
drivers/cpufreq/cpufreq_ondemand.c | 100 ++++++++-------------------------
4 files changed, 151 insertions(+), 145 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 6d45b7e6b43f..f96770dab788 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -122,47 +122,17 @@ static struct notifier_block cs_cpufreq_notifier_block = {
/************************** sysfs interface ************************/
static struct dbs_governor cs_dbs_gov;
-static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
- const char *buf, size_t count)
+static bool invalid_up_threshold(struct dbs_data *dbs_data,
+ unsigned int threshold)
{
- unsigned int input;
- int ret;
- ret = sscanf(buf, "%u", &input);
-
- if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
- return -EINVAL;
+ struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
- dbs_data->sampling_down_factor = input;
- return count;
+ return threshold > 100 || threshold <= cs_tuners->down_threshold;
}
-static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
- size_t count)
+static bool invalid_sampling_down_factor(unsigned int factor)
{
- unsigned int input;
- int ret;
- ret = sscanf(buf, "%u", &input);
-
- if (ret != 1)
- return -EINVAL;
-
- dbs_data->sampling_rate = max(input, dbs_data->min_sampling_rate);
- return count;
-}
-
-static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
- size_t count)
-{
- struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
- unsigned int input;
- int ret;
- ret = sscanf(buf, "%u", &input);
-
- if (ret != 1 || input > 100 || input <= cs_tuners->down_threshold)
- return -EINVAL;
-
- dbs_data->up_threshold = input;
- return count;
+ return factor > MAX_SAMPLING_DOWN_FACTOR;
}
static ssize_t store_down_threshold(struct dbs_data *dbs_data, const char *buf,
@@ -182,27 +152,13 @@ static ssize_t store_down_threshold(struct dbs_data *dbs_data, const char *buf,
return count;
}
-static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
- const char *buf, size_t count)
+static void update_ignore_nice_load(struct dbs_data *dbs_data)
{
- unsigned int input, j;
- int ret;
-
- ret = sscanf(buf, "%u", &input);
- if (ret != 1)
- return -EINVAL;
-
- if (input > 1)
- input = 1;
-
- if (input == dbs_data->ignore_nice_load) /* nothing to do */
- return count;
-
- dbs_data->ignore_nice_load = input;
+ struct cs_cpu_dbs_info_s *dbs_info;
+ unsigned int j;
/* we need to re-evaluate prev_cpu_idle */
for_each_online_cpu(j) {
- struct cs_cpu_dbs_info_s *dbs_info;
dbs_info = &per_cpu(cs_cpu_dbs_info, j);
dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
&dbs_info->cdbs.prev_cpu_wall, 0);
@@ -210,7 +166,6 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
dbs_info->cdbs.prev_cpu_nice =
kcpustat_cpu(j).cpustat[CPUTIME_NICE];
}
- return count;
}
static ssize_t store_freq_step(struct dbs_data *dbs_data, const char *buf,
@@ -235,21 +190,11 @@ static ssize_t store_freq_step(struct dbs_data *dbs_data, const char *buf,
return count;
}
-gov_show_one(sampling_rate);
-gov_show_one(sampling_down_factor);
-gov_show_one(up_threshold);
-gov_show_one(ignore_nice_load);
-gov_show_one(min_sampling_rate);
gov_show_one_tunable(cs, down_threshold);
gov_show_one_tunable(cs, freq_step);
-gov_attr_rw(sampling_rate);
-gov_attr_rw(sampling_down_factor);
-gov_attr_rw(up_threshold);
-gov_attr_rw(ignore_nice_load);
-gov_attr_ro(min_sampling_rate);
-gov_attr_rw(down_threshold);
-gov_attr_rw(freq_step);
+static gov_attr_rw(down_threshold);
+static gov_attr_rw(freq_step);
static struct attribute *cs_attributes[] = {
&min_sampling_rate.attr,
@@ -316,6 +261,9 @@ static struct dbs_governor cs_dbs_gov = {
.get_cpu_dbs_info_s = get_cpu_dbs_info_s,
.gov_dbs_timer = cs_dbs_timer,
.gov_check_cpu = cs_check_cpu,
+ .invalid_up_threshold = invalid_up_threshold,
+ .invalid_sampling_down_factor = invalid_sampling_down_factor,
+ .update_ignore_nice_load = update_ignore_nice_load,
.init = cs_init,
.exit = cs_exit,
};
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index 295732e06354..5403f863b14d 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -25,6 +25,105 @@
DEFINE_MUTEX(dbs_data_mutex);
EXPORT_SYMBOL_GPL(dbs_data_mutex);
+/* Common sysfs tunables */
+static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
+ size_t count)
+{
+ struct dbs_governor *gov = dbs_data->gov;
+ unsigned int rate;
+ int ret;
+ ret = sscanf(buf, "%u", &rate);
+ if (ret != 1)
+ return -EINVAL;
+
+ dbs_data->sampling_rate = max(rate, dbs_data->min_sampling_rate);
+
+ if (gov->update_sampling_rate)
+ gov->update_sampling_rate(dbs_data);
+
+ return count;
+}
+
+static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
+ size_t count)
+{
+ struct dbs_governor *gov = dbs_data->gov;
+ unsigned int input;
+ int ret;
+ ret = sscanf(buf, "%u", &input);
+
+ if (ret != 1 || gov->invalid_up_threshold(dbs_data, input))
+ return -EINVAL;
+
+ dbs_data->up_threshold = input;
+ return count;
+}
+
+static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
+ const char *buf, size_t count)
+{
+ struct dbs_governor *gov = dbs_data->gov;
+ unsigned int input;
+ int ret;
+ ret = sscanf(buf, "%u", &input);
+
+ if (ret != 1 || gov->invalid_sampling_down_factor(input) || input < 1)
+ return -EINVAL;
+
+ dbs_data->sampling_down_factor = input;
+
+ if (gov->update_sampling_down_factor)
+ gov->update_sampling_down_factor(dbs_data);
+
+ return count;
+}
+
+static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
+ const char *buf, size_t count)
+{
+ struct dbs_governor *gov = dbs_data->gov;
+ unsigned int input;
+ int ret;
+
+ ret = sscanf(buf, "%u", &input);
+ if (ret != 1)
+ return -EINVAL;
+
+ if (input > 1)
+ input = 1;
+
+ if (input == dbs_data->ignore_nice_load) { /* nothing to do */
+ return count;
+ }
+
+ dbs_data->ignore_nice_load = input;
+
+ gov->update_ignore_nice_load(dbs_data);
+ return count;
+}
+
+gov_show_one(sampling_rate);
+gov_show_one(up_threshold);
+gov_show_one(sampling_down_factor);
+gov_show_one(ignore_nice_load);
+gov_show_one(min_sampling_rate);
+
+gov_attr_rw(sampling_rate);
+EXPORT_SYMBOL_GPL(sampling_rate);
+
+gov_attr_rw(up_threshold);
+EXPORT_SYMBOL_GPL(up_threshold);
+
+gov_attr_rw(sampling_down_factor);
+EXPORT_SYMBOL_GPL(sampling_down_factor);
+
+gov_attr_rw(ignore_nice_load);
+EXPORT_SYMBOL_GPL(ignore_nice_load);
+
+gov_attr_ro(min_sampling_rate);
+EXPORT_SYMBOL_GPL(min_sampling_rate);
+
+/* Governor routines */
static inline struct dbs_data *to_dbs_data(struct kobject *kobj)
{
return container_of(kobj, struct dbs_data, kobj);
@@ -397,6 +496,7 @@ static int cpufreq_governor_init(struct cpufreq_policy *policy)
}
dbs_data->usage_count = 1;
+ dbs_data->gov = gov;
mutex_init(&dbs_data->mutex);
ret = gov->init(dbs_data, !policy->governor->initialized);
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index 886578b5a4fd..ced34ba5a18d 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -64,6 +64,7 @@ static void *get_cpu_dbs_info_s(int cpu) \
/* Governor demand based switching data (per-policy or global). */
struct dbs_data {
+ struct dbs_governor *gov;
int usage_count;
void *tuners;
unsigned int min_sampling_rate;
@@ -102,13 +103,19 @@ static ssize_t show_##file_name \
}
#define gov_attr_ro(_name) \
-static struct governor_attr _name = \
+struct governor_attr _name = \
__ATTR(_name, 0444, show_##_name, NULL)
#define gov_attr_rw(_name) \
-static struct governor_attr _name = \
+struct governor_attr _name = \
__ATTR(_name, 0644, show_##_name, store_##_name)
+extern struct governor_attr sampling_rate;
+extern struct governor_attr up_threshold;
+extern struct governor_attr sampling_down_factor;
+extern struct governor_attr ignore_nice_load;
+extern struct governor_attr min_sampling_rate;
+
/* Common to all CPUs of a policy */
struct policy_dbs_info {
struct cpufreq_policy *policy;
@@ -198,6 +205,11 @@ struct dbs_governor {
void (*gov_check_cpu)(int cpu, unsigned int load);
int (*init)(struct dbs_data *dbs_data, bool notify);
void (*exit)(struct dbs_data *dbs_data, bool notify);
+ bool (*invalid_up_threshold)(struct dbs_data *dbs_data, unsigned int threshold);
+ bool (*invalid_sampling_down_factor)(unsigned int factor);
+ void (*update_sampling_rate)(struct dbs_data *dbs_data);
+ void (*update_sampling_down_factor)(struct dbs_data *dbs_data);
+ void (*update_ignore_nice_load)(struct dbs_data *dbs_data);
/* Governor specific ops, see below */
void *gov_ops;
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index bf570800fa78..ccc3419d43f3 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -234,15 +234,12 @@ static struct dbs_governor od_dbs_gov;
* reducing the sampling rate, we need to make the new value effective
* immediately.
*/
-static void update_sampling_rate(struct dbs_data *dbs_data,
- unsigned int new_rate)
+static void update_sampling_rate(struct dbs_data *dbs_data)
{
struct cpumask cpumask;
+ unsigned int new_rate = dbs_data->sampling_rate;
int cpu;
- dbs_data->sampling_rate = new_rate = max(new_rate,
- dbs_data->min_sampling_rate);
-
/*
* Lock governor so that governor start/stop can't execute in parallel.
*/
@@ -306,17 +303,16 @@ static void update_sampling_rate(struct dbs_data *dbs_data,
mutex_unlock(&dbs_data_mutex);
}
-static ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,
- size_t count)
+static bool invalid_up_threshold(struct dbs_data *dbs_data,
+ unsigned int threshold)
{
- unsigned int input;
- int ret;
- ret = sscanf(buf, "%u", &input);
- if (ret != 1)
- return -EINVAL;
+ return threshold > MAX_FREQUENCY_UP_THRESHOLD ||
+ threshold < MIN_FREQUENCY_UP_THRESHOLD;
+}
- update_sampling_rate(dbs_data, input);
- return count;
+static bool invalid_sampling_down_factor(unsigned int factor)
+{
+ return factor > MAX_SAMPLING_DOWN_FACTOR;
}
static ssize_t store_io_is_busy(struct dbs_data *dbs_data, const char *buf,
@@ -342,66 +338,22 @@ static ssize_t store_io_is_busy(struct dbs_data *dbs_data, const char *buf,
return count;
}
-static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,
- size_t count)
+static void update_sampling_down_factor(struct dbs_data *dbs_data)
{
- unsigned int input;
- int ret;
- ret = sscanf(buf, "%u", &input);
-
- if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
- input < MIN_FREQUENCY_UP_THRESHOLD) {
- return -EINVAL;
- }
-
- dbs_data->up_threshold = input;
- return count;
-}
-
-static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,
- const char *buf, size_t count)
-{
- unsigned int input, j;
- int ret;
- ret = sscanf(buf, "%u", &input);
-
- if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
- return -EINVAL;
- dbs_data->sampling_down_factor = input;
+ unsigned int j;
/* Reset down sampling multiplier in case it was active */
- for_each_online_cpu(j) {
- struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
- j);
- dbs_info->rate_mult = 1;
- }
- return count;
+ for_each_online_cpu(j)
+ per_cpu(od_cpu_dbs_info, j).rate_mult = 1;
}
-static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
- const char *buf, size_t count)
+static void update_ignore_nice_load(struct dbs_data *dbs_data)
{
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
- unsigned int input;
- int ret;
-
+ struct od_cpu_dbs_info_s *dbs_info;
unsigned int j;
- ret = sscanf(buf, "%u", &input);
- if (ret != 1)
- return -EINVAL;
-
- if (input > 1)
- input = 1;
-
- if (input == dbs_data->ignore_nice_load) { /* nothing to do */
- return count;
- }
- dbs_data->ignore_nice_load = input;
-
- /* we need to re-evaluate prev_cpu_idle */
for_each_online_cpu(j) {
- struct od_cpu_dbs_info_s *dbs_info;
dbs_info = &per_cpu(od_cpu_dbs_info, j);
dbs_info->cdbs.prev_cpu_idle = get_cpu_idle_time(j,
&dbs_info->cdbs.prev_cpu_wall, od_tuners->io_is_busy);
@@ -410,7 +362,6 @@ static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,
kcpustat_cpu(j).cpustat[CPUTIME_NICE];
}
- return count;
}
static ssize_t store_powersave_bias(struct dbs_data *dbs_data, const char *buf,
@@ -432,21 +383,11 @@ static ssize_t store_powersave_bias(struct dbs_data *dbs_data, const char *buf,
return count;
}
-gov_show_one(sampling_rate);
-gov_show_one(up_threshold);
-gov_show_one(sampling_down_factor);
-gov_show_one(ignore_nice_load);
-gov_show_one(min_sampling_rate);
gov_show_one_tunable(od, io_is_busy);
gov_show_one_tunable(od, powersave_bias);
-gov_attr_rw(sampling_rate);
-gov_attr_rw(io_is_busy);
-gov_attr_rw(up_threshold);
-gov_attr_rw(sampling_down_factor);
-gov_attr_rw(ignore_nice_load);
-gov_attr_rw(powersave_bias);
-gov_attr_ro(min_sampling_rate);
+static gov_attr_rw(io_is_busy);
+static gov_attr_rw(powersave_bias);
static struct attribute *od_attributes[] = {
&min_sampling_rate.attr,
@@ -529,6 +470,11 @@ static struct dbs_governor od_dbs_gov = {
.get_cpu_dbs_info_s = get_cpu_dbs_info_s,
.gov_dbs_timer = od_dbs_timer,
.gov_check_cpu = od_check_cpu,
+ .update_sampling_rate = update_sampling_rate,
+ .invalid_up_threshold = invalid_up_threshold,
+ .invalid_sampling_down_factor = invalid_sampling_down_factor,
+ .update_sampling_down_factor = update_sampling_down_factor,
+ .update_ignore_nice_load = update_ignore_nice_load,
.gov_ops = &od_ops,
.init = od_init,
.exit = od_exit,
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2016-02-08 14:00 +0100 |
| Subject | Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c |
| Message-ID | <qZTA6-5ma-11@gated-at.bofh.it> |
| In reply to | #1328963 |
On Mon, Feb 8, 2016 at 12:39 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote: > We have got five common sysfs tunables between ondemand and conservative > governors, move their callbacks to cpufreq_governor.c to get rid of > redundant code. > > Because of minor differences in the implementation of the callbacks, > some more per-governor callbacks are introduced in order to not > introduce any more "governor == ONDEMAND/CONSERVATIVE" like checks. My most fundamental concern here is that attributes that don't apply to a particular governor should not appear in sysfs at all when that governor is in use (instead of appearing and always returning -EINVAL which is sort of silly). That doesn't mean the common code cannot access them, though. They still can be present in the data structure, but it may be a good idea to set them to special values clearly meaning "invalid" then. Thanks, Rafael
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 14:10 +0100 |
| Subject | Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c |
| Message-ID | <qZTJM-5FE-11@gated-at.bofh.it> |
| In reply to | #1329017 |
On 08-02-16, 13:58, Rafael J. Wysocki wrote: > My most fundamental concern here is that attributes that don't apply > to a particular governor should not appear in sysfs at all when that > governor is in use (instead of appearing and always returning -EINVAL s/is in use/is not in use/ ?? > which is sort of silly). But who said that I have made them available always ? Sorry, I didn't understood your input. I have just moved the show/store callbacks and the struct governor_attr definition to cpufreq_governor.c. And sysfs files are created only for the ones that are valid for a governor. > That doesn't mean the common code cannot access them, though. They > still can be present in the data structure, but it may be a good idea > to set them to special values clearly meaning "invalid" then. Or are you saying that we should move all the tunables to dbs_data ? -- viresh
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2016-02-08 14:30 +0100 |
| Subject | Re: [PATCH V3 09/13] cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c |
| Message-ID | <qZU39-5Ph-37@gated-at.bofh.it> |
| In reply to | #1329023 |
On Mon, Feb 8, 2016 at 2:03 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote: > On 08-02-16, 13:58, Rafael J. Wysocki wrote: >> My most fundamental concern here is that attributes that don't apply >> to a particular governor should not appear in sysfs at all when that >> governor is in use (instead of appearing and always returning -EINVAL > > s/is in use/is not in use/ ?? > >> which is sort of silly). > > But who said that I have made them available always ? Sorry, I didn't > understood your input. > > I have just moved the show/store callbacks and the struct > governor_attr definition to cpufreq_governor.c. And sysfs files are > created only for the ones that are valid for a governor. OK, I need to look at it more carefully then. >> That doesn't mean the common code cannot access them, though. They >> still can be present in the data structure, but it may be a good idea >> to set them to special values clearly meaning "invalid" then. > > Or are you saying that we should move all the tunables to dbs_data ? Well, maybe. I'm not sure, but that may be done later in any case. Thanks, Rafael
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 12:50 +0100 |
| Subject | [PATCH V3 01/13] cpufreq: governor: Create generic macro for global tuners |
| Message-ID | <qZSun-4Ei-33@gated-at.bofh.it> |
| In reply to | #1328955 |
Some tunables are present in governor specific structures, whereas one
(min_sampling_rate) is present in global 'struct dbs_data'.
The macro for that is pretty much specific to sampling_rate_min for now.
Next patch would be moving few more tunables to the 'struct dbs_data',
then it would be useful to create a generic macro for such cases.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq_conservative.c | 8 ++++----
drivers/cpufreq/cpufreq_governor.h | 36 +++++++++++++++++++---------------
drivers/cpufreq/cpufreq_ondemand.c | 8 ++++----
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 1a899bb7d1a4..8aaa8a4c2fca 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -245,7 +245,7 @@ show_store_one(cs, up_threshold);
show_store_one(cs, down_threshold);
show_store_one(cs, ignore_nice_load);
show_store_one(cs, freq_step);
-declare_show_sampling_rate_min(cs);
+show_one_global(cs, min_sampling_rate);
gov_sys_pol_attr_rw(sampling_rate);
gov_sys_pol_attr_rw(sampling_down_factor);
@@ -253,10 +253,10 @@ gov_sys_pol_attr_rw(up_threshold);
gov_sys_pol_attr_rw(down_threshold);
gov_sys_pol_attr_rw(ignore_nice_load);
gov_sys_pol_attr_rw(freq_step);
-gov_sys_pol_attr_ro(sampling_rate_min);
+gov_sys_pol_attr_ro(min_sampling_rate);
static struct attribute *dbs_attributes_gov_sys[] = {
- &sampling_rate_min_gov_sys.attr,
+ &min_sampling_rate_gov_sys.attr,
&sampling_rate_gov_sys.attr,
&sampling_down_factor_gov_sys.attr,
&up_threshold_gov_sys.attr,
@@ -272,7 +272,7 @@ static struct attribute_group cs_attr_group_gov_sys = {
};
static struct attribute *dbs_attributes_gov_pol[] = {
- &sampling_rate_min_gov_pol.attr,
+ &min_sampling_rate_gov_pol.attr,
&sampling_rate_gov_pol.attr,
&sampling_down_factor_gov_pol.attr,
&up_threshold_gov_pol.attr,
diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
index 95e6834d36a8..cc9a373b9736 100644
--- a/drivers/cpufreq/cpufreq_governor.h
+++ b/drivers/cpufreq/cpufreq_governor.h
@@ -110,6 +110,26 @@ static ssize_t store_##file_name##_gov_pol \
show_one(_gov, file_name); \
store_one(_gov, file_name)
+#define show_one_global(_gov, file_name) \
+static ssize_t show_##file_name##_gov_sys \
+(struct kobject *kobj, struct attribute *attr, char *buf) \
+{ \
+ struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \
+ return sprintf(buf, "%u\n", dbs_data->file_name); \
+} \
+ \
+static ssize_t show_##file_name##_gov_pol \
+(struct cpufreq_policy *policy, char *buf) \
+{ \
+ struct policy_dbs_info *policy_dbs = policy->governor_data; \
+ struct dbs_data *dbs_data = policy_dbs->dbs_data; \
+ return sprintf(buf, "%u\n", dbs_data->file_name); \
+}
+
+#define show_store_one_global(_gov, file_name) \
+show_one_global(_gov, file_name); \
+store_one(_gov, file_name)
+
/* create helper routines */
#define define_get_cpu_dbs_routines(_dbs_info) \
static struct cpu_dbs_info *get_cpu_cdbs(int cpu) \
@@ -264,22 +284,6 @@ static inline int delay_for_sampling_rate(unsigned int sampling_rate)
return delay;
}
-#define declare_show_sampling_rate_min(_gov) \
-static ssize_t show_sampling_rate_min_gov_sys \
-(struct kobject *kobj, struct attribute *attr, char *buf) \
-{ \
- struct dbs_data *dbs_data = _gov##_dbs_gov.gdbs_data; \
- return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \
-} \
- \
-static ssize_t show_sampling_rate_min_gov_pol \
-(struct cpufreq_policy *policy, char *buf) \
-{ \
- struct policy_dbs_info *policy_dbs = policy->governor_data; \
- struct dbs_data *dbs_data = policy_dbs->dbs_data; \
- return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \
-}
-
extern struct mutex dbs_data_mutex;
extern struct mutex cpufreq_governor_lock;
void dbs_check_cpu(struct cpufreq_policy *policy);
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index b7ef2e7f4d4a..2a71a6755998 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -443,7 +443,7 @@ show_store_one(od, up_threshold);
show_store_one(od, sampling_down_factor);
show_store_one(od, ignore_nice_load);
show_store_one(od, powersave_bias);
-declare_show_sampling_rate_min(od);
+show_one_global(od, min_sampling_rate);
gov_sys_pol_attr_rw(sampling_rate);
gov_sys_pol_attr_rw(io_is_busy);
@@ -451,10 +451,10 @@ gov_sys_pol_attr_rw(up_threshold);
gov_sys_pol_attr_rw(sampling_down_factor);
gov_sys_pol_attr_rw(ignore_nice_load);
gov_sys_pol_attr_rw(powersave_bias);
-gov_sys_pol_attr_ro(sampling_rate_min);
+gov_sys_pol_attr_ro(min_sampling_rate);
static struct attribute *dbs_attributes_gov_sys[] = {
- &sampling_rate_min_gov_sys.attr,
+ &min_sampling_rate_gov_sys.attr,
&sampling_rate_gov_sys.attr,
&up_threshold_gov_sys.attr,
&sampling_down_factor_gov_sys.attr,
@@ -470,7 +470,7 @@ static struct attribute_group od_attr_group_gov_sys = {
};
static struct attribute *dbs_attributes_gov_pol[] = {
- &sampling_rate_min_gov_pol.attr,
+ &min_sampling_rate_gov_pol.attr,
&sampling_rate_gov_pol.attr,
&up_threshold_gov_pol.attr,
&sampling_down_factor_gov_pol.attr,
--
2.7.1.370.gb2aa7f8
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2016-02-08 17:40 +0100 |
| Subject | Re: [PATCH V3 01/13] cpufreq: governor: Create generic macro for global tuners |
| Message-ID | <qZX10-7Mz-19@gated-at.bofh.it> |
| In reply to | #1328964 |
On Mon, Feb 8, 2016 at 12:39 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote: > Some tunables are present in governor specific structures, whereas one > (min_sampling_rate) is present in global 'struct dbs_data'. To me, the word "global" is not the best one to express that. "Common" would probably be better. Or "generic" or similar. It's just that these tunables apply to both governors (or "all" governors if you will) as opposed to some other ones specific to a particular governor type. So I'd suggest replacing "global" with "common" in the patch in the names of the macros too. Thanks, Rafael
[toc] | [prev] | [next] | [standalone]
| From | Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-02-08 14:00 +0100 |
| Message-ID | <qZTA5-5ma-3@gated-at.bofh.it> |
| In reply to | #1328955 |
Hi, On 02/08/2016 05:09 PM, Viresh Kumar wrote: > Hi Rafael, > > Things look much much better now. I have rebased this series over > pm/bleeding-edge, that has all your patches. > > I have moved ahead and done few more changes in this series, that should > get rid of all the lockdeps we were getting earlier, that includes > fixing lockdep issue in update_sampling_rate() that we were chasing. > > These are pushed here again: > git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject > > @Juri/Shilpa: Can you please confirm if all the issues got resolved now > ? I have tested this patchset on Power8 box and did not find any lockdep warnings. Thanks and Regards, Shilpa
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 14:00 +0100 |
| Message-ID | <qZTA6-5ma-23@gated-at.bofh.it> |
| In reply to | #1329013 |
On 08-02-16, 18:21, Shilpasri G Bhat wrote: > Hi, > > On 02/08/2016 05:09 PM, Viresh Kumar wrote: > > Hi Rafael, > > > > Things look much much better now. I have rebased this series over > > pm/bleeding-edge, that has all your patches. > > > > I have moved ahead and done few more changes in this series, that should > > get rid of all the lockdeps we were getting earlier, that includes > > fixing lockdep issue in update_sampling_rate() that we were chasing. > > > > These are pushed here again: > > git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject > > > > @Juri/Shilpa: Can you please confirm if all the issues got resolved now > > ? > > I have tested this patchset on Power8 box and did not find any lockdep warnings. Awesome news Shilpa. Thanks a lot for helping us out :) -- viresh
[toc] | [prev] | [next] | [standalone]
| From | Juri Lelli <juri.lelli@arm.com> |
|---|---|
| Date | 2016-02-08 17:40 +0100 |
| Message-ID | <qZX10-7Mz-15@gated-at.bofh.it> |
| In reply to | #1329019 |
Hi, On 08/02/16 18:24, Viresh Kumar wrote: > On 08-02-16, 18:21, Shilpasri G Bhat wrote: > > Hi, > > > > On 02/08/2016 05:09 PM, Viresh Kumar wrote: > > > Hi Rafael, > > > > > > Things look much much better now. I have rebased this series over > > > pm/bleeding-edge, that has all your patches. > > > > > > I have moved ahead and done few more changes in this series, that should > > > get rid of all the lockdeps we were getting earlier, that includes > > > fixing lockdep issue in update_sampling_rate() that we were chasing. > > > > > > These are pushed here again: > > > git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject > > > > > > @Juri/Shilpa: Can you please confirm if all the issues got resolved now > > > ? > > > > I have tested this patchset on Power8 box and did not find any lockdep warnings. > Everything looks good on TC2/Juno as well :). Best, - Juri
[toc] | [prev] | [next] | [standalone]
| From | Viresh Kumar <viresh.kumar@linaro.org> |
|---|---|
| Date | 2016-02-08 18:00 +0100 |
| Message-ID | <qZXkm-7Uw-19@gated-at.bofh.it> |
| In reply to | #1329282 |
On 08-02-16, 16:39, Juri Lelli wrote: > Hi, > > On 08/02/16 18:24, Viresh Kumar wrote: > > On 08-02-16, 18:21, Shilpasri G Bhat wrote: > > > Hi, > > > > > > On 02/08/2016 05:09 PM, Viresh Kumar wrote: > > > > Hi Rafael, > > > > > > > > Things look much much better now. I have rebased this series over > > > > pm/bleeding-edge, that has all your patches. > > > > > > > > I have moved ahead and done few more changes in this series, that should > > > > get rid of all the lockdeps we were getting earlier, that includes > > > > fixing lockdep issue in update_sampling_rate() that we were chasing. > > > > > > > > These are pushed here again: > > > > git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject > > > > > > > > @Juri/Shilpa: Can you please confirm if all the issues got resolved now > > > > ? > > > > > > I have tested this patchset on Power8 box and did not find any lockdep warnings. > > > > Everything looks good on TC2/Juno as well :). Yeah, we finally solved the puzzle :) -- viresh
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2016-02-08 22:50 +0100 |
| Message-ID | <r01R2-2zw-31@gated-at.bofh.it> |
| In reply to | #1328955 |
Hi, On Mon, Feb 8, 2016 at 12:39 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote: > Hi Rafael, > > Things look much much better now. I have rebased this series over > pm/bleeding-edge, that has all your patches. > > I have moved ahead and done few more changes in this series, that should > get rid of all the lockdeps we were getting earlier, that includes > fixing lockdep issue in update_sampling_rate() that we were chasing. > > These are pushed here again: > git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/governor-kobject > > @Juri/Shilpa: Can you please confirm if all the issues got resolved now > ? > > V2->V3: > - The first patch from V2, that was moving min_sampling_rate to > per governor structure was dropped, as you suggested. > - Also, I have moved common tunables to struct dbs_data now, which you > also suggested sometime back. > - Last 5 patches are all new and fix rest of the issues we were facing. > > -- > viresh > > Viresh Kumar (13): > cpufreq: governor: Create generic macro for global tuners > cpufreq: governor: Move common tunables to 'struct dbs_data' > cpufreq: governor: New sysfs show/store callbacks for governor > tunables > cpufreq: governor: Drop unused macros for creating governor tunable > attributes > Revert "cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT" > cpufreq: Merge cpufreq_offline_prepare/finish routines > cpufreq: Call __cpufreq_governor() with policy->rwsem held > cpufreq: Remove cpufreq_governor_lock > cpufreq: governor: Move common sysfs tunables to cpufreq_governor.c > cpufreq: governor: No need to manage state machine now > cpufreq: governor: Keep list of policy_dbs within dbs_data > cpufreq: ondemand: Traverse list of policy_dbs in > update_sampling_rate() > cpufreq: conservative: Update sample_delay_ns immediately This is OK overall, but we'll need to reorder it somewhat. I have reviewed patches [1-5,12/13]. Where I didn't send comments, I had none. In my opinion, those 6 patches should go in first. At least I don't see why [12/13] cannot be reworked on top of [1-5/13]. If there is any fundamental reason, please let me know what it is. Otherwise, please first send new versions of those 6 patches, preferably as a new series. The rest of the patchset will require more review time, so please send them again later, when you're done with the first item. Thanks, Rafael
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web