Skip to content

Commit f42c855

Browse files
committed
cpufreq/sched: schedutil: Add helper for governor checks
Add a helper for checking if schedutil is the current governor for a given cpufreq policy and use it in sched_is_eas_possible() to avoid accessing cpufreq policy internals directly from there. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Christian Loehle <[email protected]> Tested-by: Christian Loehle <[email protected]> Reviewed-by: Dietmar Eggemann <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 400da80 commit f42c855

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

include/linux/cpufreq.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,15 @@ module_exit(__governor##_exit)
650650
struct cpufreq_governor *cpufreq_default_governor(void);
651651
struct cpufreq_governor *cpufreq_fallback_governor(void);
652652

653+
#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
654+
bool sugov_is_governor(struct cpufreq_policy *policy);
655+
#else
656+
static inline bool sugov_is_governor(struct cpufreq_policy *policy)
657+
{
658+
return false;
659+
}
660+
#endif
661+
653662
static inline void cpufreq_policy_apply_limits(struct cpufreq_policy *policy)
654663
{
655664
if (policy->max < policy->cur)

kernel/sched/cpufreq_schedutil.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static const struct kobj_type sugov_tunables_ktype = {
630630

631631
/********************** cpufreq governor interface *********************/
632632

633-
struct cpufreq_governor schedutil_gov;
633+
static struct cpufreq_governor schedutil_gov;
634634

635635
static struct sugov_policy *sugov_policy_alloc(struct cpufreq_policy *policy)
636636
{
@@ -909,7 +909,7 @@ static void sugov_limits(struct cpufreq_policy *policy)
909909
WRITE_ONCE(sg_policy->limits_changed, true);
910910
}
911911

912-
struct cpufreq_governor schedutil_gov = {
912+
static struct cpufreq_governor schedutil_gov = {
913913
.name = "schedutil",
914914
.owner = THIS_MODULE,
915915
.flags = CPUFREQ_GOV_DYNAMIC_SWITCHING,
@@ -927,4 +927,9 @@ struct cpufreq_governor *cpufreq_default_governor(void)
927927
}
928928
#endif
929929

930+
bool sugov_is_governor(struct cpufreq_policy *policy)
931+
{
932+
return policy->governor == &schedutil_gov;
933+
}
934+
930935
cpufreq_governor_init(schedutil_gov);

kernel/sched/sched.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,8 +3509,6 @@ static inline bool sched_energy_enabled(void)
35093509
return static_branch_unlikely(&sched_energy_present);
35103510
}
35113511

3512-
extern struct cpufreq_governor schedutil_gov;
3513-
35143512
#else /* ! (CONFIG_ENERGY_MODEL && CONFIG_CPU_FREQ_GOV_SCHEDUTIL) */
35153513

35163514
#define perf_domain_span(pd) NULL

kernel/sched/topology.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static bool sched_is_eas_possible(const struct cpumask *cpu_mask)
213213
{
214214
bool any_asym_capacity = false;
215215
struct cpufreq_policy *policy;
216-
struct cpufreq_governor *gov;
216+
bool policy_is_ready;
217217
int i;
218218

219219
/* EAS is enabled for asymmetric CPU capacity topologies. */
@@ -258,9 +258,9 @@ static bool sched_is_eas_possible(const struct cpumask *cpu_mask)
258258
}
259259
return false;
260260
}
261-
gov = policy->governor;
261+
policy_is_ready = sugov_is_governor(policy);
262262
cpufreq_cpu_put(policy);
263-
if (gov != &schedutil_gov) {
263+
if (!policy_is_ready) {
264264
if (sched_debug()) {
265265
pr_info("rd %*pbl: Checking EAS, schedutil is mandatory\n",
266266
cpumask_pr_args(cpu_mask));

0 commit comments

Comments
 (0)