[PATCH] sched: Fix compile warning about variable 'uclamp_mutex'

From: Qi Xi
Date: Thu Oct 24 2024 - 23:52:00 EST


When build with CONFIG_UCLAMP_TASK && !CONFIG_UCLAMP_TASK_GROUP,
the variable 'uclamp_mutex' is defined but not used:

kernel/sched/core.c:1361:21: warning: 'uclamp_mutex' defined but not used [-Wunused-variable]
1361 | static DEFINE_MUTEX(uclamp_mutex);

Fix this by only defining the variable uclamp_mutex when the
CONFIG_UCLAMP_TASK_GROUP is enabled.

Fixes: 2480c093130f ("sched/uclamp: Extend CPU's cgroup controller")
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/lkml/202410250459.EJe6PJI5-lkp@xxxxxxxxx/
Signed-off-by: Qi Xi <xiqi2@xxxxxxxxxx>
---
kernel/sched/core.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f3951e4a55e5..9109fed6f022 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1348,6 +1348,7 @@ void set_load_weight(struct task_struct *p, bool update_load)
}

#ifdef CONFIG_UCLAMP_TASK
+#ifdef CONFIG_UCLAMP_TASK_GROUP
/*
* Serializes updates of utilization clamp values
*
@@ -1359,6 +1360,7 @@ void set_load_weight(struct task_struct *p, bool update_load)
* updates or API abuses.
*/
static DEFINE_MUTEX(uclamp_mutex);
+#endif /* CONFIG_UCLAMP_TASK_GROUP */

/* Max allowed minimum utilization */
static unsigned int __maybe_unused sysctl_sched_uclamp_util_min = SCHED_CAPACITY_SCALE;
--
2.33.0