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

Qi Xi posted 1 patch 1 month ago
kernel/sched/core.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
Posted by Qi Xi 1 month ago
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@intel.com>
Closes: https://lore.kernel.org/lkml/202410250459.EJe6PJI5-lkp@intel.com/
Signed-off-by: Qi Xi <xiqi2@huawei.com>
---
 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
Re: [PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
Posted by kernel test robot 1 month ago
Hi Qi,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on linus/master v6.12-rc4 next-20241025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Xi/sched-Fix-compile-warning-about-variable-uclamp_mutex/20241025-115315
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20241025034740.546570-1-xiqi2%40huawei.com
patch subject: [PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
config: i386-randconfig-053-20241026 (https://download.01.org/0day-ci/archive/20241026/202410260638.VpY4j0AB-lkp@intel.com/config)
compiler: clang version 19.1.2 (https://github.com/llvm/llvm-project 7ba7d8e2f7b6445b60679da826210cdde29eaf8b)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241026/202410260638.VpY4j0AB-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410260638.VpY4j0AB-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/sched/core.c:10:
   In file included from include/linux/highmem.h:8:
   In file included from include/linux/cacheflush.h:5:
   In file included from arch/x86/include/asm/cacheflush.h:5:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> kernel/sched/core.c:1865:16: error: use of undeclared identifier 'uclamp_mutex'; did you mean 'uclamp_none'?
    1865 |         guard(mutex)(&uclamp_mutex);
         |                       ^~~~~~~~~~~~
         |                       uclamp_none
   kernel/sched/sched.h:3377:28: note: 'uclamp_none' declared here
    3377 | static inline unsigned int uclamp_none(enum uclamp_id clamp_id)
         |                            ^
   1 warning and 1 error generated.


vim +1865 kernel/sched/core.c

494dcdf46e5cde YueHaibing        2022-04-27  1857  
78eb4ea25cd5fd Joel Granados     2024-07-24  1858  static int sysctl_sched_uclamp_handler(const struct ctl_table *table, int write,
32927393dc1ccd Christoph Hellwig 2020-04-24  1859  				void *buffer, size_t *lenp, loff_t *ppos)
e8f14172c6b11e Patrick Bellasi   2019-06-21  1860  {
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1861  	bool update_root_tg = false;
13685c4a08fca9 Qais Yousef       2020-07-16  1862  	int old_min, old_max, old_min_rt;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1863  	int result;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1864  
0f92cdf36f848f Peter Zijlstra    2023-08-01 @1865  	guard(mutex)(&uclamp_mutex);
0f92cdf36f848f Peter Zijlstra    2023-08-01  1866  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1867  	old_min = sysctl_sched_uclamp_util_min;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1868  	old_max = sysctl_sched_uclamp_util_max;
13685c4a08fca9 Qais Yousef       2020-07-16  1869  	old_min_rt = sysctl_sched_uclamp_util_min_rt_default;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1870  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1871  	result = proc_dointvec(table, write, buffer, lenp, ppos);
e8f14172c6b11e Patrick Bellasi   2019-06-21  1872  	if (result)
e8f14172c6b11e Patrick Bellasi   2019-06-21  1873  		goto undo;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1874  	if (!write)
0f92cdf36f848f Peter Zijlstra    2023-08-01  1875  		return 0;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1876  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1877  	if (sysctl_sched_uclamp_util_min > sysctl_sched_uclamp_util_max ||
13685c4a08fca9 Qais Yousef       2020-07-16  1878  	    sysctl_sched_uclamp_util_max > SCHED_CAPACITY_SCALE	||
13685c4a08fca9 Qais Yousef       2020-07-16  1879  	    sysctl_sched_uclamp_util_min_rt_default > SCHED_CAPACITY_SCALE) {
13685c4a08fca9 Qais Yousef       2020-07-16  1880  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1881  		result = -EINVAL;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1882  		goto undo;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1883  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1884  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1885  	if (old_min != sysctl_sched_uclamp_util_min) {
e8f14172c6b11e Patrick Bellasi   2019-06-21  1886  		uclamp_se_set(&uclamp_default[UCLAMP_MIN],
a509a7cd797470 Patrick Bellasi   2019-06-21  1887  			      sysctl_sched_uclamp_util_min, false);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1888  		update_root_tg = true;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1889  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1890  	if (old_max != sysctl_sched_uclamp_util_max) {
e8f14172c6b11e Patrick Bellasi   2019-06-21  1891  		uclamp_se_set(&uclamp_default[UCLAMP_MAX],
a509a7cd797470 Patrick Bellasi   2019-06-21  1892  			      sysctl_sched_uclamp_util_max, false);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1893  		update_root_tg = true;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1894  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1895  
46609ce227039f Qais Yousef       2020-06-30  1896  	if (update_root_tg) {
46609ce227039f Qais Yousef       2020-06-30  1897  		static_branch_enable(&sched_uclamp_used);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1898  		uclamp_update_root_tg();
46609ce227039f Qais Yousef       2020-06-30  1899  	}
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1900  
13685c4a08fca9 Qais Yousef       2020-07-16  1901  	if (old_min_rt != sysctl_sched_uclamp_util_min_rt_default) {
13685c4a08fca9 Qais Yousef       2020-07-16  1902  		static_branch_enable(&sched_uclamp_used);
13685c4a08fca9 Qais Yousef       2020-07-16  1903  		uclamp_sync_util_min_rt_default();
13685c4a08fca9 Qais Yousef       2020-07-16  1904  	}
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1905  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1906  	/*
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1907  	 * We update all RUNNABLE tasks only when task groups are in use.
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1908  	 * Otherwise, keep it simple and do just a lazy update at each next
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1909  	 * task enqueue time.
e8f14172c6b11e Patrick Bellasi   2019-06-21  1910  	 */
0f92cdf36f848f Peter Zijlstra    2023-08-01  1911  	return 0;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1912  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1913  undo:
e8f14172c6b11e Patrick Bellasi   2019-06-21  1914  	sysctl_sched_uclamp_util_min = old_min;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1915  	sysctl_sched_uclamp_util_max = old_max;
13685c4a08fca9 Qais Yousef       2020-07-16  1916  	sysctl_sched_uclamp_util_min_rt_default = old_min_rt;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1917  	return result;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1918  }
494dcdf46e5cde YueHaibing        2022-04-27  1919  #endif
e8f14172c6b11e Patrick Bellasi   2019-06-21  1920  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
Posted by kernel test robot 1 month ago
Hi Qi,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/sched/core]
[also build test ERROR on linus/master v6.12-rc4 next-20241025]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qi-Xi/sched-Fix-compile-warning-about-variable-uclamp_mutex/20241025-115315
base:   tip/sched/core
patch link:    https://lore.kernel.org/r/20241025034740.546570-1-xiqi2%40huawei.com
patch subject: [PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
config: i386-randconfig-052-20241026 (https://download.01.org/0day-ci/archive/20241026/202410260511.Ky8AtElD-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241026/202410260511.Ky8AtElD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410260511.Ky8AtElD-lkp@intel.com/

All errors (new ones prefixed by >>):

   kernel/sched/core.c: In function 'sysctl_sched_uclamp_handler':
>> kernel/sched/core.c:1865:23: error: 'uclamp_mutex' undeclared (first use in this function); did you mean 'uclamp_none'?
    1865 |         guard(mutex)(&uclamp_mutex);
         |                       ^~~~~~~~~~~~
         |                       uclamp_none
   kernel/sched/core.c:1865:23: note: each undeclared identifier is reported only once for each function it appears in


vim +1865 kernel/sched/core.c

494dcdf46e5cde YueHaibing        2022-04-27  1857  
78eb4ea25cd5fd Joel Granados     2024-07-24  1858  static int sysctl_sched_uclamp_handler(const struct ctl_table *table, int write,
32927393dc1ccd Christoph Hellwig 2020-04-24  1859  				void *buffer, size_t *lenp, loff_t *ppos)
e8f14172c6b11e Patrick Bellasi   2019-06-21  1860  {
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1861  	bool update_root_tg = false;
13685c4a08fca9 Qais Yousef       2020-07-16  1862  	int old_min, old_max, old_min_rt;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1863  	int result;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1864  
0f92cdf36f848f Peter Zijlstra    2023-08-01 @1865  	guard(mutex)(&uclamp_mutex);
0f92cdf36f848f Peter Zijlstra    2023-08-01  1866  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1867  	old_min = sysctl_sched_uclamp_util_min;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1868  	old_max = sysctl_sched_uclamp_util_max;
13685c4a08fca9 Qais Yousef       2020-07-16  1869  	old_min_rt = sysctl_sched_uclamp_util_min_rt_default;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1870  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1871  	result = proc_dointvec(table, write, buffer, lenp, ppos);
e8f14172c6b11e Patrick Bellasi   2019-06-21  1872  	if (result)
e8f14172c6b11e Patrick Bellasi   2019-06-21  1873  		goto undo;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1874  	if (!write)
0f92cdf36f848f Peter Zijlstra    2023-08-01  1875  		return 0;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1876  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1877  	if (sysctl_sched_uclamp_util_min > sysctl_sched_uclamp_util_max ||
13685c4a08fca9 Qais Yousef       2020-07-16  1878  	    sysctl_sched_uclamp_util_max > SCHED_CAPACITY_SCALE	||
13685c4a08fca9 Qais Yousef       2020-07-16  1879  	    sysctl_sched_uclamp_util_min_rt_default > SCHED_CAPACITY_SCALE) {
13685c4a08fca9 Qais Yousef       2020-07-16  1880  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1881  		result = -EINVAL;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1882  		goto undo;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1883  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1884  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1885  	if (old_min != sysctl_sched_uclamp_util_min) {
e8f14172c6b11e Patrick Bellasi   2019-06-21  1886  		uclamp_se_set(&uclamp_default[UCLAMP_MIN],
a509a7cd797470 Patrick Bellasi   2019-06-21  1887  			      sysctl_sched_uclamp_util_min, false);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1888  		update_root_tg = true;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1889  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1890  	if (old_max != sysctl_sched_uclamp_util_max) {
e8f14172c6b11e Patrick Bellasi   2019-06-21  1891  		uclamp_se_set(&uclamp_default[UCLAMP_MAX],
a509a7cd797470 Patrick Bellasi   2019-06-21  1892  			      sysctl_sched_uclamp_util_max, false);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1893  		update_root_tg = true;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1894  	}
e8f14172c6b11e Patrick Bellasi   2019-06-21  1895  
46609ce227039f Qais Yousef       2020-06-30  1896  	if (update_root_tg) {
46609ce227039f Qais Yousef       2020-06-30  1897  		static_branch_enable(&sched_uclamp_used);
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1898  		uclamp_update_root_tg();
46609ce227039f Qais Yousef       2020-06-30  1899  	}
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1900  
13685c4a08fca9 Qais Yousef       2020-07-16  1901  	if (old_min_rt != sysctl_sched_uclamp_util_min_rt_default) {
13685c4a08fca9 Qais Yousef       2020-07-16  1902  		static_branch_enable(&sched_uclamp_used);
13685c4a08fca9 Qais Yousef       2020-07-16  1903  		uclamp_sync_util_min_rt_default();
13685c4a08fca9 Qais Yousef       2020-07-16  1904  	}
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1905  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1906  	/*
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1907  	 * We update all RUNNABLE tasks only when task groups are in use.
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1908  	 * Otherwise, keep it simple and do just a lazy update at each next
7274a5c1bbec45 Patrick Bellasi   2019-08-22  1909  	 * task enqueue time.
e8f14172c6b11e Patrick Bellasi   2019-06-21  1910  	 */
0f92cdf36f848f Peter Zijlstra    2023-08-01  1911  	return 0;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1912  
e8f14172c6b11e Patrick Bellasi   2019-06-21  1913  undo:
e8f14172c6b11e Patrick Bellasi   2019-06-21  1914  	sysctl_sched_uclamp_util_min = old_min;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1915  	sysctl_sched_uclamp_util_max = old_max;
13685c4a08fca9 Qais Yousef       2020-07-16  1916  	sysctl_sched_uclamp_util_min_rt_default = old_min_rt;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1917  	return result;
e8f14172c6b11e Patrick Bellasi   2019-06-21  1918  }
494dcdf46e5cde YueHaibing        2022-04-27  1919  #endif
e8f14172c6b11e Patrick Bellasi   2019-06-21  1920  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] sched: Fix compile warning about variable 'uclamp_mutex'
Posted by Peter Zijlstra 1 month ago
On Fri, Oct 25, 2024 at 11:47:40AM +0800, Qi Xi wrote:
> 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.

sigh.. I hate our CONFIG space :/

Perhaps add __maybe_unused like the other variables it sits right next
to instead of adding yet more #ifdef crud?