2022-02-09 12:30:46

by Zhen Ni

[permalink] [raw]
Subject: [PATCH] sched: move uclamp_util sysctls to core.c

move uclamp_util sysctls to core.c and use the new
register_sysctl_init() to register the sysctl interface.

Signed-off-by: Zhen Ni <[email protected]>
---
include/linux/sched/sysctl.h | 8 -------
kernel/sched/core.c | 43 ++++++++++++++++++++++++++++++++----
kernel/sysctl.c | 23 -------------------
3 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
index c19dd5a2c05c..1f07d14cf9fc 100644
--- a/include/linux/sched/sysctl.h
+++ b/include/linux/sched/sysctl.h
@@ -35,12 +35,6 @@ extern int sysctl_sched_rt_runtime;
extern unsigned int sysctl_sched_dl_period_max;
extern unsigned int sysctl_sched_dl_period_min;

-#ifdef CONFIG_UCLAMP_TASK
-extern unsigned int sysctl_sched_uclamp_util_min;
-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
@@ -56,8 +50,6 @@ int sched_rr_handler(struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos);
int sched_rt_handler(struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos);
-int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
- void *buffer, size_t *lenp, loff_t *ppos);
int sysctl_numa_balancing(struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos);
int sysctl_schedstats(struct ctl_table *table, int write, void *buffer,
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 848eaa0efe0e..1962111416e4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1254,10 +1254,10 @@ static void set_load_weight(struct task_struct *p, bool update_load)
static DEFINE_MUTEX(uclamp_mutex);

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

/* Max allowed maximum utilization */
-unsigned int sysctl_sched_uclamp_util_max = SCHED_CAPACITY_SCALE;
+static unsigned int sysctl_sched_uclamp_util_max = SCHED_CAPACITY_SCALE;

/*
* By default RT tasks run at the maximum performance point/capacity of the
@@ -1274,7 +1274,7 @@ unsigned int sysctl_sched_uclamp_util_max = SCHED_CAPACITY_SCALE;
* This knob will not override the system default sched_util_clamp_min defined
* above.
*/
-unsigned int sysctl_sched_uclamp_util_min_rt_default = SCHED_CAPACITY_SCALE;
+static unsigned int sysctl_sched_uclamp_util_min_rt_default = SCHED_CAPACITY_SCALE;

/* All clamps are required to be less or equal than these values */
static struct uclamp_se uclamp_default[UCLAMP_CNT];
@@ -1727,7 +1727,7 @@ static void uclamp_update_root_tg(void)
static void uclamp_update_root_tg(void) { }
#endif

-int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
+static int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
bool update_root_tg = false;
@@ -1792,6 +1792,40 @@ int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
return result;
}

+#ifdef CONFIG_SYSCTL
+static struct ctl_table sched_uclamp_util_sysctls[] = {
+ {
+ .procname = "sched_util_clamp_min",
+ .data = &sysctl_sched_uclamp_util_min,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = sysctl_sched_uclamp_handler,
+ },
+ {
+ .procname = "sched_util_clamp_max",
+ .data = &sysctl_sched_uclamp_util_max,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = sysctl_sched_uclamp_handler,
+ },
+ {
+ .procname = "sched_util_clamp_min_rt_default",
+ .data = &sysctl_sched_uclamp_util_min_rt_default,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = sysctl_sched_uclamp_handler,
+ },
+ {}
+};
+
+static void __init sched_uclamp_sysctl_init(void)
+{
+ register_sysctl_init("kernel", sched_uclamp_util_sysctls);
+}
+#else
+#define sched_uclamp_sysctl_init() do { } while (0)
+#endif
+
static int uclamp_validate(struct task_struct *p,
const struct sched_attr *attr)
{
@@ -1955,6 +1989,7 @@ static void __init init_uclamp(void)
root_task_group.uclamp[clamp_id] = uc_max;
#endif
}
+ sched_uclamp_sysctl_init();
}

#else /* CONFIG_UCLAMP_TASK */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 5ae443b2882e..78996c0c8852 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1727,29 +1727,6 @@ static struct ctl_table kern_table[] = {
.mode = 0644,
.proc_handler = sched_rr_handler,
},
-#ifdef CONFIG_UCLAMP_TASK
- {
- .procname = "sched_util_clamp_min",
- .data = &sysctl_sched_uclamp_util_min,
- .maxlen = sizeof(unsigned int),
- .mode = 0644,
- .proc_handler = sysctl_sched_uclamp_handler,
- },
- {
- .procname = "sched_util_clamp_max",
- .data = &sysctl_sched_uclamp_util_max,
- .maxlen = sizeof(unsigned int),
- .mode = 0644,
- .proc_handler = sysctl_sched_uclamp_handler,
- },
- {
- .procname = "sched_util_clamp_min_rt_default",
- .data = &sysctl_sched_uclamp_util_min_rt_default,
- .maxlen = sizeof(unsigned int),
- .mode = 0644,
- .proc_handler = sysctl_sched_uclamp_handler,
- },
-#endif
#ifdef CONFIG_SCHED_AUTOGROUP
{
.procname = "sched_autogroup_enabled",
--
2.20.1





2022-02-09 23:52:53

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [PATCH] sched: move uclamp_util sysctls to core.c

On Wed, Feb 09, 2022 at 04:57:30PM +0800, Zhen Ni wrote:
> move uclamp_util sysctls to core.c and use the new
> register_sysctl_init() to register the sysctl interface.
>
> Signed-off-by: Zhen Ni <[email protected]>

Reviewed-by: Luis Chamberlain <[email protected]>

Luis