From 472c5b96bea05f2e087ab3381c5554dc692bab71 Mon Sep 17 00:00:00 2001 From: Xuewen Yan Date: Thu, 13 Feb 2025 16:42:35 +0800 Subject: [PATCH] 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 --- kernel/sched/syscalls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c index dd06abf96246..a5d913535613 100644 --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -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; }