Skip to content

Commit efaa022

Browse files
imtangmengKAGA-KOKO
authored andcommitted
timers: Move timer sysctl into the timer code
This is part of the effort to reduce kernel/sysctl.c to only contain the core logic. Signed-off-by: tangmeng <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2966a99 commit efaa022

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

include/linux/timer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ extern void init_timers(void);
196196
struct hrtimer;
197197
extern enum hrtimer_restart it_real_fn(struct hrtimer *);
198198

199-
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
200-
struct ctl_table;
201-
202-
extern unsigned int sysctl_timer_migration;
203-
int timer_migration_handler(struct ctl_table *table, int write,
204-
void *buffer, size_t *lenp, loff_t *ppos);
205-
#endif
206-
207199
unsigned long __round_jiffies(unsigned long j, int cpu);
208200
unsigned long __round_jiffies_relative(unsigned long j, int cpu);
209201
unsigned long round_jiffies(unsigned long j);

kernel/sysctl.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,17 +2288,6 @@ static struct ctl_table kern_table[] = {
22882288
.extra1 = SYSCTL_ZERO,
22892289
.extra2 = SYSCTL_ONE,
22902290
},
2291-
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2292-
{
2293-
.procname = "timer_migration",
2294-
.data = &sysctl_timer_migration,
2295-
.maxlen = sizeof(unsigned int),
2296-
.mode = 0644,
2297-
.proc_handler = timer_migration_handler,
2298-
.extra1 = SYSCTL_ZERO,
2299-
.extra2 = SYSCTL_ONE,
2300-
},
2301-
#endif
23022291
#ifdef CONFIG_BPF_SYSCALL
23032292
{
23042293
.procname = "unprivileged_bpf_disabled",

kernel/time/timer.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <linux/slab.h>
4545
#include <linux/compat.h>
4646
#include <linux/random.h>
47+
#include <linux/sysctl.h>
4748

4849
#include <linux/uaccess.h>
4950
#include <asm/unistd.h>
@@ -223,7 +224,7 @@ static void timer_update_keys(struct work_struct *work);
223224
static DECLARE_WORK(timer_update_work, timer_update_keys);
224225

225226
#ifdef CONFIG_SMP
226-
unsigned int sysctl_timer_migration = 1;
227+
static unsigned int sysctl_timer_migration = 1;
227228

228229
DEFINE_STATIC_KEY_FALSE(timers_migration_enabled);
229230

@@ -234,7 +235,42 @@ static void timers_update_migration(void)
234235
else
235236
static_branch_disable(&timers_migration_enabled);
236237
}
237-
#else
238+
239+
#ifdef CONFIG_SYSCTL
240+
static int timer_migration_handler(struct ctl_table *table, int write,
241+
void *buffer, size_t *lenp, loff_t *ppos)
242+
{
243+
int ret;
244+
245+
mutex_lock(&timer_keys_mutex);
246+
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
247+
if (!ret && write)
248+
timers_update_migration();
249+
mutex_unlock(&timer_keys_mutex);
250+
return ret;
251+
}
252+
253+
static struct ctl_table timer_sysctl[] = {
254+
{
255+
.procname = "timer_migration",
256+
.data = &sysctl_timer_migration,
257+
.maxlen = sizeof(unsigned int),
258+
.mode = 0644,
259+
.proc_handler = timer_migration_handler,
260+
.extra1 = SYSCTL_ZERO,
261+
.extra2 = SYSCTL_ONE,
262+
},
263+
{}
264+
};
265+
266+
static int __init timer_sysctl_init(void)
267+
{
268+
register_sysctl("kernel", timer_sysctl);
269+
return 0;
270+
}
271+
device_initcall(timer_sysctl_init);
272+
#endif /* CONFIG_SYSCTL */
273+
#else /* CONFIG_SMP */
238274
static inline void timers_update_migration(void) { }
239275
#endif /* !CONFIG_SMP */
240276

@@ -251,19 +287,6 @@ void timers_update_nohz(void)
251287
schedule_work(&timer_update_work);
252288
}
253289

254-
int timer_migration_handler(struct ctl_table *table, int write,
255-
void *buffer, size_t *lenp, loff_t *ppos)
256-
{
257-
int ret;
258-
259-
mutex_lock(&timer_keys_mutex);
260-
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
261-
if (!ret && write)
262-
timers_update_migration();
263-
mutex_unlock(&timer_keys_mutex);
264-
return ret;
265-
}
266-
267290
static inline bool is_timers_nohz_active(void)
268291
{
269292
return static_branch_unlikely(&timers_nohz_active);

0 commit comments

Comments
 (0)