linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trevor Brandt <tjbrandt@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Eric Paris <eparis@redhat.com>,
	Fabio Estevam <fabio.estevam@freescale.com>,
	Trevor Brandt <tjbrandt@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Thomas Gleixner <tglx@linutronix.de>,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	Glauber Costa <glommer@parallels.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>,
	Mike Galbraith <efault@gmx.de>,
	linux-kernel@vger.kernel.org
Cc: team-fjord@googlegroups.com
Subject: [PATCH] sched: Support compiling out real-time scheduling with REALTIME_SCHED.
Date: Tue, 14 Aug 2012 13:50:09 -0700	[thread overview]
Message-ID: <1344977423-28900-1-git-send-email-tjbrandt@gmail.com> (raw)
In-Reply-To: <y>

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."

Signed-off-by: Trevor Brandt <tjbrandt@gmail.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
---
 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(-)

diff --git a/init/Kconfig b/init/Kconfig
index 3f42cd6..768dc76 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -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
diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile
index 9a7dd35..a9bee25 100644
--- a/kernel/sched/Makefile
+++ b/kernel/sched/Makefile
@@ -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
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 478a04c..3579286 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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, &param);
+		sched_setscheduler_nocheck(stop, SCHED_NORMAL, &param);
 
 		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;
 	}
 }
 
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f42ae7f..4100803 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -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 =
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 98c0c26..ed41cb7 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -47,6 +47,8 @@ extern __read_mostly int scheduler_running;
  */
 #define RUNTIME_INF	((u64)~0ULL)
 
+#ifdef CONFIG_REALTIME_SCHED
+
 static inline int rt_policy(int policy)
 {
 	if (policy == SCHED_FIFO || policy == SCHED_RR)
@@ -59,6 +61,19 @@ static inline int task_has_rt_policy(struct task_struct *p)
 	return rt_policy(p->policy);
 }
 
+#else /* CONFIG_REALTIME_SCHED */
+
+static inline int rt_policy(int policy)
+{
+	return 0;
+}
+static inline int task_has_rt_policy(struct task_struct *p)
+{
+	return 0;
+}
+
+#endif /* CONFIG_REALTIME_SCHED */
+
 /*
  * This is the priority-queue data structure of the RT scheduling class:
  */
@@ -190,8 +205,17 @@ extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b);
 extern void __start_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
 extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq);
 
+#ifdef CONFIG_REALTIME_SCHED
 extern void free_rt_sched_group(struct task_group *tg);
 extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent);
+#else
+static inline void free_rt_sched_group(struct task_group *tg) { }
+static inline int alloc_rt_sched_group(struct task_group *tg,
+			struct task_group *parent)
+{
+	return 1;
+}
+#endif
 extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
 		struct sched_rt_entity *rt_se, int cpu,
 		struct sched_rt_entity *parent);
@@ -852,7 +876,11 @@ enum cpuacct_stat_index {
    for (class = sched_class_highest; class; class = class->next)
 
 extern const struct sched_class stop_sched_class;
+#ifdef CONFIG_REALTIME_SCHED
 extern const struct sched_class rt_sched_class;
+#else
+static const struct sched_class rt_sched_class = { };
+#endif
 extern const struct sched_class fair_sched_class;
 extern const struct sched_class idle_sched_class;
 
@@ -874,15 +902,29 @@ extern void sysrq_sched_debug_show(void);
 extern void sched_init_granularity(void);
 extern void update_max_interval(void);
 extern void update_group_power(struct sched_domain *sd, int cpu);
+#ifdef CONFIG_REALTIME_SCHED
 extern int update_runtime(struct notifier_block *nfb, unsigned long action, void *hcpu);
 extern void init_sched_rt_class(void);
+#else
+static inline int update_runtime(struct notifier_block *nfb,
+			unsigned long action, void *hcpu)
+{
+	return 0;
+}
+static inline void init_sched_rt_class(void) { }
+#endif
 extern void init_sched_fair_class(void);
 
 extern void resched_task(struct task_struct *p);
 extern void resched_cpu(int cpu);
 
 extern struct rt_bandwidth def_rt_bandwidth;
+#ifdef CONFIG_REALTIME_SCHED
 extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
+#else
+static inline void init_rt_bandwidth(struct rt_bandwidth *rt_b,
+			u64 period, u64 runtime) { }
+#endif
 
 extern void update_cpu_load(struct rq *this_rq);
 
@@ -1150,7 +1192,11 @@ extern void print_cfs_stats(struct seq_file *m, int cpu);
 extern void print_rt_stats(struct seq_file *m, int cpu);
 
 extern void init_cfs_rq(struct cfs_rq *cfs_rq);
+#ifdef CONFIG_REALTIME_SCHED
 extern void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq);
+#else
+static inline void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq) { }
+#endif
 extern void unthrottle_offline_cfs_rqs(struct rq *rq);
 
 extern void account_cfs_bandwidth_used(int enabled, int was_enabled);
diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c
index 7b386e8..5c29766 100644
--- a/kernel/sched/stop_task.c
+++ b/kernel/sched/stop_task.c
@@ -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,
-- 
1.7.9.5


             reply	other threads:[~2012-08-14 20:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 20:50 Trevor Brandt [this message]
2012-08-15  7:12 ` [PATCH] sched: Support compiling out real-time scheduling with REALTIME_SCHED Mike Galbraith
2012-08-15 15:10   ` Josh Triplett
2012-08-16  4:30     ` Mike Galbraith
2012-08-15 15:14 ` Peter Zijlstra
2012-08-15 19:58   ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1344977423-28900-1-git-send-email-tjbrandt@gmail.com \
    --to=tjbrandt@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=efault@gmx.de \
    --cc=eparis@redhat.com \
    --cc=fabio.estevam@freescale.com \
    --cc=glommer@parallels.com \
    --cc=josh@joshtriplett.org \
    --cc=kamalesh@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=suresh.b.siddha@intel.com \
    --cc=team-fjord@googlegroups.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).