sched: Support compiling out real-time scheduling with REALTIME_SCHED.
PATCH 1/1 sched: Support compiling out real-time scheduling with REALTIME_SCHED.
Adds support for compiling out the real-time scheduler (SCHED_FIFO and SCHED_RR) to save space. Changes sched_set_stop_task to use SCHED_NORMAL rather than SCHED_FIFO, since the kernel only uses this function as a fake scheduling priority for userspace to read to avoid exposing the stop class to userspace. Bloat-o-meter gives a space savings of 1877 bytes with REALTIME_SCHED turned off.
Userspace works fine with REALTIME_SCHED turned off. Processes attempting to set a real-time scheduling policy get EINVAL, exactly the response that the sched_setscheduler manpage documents you will get if the "scheduling policy is not one of the recognized policies."
--- init/Kconfig | 8 ++++++++ kernel/sched/Makefile | 3 ++- kernel/sched/core.c | 14 ++++++-------- kernel/sched/rt.c | 2 -- kernel/sched/sched.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/stop_task.c | 4 ++++ 6 files changed, 66 insertions(+), 11 deletions(-)
init/Kconfig +8 -0
@@ -27,6 +27,13 @@ config IRQ_WORK bool depends on HAVE_IRQ_WORK +config REALTIME_SCHED + bool "Realtime Scheduler" if EXPERT + default y + help + This option enables support for the realtime scheduler and the + corresponding scheduling classes SCHED_FIFO and SCHED_RR. + menu "General setup" config EXPERIMENTAL
@@ -753,6 +760,7 @@ config CFS_BANDWIDTH config RT_GROUP_SCHED bool "Group scheduling for SCHED_RR/FIFO" + depends on REALTIME_SCHED depends on EXPERIMENTAL depends on CGROUP_SCHED default n
kernel/sched/Makefile +2 -1
@@ -11,7 +11,8 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer endif -obj-y += core.o clock.o idle_task.o fair.o rt.o stop_task.o +obj-y += core.o clock.o idle_task.o fair.o stop_task.o +obj-$(CONFIG_REALTIME_SCHED) += rt.o obj-$(CONFIG_SMP) += cpupri.o obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o obj-$(CONFIG_SCHEDSTATS) += stats.o
kernel/sched/core.c +6 -8
@@ -85,6 +85,8 @@#define CREATE_TRACE_POINTS #include <trace/events/sched.h> +struct rt_bandwidth def_rt_bandwidth; +void start_bandwidth_timer (struct hrtimer *period_timer,ktime_t period) {unsigned long delta;
@@ -959,19 +961,15 @@ static int irqtime_account_si_update(void)void sched_set_stop_task (int cpu,struct task_struct *stop) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; +struct sched_param param = { .sched_priority =0 };struct task_struct *old_stop =cpu_rq (cpu)->stop;if (stop) {/* -* Make it appear like a SCHED_FIFO task, its something +* Make it appear like a SCHED_NORMAL task, its something * userspace knows about and won't get confused about. -* -* Also, it will make PI more or less work without too -* much confusion -- but then, stop work should not -* rely on PI working anyway. */ -sched_setscheduler_nocheck (stop,SCHED_FIFO , ¶m); +sched_setscheduler_nocheck (stop,SCHED_NORMAL , ¶m); stop->sched_class = &stop_sched_class; }
@@ -983,7 +981,7 @@ void sched_set_stop_task(int cpu, struct task_struct *stop)* Reset it back to a normal scheduling class so that * it can die in pieces. */ - old_stop->sched_class = &rt_sched_class; + old_stop->sched_class = &fair_sched_class; } }
kernel/sched/rt.c +0 -2
@@ -9,8 +9,6 @@static int do_sched_rt_period_timer (struct rt_bandwidth *rt_b,int overrun); -struct rt_bandwidth def_rt_bandwidth; -static enum hrtimer_restart sched_rt_period_timer (struct hrtimer *timer) { struct rt_bandwidth *rt_b =
kernel/sched/sched.h +46 -0
95 lines not on this page · raw message
kernel/sched/stop_task.c +4 -0
@@ -83,7 +83,11 @@ get_rr_interval_stop(struct rq *rq, struct task_struct *task)* Simple, special scheduling class for the per-CPU stop tasks: */ const struct sched_class stop_sched_class = { +#ifdef CONFIG_REALTIME_SCHED .next = &rt_sched_class, +#else + .next = &fair_sched_class, +#endif .enqueue_task = enqueue_task_stop, .dequeue_task = dequeue_task_stop,
Signature · 1 line
1.7.9.5
Quoted 8 lines · Trevor Brandt
init/Kconfig +0
-0@@ -27,6 +27,13 @@ config IRQ_WORK bool depends on HAVE_IRQ_WORK
init/Kconfig config IRQ_WORK · line 39
Quoted 10 lines
init/Kconfig +7
-0+config REALTIME_SCHED + bool "Realtime Scheduler" if EXPERT + default y + help + This option enables support for the realtime scheduler and the + corresponding scheduling classes SCHED_FIFO and SCHED_RR. + menu "General setup" config EXPERIMENTAL
If you inverted that, it could be a proper default n new feature [1].
However, if weight loss is the goal, why not go whole hog, and create sched/thin.c containing no lard... or just integrate an existing thin scheduler as a config option? Whole body replacement is a very radical diet, but somehow seems less so than chopping off fingers and toes.
-Mike
(that SMP could select to greatly simplify RT)
Quoted 18 lines · Mike Galbraith
Quoted 17 lines · Trevor Brandt
init/Kconfig +7
-0@@ -27,6 +27,13 @@ config IRQ_WORK bool depends on HAVE_IRQ_WORK +config REALTIME_SCHED + bool "Realtime Scheduler" if EXPERT + default y + help + This option enables support for the realtime scheduler and the + corresponding scheduling classes SCHED_FIFO and SCHED_RR. + menu "General setup"
Quoted 3 lines
init/Kconfig config IRQ_WORK · line 39
Quoted 1 line
init/Kconfig +0
-0config EXPERIMENTALIf you inverted that, it could be a proper default n new feature [1].
Huh. You mean, DISABLE_REALTIME_SCHED? How would that help? DISABLE_REALTIME_SCHED=n seems like an unnecessary double negative, and I see very little precedent for that in Kconfig options.
Quoted 1 line
(that SMP could select to greatly simplify RT)
I hope this isn't a serious suggestion. :) In any case, that doesn't seem like something that should happen in *this* patch, if it should happen at all.
Quoted 3 lines
However, if weight loss is the goal, why not go whole hog, and create
sched/thin.ccontaining no lard... or just integrate an existing thin scheduler as a config option?
Historically, the response to configurable/modular/selectable schedulers has been entirely negative, with most responses amounting to "we should fix the scheduler we have to work for all workloads", which doesn't seem like an unreasonable response to me.
The kernel also has a *large* number of dependencies on the workings of the fair scheduler, and as this patch shows, far fewer on the real-time scheduler.
Given both of the above, writing and integrating an entirely new scheduler (*and* dealing with the repeats of old flamewars that would ensue after posting it) seems a bit much to ask for a student project. :)
- Josh Triplett
Quoted 19 lines · Josh Triplett
Quoted 18 lines · Mike Galbraith
Quoted 17 lines · Trevor Brandt
init/Kconfig +7
-0@@ -27,6 +27,13 @@ config IRQ_WORK bool depends on HAVE_IRQ_WORK +config REALTIME_SCHED + bool "Realtime Scheduler" if EXPERT + default y + help + This option enables support for the realtime scheduler and the + corresponding scheduling classes SCHED_FIFO and SCHED_RR. + menu "General setup"
Quoted 7 lines
Quoted 3 lines
init/Kconfig config IRQ_WORK · line 39
Quoted 1 line
init/Kconfig +0
-0config EXPERIMENTALIf you inverted that, it could be a proper default n new feature [1].
Huh. You mean,
DISABLE_REALTIME_SCHED? How would that help? DISABLE_REALTIME_SCHED=n seems like an unnecessary double negative, and I see very little precedent for that inKconfigoptions.
No, it doesn't change anything.
Quoted 5 lines
Quoted 1 line
(that SMP could select to greatly simplify RT)
I hope this isn't a serious suggestion. :) In any case, that doesn't seem like something that should happen in *this* patch, if it should happen at all.
Slightly deformed funny-bone.
Quoted 9 lines
Quoted 3 lines
However, if weight loss is the goal, why not go whole hog, and create
sched/thin.ccontaining no lard... or just integrate an existing thin scheduler as a config option?Historically, the response to configurable/modular/selectable schedulers has been entirely negative, with most responses amounting to "we should fix the scheduler we have to work for all workloads", which doesn't seem like an unreasonable response to me.
Quoted 8 lines
The kernel also has a *large* number of dependencies on the workings of the fair scheduler, and as this patch shows, far fewer on the real-time scheduler.
Given both of the above, writing and integrating an entirely new scheduler (*and* dealing with the repeats of old flamewars that would ensue after posting it) seems a bit much to ask for a student project. :)
I think you could make something more generally useful to size extra dinky boxen by doing that regardless. But yeah, the bar for inclusion might be a _tad_ high ;-)
Maintainers certainly wouldn't find it lovely, but there is some utility. I can imagine a single array version of the O(1) scheduler saving lots of space. If you made it single queue like BFS (or for that matter maybe just uses BFS out of the box, dunno) you'd get rid of the load balancing code as well, so would probably have a small footprint scheduler without having to axe standard classes that may well be needed in even size extra dinky boxen.
-Mike
Quoted 11 lines · Trevor Brandt
Adds support for compiling out the real-time scheduler (
SCHED_FIFOandSCHED_RR) to save space. Changessched_set_stop_taskto useSCHED_NORMALrather thanSCHED_FIFO, since the kernel only uses this function as a fake scheduling priority for userspace to read to avoid exposing the stop class to userspace. Bloat-o-meter gives a space savings of 1877 bytes withREALTIME_SCHEDturned off.Userspace works fine with
REALTIME_SCHEDturned off. Processes attempting to set a real-time scheduling policy get EINVAL, exactly the response that thesched_setschedulermanpage documents you will get if the "scheduling policy is not one of the recognized policies."
Are you in the same group that wanted to make SCHED_FAIR optional as well?
Quoted 8 lines
Signed-off-by Trevor Brandt <[email protected]>Reviewed-by Josh Triplett <[email protected]>kernel/sched/Makefile +0
-0
kernel/sched/Makefile ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) · line 16
Quoted 7 lines
kernel/sched/Makefile +2
-1@@ -11,7 +11,8 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer endif -obj-y += core.o clock.o idle_task.o fair.o rt.o stop_task.o +obj-y += core.o clock.o idle_task.o fair.o stop_task.o +obj-$(CONFIG_REALTIME_SCHED) += rt.o obj-$(CONFIG_SMP) += cpupri.o
This wants extra magic, cpupri is only used for rt, cutting that will of course increase your savings.
kernel/sched/Makefile ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) · line 18
Quoted 2 lines
kernel/sched/Makefile +0
-0obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o obj-$(CONFIG_SCHEDSTATS) += stats.o
Other than that I'm not entirely happy with the growing #ifdef maze. Granted this new one isn't nearly as bad as some of the existing ones, but I do wish someone would clean up some of that.
Steven Rostedt
reviewerQuoted 3 lines · Peter Zijlstra
Other than that I'm not entirely happy with the growing #ifdef maze. Granted this new one isn't nearly as bad as some of the existing ones, but I do wish someone would clean up some of that.
To get rid of the #ifdefs, just make the RT scheduler into a module that gets loaded for those that want it.
/me runs!
-- Steve