Skip to content

Commit

Permalink
sched/cpufreq_schedutil: create a function for common steps
Browse files Browse the repository at this point in the history
There are many callsites that do exactly same steps as

hs_util = freq_to_util(sg_policy,
		sg_policy->tunables->hispeed_freq);
hs_util = mult_frac(hs_util, TARGET_LOAD, 100);

Capture them in a function and change all callsites to use it.

Change-Id: Ie7138de7942c51027309101eb6429208a711da74
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
[render: minor fixups]
Signed-off-by: Zachariah Kennedy <zkennedy87@gmail.com>
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: mcdofrenchfreis <xyzevan@androidist.net>
  • Loading branch information
Abhijeet Dharmapurikar authored and mizdrake7 committed Mar 14, 2024
1 parent 4e1f00b commit 3232441
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions kernel/sched/cpufreq_schedutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ static void sugov_walt_adjust(struct sugov_cpu *sg_cpu, unsigned long *util,
}
}

static inline unsigned long target_util(struct sugov_policy *sg_policy,
unsigned int freq)
{
unsigned long util;

util = freq_to_util(sg_policy, freq);
util = mult_frac(util, TARGET_LOAD, 100);
return util;
}

static void sugov_update_single(struct update_util_data *hook, u64 time,
unsigned int flags)
{
Expand Down Expand Up @@ -491,14 +501,12 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
sugov_get_util(&util, &max, sg_cpu->cpu, time);
if (sg_policy->max != max) {
sg_policy->max = max;
hs_util = freq_to_util(sg_policy,
hs_util = target_util(sg_policy,
sg_policy->tunables->hispeed_freq);
hs_util = mult_frac(hs_util, TARGET_LOAD, 100);
sg_policy->hispeed_util = hs_util;

boost_util = freq_to_util(sg_policy,
boost_util = target_util(sg_policy,
sg_policy->tunables->rtg_boost_freq);
boost_util = mult_frac(boost_util, TARGET_LOAD, 100);
sg_policy->rtg_boost_util = boost_util;
}

Expand Down Expand Up @@ -598,14 +606,12 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,

if (sg_policy->max != max) {
sg_policy->max = max;
hs_util = freq_to_util(sg_policy,
hs_util = target_util(sg_policy,
sg_policy->tunables->hispeed_freq);
hs_util = mult_frac(hs_util, TARGET_LOAD, 100);
sg_policy->hispeed_util = hs_util;

boost_util = freq_to_util(sg_policy,
boost_util = target_util(sg_policy,
sg_policy->tunables->rtg_boost_freq);
boost_util = mult_frac(boost_util, TARGET_LOAD, 100);
sg_policy->rtg_boost_util = boost_util;
}

Expand Down Expand Up @@ -791,9 +797,8 @@ static ssize_t hispeed_freq_store(struct gov_attr_set *attr_set,
tunables->hispeed_freq = val;
list_for_each_entry(sg_policy, &attr_set->policy_list, tunables_hook) {
raw_spin_lock_irqsave(&sg_policy->update_lock, flags);
hs_util = freq_to_util(sg_policy,
hs_util = target_util(sg_policy,
sg_policy->tunables->hispeed_freq);
hs_util = mult_frac(hs_util, TARGET_LOAD, 100);
sg_policy->hispeed_util = hs_util;
raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags);
}
Expand Down Expand Up @@ -823,9 +828,8 @@ static ssize_t rtg_boost_freq_store(struct gov_attr_set *attr_set,
tunables->rtg_boost_freq = val;
list_for_each_entry(sg_policy, &attr_set->policy_list, tunables_hook) {
raw_spin_lock_irqsave(&sg_policy->update_lock, flags);
boost_util = freq_to_util(sg_policy,
boost_util = target_util(sg_policy,
sg_policy->tunables->rtg_boost_freq);
boost_util = mult_frac(boost_util, TARGET_LOAD, 100);
sg_policy->rtg_boost_util = boost_util;
raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags);
}
Expand Down Expand Up @@ -1090,8 +1094,7 @@ static int sugov_init(struct cpufreq_policy *policy)
policy->governor_data = sg_policy;
sg_policy->tunables = tunables;

util = freq_to_util(sg_policy, sg_policy->tunables->rtg_boost_freq);
util = mult_frac(util, TARGET_LOAD, 100);
util = target_util(sg_policy, sg_policy->tunables->rtg_boost_freq);
sg_policy->rtg_boost_util = util;

stale_ns = sched_ravg_window + (sched_ravg_window >> 3);
Expand Down

0 comments on commit 3232441

Please sign in to comment.