From 7d1e74f709a0b88b27124bad1735d3f0dcedce7e Mon Sep 17 00:00:00 2001 From: Rishabh Bhatnagar Date: Tue, 24 Aug 2021 10:45:35 -0700 Subject: [PATCH] sched/walt: Improve the scheduler This change is for general scheduler improvement. Change-Id: I6f953cd04ada8ccb36bbf1e2fe341375092b35c4 Signed-off-by: Rishabh Bhatnagar --- kernel/sched/walt/cpufreq_walt.c | 53 ++++++++++++++++++++++++++++++-- kernel/sched/walt/trace.h | 9 ++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/kernel/sched/walt/cpufreq_walt.c b/kernel/sched/walt/cpufreq_walt.c index 53b477fcbce0..f13b9969bb46 100644 --- a/kernel/sched/walt/cpufreq_walt.c +++ b/kernel/sched/walt/cpufreq_walt.c @@ -22,6 +22,8 @@ struct waltgov_tunables { unsigned int hispeed_load; unsigned int hispeed_freq; unsigned int rtg_boost_freq; + unsigned int adaptive_min_freq; + unsigned int adaptive_max_freq; bool pl; int boost; }; @@ -215,10 +217,19 @@ static unsigned int get_next_freq(struct waltgov_policy *wg_policy, struct waltgov_cpu *wg_cpu) { struct cpufreq_policy *policy = wg_policy->policy; - unsigned int freq = policy->cpuinfo.max_freq; + unsigned int freq, raw_freq; - freq = walt_map_util_freq(util, freq, max, wg_cpu->cpu); - trace_waltgov_next_freq(policy->cpu, util, max, freq, policy->min, policy->max, + raw_freq = walt_map_util_freq(util, policy->cpuinfo.max_freq, max, wg_cpu->cpu); + freq = raw_freq; + + if (wg_policy->tunables->adaptive_max_freq) { + if (raw_freq < wg_policy->tunables->adaptive_min_freq) + freq = wg_policy->tunables->adaptive_min_freq; + else if (raw_freq <= wg_policy->tunables->adaptive_max_freq) + freq = wg_policy->tunables->adaptive_max_freq; + } + + trace_waltgov_next_freq(policy->cpu, util, max, raw_freq, freq, policy->min, policy->max, wg_policy->cached_raw_freq, wg_policy->need_freq_update); if (freq == wg_policy->cached_raw_freq && !wg_policy->need_freq_update) @@ -608,11 +619,41 @@ static ssize_t boost_store(struct gov_attr_set *attr_set, const char *buf, return count; } +#define WALTGOV_ATTR_RW(_name) \ +static struct governor_attr _name = \ +__ATTR(_name, 0644, show_##_name, store_##_name) \ + +#define show_attr(name) \ +static ssize_t show_##name(struct gov_attr_set *attr_set, char *buf) \ +{ \ + struct waltgov_tunables *tunables = to_waltgov_tunables(attr_set); \ + return scnprintf(buf, PAGE_SIZE, "%lu\n", tunables->name); \ +} \ + +#define store_attr(name) \ +static ssize_t store_##name(struct gov_attr_set *attr_set, \ + const char *buf, size_t count) \ +{ \ + struct waltgov_tunables *tunables = to_waltgov_tunables(attr_set); \ + \ + if (kstrtouint(buf, 10, &tunables->name)) \ + return -EINVAL; \ + \ + return count; \ +} \ + +show_attr(adaptive_min_freq); +store_attr(adaptive_min_freq); +show_attr(adaptive_max_freq); +store_attr(adaptive_max_freq); + static struct governor_attr hispeed_load = __ATTR_RW(hispeed_load); static struct governor_attr hispeed_freq = __ATTR_RW(hispeed_freq); static struct governor_attr rtg_boost_freq = __ATTR_RW(rtg_boost_freq); static struct governor_attr pl = __ATTR_RW(pl); static struct governor_attr boost = __ATTR_RW(boost); +WALTGOV_ATTR_RW(adaptive_min_freq); +WALTGOV_ATTR_RW(adaptive_max_freq); static struct attribute *waltgov_attributes[] = { &up_rate_limit_us.attr, @@ -622,6 +663,8 @@ static struct attribute *waltgov_attributes[] = { &rtg_boost_freq.attr, &pl.attr, &boost.attr, + &adaptive_min_freq.attr, + &adaptive_max_freq.attr, NULL }; @@ -723,6 +766,8 @@ static void waltgov_tunables_save(struct cpufreq_policy *policy, cached->up_rate_limit_us = tunables->up_rate_limit_us; cached->down_rate_limit_us = tunables->down_rate_limit_us; cached->boost = tunables->boost; + cached->adaptive_min_freq = tunables->adaptive_min_freq; + cached->adaptive_max_freq = tunables->adaptive_max_freq; } static void waltgov_tunables_restore(struct cpufreq_policy *policy) @@ -741,6 +786,8 @@ static void waltgov_tunables_restore(struct cpufreq_policy *policy) tunables->up_rate_limit_us = cached->up_rate_limit_us; tunables->down_rate_limit_us = cached->down_rate_limit_us; tunables->boost = cached->boost; + tunables->adaptive_min_freq = cached->adaptive_min_freq; + tunables->adaptive_max_freq = cached->adaptive_max_freq; } static int waltgov_init(struct cpufreq_policy *policy) diff --git a/kernel/sched/walt/trace.h b/kernel/sched/walt/trace.h index 19cd65690f62..eeb9af0aac80 100644 --- a/kernel/sched/walt/trace.h +++ b/kernel/sched/walt/trace.h @@ -693,15 +693,16 @@ TRACE_EVENT(waltgov_util_update, ); TRACE_EVENT(waltgov_next_freq, - TP_PROTO(unsigned int cpu, unsigned long util, unsigned long max, + TP_PROTO(unsigned int cpu, unsigned long util, unsigned long max, unsigned int raw_freq, unsigned int freq, unsigned int policy_min_freq, unsigned int policy_max_freq, unsigned int cached_raw_freq, bool need_freq_update), - TP_ARGS(cpu, util, max, freq, policy_min_freq, policy_max_freq, + TP_ARGS(cpu, util, max, raw_freq, freq, policy_min_freq, policy_max_freq, cached_raw_freq, need_freq_update), TP_STRUCT__entry( __field(unsigned int, cpu) __field(unsigned long, util) __field(unsigned long, max) + __field(unsigned int, raw_freq) __field(unsigned int, freq) __field(unsigned int, policy_min_freq) __field(unsigned int, policy_max_freq) @@ -713,6 +714,7 @@ TRACE_EVENT(waltgov_next_freq, __entry->cpu = cpu; __entry->util = util; __entry->max = max; + __entry->raw_freq = raw_freq; __entry->freq = freq; __entry->policy_min_freq = policy_min_freq; __entry->policy_max_freq = policy_max_freq; @@ -720,10 +722,11 @@ TRACE_EVENT(waltgov_next_freq, __entry->need_freq_update = need_freq_update; __entry->rt_util = cpu_util_rt(cpu_rq(cpu)); ), - TP_printk("cpu=%u util=%lu max=%lu freq=%u policy_min_freq=%u policy_max_freq=%u cached_raw_freq=%u need_update=%d rt_util=%u", + TP_printk("cpu=%u util=%lu max=%lu raw_freq=%lu freq=%u policy_min_freq=%u policy_max_freq=%u cached_raw_freq=%u need_update=%d rt_util=%u", __entry->cpu, __entry->util, __entry->max, + __entry->raw_freq, __entry->freq, __entry->policy_min_freq, __entry->policy_max_freq,