From 4e8841e155560026d620542d4307a8a95915a68b Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Tue, 13 Sep 2022 10:11:17 +0800 Subject: [PATCH] sched: cpufreq_schedutil: add attribute for change target_load Default target_load is 80% and change it by the follow command: echo 65 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/target_load Change-Id: Icb02c36eab345a3f2e2d065fba76fdc015f47fa4 Signed-off-by: Liang Chen --- kernel/sched/cpufreq_schedutil.c | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index b365895c2e2e..26cf3c3d7032 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -19,6 +19,9 @@ struct sugov_tunables { struct gov_attr_set attr_set; unsigned int rate_limit_us; +#ifdef CONFIG_ARCH_ROCKCHIP + unsigned int target_load; +#endif }; struct sugov_policy { @@ -170,7 +173,11 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, if (next_freq) freq = next_freq; else +#ifdef CONFIG_ARCH_ROCKCHIP + freq = div64_ul((u64)(100 * freq / sg_policy->tunables->target_load) * util, max); +#else freq = map_util_freq(util, freq, max); +#endif if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) return sg_policy->next_freq; @@ -612,8 +619,39 @@ rate_limit_us_store(struct gov_attr_set *attr_set, const char *buf, size_t count static struct governor_attr rate_limit_us = __ATTR_RW(rate_limit_us); +#ifdef CONFIG_ARCH_ROCKCHIP +static ssize_t target_load_show(struct gov_attr_set *attr_set, char *buf) +{ + struct sugov_tunables *tunables = to_sugov_tunables(attr_set); + + return sprintf(buf, "%u\n", tunables->target_load); +} + +static ssize_t +target_load_store(struct gov_attr_set *attr_set, const char *buf, size_t count) +{ + struct sugov_tunables *tunables = to_sugov_tunables(attr_set); + unsigned int target_load; + + if (kstrtouint(buf, 10, &target_load)) + return -EINVAL; + + if (!target_load || (target_load > 100)) + return -EINVAL; + + tunables->target_load = target_load; + + return count; +} + +static struct governor_attr target_load = __ATTR_RW(target_load); +#endif + static struct attribute *sugov_attrs[] = { &rate_limit_us.attr, +#ifdef CONFIG_ARCH_ROCKCHIP + &target_load.attr, +#endif NULL }; ATTRIBUTE_GROUPS(sugov); @@ -777,6 +815,9 @@ static int sugov_init(struct cpufreq_policy *policy) } tunables->rate_limit_us = cpufreq_policy_transition_delay_us(policy); +#ifdef CONFIG_ARCH_ROCKCHIP + tunables->target_load = 80; +#endif policy->governor_data = sg_policy; sg_policy->tunables = tunables;