Skip to content

Commit 218a06a

Browse files
Jie Zhanrafaeljw
authored andcommitted
cpufreq: Support per-policy performance boost
The boost control currently applies to the whole system. However, users may prefer to boost a subset of cores in order to provide prioritized performance to workloads running on the boosted cores. Enable per-policy boost by adding a 'boost' sysfs interface under each policy path. This can be found at: /sys/devices/system/cpu/cpufreq/policy<*>/boost Same to the global boost switch, writing 1/0 to the per-policy 'boost' enables/disables boost on a cpufreq policy respectively. The user view of global and per-policy boost controls should be: 1. Enabling global boost initially enables boost on all policies, and per-policy boost can then be enabled or disabled individually, given that the platform does support so. 2. Disabling global boost makes the per-policy boost interface illegal. Signed-off-by: Jie Zhan <zhanjie9@hisilicon.com> Reviewed-by: Wei Xu <xuwei5@hisilicon.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 4c2fdf7 commit 218a06a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static void cpufreq_governor_limits(struct cpufreq_policy *policy);
8686
static int cpufreq_set_policy(struct cpufreq_policy *policy,
8787
struct cpufreq_governor *new_gov,
8888
unsigned int new_pol);
89+
static bool cpufreq_boost_supported(void);
8990

9091
/*
9192
* Two notifier lists: the "policy" list is involved in the
@@ -623,6 +624,40 @@ static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr,
623624
}
624625
define_one_global_rw(boost);
625626

627+
static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf)
628+
{
629+
return sysfs_emit(buf, "%d\n", policy->boost_enabled);
630+
}
631+
632+
static ssize_t store_local_boost(struct cpufreq_policy *policy,
633+
const char *buf, size_t count)
634+
{
635+
int ret, enable;
636+
637+
ret = kstrtoint(buf, 10, &enable);
638+
if (ret || enable < 0 || enable > 1)
639+
return -EINVAL;
640+
641+
if (!cpufreq_driver->boost_enabled)
642+
return -EINVAL;
643+
644+
if (policy->boost_enabled == enable)
645+
return count;
646+
647+
cpus_read_lock();
648+
ret = cpufreq_driver->set_boost(policy, enable);
649+
cpus_read_unlock();
650+
651+
if (ret)
652+
return ret;
653+
654+
policy->boost_enabled = enable;
655+
656+
return count;
657+
}
658+
659+
static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);
660+
626661
static struct cpufreq_governor *find_governor(const char *str_governor)
627662
{
628663
struct cpufreq_governor *t;
@@ -1057,6 +1092,12 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
10571092
return ret;
10581093
}
10591094

1095+
if (cpufreq_boost_supported()) {
1096+
ret = sysfs_create_file(&policy->kobj, &local_boost.attr);
1097+
if (ret)
1098+
return ret;
1099+
}
1100+
10601101
return 0;
10611102
}
10621103

@@ -2718,6 +2759,8 @@ int cpufreq_boost_trigger_state(int state)
27182759
ret = cpufreq_driver->set_boost(policy, state);
27192760
if (ret)
27202761
goto err_reset_state;
2762+
2763+
policy->boost_enabled = state;
27212764
}
27222765
cpus_read_unlock();
27232766

include/linux/cpufreq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ struct cpufreq_policy {
141141
*/
142142
bool dvfs_possible_from_any_cpu;
143143

144+
/* Per policy boost enabled flag. */
145+
bool boost_enabled;
146+
144147
/* Cached frequency lookup from cpufreq_driver_resolve_freq. */
145148
unsigned int cached_target_freq;
146149
unsigned int cached_resolved_idx;

0 commit comments

Comments
 (0)