Skip to content

Commit

Permalink
cpufreq: Support per-policy performance boost
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jie Zhan authored and Rafael J. Wysocki committed Aug 29, 2023
1 parent 4c2fdf7 commit 218a06a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions drivers/cpufreq/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void cpufreq_governor_limits(struct cpufreq_policy *policy);
static int cpufreq_set_policy(struct cpufreq_policy *policy,
struct cpufreq_governor *new_gov,
unsigned int new_pol);
static bool cpufreq_boost_supported(void);

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

static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf)
{
return sysfs_emit(buf, "%d\n", policy->boost_enabled);
}

static ssize_t store_local_boost(struct cpufreq_policy *policy,
const char *buf, size_t count)
{
int ret, enable;

ret = kstrtoint(buf, 10, &enable);
if (ret || enable < 0 || enable > 1)
return -EINVAL;

if (!cpufreq_driver->boost_enabled)
return -EINVAL;

if (policy->boost_enabled == enable)
return count;

cpus_read_lock();
ret = cpufreq_driver->set_boost(policy, enable);
cpus_read_unlock();

if (ret)
return ret;

policy->boost_enabled = enable;

return count;
}

static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);

static struct cpufreq_governor *find_governor(const char *str_governor)
{
struct cpufreq_governor *t;
Expand Down Expand Up @@ -1057,6 +1092,12 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
return ret;
}

if (cpufreq_boost_supported()) {
ret = sysfs_create_file(&policy->kobj, &local_boost.attr);
if (ret)
return ret;
}

return 0;
}

Expand Down Expand Up @@ -2718,6 +2759,8 @@ int cpufreq_boost_trigger_state(int state)
ret = cpufreq_driver->set_boost(policy, state);
if (ret)
goto err_reset_state;

policy->boost_enabled = state;
}
cpus_read_unlock();

Expand Down
3 changes: 3 additions & 0 deletions include/linux/cpufreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ struct cpufreq_policy {
*/
bool dvfs_possible_from_any_cpu;

/* Per policy boost enabled flag. */
bool boost_enabled;

/* Cached frequency lookup from cpufreq_driver_resolve_freq. */
unsigned int cached_target_freq;
unsigned int cached_resolved_idx;
Expand Down

0 comments on commit 218a06a

Please sign in to comment.