Skip to content

Commit cf6fada

Browse files
fenghusthurafaeljw
authored andcommitted
cpufreq: change '.set_boost' to act on one policy
Macro 'for_each_active_policy()' is defined internally. To avoid some cpufreq driver needing this macro to iterate over all the policies in '.set_boost' callback, we redefine '.set_boost' to act on only one policy and pass the policy as an argument. 'cpufreq_boost_trigger_state()' iterates over all the policies to set boost for the system. This is preparation for adding SW BOOST support for CPPC. To protect Boost enable/disable by sysfs from CPU online/offline, add 'cpu_hotplug_lock' before calling '.set_boost' for each CPU. Also move the lock from 'set_boost()' to 'store_cpb()' in acpi_cpufreq. Signed-off-by: Xiongfeng Wang <[email protected]> Suggested-by: Viresh Kumar <[email protected]> Acked-by: Viresh Kumar <[email protected]> [ rjw: Subject & changelog ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 73e5f9c commit cf6fada

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ static void boost_set_msr_each(void *p_en)
126126
boost_set_msr(enable);
127127
}
128128

129-
static int set_boost(int val)
129+
static int set_boost(struct cpufreq_policy *policy, int val)
130130
{
131-
get_online_cpus();
132-
on_each_cpu(boost_set_msr_each, (void *)(long)val, 1);
133-
put_online_cpus();
134-
pr_debug("Core Boosting %sabled.\n", val ? "en" : "dis");
131+
on_each_cpu_mask(policy->cpus, boost_set_msr_each,
132+
(void *)(long)val, 1);
133+
pr_debug("CPU %*pbl: Core Boosting %sabled.\n",
134+
cpumask_pr_args(policy->cpus), val ? "en" : "dis");
135135

136136
return 0;
137137
}
@@ -162,7 +162,9 @@ static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf,
162162
if (ret || val > 1)
163163
return -EINVAL;
164164

165-
set_boost(val);
165+
get_online_cpus();
166+
set_boost(policy, val);
167+
put_online_cpus();
166168

167169
return count;
168170
}

drivers/cpufreq/cpufreq.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,34 +2532,29 @@ EXPORT_SYMBOL_GPL(cpufreq_update_limits);
25322532
/*********************************************************************
25332533
* BOOST *
25342534
*********************************************************************/
2535-
static int cpufreq_boost_set_sw(int state)
2535+
static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
25362536
{
2537-
struct cpufreq_policy *policy;
2538-
2539-
for_each_active_policy(policy) {
2540-
int ret;
2537+
int ret;
25412538

2542-
if (!policy->freq_table)
2543-
return -ENXIO;
2539+
if (!policy->freq_table)
2540+
return -ENXIO;
25442541

2545-
ret = cpufreq_frequency_table_cpuinfo(policy,
2546-
policy->freq_table);
2547-
if (ret) {
2548-
pr_err("%s: Policy frequency update failed\n",
2549-
__func__);
2550-
return ret;
2551-
}
2552-
2553-
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2554-
if (ret < 0)
2555-
return ret;
2542+
ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
2543+
if (ret) {
2544+
pr_err("%s: Policy frequency update failed\n", __func__);
2545+
return ret;
25562546
}
25572547

2548+
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2549+
if (ret < 0)
2550+
return ret;
2551+
25582552
return 0;
25592553
}
25602554

25612555
int cpufreq_boost_trigger_state(int state)
25622556
{
2557+
struct cpufreq_policy *policy;
25632558
unsigned long flags;
25642559
int ret = 0;
25652560

@@ -2570,15 +2565,25 @@ int cpufreq_boost_trigger_state(int state)
25702565
cpufreq_driver->boost_enabled = state;
25712566
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
25722567

2573-
ret = cpufreq_driver->set_boost(state);
2574-
if (ret) {
2575-
write_lock_irqsave(&cpufreq_driver_lock, flags);
2576-
cpufreq_driver->boost_enabled = !state;
2577-
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2578-
2579-
pr_err("%s: Cannot %s BOOST\n",
2580-
__func__, state ? "enable" : "disable");
2568+
get_online_cpus();
2569+
for_each_active_policy(policy) {
2570+
ret = cpufreq_driver->set_boost(policy, state);
2571+
if (ret)
2572+
goto err_reset_state;
25812573
}
2574+
put_online_cpus();
2575+
2576+
return 0;
2577+
2578+
err_reset_state:
2579+
put_online_cpus();
2580+
2581+
write_lock_irqsave(&cpufreq_driver_lock, flags);
2582+
cpufreq_driver->boost_enabled = !state;
2583+
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2584+
2585+
pr_err("%s: Cannot %s BOOST\n",
2586+
__func__, state ? "enable" : "disable");
25822587

25832588
return ret;
25842589
}

include/linux/cpufreq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ struct cpufreq_driver {
367367

368368
/* platform specific boost support code */
369369
bool boost_enabled;
370-
int (*set_boost)(int state);
370+
int (*set_boost)(struct cpufreq_policy *policy, int state);
371371
};
372372

373373
/* flags */

0 commit comments

Comments
 (0)