Skip to contentSkip to conversation

sched: move cfs_bandwidth_slice sysctls to fair.c

PATCH Superseded Zhen Ni 2 participants 2 messages Feb 10, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH v2 1/1 sched: move cfs_bandwidth_slice sysctls to fair.c

move cfs_bandwidth_slice sysctls to fair.c and use the new register_sysctl_init() to register the sysctl interface.

---
 include/linux/sched/sysctl.h |  4 ----
 kernel/sched/fair.c          | 25 +++++++++++++++++++++++--
 kernel/sysctl.c              | 10 ----------
 3 files changed, 23 insertions(+), 16 deletions(-)
include/linux/sched/sysctl.h +0 -4
index c19dd5a2c05c..d416d8f45186 100644
@@ -41,10 +41,6 @@ extern unsigned int sysctl_sched_uclamp_util_max;
 extern unsigned int sysctl_sched_uclamp_util_min_rt_default;
 #endif
 
-#ifdef CONFIG_CFS_BANDWIDTH
-extern unsigned int sysctl_sched_cfs_bandwidth_slice;
-#endif
-
 #ifdef CONFIG_SCHED_AUTOGROUP
 extern unsigned int sysctl_sched_autogroup_enabled;
 #endif
kernel/sched/fair.c +23 -2
index 5146163bfabb..354ebf938567 100644
@@ -141,8 +141,26 @@ int __weak arch_asym_cpu_priority(int cpu)
  *
  * (default: 5 msec, units: microseconds)
  */
-unsigned int sysctl_sched_cfs_bandwidth_slice		= 5000UL;
-#endif
+static unsigned int sysctl_sched_cfs_bandwidth_slice		= 5000UL;
+#ifdef CONFIG_SYSCTL
+static struct ctl_table sched_cfs_bandwidth_sysctls[] = {
+	{
+		.procname       = "sched_cfs_bandwidth_slice_us",
+		.data           = &sysctl_sched_cfs_bandwidth_slice,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_dointvec_minmax,
+		.extra1         = SYSCTL_ONE,
+	},
+	{}
+};
+
+static void __init sched_cfs_bandwidth_sysctl_init(void)
+{
+	register_sysctl_init("kernel", sched_cfs_bandwidth_sysctls);
+}
+#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_CFS_BANDWIDTH */
 
 static inline void update_load_add(struct load_weight *lw, unsigned long inc)
 {
@@ -207,6 +225,9 @@ static void update_sysctl(void)
 void __init sched_init_granularity(void)
 {
 	update_sysctl();
+#if defined(CONFIG_CFS_BANDWIDTH) && defined(CONFIG_SYSCTL)
+	sched_cfs_bandwidth_sysctl_init();
+#endif
 }
 
 #define WMULT_CONST	(~0U)
kernel/sysctl.c +0 -10
index 5ae443b2882e..981a1902d7a4 100644
@@ -1761,16 +1761,6 @@ static struct ctl_table kern_table[] = {
 		.extra2		= SYSCTL_ONE,
 	},
 #endif
-#ifdef CONFIG_CFS_BANDWIDTH
-	{
-		.procname	= "sched_cfs_bandwidth_slice_us",
-		.data		= &sysctl_sched_cfs_bandwidth_slice,
-		.maxlen		= sizeof(unsigned int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ONE,
-	},
-#endif
 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
 	{
 		.procname	= "sched_energy_aware",
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · Zhen Ni

move cfs_bandwidth_slice sysctls to fair.c and use the new register_sysctl_init() to register the sysctl interface.

---

Your description of what has changed in your v2 should go here. If a v3, then your v2 notes and v3 notes should be here as well.

Quoted 39 lines
 include/linux/sched/sysctl.h |  4 ----
 kernel/sched/fair.c          | 25 +++++++++++++++++++++++--
 kernel/sysctl.c              | 10 ----------
 3 files changed, 23 insertions(+), 16 deletions(-)
include/linux/sched/sysctl.h +0 -4
index c19dd5a2c05c..d416d8f45186 100644
@@ -41,10 +41,6 @@ extern unsigned int sysctl_sched_uclamp_util_max;
 extern unsigned int sysctl_sched_uclamp_util_min_rt_default;
 #endif
 
-#ifdef CONFIG_CFS_BANDWIDTH
-extern unsigned int sysctl_sched_cfs_bandwidth_slice;
-#endif
-
 #ifdef CONFIG_SCHED_AUTOGROUP
 extern unsigned int sysctl_sched_autogroup_enabled;
 #endif
kernel/sched/fair.c +9 -2
index 5146163bfabb..354ebf938567 100644
@@ -141,8 +141,26 @@ int __weak arch_asym_cpu_priority(int cpu)
  *
  * (default: 5 msec, units: microseconds)
  */
-unsigned int sysctl_sched_cfs_bandwidth_slice		= 5000UL;
-#endif
+static unsigned int sysctl_sched_cfs_bandwidth_slice		= 5000UL;
+#ifdef CONFIG_SYSCTL
+static struct ctl_table sched_cfs_bandwidth_sysctls[] = {
+	{
+		.procname       = "sched_cfs_bandwidth_slice_us",
+		.data           = &sysctl_sched_cfs_bandwidth_slice,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_dointvec_minmax,

kernel/sched/fair.c int __weak arch_asym_cpu_priority(int cpu) · line 162

Quoted 10 lines
kernel/sched/fair.c +10 -0
+		.extra1         = SYSCTL_ONE,
+	},
+	{}
+};
+
+static void __init sched_cfs_bandwidth_sysctl_init(void)
+{
+	register_sysctl_init("kernel", sched_cfs_bandwidth_sysctls);
+}
+#endif /* CONFIG_SYSCTL */

Maybe an #else which then adds a no-op sched_cfs_bandwidth_sysctl_init

kernel/sched/fair.c int __weak arch_asym_cpu_priority(int cpu) · line 163

Quoted 1 line
kernel/sched/fair.c +1 -0
+#endif /* CONFIG_CFS_BANDWIDTH */

Likewise, if disabled, then have a no-op sched_cfs_bandwidth_sysctl_init()

kernel/sched/fair.c static void update_sysctl(void) · line 230

Quoted 9 lines
kernel/sched/fair.c +3 -0
 static inline void update_load_add(struct load_weight *lw, unsigned long inc)
 {
@@ -207,6 +225,9 @@ static void update_sysctl(void)
 void __init sched_init_granularity(void)
 {
 	update_sysctl();
+#if defined(CONFIG_CFS_BANDWIDTH) && defined(CONFIG_SYSCTL)
+	sched_cfs_bandwidth_sysctl_init();
+#endif

Then you can get remove the #ifdef mess from this code.

But this is a style issue nothing major.

Luis