FROMLIST: sched/uclamp: Add uclamp_is_used() check before enable it

Because the static_branch_enable() would get the cpus_read_lock(),
and sometimes users may frequently set the uclamp value of tasks,
and the uclamp_validate() would call the static_branch_enable()
frequently, so add the uclamp_is_used() check to prevent calling
the cpus_read_lock() frequently.

Bug: 396568225
Link: https://lore.kernel.org/all/20250213091554.2593-2-xuewen.yan@unisoc.com/

Change-Id: I3b1e575d3ee6e7c0e668d1eba2bcae7f5cad4fb0
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
This commit is contained in:
Xuewen Yan
2025-02-13 16:42:35 +08:00
committed by Vincent Donnefort
parent 3c2ce50d66
commit 472c5b96be
+2 -1
View File
@@ -383,7 +383,8 @@ static int uclamp_validate(struct task_struct *p,
* blocking operation which obviously cannot be done while holding
* scheduler locks.
*/
static_branch_enable(&sched_uclamp_used);
if (!uclamp_is_used())
static_branch_enable(&sched_uclamp_used);
return 0;
}