Skip to content

Commit ce0dbbb

Browse files
clrkwllmsingomolnar
authored andcommitted
sched/rt: Add a tuning knob to allow changing SCHED_RR timeslice
Add a /proc/sys/kernel scheduler knob named sched_rr_timeslice_ms that allows global changing of the SCHED_RR timeslice value. User visable value is in milliseconds but is stored as jiffies. Setting to 0 (zero) resets to the default (currently 100ms). Signed-off-by: Clark Williams <williams@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/20130207094704.13751796@riff.lan Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent cf4aebc commit ce0dbbb

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎include/linux/sched/sysctl.h‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ static inline unsigned int get_sysctl_timer_migration(void)
7373
return 1;
7474
}
7575
#endif
76+
77+
/*
78+
* control realtime throttling:
79+
*
80+
* /proc/sys/kernel/sched_rt_period_us
81+
* /proc/sys/kernel/sched_rt_runtime_us
82+
*/
7683
extern unsigned int sysctl_sched_rt_period;
7784
extern int sysctl_sched_rt_runtime;
7885

@@ -90,7 +97,13 @@ extern unsigned int sysctl_sched_autogroup_enabled;
9097
*/
9198
#define RR_TIMESLICE (100 * HZ / 1000)
9299

93-
int sched_rt_handler(struct ctl_table *table, int write,
100+
extern int sched_rr_timeslice;
101+
102+
extern int sched_rr_handler(struct ctl_table *table, int write,
103+
void __user *buffer, size_t *lenp,
104+
loff_t *ppos);
105+
106+
extern int sched_rt_handler(struct ctl_table *table, int write,
94107
void __user *buffer, size_t *lenp,
95108
loff_t *ppos);
96109

‎kernel/sched/core.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,6 +7509,25 @@ static int sched_rt_global_constraints(void)
75097509
}
75107510
#endif /* CONFIG_RT_GROUP_SCHED */
75117511

7512+
int sched_rr_handler(struct ctl_table *table, int write,
7513+
void __user *buffer, size_t *lenp,
7514+
loff_t *ppos)
7515+
{
7516+
int ret;
7517+
static DEFINE_MUTEX(mutex);
7518+
7519+
mutex_lock(&mutex);
7520+
ret = proc_dointvec(table, write, buffer, lenp, ppos);
7521+
/* make sure that internally we keep jiffies */
7522+
/* also, writing zero resets timeslice to default */
7523+
if (!ret && write) {
7524+
sched_rr_timeslice = sched_rr_timeslice <= 0 ?
7525+
RR_TIMESLICE : msecs_to_jiffies(sched_rr_timeslice);
7526+
}
7527+
mutex_unlock(&mutex);
7528+
return ret;
7529+
}
7530+
75127531
int sched_rt_handler(struct ctl_table *table, int write,
75137532
void __user *buffer, size_t *lenp,
75147533
loff_t *ppos)

‎kernel/sched/rt.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <linux/slab.h>
99

10+
int sched_rr_timeslice = RR_TIMESLICE;
11+
1012
static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun);
1113

1214
struct rt_bandwidth def_rt_bandwidth;
@@ -2016,7 +2018,7 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
20162018
if (--p->rt.time_slice)
20172019
return;
20182020

2019-
p->rt.time_slice = RR_TIMESLICE;
2021+
p->rt.time_slice = sched_rr_timeslice;
20202022

20212023
/*
20222024
* Requeue to the end of queue if we (and all of our ancestors) are the
@@ -2047,7 +2049,7 @@ static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)
20472049
* Time slice is 0 for SCHED_FIFO tasks
20482050
*/
20492051
if (task->policy == SCHED_RR)
2050-
return RR_TIMESLICE;
2052+
return sched_rr_timeslice;
20512053
else
20522054
return 0;
20532055
}

‎kernel/sysctl.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ static struct ctl_table kern_table[] = {
404404
.mode = 0644,
405405
.proc_handler = sched_rt_handler,
406406
},
407+
{
408+
.procname = "sched_rr_timeslice_ms",
409+
.data = &sched_rr_timeslice,
410+
.maxlen = sizeof(int),
411+
.mode = 0644,
412+
.proc_handler = sched_rr_handler,
413+
},
407414
#ifdef CONFIG_SCHED_AUTOGROUP
408415
{
409416
.procname = "sched_autogroup_enabled",

0 commit comments

Comments
 (0)