From 3c2ce50d6600cce7842ad1949bde28b0b120611f Mon Sep 17 00:00:00 2001 From: Xuewen Yan Date: Thu, 13 Feb 2025 16:33:56 +0800 Subject: [PATCH] FROMLIST: sched/uclamp: Always using uclamp_is_used() Now, we have the uclamp_is_used() func to judge the uclamp enabled, so replace the static_branch_unlikely(&sched_uclamp_used) with it. Bug: 396568225 Link: https://lore.kernel.org/all/20250213091554.2593-1-xuewen.yan@unisoc.com/ Change-Id: Ia521b074c4a6411a031e17b2bd3db37a2a69aa9e Signed-off-by: Xuewen Yan --- kernel/sched/core.c | 4 ++-- kernel/sched/sched.h | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4fb6de44a208..9098f28b3cbc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1774,7 +1774,7 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p) * The condition is constructed such that a NOP is generated when * sched_uclamp_used is disabled. */ - if (!static_branch_unlikely(&sched_uclamp_used)) + if (!uclamp_is_used()) return; if (unlikely(!p->sched_class->uclamp_enabled)) @@ -1801,7 +1801,7 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) * The condition is constructed such that a NOP is generated when * sched_uclamp_used is disabled. */ - if (!static_branch_unlikely(&sched_uclamp_used)) + if (!uclamp_is_used()) return; if (unlikely(!p->sched_class->uclamp_enabled)) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 0ea696b11f8b..da94cdea8754 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -3416,6 +3416,19 @@ static inline bool update_other_load_avgs(struct rq *rq) { return false; } unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id); +/* + * When uclamp is compiled in, the aggregation at rq level is 'turned off' + * by default in the fast path and only gets turned on once userspace performs + * an operation that requires it. + * + * Returns true if userspace opted-in to use uclamp and aggregation at rq level + * hence is active. + */ +static inline bool uclamp_is_used(void) +{ + return static_branch_likely(&sched_uclamp_used); +} + static inline unsigned long uclamp_rq_get(struct rq *rq, enum uclamp_id clamp_id) { @@ -3439,7 +3452,7 @@ static inline bool uclamp_rq_is_capped(struct rq *rq) unsigned long rq_util; unsigned long max_util; - if (!static_branch_likely(&sched_uclamp_used)) + if (!uclamp_is_used()) return false; rq_util = cpu_util_cfs(cpu_of(rq)) + cpu_util_rt(rq); @@ -3448,19 +3461,6 @@ static inline bool uclamp_rq_is_capped(struct rq *rq) return max_util != SCHED_CAPACITY_SCALE && rq_util >= max_util; } -/* - * When uclamp is compiled in, the aggregation at rq level is 'turned off' - * by default in the fast path and only gets turned on once userspace performs - * an operation that requires it. - * - * Returns true if userspace opted-in to use uclamp and aggregation at rq level - * hence is active. - */ -static inline bool uclamp_is_used(void) -{ - return static_branch_likely(&sched_uclamp_used); -} - #define for_each_clamp_id(clamp_id) \ for ((clamp_id) = 0; (clamp_id) < UCLAMP_CNT; (clamp_id)++)