Skip to contentSkip to conversation

sched: SCHED_DEADLINE v3

RFC PATCH In review Raistlin 12 participants 135 messages Oct 29, 2010 – Nov 23, 2010 1 message not in the archive

Subsystems (12)
lore
Share & tools
lore

Raistlin

author
#0 lore raw

cover sched: SCHED_DEADLINE v3

Hello everyone,

This is the take 3 for the SCHED_DEADLINE patchset. I've done my best to have something that can be publicly shown by the Kernel Summit. To be sincere, I didn't make in getting the code to the point I wanted to but, hey, I hope this can be at least something from where to start the discussion. :-)

BTW, the patchset introduces a new deadline based real-time task scheduling policy --called SCHED_DEADLINE-- with bandwidth isolation (aka "resource reservation") capabilities. It now supports global/clustered multiprocessor scheduling through dynamic task migrations.

The code is being jointly developed by ReTiS Lab (http://retis.sssup.it)
and Evidence S.r.l (http://www.evidence.eu.com) in the context of the ACTORS EU-funded project (http://www.actors-project.eu).
It is also starting to get some users, both in academic and applied research, considered I'm getting some feedback from Ericsson, MIT and from Iowa State, Porto (ISEP), Carnegie Mellon, Barcelona and Trento universities.

From the previous release[*]:
- all the comments and the fixes coming from the reviews we got have been considered and applied;
- global and clustered (e.g., through cpusets) scheduling is now available. This means that tasks can migrate among (a subset of) CPUs when this is needed, by means of pushes & pulls, like in sched_rt.c;
- (c)group based task admission logic and bandwidth management has been removed, in favour of a per root_domain tasks bandwidth accounting mechanism;
- finally, all the code underwent major restructuring (many parts have been almost completely rewritten), to make it easier to read and understand, as well as more consistent with kernel mechanisms and conventions;

Still missing/incomplete:
- (c)group based bandwidth management, and maybe scheduling. It seems some more discussion on what precisely we want is *really* needed for this point;
- better handling of rq selection for dynamic task migration, by means of a cpupri equivalent for -deadline tasks. Not that hard to do, we already have some ideas and hope to have the code soon;
- bandwidth inheritance (to replace deadline/priority inheritance). What's in the patchset is just very few more than a simple placeholder. I tried doing something that may fit in the current architecture of rt_mutexes (i.e., the pi-chain of waiters) but did not get to anything meaningful. We are now working on migrating to something similar to what it's probably known here as proxy execution... It's not easy at all, but we are on it. :-)

The official page of the project is:
http://www.evidence.eu.com/sched_deadline.html

while the development is taking place at:
http://gitorious.org/sched_deadline/pages/Home
http://gitorious.org/sched_deadline

Check the repositories frequently if you're interested, and feel free to e-mail me for any issue you run into.

Patchset is on top of tip/master (as of today). The git-tree and patches for PREEMPT_RT will be available on the project website in the next days.

Relationship of this patchset with the EDF-throttling one is tight, although the two implementations add different (new) features and solve different problems. In case they have to coexist, a lot of code could be shared and duplications would be easily avoided.

As usual, any kind of feedback is welcome and appreciated.

Thanks in advice and regards,
Dario

[*] http://lwn.net/Articles/376502, http://lwn.net/Articles/353797

Dario Faggioi, SCHED_DEADLINE (22)

sched: add sched_class->task_dead.
sched: add extended scheduling interface.
sched: SCHED_DEADLINE data structures.
sched: SCHED_DEADLINE SMP-related data structures.
sched: SCHED_DEADLINE policy implementation.
sched: SCHED_DEADLINE handles spacial kthreads.
sched: SCHED_DEADLINE push and pull logic.
sched: SCHED_DEADLINE avg_update accounting.
sched: add period support for -deadline tasks.
sched: add a syscall to wait for the next instance.
sched: add schedstats for -deadline tasks.
sched: add runtime reporting for -deadline tasks.
sched: add resource limits for -deadline tasks.
sched: add latency tracing for -deadline tasks.
sched: add traceporints for -deadline tasks.
sched: add SMP traceporints for -deadline tasks.
sched: add signaling overrunning -deadline tasks.
sched: add reclaiming logic to -deadline tasks.
rtmutex: turn the plist into an rb-tree.
sched: drafted deadline inheritance logic.
sched: add bandwidth management for sched_dl.
sched: add sched_dl documentation.

 Documentation/scheduler/sched-deadline.txt |  147 +++
 arch/arm/include/asm/unistd.h              |    4 +
 arch/arm/kernel/calls.S                    |    4 +
 arch/x86/ia32/ia32entry.S                  |    4 +
 arch/x86/include/asm/unistd_32.h           |    6 +-
 arch/x86/include/asm/unistd_64.h           |    8 +
 arch/x86/kernel/syscall_table_32.S         |    4 +
 include/asm-generic/resource.h             |    7 +-
 include/linux/init_task.h                  |   10 +
 include/linux/rtmutex.h                    |   13 +-
 include/linux/sched.h                      |  208 ++++-
 include/linux/syscalls.h                   |    9 +
 include/trace/events/sched.h               |  312 +++++-
 kernel/fork.c                              |    4 +-
 kernel/hrtimer.c                           |    2 +-
 kernel/posix-cpu-timers.c                  |   55 +
 kernel/rtmutex-debug.c                     |    8 +-
 kernel/rtmutex.c                           |  146 ++-
 kernel/rtmutex_common.h                    |   22 +-
 kernel/sched.c                             | 1046 ++++++++++++++++--
 kernel/sched_debug.c                       |   46 +
 kernel/sched_dl.c                          | 1713 ++++++++++++++++++++++++++++
 kernel/sched_fair.c                        |    6 +-
 kernel/sched_rt.c                          |    7 +-
 kernel/sched_stoptask.c                    |    2 +-
 kernel/softirq.c                           |    6 +-
 kernel/sysctl.c                            |   14 +
 kernel/trace/trace_sched_wakeup.c          |   44 +-
 kernel/trace/trace_selftest.c              |   31 +-
 kernel/watchdog.c                          |    3 +-
 30 files changed, 3721 insertions(+), 170 deletions(-)
Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#1 lore raw

RFC PATCH 1/22 sched: add sched_class->task_dead.

Add a new function to the scheduling class interface. It is called at the end of a context switch, if the prev task is in TASK_DEAD state.

It might be useful for the scheduling classes that want to be notified when one of their task dies, e.g. to perform some cleanup actions.

---
 include/linux/sched.h |    1 +
 kernel/sched.c        |    3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)
include/linux/sched.h +1 -0
index b3d07df..6053b4b 100644
@@ -1068,6 +1068,7 @@ struct sched_class {
 	void (*set_curr_task) (struct rq *rq);
 	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
 	void (*task_fork) (struct task_struct *p);
+	void (*task_dead) (struct task_struct *p);
 
 	void (*switched_from) (struct rq *this_rq, struct task_struct *task,
 			       int running);
kernel/sched.c +3 -0
index 41f1869..07f5a0c 100644
@@ -2891,6 +2891,9 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
 	if (mm)
 		mmdrop(mm);
 	if (unlikely(prev_state == TASK_DEAD)) {
+		if (prev->sched_class->task_dead)
+			prev->sched_class->task_dead(prev);
+
 		/*
 		 * Remove function-return probe instances associated with this
 		 * task and put them back on the free list.
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#2 lore raw

RFC PATCH 2/22 sched: add extended scheduling interface

In reply to Raistlin

Add the interface bits needed for supporting scheduling algorithms with extended parameters (e.g., SCHED_DEADLINE).

In general, it makes it possible to specify a periodic/sporadic task, that executes for a given amount of runtime at each instance, and is scheduled according to the urgency of their own timing constraints, i.e.:
- a (maximum/typical) instance execution time,
- a minimum interval between consecutive instances,
- a time constraint by which each instance must be completed.

Thus, both the data structure that holds the scheduling parameters of the tasks and the system calls dealing with it must be extended. Unfortunately, modifying the existing struct sched_param would break the ABI and result in potentially serious compatibility issues with legacy binaries.

For these reasons, this patch:
- defines the new struct sched_param_ex, containing all the fields that are necessary for specifying a task in the computational model described above;
- defines and implements the new scheduling related syscalls that manipulate it, i.e., sched_setscheduler_ex(), sched_setparam_ex() and sched_getparam_ex().

Syscalls are introduced for x86 (32 and 64 bits) and ARM only, as a proof of concept and for developing and testing purposes. Making them available on other architectures is straightforward.

Since no "user" for these new parameters is introduced in this patch, the implementation of the new system calls is just identical to their already existing counterpart. Future patches that implement scheduling policies able to exploit the new data structure must also take care of modifying the *_ex() calls accordingly with their own purposes.

---
 arch/arm/include/asm/unistd.h      |    3 +
 arch/arm/kernel/calls.S            |    3 +
 arch/x86/ia32/ia32entry.S          |    3 +
 arch/x86/include/asm/unistd_32.h   |    5 +-
 arch/x86/include/asm/unistd_64.h   |    6 ++
 arch/x86/kernel/syscall_table_32.S |    3 +
 include/linux/sched.h              |   58 +++++++++++++++
 include/linux/syscalls.h           |    7 ++
 kernel/sched.c                     |  135 +++++++++++++++++++++++++++++++++++-
 9 files changed, 219 insertions(+), 4 deletions(-)
arch/arm/include/asm/unistd.h +3 -0
index c891eb7..6f18f72 100644
@@ -396,6 +396,9 @@
 #define __NR_fanotify_init		(__NR_SYSCALL_BASE+367)
 #define __NR_fanotify_mark		(__NR_SYSCALL_BASE+368)
 #define __NR_prlimit64			(__NR_SYSCALL_BASE+369)
+#define __NR_sched_setscheduler_ex	(__NR_SYSCALL_BASE+370)
+#define __NR_sched_setparam_ex		(__NR_SYSCALL_BASE+371)
+#define __NR_sched_getparam_ex		(__NR_SYSCALL_BASE+372)
 
 /*
  * The following SWIs are ARM private.
arch/arm/kernel/calls.S +3 -0
index 5c26ecc..c131615 100644
@@ -379,6 +379,9 @@
 		CALL(sys_fanotify_init)
 		CALL(sys_fanotify_mark)
 		CALL(sys_prlimit64)
+/* 370 */	CALL(sys_sched_setscheduler_ex)
+		CALL(sys_sched_setparam_ex)
+		CALL(sys_sched_getparam_ex)
 #ifndef syscalls_counted
 .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
 #define syscalls_counted
arch/x86/ia32/ia32entry.S +3 -0
index 518bb99..0c6f451 100644
@@ -851,4 +851,7 @@ ia32_sys_call_table:
 	.quad sys_fanotify_init
 	.quad sys32_fanotify_mark
 	.quad sys_prlimit64		/* 340 */
+	.quad sys_sched_setscheduler_ex
+	.quad sys_sched_setparam_ex
+	.quad sys_sched_getparam_ex
 ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +4 -1
index b766a5e..437383b 100644
@@ -346,10 +346,13 @@
 #define __NR_fanotify_init	338
 #define __NR_fanotify_mark	339
 #define __NR_prlimit64		340
+#define __NR_sched_setscheduler_ex	341
+#define __NR_sched_setparam_ex		342
+#define __NR_sched_getparam_ex		343
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 341
+#define NR_syscalls 344
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +6 -0
index 363e9b8..fc4618b 100644
@@ -669,6 +669,12 @@ __SYSCALL(__NR_fanotify_init, sys_fanotify_init)
 __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
 #define __NR_prlimit64				302
 __SYSCALL(__NR_prlimit64, sys_prlimit64)
+#define __NR_sched_setscheduler_ex		303
+__SYSCALL(__NR_sched_setscheduler_ex, sys_sched_setscheduler_ex)
+#define __NR_sched_setparam_ex			304
+__SYSCALL(__NR_sched_setparam_ex, sys_sched_setparam_ex)
+#define __NR_sched_getparam_ex			305
+__SYSCALL(__NR_sched_getparam_ex, sys_sched_getparam_ex)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +3 -0
index b35786d..7d4ed62 100644
@@ -340,3 +340,6 @@ ENTRY(sys_call_table)
 	.long sys_fanotify_init
 	.long sys_fanotify_mark
 	.long sys_prlimit64		/* 340 */
+	.long sys_sched_setscheduler_ex
+	.long sys_sched_setparam_ex
+	.long sys_sched_getparam_ex
include/linux/sched.h +58 -0

70 lines not on this page · raw message

include/linux/syscalls.h +7 -0
index cacc27a..46b461e 100644
@@ -38,6 +38,7 @@ struct rlimit;
 struct rlimit64;
 struct rusage;
 struct sched_param;
+struct sched_param_ex;
 struct sel_arg_struct;
 struct semaphore;
 struct sembuf;
@@ -322,11 +323,17 @@ asmlinkage long sys_clock_nanosleep(clockid_t which_clock, int flags,
 asmlinkage long sys_nice(int increment);
 asmlinkage long sys_sched_setscheduler(pid_t pid, int policy,
 					struct sched_param __user *param);
+asmlinkage long sys_sched_setscheduler_ex(pid_t pid, int policy, unsigned len,
+					struct sched_param_ex __user *param);
 asmlinkage long sys_sched_setparam(pid_t pid,
 					struct sched_param __user *param);
+asmlinkage long sys_sched_setparam_ex(pid_t pid, unsigned len,
+					struct sched_param_ex __user *param);
 asmlinkage long sys_sched_getscheduler(pid_t pid);
 asmlinkage long sys_sched_getparam(pid_t pid,
 					struct sched_param __user *param);
+asmlinkage long sys_sched_getparam_ex(pid_t pid, unsigned len,
+					struct sched_param_ex __user *param);
 asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
 					unsigned long __user *user_mask_ptr);
 asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
kernel/sched.c +132 -3

180 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
#3 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 45 lines
include/linux/sched.h +45 -0
+/*
+ * Extended scheduling parameters data structure.
+ *
+ * This is needed because the original struct sched_param can not be
+ * altered without introducing ABI issues with legacy applications
+ * (e.g., in sched_getparam()).
+ *
+ * However, the possibility of specifying more than just a priority for
+ * the tasks may be useful for a wide variety of application fields, e.g.,
+ * multimedia, streaming, automation and control, and many others.
+ *
+ * This variant (sched_param_ex) is meant at describing a so-called
+ * sporadic time-constrained task. In such model a task is specified by:
+ *  - the activation period or minimum instance inter-arrival time;
+ *  - the maximum (or average, depending on the actual scheduling
+ *    discipline) computation time of all instances, a.k.a. runtime;
+ *  - the deadline (relative to the actual activation time) of each
+ *    instance.
+ * Very briefly, a periodic (sporadic) task asks for the execution of
+ * some specific computation --which is typically called an instance--
+ * (at most) every period. Moreover, each instance typically lasts no more
+ * than the runtime and must be completed by time instant t equal to
+ * the instance activation time + the deadline.
+ *
+ * This is reflected by the actual fields of the sched_param_ex structure:
+ *
+ *  @sched_priority     task's priority (might still be useful)
+ *  @sched_deadline     representative of the task's deadline
+ *  @sched_runtime      representative of the task's runtime
+ *  @sched_period       representative of the task's period
+ *  @sched_flags        for customizing the scheduler behaviour
+ *
+ * There are other fields, which may be useful for implementing (in
+ * user-space) advanced scheduling behaviours, e.g., feedback scheduling:
+ *
+ *  @curr_runtime       task's currently available runtime
+ *  @used_runtime       task's totally used runtime
+ *  @curr_deadline      task's current absolute deadline
+ *
+ * Given this task model, there are a multiplicity of scheduling algorithms
+ * and policies, that can be used to ensure all the tasks will make their
+ * timing constraints.
+ */
+struct sched_param_ex {
+	int sched_priority;

include/linux/sched.h struct sched_param { · line 151

Quoted 10 lines
include/linux/sched.h +10 -0
+	struct timespec sched_runtime;
+	struct timespec sched_deadline;
+	struct timespec sched_period;
+	unsigned int sched_flags;
+
+	struct timespec curr_runtime;
+	struct timespec used_runtime;
+	struct timespec curr_deadline;
+};
+

So, how extensible is this. What about when real time theory develops a new algorithm which actually works practically, but needs additional parameters? :-). (I am guessing that this interface should handle most of the algorithms used these days). Any ideas?

Thanks,
Dhaval

#4 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 45 lines · Dhaval Giani
Quoted 45 lines
include/linux/sched.h +45 -0
+/*
+ * Extended scheduling parameters data structure.
+ *
+ * This is needed because the original struct sched_param can not be
+ * altered without introducing ABI issues with legacy applications
+ * (e.g., in sched_getparam()).
+ *
+ * However, the possibility of specifying more than just a priority for
+ * the tasks may be useful for a wide variety of application fields, e.g.,
+ * multimedia, streaming, automation and control, and many others.
+ *
+ * This variant (sched_param_ex) is meant at describing a so-called
+ * sporadic time-constrained task. In such model a task is specified by:
+ *  - the activation period or minimum instance inter-arrival time;
+ *  - the maximum (or average, depending on the actual scheduling
+ *    discipline) computation time of all instances, a.k.a. runtime;
+ *  - the deadline (relative to the actual activation time) of each
+ *    instance.
+ * Very briefly, a periodic (sporadic) task asks for the execution of
+ * some specific computation --which is typically called an instance--
+ * (at most) every period. Moreover, each instance typically lasts no more
+ * than the runtime and must be completed by time instant t equal to
+ * the instance activation time + the deadline.
+ *
+ * This is reflected by the actual fields of the sched_param_ex structure:
+ *
+ *  @sched_priority     task's priority (might still be useful)
+ *  @sched_deadline     representative of the task's deadline
+ *  @sched_runtime      representative of the task's runtime
+ *  @sched_period       representative of the task's period
+ *  @sched_flags        for customizing the scheduler behaviour
+ *
+ * There are other fields, which may be useful for implementing (in
+ * user-space) advanced scheduling behaviours, e.g., feedback scheduling:
+ *
+ *  @curr_runtime       task's currently available runtime
+ *  @used_runtime       task's totally used runtime
+ *  @curr_deadline      task's current absolute deadline
+ *
+ * Given this task model, there are a multiplicity of scheduling algorithms
+ * and policies, that can be used to ensure all the tasks will make their
+ * timing constraints.
+ */
+struct sched_param_ex {
+     int sched_priority;
Quoted 8 lines
Quoted 8 lines

+     struct timespec sched_runtime;
+     struct timespec sched_deadline;
+     struct timespec sched_period;
+     unsigned int sched_flags;
+
+     struct timespec curr_runtime;
+     struct timespec used_runtime;
+     struct timespec curr_deadline;

Can we expose soem of these details via schedstats as opposed to a syscall?

Dhaval

author
#5 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 12 lines · Dhaval Giani
Quoted 12 lines
Quoted 12 lines
+ *  @curr_runtime       task's currently available runtime
+ *  @used_runtime       task's totally used runtime
+ *  @curr_deadline      task's current absolute deadline

+ *
+ * Given this task model, there are a multiplicity of scheduling algorithms
+ * and policies, that can be used to ensure all the tasks will make their
+ * timing constraints.
+ */

include/linux/sched.h +4 -0
+struct sched_param_ex {
+     int sched_priority;
+     struct timespec sched_runtime;
+     struct timespec sched_deadline;
Quoted 9 lines
Quoted 6 lines

include/linux/sched.h struct sched_param { · line 149

Quoted 6 lines
include/linux/sched.h +6 -0
+     struct timespec sched_period;
+     unsigned int sched_flags;
+
+     struct timespec curr_runtime;
+     struct timespec used_runtime;
+     struct timespec curr_deadline;

Can we expose soem of these details via schedstats as opposed to a syscall?

Actually, good point... schedstats seems very reasonable to me... What do the others think?

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
#6 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Dhaval Giani

Dhaval Giani ha scritto:

Quoted 52 lines
Quoted 52 lines
include/linux/sched.h +52 -0
+/*
+ * Extended scheduling parameters data structure.
+ *
+ * This is needed because the original struct sched_param can not be
+ * altered without introducing ABI issues with legacy applications
+ * (e.g., in sched_getparam()).
+ *
+ * However, the possibility of specifying more than just a priority for
+ * the tasks may be useful for a wide variety of application fields, e.g.,
+ * multimedia, streaming, automation and control, and many others.
+ *
+ * This variant (sched_param_ex) is meant at describing a so-called
+ * sporadic time-constrained task. In such model a task is specified by:
+ *  - the activation period or minimum instance inter-arrival time;
+ *  - the maximum (or average, depending on the actual scheduling
+ *    discipline) computation time of all instances, a.k.a. runtime;
+ *  - the deadline (relative to the actual activation time) of each
+ *    instance.
+ * Very briefly, a periodic (sporadic) task asks for the execution of
+ * some specific computation --which is typically called an instance--
+ * (at most) every period. Moreover, each instance typically lasts no more
+ * than the runtime and must be completed by time instant t equal to
+ * the instance activation time + the deadline.
+ *
+ * This is reflected by the actual fields of the sched_param_ex structure:
+ *
+ *  @sched_priority     task's priority (might still be useful)
+ *  @sched_deadline     representative of the task's deadline
+ *  @sched_runtime      representative of the task's runtime
+ *  @sched_period       representative of the task's period
+ *  @sched_flags        for customizing the scheduler behaviour
+ *
+ * There are other fields, which may be useful for implementing (in
+ * user-space) advanced scheduling behaviours, e.g., feedback scheduling:
+ *
+ *  @curr_runtime       task's currently available runtime
+ *  @used_runtime       task's totally used runtime
+ *  @curr_deadline      task's current absolute deadline
+ *
+ * Given this task model, there are a multiplicity of scheduling algorithms
+ * and policies, that can be used to ensure all the tasks will make their
+ * timing constraints.
+ */
+struct sched_param_ex {
+	int sched_priority;
+	struct timespec sched_runtime;
+	struct timespec sched_deadline;
+	struct timespec sched_period;
+	unsigned int sched_flags;
+
+	struct timespec curr_runtime;
+	struct timespec used_runtime;
Quoted 8 lines

include/linux/sched.h struct sched_param { · line 151

Quoted 3 lines
include/linux/sched.h +3 -0
+	struct timespec curr_deadline;
+};
+

So, how extensible is this. What about when real time theory develops a new algorithm which actually works practically, but needs additional parameters? :-). (I am guessing that this interface should handle most of the algorithms used these days). Any ideas?

AFAIK, these parameters already address most real-time algorithms.

It could happen that in the future a new algorithm will need some further parameter (like jitter). However, IMHO, this is too unlikely to justify the addition of some padding in this data structure.

Best regards,

Claudio

maintainer
#7 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Raistlin

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

It would be better for alignment reasons to move the sched_flags field next to the sched_priority field.

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

maintainer
#8 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 16 lines · Peter Zijlstra

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

It would be better for alignment reasons to move the sched_flags field next to the sched_priority field.

Quoted 3 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Oh, and their model has something akin to: sched_runtime_max, these Gaussian bell curves go to inf. which is kinda bad for trying to compute bounds.

#9 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Il 10/11/2010 20:26, Peter Zijlstra ha scritto:

Quoted 6 lines
Quoted 3 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Oh, and their model has something akin to: sched_runtime_max, these Gaussian bell curves go to inf. which is kinda bad for trying to compute bounds.

If I understand well the paper you're referring to, the actual admission test would require also to specify a maximum acceptable expected tardiness, and/or proper quantiles of the tardiness distribution, and also it would require to solve a linear programming optimization problem in order to check those bounds. You don't want this stuff to go into the kernel, do you ?

There are plenty of complex schedulability tests for complex (and also distributed) RT applications modeled in a more or less complex way, scheduled under a variety of scheduling policies, with models including maximum and stochastic blocking times, task dependencies, offsets, and I don't know whatever else. These tests may be part of a user-space component. I would recommend to keep at the kernel level only a bare minimal set of functionality.

Deadlines different from periods are already a first complexity that I'm not sure we want to have in the interface. The easiest thing you can do there is to consider simply the minimum among the relative deadline and the period, but that would be equivalent to having only one parameter. More importantly, realizing complex admission control tests raises the issue of how to represent the "availability of RT CPU power" (as needed by "higher-level" logic/middleware). As far as we keep simple utilization-based admission tests (which might optionally be disabled), we still have some chance of representing such quantity.

Apologies for my 2 poor cents. I hope to see here a discussion (and I'll try to shut-up as much as possible :-) ).

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
maintainer
#10 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 7 lines · Tommaso Cucinotta

Il 10/11/2010 20:26, Peter Zijlstra ha scritto:

Quoted 6 lines
Quoted 3 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Oh, and their model has something akin to: sched_runtime_max, these Gaussian bell curves go to inf. which is kinda bad for trying to compute bounds.

Quoted 6 lines

If I understand well the paper you're referring to, the actual admission test would require also to specify a maximum acceptable expected tardiness, and/or proper quantiles of the tardiness distribution, and also it would require to solve a linear programming optimization problem in order to check those bounds. You don't want this stuff to go into the kernel, do you ?

I'm not sure it does, the admission test only uses the average runtime and uses the fact that it averages out to this (or less) to ensure tardiness is bounded.

So the stochastic model allows for temporal overload situations but because of the average nature next jobs must make up for the overrun of a previous job, negating the overload.

So on average the system isn't overloaded.

The only reason we need the max runtime limit is because avg+stdev dont actually place a bound on anything, like said the Gaussian bell curve goes all the way out to infinity.

author
#11 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Peter Zijlstra
Quoted 16 lines · Peter Zijlstra

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

It would be better for alignment reasons to move the sched_flags field next to the sched_priority field.

Makes sense, thanks. :-)

Quoted 4 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Ok, no problem with that too.

BTW, as Dhaval was suggesting, are (after those changes) fine with this new sched_param? Do we need some further mechanism to grant its extendability?
Padding?
Versioning?
void *data field?
Whatever?

:-O

I'd like very much to have some discussion here, if you think it is needed, in hope of avoiding future ABI issues as much as possible! :-P

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
#12 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Il 10/11/2010 23:17, Raistlin ha scritto:

Quoted 9 lines
Quoted 3 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Do we need some further mechanism to grant its
extendability?
Padding?
Versioning?
void *data field?
Whatever?

This is a key point. Let me copy text from a slide of my LPC main-conf talk:

Warning: features & parameters may easily grow
- Addition of parameters, such as
- deadline
- desired vs guaranteed runtime (for adaptive reservations &
controlled overcommitment)
- Set of flags for controlling variations on behavior
- work conserving vs non-conserving reservations
- what happens at fork() time
- what happens on tasks death (automatic reclamation)
- notifications from kernel (e.g., runtime exhaustion)
- Controlled access to RT scheduling by unprivileged applications (e.g., per-user “quotas”)
- Monitoring (e.g., residual runtime, available bandwidth)
- Integration/interaction with power management
(e.g., spec of per-cpu-frequency budget)

How can we guarantee extensibility (or replacement) of parameters in the future ?

What about something like _attr_*() in POSIX-like interfaces ?

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
maintainer
#13 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Raistlin
Quoted 33 lines · Raistlin
Quoted 16 lines · Peter Zijlstra

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

It would be better for alignment reasons to move the sched_flags field next to the sched_priority field.

Makes sense, thanks. :-)

Quoted 4 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Ok, no problem with that too.

BTW, as Dhaval was suggesting, are (after those changes) fine with this new sched_param? Do we need some further mechanism to grant its extendability?
Padding?
Versioning?
void *data field?
Whatever?

Quoted 4 lines

:-O

I'd like very much to have some discussion here, if you think it is needed, in hope of avoiding future ABI issues as much as possible! :-P

Right, so you mentioned doing s/_ex/2/ on all this stuff, which brings it more in line with that other syscalls have done.

The last three parameters look to be output only as I've not yet found code that reads it, and __getparam_dl() doesn't even appear to set used_runtime.

One thing you can do is add some padding, versioning and void* extentions are doable for the setparam() path, but getparam() is going to be mighty interesting.

author
#14 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 8 lines · Peter Zijlstra
Quoted 8 lines

BTW, as Dhaval was suggesting, are (after those changes) fine with this new sched_param? Do we need some further mechanism to grant its extendability?
Padding?
Versioning?
void *data field?
Whatever?

Quoted 8 lines
Quoted 4 lines

:-O

I'd like very much to have some discussion here, if you think it is needed, in hope of avoiding future ABI issues as much as possible! :-P

Right, so you mentioned doing s/_ex/2/ on all this stuff, which brings it more in line with that other syscalls have done.

Sure, this is necessary and easy to achieve. :-)

Quoted 4 lines

The last three parameters look to be output only as I've not yet found code that reads it, and __getparam_dl() doesn't even appear to set used_runtime.

Yeah, just kind of statistical reporting of the task's behaviour. That's why I was in agreement with Dhaval about using schedstats for those (bumping the version, obviously). What do you think?

Quoted 4 lines

One thing you can do is add some padding, versioning and void* extentions are doable for the setparam() path, but getparam() is going to be mighty interesting.

Mmm... So, tell me if I got it well: I remove the last three parameters (e.g., moving them toward schedstats) and add (besides _var and _max) some padding? It that correct?

what about the len <== sizeof(struct sched_param2) in sched_{set,get}{param,scheduler}2()... Does this still make sense, or are we removing it?

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#15 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 7 lines · Raistlin
Quoted 4 lines

The last three parameters look to be output only as I've not yet found code that reads it, and __getparam_dl() doesn't even appear to set used_runtime.

Yeah, just kind of statistical reporting of the task's behaviour. That's why I was in agreement with Dhaval about using schedstats for those (bumping the version, obviously). What do you think?

So its pure output? In that case its not really a nice fit for sched_param, however..

I'm not really a fan of schedstat, esp if you have to use it very frequently, the overhead of open()+read()+close() + parsing text is quite high.

Then again, if people are really going to use this (big if I guess) we could add yet another syscall for this or whatever.

Quoted 7 lines
Quoted 4 lines

One thing you can do is add some padding, versioning and void* extentions are doable for the setparam() path, but getparam() is going to be mighty interesting.

Mmm... So, tell me if I got it well: I remove the last three parameters (e.g., moving them toward schedstats) and add (besides _var and _max) some padding? It that correct?

grmbl, so I was going to say, just pad it to a nice 2^n size, but then I saw that struct timespec is defined as two long's, which means we're going to have to do compat crap.

Thomas is there a sane time format in existence? I thought the whole purpose of timeval/timespec was to avoid having to use a u64, but then using longs as opposed to int totally defeats the purpose.

Quoted 3 lines

what about the len <== sizeof(struct sched_param2) in sched_{set,get}{param,scheduler}2()... Does this still make sense, or are we removing it?

Since we're going for a constant sized structure we might as well take it out.

author
#16 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 7 lines · Peter Zijlstra

I'm not really a fan of schedstat, esp if you have to use it very frequently, the overhead of open()+read()+close() + parsing text is quite high.

Then again, if people are really going to use this (big if I guess) we could add yet another syscall for this or whatever.

Ok, we'll see at that time.

Quoted 8 lines

grmbl, so I was going to say, just pad it to a nice 2^n size, but then I saw that struct timespec is defined as two long's, which means we're going to have to do compat crap.

Thomas is there a sane time format in existence? I thought the whole purpose of timeval/timespec was to avoid having to use a u64, but then using longs as opposed to int totally defeats the purpose.

Fine, and u64 will be. Going for that...

Quoted 7 lines
Quoted 3 lines

what about the len <== sizeof(struct sched_param2) in sched_{set,get}{param,scheduler}2()... Does this still make sense, or are we removing it?

Since we're going for a constant sized structure we might as well take it out.

... and for that!

thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
#17 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Peter Zijlstra
Quoted 39 lines · Peter Zijlstra
Quoted 33 lines · Raistlin
Quoted 16 lines · Peter Zijlstra

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

It would be better for alignment reasons to move the sched_flags field next to the sched_priority field.

Makes sense, thanks. :-)

Quoted 4 lines

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Ok, no problem with that too.

BTW, as Dhaval was suggesting, are (after those changes) fine with this new sched_param? Do we need some further mechanism to grant its extendability?
Padding?
Versioning?
void *data field?
Whatever?

Quoted 4 lines

:-O

I'd like very much to have some discussion here, if you think it is needed, in hope of avoiding future ABI issues as much as possible! :-P

Quoted 7 lines

Right, so you mentioned doing s/_ex/2/ on all this stuff, which brings it more in line with that other syscalls have done.

The last three parameters look to be output only as I've not yet found code that reads it, and __getparam_dl() doesn't even appear to set used_runtime.

So, do you think its a good idea moving this information to schedstats? It seems more in line for monitoring, which schedstat seems a more appropriate destination.

thanks,
Dhaval

author
#18 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Peter Zijlstra
Quoted 17 lines · Peter Zijlstra

include/linux/sched.h struct sched_param { · line 150

Quoted 11 lines · Raistlin
include/linux/sched.h +11 -0
+struct sched_param_ex {
+       int sched_priority;
+       struct timespec sched_runtime;
+       struct timespec sched_deadline;
+       struct timespec sched_period;
+       unsigned int sched_flags;
+
+       struct timespec curr_runtime;
+       struct timespec used_runtime;
+       struct timespec curr_deadline;
+}; 

I would suggest we add at least one more field so we can implement the stochastic model from UNC, sched_runtime_dev or sched_runtime_var or somesuch.

Moreover, I really think that the capability of reporting back current and used runtime (and deadline) would be very useful for implementing more complex (and effective) scheduling behaviour in userspace... And in fact I added them here.

Something I was not so sure, and thus about what I wanted your opinion, was if I should put these things here --so that they are retrievable by a sched_getparam[_ex, 2], or either add yet another syscall specific for that? Thoughts?

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#19 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Raistlin
Quoted 14 lines · Raistlin

static int __sched_setscheduler(struct task_struct *p, int policy,

kernel/sched.c +4 -2
-                               const struct sched_param *param, bool user)
+                               const struct sched_param *param,
+                               const struct sched_param_ex *param_ex,
+                               bool user)
 {
        int retval, oldprio, oldpolicy = -1, on_rq, running;
        unsigned long flags;
@@ -4861,10 +4863,18 @@ recheck:
 int sched_setscheduler(struct task_struct *p, int policy,
                       const struct sched_param *param)
 {
-       return __sched_setscheduler(p, policy, param, true);
+       return __sched_setscheduler(p, policy, param, NULL, true);

kernel/sched.c recheck: · line 4876

Quoted 10 lines
kernel/sched.c +7 -0
 }
 EXPORT_SYMBOL_GPL(sched_setscheduler);
 
+int sched_setscheduler_ex(struct task_struct *p, int policy,
+                         const struct sched_param *param,
+                         const struct sched_param_ex *param_ex)
+{
+       return __sched_setscheduler(p, policy, param, param_ex, true);
+}
+EXPORT_SYMBOL_GPL(sched_setscheduler_ex); 

Do we really need to pass both params? Can't we simply create a struct sched_param_ex new_param = { .sched_priority = param->sched_priority }; on stack and pass that?

author
#20 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 12 lines · Peter Zijlstra

kernel/sched.c recheck: · line 4876

Quoted 7 lines
kernel/sched.c +7 -0
+int sched_setscheduler_ex(struct task_struct *p, int policy,
+                         const struct sched_param *param,
+                         const struct sched_param_ex *param_ex)
+{
+       return __sched_setscheduler(p, policy, param, param_ex, true);
+}
+EXPORT_SYMBOL_GPL(sched_setscheduler_ex); 

Do we really need to pass both params? Can't we simply create a struct sched_param_ex new_param = { .sched_priority = param->sched_priority }; on stack and pass that?

We can. I'll do that way.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#21 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Raistlin
Quoted 35 lines · Raistlin

+/*
+ * Extended scheduling parameters data structure.
+ *
+ * This is needed because the original struct sched_param can not be
+ * altered without introducing ABI issues with legacy applications
+ * (e.g., in sched_getparam()).
+ *
+ * However, the possibility of specifying more than just a priority for
+ * the tasks may be useful for a wide variety of application fields, e.g.,
+ * multimedia, streaming, automation and control, and many others.
+ *
+ * This variant (sched_param_ex) is meant at describing a so-called
+ * sporadic time-constrained task. In such model a task is specified by:
+ * - the activation period or minimum instance inter-arrival time;
+ * - the maximum (or average, depending on the actual scheduling
+ * discipline) computation time of all instances, a.k.a. runtime;
+ * - the deadline (relative to the actual activation time) of each
+ * instance.
+ * Very briefly, a periodic (sporadic) task asks for the execution of
+ * some specific computation --which is typically called an instance--
+ * (at most) every period. Moreover, each instance typically lasts no more
+ * than the runtime and must be completed by time instant t equal to
+ * the instance activation time + the deadline.
+ *
+ * This is reflected by the actual fields of the sched_param_ex structure:
+ *

+ *  @sched_priority     task's priority (might still be useful)
+ *  @sched_deadline     representative of the task's deadline
+ *  @sched_runtime      representative of the task's runtime
+ *  @sched_period       representative of the task's period
+ *  @sched_flags        for customizing the scheduler behaviour

+ *
+ * There are other fields, which may be useful for implementing (in
+ * user-space) advanced scheduling behaviours, e.g., feedback scheduling:
+ *

Quoted 8 lines
+ *  @curr_runtime       task's currently available runtime
+ *  @used_runtime       task's totally used runtime
+ *  @curr_deadline      task's current absolute deadline

+ *
+ * Given this task model, there are a multiplicity of scheduling algorithms
+ * and policies, that can be used to ensure all the tasks will make their
+ * timing constraints.
+ */

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Is this supported?

-- Steve

maintainer
#22 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 7 lines · Steven Rostedt

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Is this supported?

No, some of the bits in 18/22 come near, but I'd prefer not to add such things until we've got a convincing use-case.

maintainer
#23 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 11 lines · Peter Zijlstra
Quoted 7 lines · Steven Rostedt

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Is this supported?

No, some of the bits in 18/22 come near, but I'd prefer not to add such things until we've got a convincing use-case.

I'm fine with that, but I would like to know if the ABI would be able to add such an extension in the future if we find a convincing use-case.

-- Steve

author
#24 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 6 lines · Steven Rostedt
Quoted 2 lines

No, some of the bits in 18/22 come near, but I'd prefer not to add such things until we've got a convincing use-case.

I'm fine with that, but I would like to know if the ABI would be able to add such an extension in the future if we find a convincing use-case.

Scared about ABIs' stability eh? :-PP

BTW, in this case everything should be fine, since the very exact behaviour you described was triggered by a (couple of) flag(s), which can be added and dealt with during sched_setscheduler2() at any time.

As Peter was saying, see patch 18 for details.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#25 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 8 lines · Raistlin
Quoted 6 lines · Steven Rostedt
Quoted 2 lines

No, some of the bits in 18/22 come near, but I'd prefer not to add such things until we've got a convincing use-case.

I'm fine with that, but I would like to know if the ABI would be able to add such an extension in the future if we find a convincing use-case.

Scared about ABIs' stability eh? :-PP

Nah, why should I be? ;-)

Quoted 4 lines

BTW, in this case everything should be fine, since the very exact behaviour you described was triggered by a (couple of) flag(s), which can be added and dealt with during sched_setscheduler2() at any time.

Yep.

Quoted 2 lines

As Peter was saying, see patch 18 for details.

I'm slowly getting there ;-)

-- Steve

#26 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Steven Rostedt

Il 12/11/2010 17:38, Steven Rostedt ha scritto:

Quoted 7 lines

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Is this supported?

Actually, I know that Dario has an implementation of exactly this feature (and it used to be implemented in our previous scheduler as well, i.e., the old AQuoSA stuff):
a per-task flag, when enabled, allows to put temporarily the task into SCHED_OTHER when its budget is exhausted. Therefore, it will be allowed to run for more than its budget but without breaking the temporal isolation with the other SCHED_DEADLINE tasks. Furthermore, it won't starve other SCHED_OTHER tasks, as it will compete with them for the CPU during the budget-exhausted time windows.

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
maintainer
#27 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

Quoted 8 lines · Tommaso Cucinotta

Il 12/11/2010 17:38, Steven Rostedt ha scritto:

Quoted 7 lines

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Is this supported?

Quoted 9 lines

Actually, I know that Dario has an implementation of exactly this feature (and it used to be implemented in our previous scheduler as well, i.e., the old AQuoSA stuff):
a per-task flag, when enabled, allows to put temporarily the task into SCHED_OTHER when its budget is exhausted. Therefore, it will be allowed to run for more than its budget but without breaking the temporal isolation with the other SCHED_DEADLINE tasks. Furthermore, it won't starve other SCHED_OTHER tasks, as it will compete with them for the CPU during the budget-exhausted time windows.

Good to know, thanks!

-- Steve

author
#28 lore raw

Re: [RFC][PATCH 02/22] sched: add extended scheduling interface

In reply to Steven Rostedt
Quoted 6 lines · Steven Rostedt

A while ago I implemented an EDF scheduler for a client (before working with Red Hat), and one thing they asked about was having a "soft group", which was basically: This group is guaranteed X runtime in Y period, but if the system is idle, let the group run, even if it has exhausted its X runtime.

Sounds reasonable...

Quoted 2 lines

Is this supported?

Yep, as both Tommaso and Peter were saying, patch 18 gives you exactly that. In some more details, after X is over, you can chose (just by setting a flag in sched_param2 and calling setscheduler2()) if you want to keep running as a -deadline task (but without hurting other -deadline tasks), or if you want to still be able to compete for CPU, but as a -rt or -fair task.

However, we're delaying this for now. It won't be hard to add it back if we change our mind. :-)

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#29 lore raw

RFC PATCH 3/22 sched: SCHED_DEADLINE data structures.

In reply to Raistlin

Introduce the data structures, constants and symbols needed for SCHED_DEADLINE implementation.

Core data structure of SCHED_DEADLINE are defined, along with their initializers. Hooks for checking if a task belong to the new policy are also added where they are needed.

---
 include/linux/sched.h |   68 ++++++++++++++++++++++++++++++++++++++++++-
 kernel/hrtimer.c      |    2 +-
 kernel/sched.c        |   78 ++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 135 insertions(+), 13 deletions(-)
include/linux/sched.h +67 -1
index cf20084..c72a132 100644
@@ -38,6 +38,7 @@
 #define SCHED_BATCH		3
 /* SCHED_ISO: reserved but not implemented yet */
 #define SCHED_IDLE		5
+#define SCHED_DEADLINE		6
 /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
 #define SCHED_RESET_ON_FORK     0x40000000
 
@@ -136,6 +137,10 @@ struct sched_param {
  * Given this task model, there are a multiplicity of scheduling algorithms
  * and policies, that can be used to ensure all the tasks will make their
  * timing constraints.
+ *
+ * As of now, the SCHED_DEADLINE policy (sched_dl scheduling class) is the
+ * only user of this new interface. More information about the algorithm
+ * available in the scheduling class file or in Documentation/.
  */
 struct sched_param_ex {
 	int sched_priority;
@@ -1089,6 +1094,7 @@ struct sched_domain;
 #define ENQUEUE_WAKEUP		1
 #define ENQUEUE_WAKING		2
 #define ENQUEUE_HEAD		4
+#define ENQUEUE_REPLENISH	8
 
 #define DEQUEUE_SLEEP		1
 
@@ -1222,6 +1228,47 @@ struct sched_rt_entity {
 #endif
 };
 
+struct sched_dl_entity {
+	struct rb_node	rb_node;
+	int nr_cpus_allowed;
+
+	/*
+	 * Original scheduling parameters. Copied here from sched_param_ex
+	 * during sched_setscheduler_ex(), they will remain the same until
+	 * the next sched_setscheduler_ex().
+	 */
+	u64 dl_runtime;		/* maximum runtime for each instance 	*/
+	u64 dl_deadline;	/* relative deadline of each instance	*/
+
+	/*
+	 * Actual scheduling parameters. Initialized with the values above,
+	 * they are continously updated during task execution. Note that
+	 * the remaining runtime could be < 0 in case we are in overrun.
+	 */
+	s64 runtime;		/* remaining runtime for this instance	*/
+	u64 deadline;		/* absolute deadline for this instance	*/
+	unsigned int flags;	/* specifying the scheduler behaviour   */
+
+	/*
+	 * Some bool flags:
+	 *
+	 * @dl_throttled tells if we exhausted the runtime. If so, the
+	 * task has to wait for a replenishment to be performed at the
+	 * next firing of dl_timer.
+	 *
+	 * @dl_new tells if a new instance arrived. If so we must
+	 * start executing it with full runtime and reset its absolute
+	 * deadline;
+	 */
+	int dl_throttled, dl_new;
+
+	/*
+	 * Bandwidth enforcement timer. Each -deadline task has its
+	 * own bandwidth to be enforced, thus we need one timer per task.
+	 */
+	struct hrtimer dl_timer;
+};
+
 struct rcu_node;
 
 enum perf_event_task_context {
@@ -1251,6 +1298,7 @@ struct task_struct {
 	const struct sched_class *sched_class;
 	struct sched_entity se;
 	struct sched_rt_entity rt;
+	struct sched_dl_entity dl;
 
 #ifdef CONFIG_PREEMPT_NOTIFIERS
 	/* list of struct preempt_notifier: */
@@ -1580,6 +1628,10 @@ struct task_struct {
  * user-space.  This allows kernel threads to set their
  * priority to a value higher than any user task. Note:
  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
+ *
+ * SCHED_DEADLINE tasks has negative priorities, reflecting
+ * the fact that any of them has higher prio than RT and
+ * NORMAL/BATCH tasks.
  */
 
 #define MAX_USER_RT_PRIO	100
@@ -1588,9 +1640,23 @@ struct task_struct {
 #define MAX_PRIO		(MAX_RT_PRIO + 40)
 #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
 
+#define MAX_DL_PRIO		0
+
+static inline int dl_prio(int prio)
+{
+	if (unlikely(prio < MAX_DL_PRIO))
+		return 1;
+	return 0;
+}
+
+static inline int dl_task(struct task_struct *p)
+{
+	return dl_prio(p->prio);
+}
+
 static inline int rt_prio(int prio)
 {
-	if (unlikely(prio < MAX_RT_PRIO))
+	if (unlikely(prio >= MAX_DL_PRIO && prio < MAX_RT_PRIO))
 		return 1;
 	return 0;
 }
kernel/hrtimer.c +1 -1
index 72206cf..9cd8564 100644
@@ -1574,7 +1574,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
 	unsigned long slack;
 
 	slack = current->timer_slack_ns;
-	if (rt_task(current))
+	if (dl_task(current) || rt_task(current))
 		slack = 0;
 
 	hrtimer_init_on_stack(&t.timer, clockid, mode);
kernel/sched.c +67 -11

186 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#30 lore raw

Re: [RFC][PATCH 03/22] sched: SCHED_DEADLINE data structures.

include/linux/sched.h struct sched_rt_entity { · line 1269

Quoted 5 lines · Raistlin
include/linux/sched.h +5 -0
+       /*
+        * Bandwidth enforcement timer. Each -deadline task has its
+        * own bandwidth to be enforced, thus we need one timer per task.
+        */
+       struct hrtimer dl_timer; 

This is for the bandwidth replenishment right? Not the runtime throttle?

The throttle thing should only need a single timer per rq as only the current task will be consuming runtime.

author
#31 lore raw

Re: [RFC][PATCH 03/22] sched: SCHED_DEADLINE data structures.

Quoted 8 lines · Peter Zijlstra

include/linux/sched.h struct sched_rt_entity { · line 1269

Quoted 5 lines · Raistlin
include/linux/sched.h +5 -0
+       /*
+        * Bandwidth enforcement timer. Each -deadline task has its
+        * own bandwidth to be enforced, thus we need one timer per task.
+        */
+       struct hrtimer dl_timer; 

This is for the bandwidth replenishment right?

Yep.

Quoted 2 lines

Not the runtime throttle?

Not, that is done on tick basis, or by means of hrtick, if enabled.

Quoted 3 lines

The throttle thing should only need a single timer per rq as only the current task will be consuming runtime.

Sure, and that's what the hrtick does (again, if enabled).

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#32 lore raw

Re: [RFC][PATCH 03/22] sched: SCHED_DEADLINE data structures.

In reply to Raistlin
Quoted 1 line · Raistlin

+ if (unlikely(prio >= MAX_DL_PRIO && prio < MAX_RT_PRIO))

Since MAX_DL_PRIO is 0, you can write that as:
((unsigned)prio) < MAX_RT_PRIO

maintainer
#33 lore raw

Re: [RFC][PATCH 03/22] sched: SCHED_DEADLINE data structures.

Quoted 5 lines · Peter Zijlstra
Quoted 1 line · Raistlin

+ if (unlikely(prio >= MAX_DL_PRIO && prio < MAX_RT_PRIO))

Since MAX_DL_PRIO is 0, you can write that as:
((unsigned)prio) < MAX_RT_PRIO

Does this make a difference? If not, I rather leave it out since it just makes it less readable, and a bit confusing for reviewers.

-- Steve

author
#34 lore raw

RFC PATCH 4/22 sched: SCHED_DEADLINE SMP-related data structures

In reply to Raistlin

Introduce data structures relevant for implementing dynamic migration of -deadline tasks.

Mainly, this is the logic for checking if runqueues are overloaded with -deadline tasks and for choosing where a task should migrate, when it is the case.

---
 include/linux/sched.h |    1 +
 kernel/sched.c        |   58 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 1 deletions(-)
include/linux/sched.h +1 -0
index c72a132..f94da51 100644
@@ -1336,6 +1336,7 @@ struct task_struct {
 
 	struct list_head tasks;
 	struct plist_node pushable_tasks;
+	struct rb_node pushable_dl_tasks;
 
 	struct mm_struct *mm, *active_mm;
 #if defined(SPLIT_RSS_COUNTING)
kernel/sched.c +57 -1

107 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#35 lore raw

Re: [RFC][PATCH 04/22] sched: SCHED_DEADLINE SMP-related data structures

include/linux/sched.h struct task_struct { · line 1339

Quoted 5 lines · Raistlin
include/linux/sched.h +1 -0
@@ -1336,6 +1336,7 @@ struct task_struct {
 
        struct list_head tasks;
        struct plist_node pushable_tasks;
+       struct rb_node pushable_dl_tasks; 

Shouldn't these be CONFIG_SMP too? Not much use in tracking pushable tasks when there's nothing to push them to, eh?

author
#36 lore raw

RFC PATCH 5/22 sched: SCHED_DEADLINE policy implementation

In reply to Raistlin

Add a scheduling class, in sched_dl.c and a new policy called SCHED_DEADLINE. It is an implementation of the Earliest Deadline First (EDF) scheduling algorithm, augmented with a mechanism (called Constant Bandwidth Server, CBS) that makes it possible to isolate the behaviour of tasks between each other.

The typical -deadline task will be made up of a computation phase (instance) which is activated on a periodic or sporadic fashion. The expected (maximum) duration of such computation is called the task's runtime; the time interval by which each instance need to be completed is called the task's relative deadline. The task's absolute deadline is dynamically calculated as the time instant a task (better, an instance) activates plus the relative deadline.

The EDF algorithms selects the task with the smallest absolute deadline as the one to be executed first, while the CBS ensures each task to run for at most the its runtime every (relative) deadline length time interval, avoiding any interference between different tasks (bandwidth isolation).
Thanks to this feature, also tasks that do not strictly comply with the computational model sketched above can effectively use the new policy.

This patch:
- implements the core logic of the scheduling algorithm in the new scheduling class file;
- provides all the glue code between the new scheduling class and the core scheduler and refines the interactions between sched_dl and the other existing scheduling classes.

---
 kernel/sched.c          |   67 +++++-
 kernel/sched_dl.c       |  643 +++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched_fair.c     |    2 +-
 kernel/sched_rt.c       |    5 +
 kernel/sched_stoptask.c |    2 +-
 5 files changed, 711 insertions(+), 8 deletions(-)
 create mode 100644 kernel/sched_dl.c
kernel/sched.c +61 -6
index b11e888..208fa08 100644
@@ -1928,6 +1928,12 @@ static void dec_nr_running(struct rq *rq)
 
 static void set_load_weight(struct task_struct *p)
 {
+	if (task_has_dl_policy(p) || task_has_rt_policy(p)) {
+		p->se.load.weight = 0;
+		p->se.load.inv_weight = WMULT_CONST;
+		return;
+	}
+
 	/*
 	 * SCHED_IDLE tasks get minimal weight:
 	 */
@@ -2072,6 +2078,7 @@ static void sched_irq_time_avg_update(struct rq *rq, u64 curr_irq_time) { }
 #include "sched_idletask.c"
 #include "sched_fair.c"
 #include "sched_rt.c"
+#include "sched_dl.c"
 #include "sched_stoptask.c"
 #ifdef CONFIG_SCHED_DEBUG
 # include "sched_debug.c"
@@ -2750,7 +2757,11 @@ void sched_fork(struct task_struct *p, int clone_flags)
 	 */
 	p->prio = current->normal_prio;
 
-	if (!rt_prio(p->prio))
+	if (dl_prio(p->prio))
+		p->sched_class = &dl_sched_class;
+	else if (rt_prio(p->prio))
+		p->sched_class = &rt_sched_class;
+	else
 		p->sched_class = &fair_sched_class;
 
 	if (p->sched_class->task_fork)
@@ -4530,8 +4541,6 @@ long __sched sleep_on_timeout(wait_queue_head_t *q, long timeout)
 }
 EXPORT_SYMBOL(sleep_on_timeout);
 
-static const struct sched_class dl_sched_class;
-
 #ifdef CONFIG_RT_MUTEXES
 
 /*
@@ -4760,6 +4769,40 @@ __setscheduler(struct rq *rq, struct task_struct *p, int policy, int prio)
 }
 
 /*
+ * This function initializes the sched_dl_entity of a newly becoming
+ * SCHED_DEADLINE task.
+ *
+ * Only the static values are considered here, the actual runtime and the
+ * absolute deadline will be properly calculated when the task is enqueued
+ * for the first time with its new policy.
+ */
+static void
+__setparam_dl(struct task_struct *p, const struct sched_param_ex *param_ex)
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	init_dl_task_timer(dl_se);
+	dl_se->dl_runtime = timespec_to_ns(&param_ex->sched_runtime);
+	dl_se->dl_deadline = timespec_to_ns(&param_ex->sched_deadline);
+	dl_se->flags = param_ex->sched_flags;
+	dl_se->dl_throttled = 0;
+	dl_se->dl_new = 1;
+}
+
+static void
+__getparam_dl(struct task_struct *p, struct sched_param_ex *param_ex)
+{
+	struct sched_dl_entity *dl_se = &p->dl;
+
+	param_ex->sched_priority = p->rt_priority;
+	param_ex->sched_runtime = ns_to_timespec(dl_se->dl_runtime);
+	param_ex->sched_deadline = ns_to_timespec(dl_se->dl_deadline);
+	param_ex->sched_flags = dl_se->flags;
+	param_ex->curr_runtime = ns_to_timespec(dl_se->runtime);
+	param_ex->curr_deadline = ns_to_timespec(dl_se->deadline);
+}
+
+/*
  * This function validates the new parameters of a -deadline task.
  * We ask for the deadline not being zero, and greater or equal
  * than the runtime.
@@ -4922,7 +4965,11 @@ recheck:
 
 	oldprio = p->prio;
 	prev_class = p->sched_class;
-	__setscheduler(rq, p, policy, param->sched_priority);
+	if (dl_policy(policy)) {
+		__setparam_dl(p, param_ex);
+		__setscheduler(rq, p, policy, param_ex->sched_priority);
+	} else
+		__setscheduler(rq, p, policy, param->sched_priority);
 
 	if (running)
 		p->sched_class->set_curr_task(rq);
@@ -5043,7 +5090,10 @@ do_sched_setscheduler_ex(pid_t pid, int policy, unsigned len,
 	retval = -ESRCH;
 	p = find_process_by_pid(pid);
 	if (p != NULL) {
-		lparam.sched_priority = lparam_ex.sched_priority;
+		if (dl_policy(policy))
+			lparam.sched_priority = 0;
+		else
+			lparam.sched_priority = lparam_ex.sched_priority;
 		retval = sched_setscheduler_ex(p, policy, &lparam, &lparam_ex);
 	}
 	rcu_read_unlock();
@@ -5197,7 +5247,10 @@ SYSCALL_DEFINE3(sched_getparam_ex, pid_t, pid, unsigned, len,
 	if (retval)
 		goto out_unlock;
 
-	lp.sched_priority = p->rt_priority;
+	if (task_has_dl_policy(p))
+		__getparam_dl(p, &lp);
+	else
+		lp.sched_priority = p->rt_priority;
 	rcu_read_unlock();
 
 	retval = copy_to_user(param_ex, &lp, len) ? -EFAULT : 0;
@@ -5523,6 +5576,7 @@ SYSCALL_DEFINE1(sched_get_priority_max, int, policy)
 	case SCHED_RR:
 		ret = MAX_USER_RT_PRIO-1;
 		break;
+	case SCHED_DEADLINE:
 	case SCHED_NORMAL:
 	case SCHED_BATCH:
 	case SCHED_IDLE:
@@ -5548,6 +5602,7 @@ SYSCALL_DEFINE1(sched_get_priority_min, int, policy)
 	case SCHED_RR:
 		ret = 1;
 		break;
+	case SCHED_DEADLINE:
 	case SCHED_NORMAL:
 	case SCHED_BATCH:
 	case SCHED_IDLE:
kernel/sched_dl.c new file +643 -0

643 lines not on this page · raw message

kernel/sched_fair.c +1 -1
index f4f6a83..54c869c 100644
@@ -1654,7 +1654,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
 	struct cfs_rq *cfs_rq = task_cfs_rq(curr);
 	int scale = cfs_rq->nr_running >= sched_nr_latency;
 
-	if (unlikely(rt_prio(p->prio)))
+	if (unlikely(dl_prio(p->prio) || rt_prio(p->prio)))
 		goto preempt;
 
 	if (unlikely(p->sched_class != &fair_sched_class))
kernel/sched_rt.c +5 -0
index bea7d79..56c00fa 100644
@@ -1014,6 +1014,11 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
  */
 static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags)
 {
+	/*
+	 * Since MAX_DL_PRIO is less than any possible RT
+	 * prio, this also guarantees that all -deadline tasks
+	 * preempt -rt ones.
+	 */
 	if (p->prio < rq->curr->prio) {
 		resched_task(rq->curr);
 		return;
kernel/sched_stoptask.c +1 -1
index 45bddc0..25624df 100644
@@ -81,7 +81,7 @@ get_rr_interval_stop(struct rq *rq, struct task_struct *task)
  * Simple, special scheduling class for the per-CPU stop tasks:
  */
 static const struct sched_class stop_sched_class = {
-	.next			= &rt_sched_class,
+	.next			= &dl_sched_class,
 
 	.enqueue_task		= enqueue_task_stop,
 	.dequeue_task		= dequeue_task_stop,
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#37 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Review

Quoted 5 lines · Raistlin
(quoted diff) +5 -0
+       if (task_has_dl_policy(p) || task_has_rt_policy(p)) {
+               p->se.load.weight = 0;
+               p->se.load.inv_weight = WMULT_CONST;
+               return;
+       } 

---
commit 17bdcf949d03306b308c5fb694849cd35f119807

Author: Linus Walleij <[email protected]>
Date:   Mon Oct 11 16:36:51 2010 +0200

sched: Drop all load weight manipulation for RT tasks

Load weights are for the CFS, they do not belong in the RT task. This makes all RT scheduling classes leave the CFS weights alone.

This fixes a real bug as well: I noticed the following phonomena: a process elevated to SCHED_RR forks with SCHED_RESET_ON_FORK set, and the child is indeed SCHED_OTHER, and the niceval is indeed reset to 0. However the weight inserted by set_load_weight() remains at 0, giving the task insignificat priority.

With this fix, the weight is reset to what the task had before being elevated to SCHED_RR/SCHED_FIFO.

LKML-Reference: <[email protected]>

kernel/sched.c +0 -6
index 5f64fed..728081a 100644
@@ -1855,12 +1855,6 @@ static void dec_nr_running(struct rq *rq)
 
 static void set_load_weight(struct task_struct *p)
 {
-	if (task_has_rt_policy(p)) {
-		p->se.load.weight = 0;
-		p->se.load.inv_weight = WMULT_CONST;
-		return;
-	}
-
 	/*
 	 * SCHED_IDLE tasks get minimal weight:
 	 */
maintainer
#38 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin
Quoted 5 lines · Raistlin

+ * We are being explicitly informed that a new instance is starting,
+ * and this means that:
+ * - the absolute deadline of the entity has to be placed at
+ * current time + relative deadline;
+ * - the runtime of the entity has to be set to the maximum value.

When exactly are we a new instance? From a quick look dl_new gets set after a sched_setscheduler() call, is that the only way?

Could a task calling sched_setscheduler() on itself cheat the system?

author
#39 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 10 lines · Peter Zijlstra
Quoted 5 lines · Raistlin

+ * We are being explicitly informed that a new instance is starting,
+ * and this means that:
+ * - the absolute deadline of the entity has to be placed at
+ * current time + relative deadline;
+ * - the runtime of the entity has to be set to the maximum value.

When exactly are we a new instance? From a quick look dl_new gets set after a sched_setscheduler() call, is that the only way?

One of the only two ways. Later in the queue, that flag is set by a new system call, i.e., sched_wait_interval, that can be used to inform the scheduler (for example at the end of a periodic/sporadic job) that an instance just ended. Moreover, it can be exploited by a task which want the scheduler to wake it up when it can be given its full runtime. It as been added as a consequence of the discussion happened in Dresden, at last year RTLWS, aside of my presentation...

Whether or not this could be useful, I don't know, and I accept comments as usual. My opinion is that it might be something worthwhile to have, especially from the point of view of hard real-time-ish scenarios, but we can remove it appears unnecessary.

Quoted 2 lines

Could a task calling sched_setscheduler() on itself cheat the system?

I obviously might be wrong (especially at this time), but I would say no for the following reasons.

If you are an overrunning -deadline task calling sched_setscheduler() the deactivate_task->dequeue_task->dequeue_task_dl() below will trigger the bandwidth enforcement, i.e., will set dl_throttled=1 and start dl_timer:

	...
        on_rq = p->se.on_rq;                                                                                          
        running = task_current(rq, p);                                                                                
        if (on_rq)
                deactivate_task(rq, p, 0);
        if (running)
                p->sched_class->put_prev_task(rq, p);
	...

Later, this enqueue:

	...
	if (running)                                                                                                  
                p->sched_class->set_curr_task(rq);                                                                    
        if (on_rq) {
                activate_task(rq, p, 0);                                                                              
                                                                                                                      
                check_class_changed(rq, p, prev_class, oldprio, running);
        }
	...

even if it will find dl_new=1, will not enqueue the task back in its dl_rq (since dl_throttled=1). The actual enqueueing happens at the firing of dl_timer, where an update instead than a replenishment will be performed, right because of the fact that dl_new=1. This means the runtime will be fully replenished and the deadline moved toward rq->clock+dl_se->dl_deadline.

Did this answer your question?

Thanks and Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#40 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin

Review recheck:

Quoted 1 line · Raistlin
(quoted diff) +0 -0
@@ -4922,7 +4965,11 @@ recheck:

if you add:

QUILT_DIFF_OPTS="-F ^[[:alpha:]\$_].*[^:]\$"

to your /etc/quilt.quiltrc, it won't see labels as functions.

author
#41 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 9 lines · Peter Zijlstra

Review recheck:

Quoted 1 line · Raistlin
(quoted diff) +0 -0
@@ -4922,7 +4965,11 @@ recheck:

if you add:

QUILT_DIFF_OPTS="-F ^[[:alpha:]\$_].*[^:]\$"

to your /etc/quilt.quiltrc, it won't see labels as functions.

Mmm... Even if I don't use quilt at all and all this is the output of git-format-patch? :-O

BTW, thanks, I'll figure it out! ;-P

Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#42 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin
Quoted 10 lines · Raistlin
kernel/sched_dl.c new file +10 -0
+static void update_dl_entity(struct sched_dl_entity *dl_se)
+{
+       struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
+       struct rq *rq = rq_of_dl_rq(dl_rq);
+
+       /*
+        * The arrival of a new instance needs special treatment, i.e.,
+        * the actual scheduling parameters have to be "renewed".
+        */
+       if (dl_se->dl_new) {

kernel/sched_dl.c line 184

Quoted 10 lines
kernel/sched_dl.c new file +10 -0
+               setup_new_dl_entity(dl_se);
+               return;
+       }
+
+       if (dl_time_before(dl_se->deadline, rq->clock) ||
+           dl_entity_overflow(dl_se, rq->clock)) {
+               dl_se->deadline = rq->clock + dl_se->dl_deadline;
+               dl_se->runtime = dl_se->dl_runtime;
+       }
+} 

Can't we loose runtime deficit this way?

author
#43 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 9 lines · Peter Zijlstra

kernel/sched_dl.c line 184

Quoted 6 lines
kernel/sched_dl.c new file +6 -0
+       if (dl_time_before(dl_se->deadline, rq->clock) ||
+           dl_entity_overflow(dl_se, rq->clock)) {
+               dl_se->deadline = rq->clock + dl_se->dl_deadline;
+               dl_se->runtime = dl_se->dl_runtime;
+       }
+} 

Can't we loose runtime deficit this way?

No, this should not be the case (I hope!). The rationale is basically the same of the other e-mail about new instances.

In fact, a task that goes to sleep with some available runtime will be given new parameters or not, depending on the return value of dl_entity_overflow, and that's fine, right?

On the other hand, a task blocking while in overrun will (at dequeue_* and/or put_* time) trigger the bandwidth enforcement logic (which arms dl_timer) so that:
- if unblocking happens _before_ it becomes eligible again, the enqueue will be later handled by the dl_timer itself, when it'll fire, and the task will be given a replenishment starting from its negative runtime;
- if unblocking happens _later_ than the firing of dl_timer, resetting the scheduling parameters should be just fine, from the bandwidth point of view.

Does it make sense?

Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#44 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 18 lines · Raistlin
Quoted 8 lines · Peter Zijlstra

kernel/sched_dl.c line 184

Quoted 6 lines
kernel/sched_dl.c new file +6 -0
+       if (dl_time_before(dl_se->deadline, rq->clock) ||
+           dl_entity_overflow(dl_se, rq->clock)) {
+               dl_se->deadline = rq->clock + dl_se->dl_deadline;
+               dl_se->runtime = dl_se->dl_runtime;
+       }
+} 

Can't we loose runtime deficit this way?

- if unblocking happens _before_ it becomes eligible again, the enqueue will be later handled by the dl_timer itself, when it'll fire, and the task will be given a replenishment starting from its negative runtime;
- if unblocking happens _later_ than the firing of dl_timer, resetting the scheduling parameters should be just fine, from the bandwidth point of view.

Quoted 1 line

Does it make sense?

Yes, I think so. Thanks!

maintainer
#45 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin
Quoted 1 line · Raistlin

+ delta_exec = rq->clock - curr->se.exec_start;

This changed to rq->clock_task, the difference between rq->clock and rq->clock_task is that the latter only counts time actually spend on the task context (ie. it doesn't count softirq and hardirq context).

author
#46 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 7 lines · Peter Zijlstra
Quoted 1 line · Raistlin

+ delta_exec = rq->clock - curr->se.exec_start;

This changed to rq->clock_task, the difference between rq->clock and rq->clock_task is that the latter only counts time actually spend on the task context (ie. it doesn't count softirq and hardirq context).

Yeah, I noticed later that Venki's changes in accounting could be super-useful here. I'm already on it! :-P

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#47 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin
Quoted 23 lines · Raistlin
kernel/sched_dl.c new file +23 -0
+static void update_curr_dl(struct rq *rq)
+{
+       struct task_struct *curr = rq->curr;
+       struct sched_dl_entity *dl_se = &curr->dl;
+       u64 delta_exec;
+
+       if (!dl_task(curr) || !on_dl_rq(dl_se))
+               return;
+
+       delta_exec = rq->clock - curr->se.exec_start;
+       if (unlikely((s64)delta_exec < 0))
+               delta_exec = 0;
+
+       schedstat_set(curr->se.statistics.exec_max,
+                     max(curr->se.statistics.exec_max, delta_exec));
+
+       curr->se.sum_exec_runtime += delta_exec;
+       account_group_exec_runtime(curr, delta_exec);
+
+       curr->se.exec_start = rq->clock;
+       cpuacct_charge(curr, delta_exec);
+
+       dl_se->runtime -= delta_exec;

kernel/sched_dl.c line 347

Quoted 10 lines
kernel/sched_dl.c new file +10 -0
+       if (dl_runtime_exceeded(rq, dl_se)) {
+               __dequeue_task_dl(rq, curr, 0);
+               if (likely(start_dl_timer(dl_se)))
+                       dl_se->dl_throttled = 1;
+               else
+                       enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH);
+
+               resched_task(curr);
+       }
+} 

So you keep the current task in the rb-tree? If you remove the current task from the tree you don't have to do the whole dequeue/enqueue thing. Then again, I guess it only really matters once you push the deadline, which shouldn't be that often.

Also, you might want to put a conditional around that resched, no point rescheduling if you're still the leftmost task.

author
#48 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 5 lines · Peter Zijlstra
Quoted 5 lines
kernel/sched_dl.c new file +5 -0
+       dl_se->runtime -= delta_exec;
+       if (dl_runtime_exceeded(rq, dl_se)) {
+               __dequeue_task_dl(rq, curr, 0);
+               if (likely(start_dl_timer(dl_se)))
+                       dl_se->dl_throttled = 1;
Quoted 9 lines

kernel/sched_dl.c line 347

Quoted 6 lines
kernel/sched_dl.c new file +6 -0
+               else
+                       enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH);
+
+               resched_task(curr);
+       }
+} 

So you keep the current task in the rb-tree?

Yes, I do.

Quoted 5 lines

If you remove the current
task from the tree you don't have to do the whole dequeue/enqueue thing. Then again, I guess it only really matters once you push the deadline, which shouldn't be that often.

I'm not sure. The likelihood of runtime overrun/deadline pushing depends on many things, and might happen even if nothing is going bad... Might be wanted actually!

Suppose you have some sporadic task of some sort with computation ~10ms and (minimum) interarrival time of jobs of 100ms. Moreover, I want it to be able to react with a latency in the order of 100us. If I give it 10ms/100ms (or maybe 12ms/100ms, or whatever overprovisioning is considered enough to be safe), and an instance arrives as soon as the it has been throttled I may have to wait for 90ms (88, ?). Thus, I give it 10us/100us, which means it won't stay throttled for more tha 90us, but also that it's runtime will be exhausted (and it's deadline pushed away) 1000 times for a typical instance!

Forgive me for the stupid example... What I was trying to point out is that, especially considering we don't (want to!) have rock solid WCET analysis, too much bias toward the case were the scheduling parameters perfectly matches the applications' ones would not be as much preferable.

For this reasons, I structured the code this way, and it seems to me that keeping current out the the tree would complicate the code quite a bit, but I'm also sure it's doable if you really think it is needed. Just let me know... :-)

Quoted 3 lines

Also, you might want to put a conditional around that resched, no point rescheduling if you're still the leftmost task.

Right. This should be done, indeed.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#49 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin

kernel/sched_dl.c line 476

Quoted 7 lines · Raistlin
kernel/sched_dl.c new file +7 -0
+static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
+                                 int flags)
+{
+       if (!dl_task(rq->curr) || (dl_task(p) &&
+           dl_time_before(p->dl.deadline, rq->curr->dl.deadline)))
+               resched_task(rq->curr);
+} 

every moment now a patch will hit -tip that ensures ->check_preempt_curr() is only called when both the current and waking task belong to the same sched_class.

author
#50 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 13 lines · Peter Zijlstra

kernel/sched_dl.c line 476

Quoted 7 lines · Raistlin
kernel/sched_dl.c new file +7 -0
+static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
+                                 int flags)
+{
+       if (!dl_task(rq->curr) || (dl_task(p) &&
+           dl_time_before(p->dl.deadline, rq->curr->dl.deadline)))
+               resched_task(rq->curr);
+} 

every moment now a patch will hit -tip that ensures ->check_preempt_curr() is only called when both the current and waking task belong to the same sched_class.

Again, I saw your fix to this, which is later than this patchset... :-)

I'll take care of this while rebasing right in these days.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#51 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

In reply to Raistlin

kernel/sched_dl.c line 553

Quoted 12 lines · Raistlin
kernel/sched_dl.c new file +12 -0
+static void task_fork_dl(struct task_struct *p)
+{
+	/*
+	 * The child of a -deadline task will be SCHED_DEADLINE, but
+	 * as a throttled task. This means the parent (or someone else)
+	 * must call sched_setscheduler_ex() on it, or it won't even
+	 * start.
+	 */
+	p->dl.dl_throttled = 1;
+	p->dl.dl_new = 0;
+}
+

So, this is also something we only discussed once without reaching a conclusive statement... Are we ok with this behaviour?

I'm not, actually, but I'm not sure how to do better, considering:
- resetting task to SCHED_OTHER on fork is useless and confusing, since RESET_ON_FORK already exists and allows for this.
- cloning the parent's bandwidth and try to see if it fits might be nice, but what if the check fails? fork fails as well? If yes, what should the parent do, lower its own bandwidth (since it's being cloned) and try forking again? If yes, lowering it by how much? Mmm... Not sure it would fly... :-(
- splitting the bandwidth of the parent in two would make sense to me, but then it has to be returned at some point, or a poor -deadline shell will reach zero bandwidth after a few `ls'! So, when are we giving the bandwidth back to the parent? When the child dies? What if the child is sched_setscheduled_ex()-ed (either to -deadline or to something else), we return the bw back (if the call succeeds) as well?

I was thinking wither to force RESET_ON_FORK for SCHED_DEADLINE or to try to pursue the 3rd solution (provided I figure out what to do on detaching, parent dying, and such things... :-P).

Comments very very welcome!

Thanks and Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#52 lore raw

Re: [RFC][PATCH 05/22] sched: SCHED_DEADLINE policy implementation

Quoted 32 lines · Raistlin

kernel/sched_dl.c line 553

Quoted 12 lines · Raistlin
kernel/sched_dl.c new file +12 -0
+static void task_fork_dl(struct task_struct *p)
+{
+	/*
+	 * The child of a -deadline task will be SCHED_DEADLINE, but
+	 * as a throttled task. This means the parent (or someone else)
+	 * must call sched_setscheduler_ex() on it, or it won't even
+	 * start.
+	 */
+	p->dl.dl_throttled = 1;
+	p->dl.dl_new = 0;
+}
+

So, this is also something we only discussed once without reaching a conclusive statement... Are we ok with this behaviour?

I'm not, actually, but I'm not sure how to do better, considering:
- resetting task to SCHED_OTHER on fork is useless and confusing, since RESET_ON_FORK already exists and allows for this.
- cloning the parent's bandwidth and try to see if it fits might be nice, but what if the check fails? fork fails as well? If yes, what should the parent do, lower its own bandwidth (since it's being cloned) and try forking again? If yes, lowering it by how much? Mmm... Not sure it would fly... :-(
- splitting the bandwidth of the parent in two would make sense to me, but then it has to be returned at some point, or a poor -deadline shell will reach zero bandwidth after a few `ls'! So, when are we giving the bandwidth back to the parent? When the child dies? What if the child is sched_setscheduled_ex()-ed (either to -deadline or to something else), we return the bw back (if the call succeeds) as well?

Quoted 5 lines

I was thinking wither to force RESET_ON_FORK for SCHED_DEADLINE or to try to pursue the 3rd solution (provided I figure out what to do on detaching, parent dying, and such things... :-P).

Comments very very welcome!

Right, so either this, or we could make sched_deadline tasks fail fork() ;-)

from a RT perspective such tasks shouldn't fork() anyway, fork() includes a lot of implicit memory allocations which definitely are not deterministic (page reclaim etc.).

So yeah, I'm fine with this, it causes some pain, but then, you've earned this pain by doing this in the first place.

author
#53 lore raw

RFC PATCH 6/22 sched: SCHED_DEADLINE handles spacial kthreads

In reply to Raistlin

There sometimes is the need of executing a task as if it would have the maximum possible priority in the entire system, i.e., whenever it gets ready it must run! This is for example the case for some maintainance kernel thread like migration and (sometimes) watchdog or ksoftirq.

Since SCHED_DEADLINE is now the highest priority scheduling class these tasks have to be handled therein, but it is not obvious how to choose a runtime and a deadline that guarantee what explained above. Therefore, we need a mean of recognizing system tasks inside the -deadline class and always run them as soon as possible, without any kind of runtime and bandwidth limitation.

This patch:
- adds the SF_HEAD flag, which identify a special task that need absolute prioritization among any other task;
- ensures that special tasks always preempt everyone else (and, obviously, are not preempted by non special tasks);
- disables runtime and bandwidth checking for such tasks, hoping that the interference they cause is small enough.

---
 include/linux/sched.h |   13 ++++++++++
 kernel/sched.c        |   59 ++++++++++++++++++++++++++++++++++++++----------
 kernel/sched_dl.c     |   27 ++++++++++++++++++++--
 kernel/softirq.c      |    6 +----
 kernel/watchdog.c     |    3 +-
 5 files changed, 85 insertions(+), 23 deletions(-)
include/linux/sched.h +13 -0
index f94da51..f25d3a6 100644
@@ -154,6 +154,18 @@ struct sched_param_ex {
 	struct timespec curr_deadline;
 };
 
+/*
+ * Scheduler flags.
+ *
+ *  @SF_HEAD    tells us that the task has to be considered one of the
+ *              maximum priority tasks in the system. This means it
+ *              always enqueued with maximum priority in the runqueue
+ *              of the highest priority scheduling class. In case it
+ *              it sched_deadline, the task also ignore runtime and
+ *              bandwidth limitations.
+ */
+#define SF_HEAD		1
+
 struct exec_domain;
 struct futex_pi_state;
 struct robust_list_head;
@@ -2072,6 +2084,7 @@ extern int sched_setscheduler(struct task_struct *, int,
 			      const struct sched_param *);
 extern int sched_setscheduler_nocheck(struct task_struct *, int,
 				      const struct sched_param *);
+extern void setscheduler_dl_special(struct task_struct *);
 extern int sched_setscheduler_ex(struct task_struct *, int,
 				 const struct sched_param *,
 				 const struct sched_param_ex *);
kernel/sched.c +46 -13

101 lines not on this page · raw message

kernel/sched_dl.c +24 -3
index 9d0443e..17973aa 100644
@@ -19,6 +19,21 @@ static inline int dl_time_before(u64 a, u64 b)
 	return (s64)(a - b) < 0;
 }
 
+/*
+ * Tells if entity @a should preempt entity @b.
+ */
+static inline
+int dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b)
+{
+	/*
+	 * A system task marked with SF_HEAD flag will always
+	 * preempt a non 'special' one.
+	 */
+	return a->flags & SF_HEAD ||
+	       (!(b->flags & SF_HEAD) &&
+		dl_time_before(a->deadline, b->deadline));
+}
+
 static inline struct task_struct *dl_task_of(struct sched_dl_entity *dl_se)
 {
 	return container_of(dl_se, struct task_struct, dl);
@@ -291,7 +306,13 @@ int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se)
 	int dmiss = dl_time_before(dl_se->deadline, rq->clock);
 	int rorun = dl_se->runtime <= 0;
 
-	if (!rorun && !dmiss)
+	/*
+	 * No need for checking if it's time to enforce the
+	 * bandwidth for the tasks that are:
+	 *  - maximum priority (SF_HEAD),
+	 *  - not overrunning nor missing a deadline.
+	 */
+	if (dl_se->flags & SF_HEAD || (!rorun && !dmiss))
 		return 0;
 
 	/*
@@ -359,7 +380,7 @@ static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
 	while (*link) {
 		parent = *link;
 		entry = rb_entry(parent, struct sched_dl_entity, rb_node);
-		if (dl_time_before(dl_se->deadline, entry->deadline))
+		if (dl_entity_preempt(dl_se, entry))
 			link = &parent->rb_left;
 		else {
 			link = &parent->rb_right;
@@ -471,7 +492,7 @@ static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
 				  int flags)
 {
 	if (!dl_task(rq->curr) || (dl_task(p) &&
-	    dl_time_before(p->dl.deadline, rq->curr->dl.deadline)))
+	    dl_entity_preempt(&p->dl, &rq->curr->dl)))
 		resched_task(rq->curr);
 }
 
kernel/softirq.c +1 -5
index d4d918a..9c4c967 100644
@@ -853,13 +853,9 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
 			     cpumask_any(cpu_online_mask));
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN: {
-		static struct sched_param param = {
-			.sched_priority = MAX_RT_PRIO-1
-		};
-
 		p = per_cpu(ksoftirqd, hotcpu);
 		per_cpu(ksoftirqd, hotcpu) = NULL;
-		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+		setscheduler_dl_special(p);
 		kthread_stop(p);
 		takeover_tasklets(hotcpu);
 		break;
kernel/watchdog.c +1 -2
index 94ca779..2b7f259 100644
@@ -307,10 +307,9 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
  */
 static int watchdog(void *unused)
 {
-	static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
 
-	sched_setscheduler(current, SCHED_FIFO, &param);
+	setscheduler_dl_special(current);
 
 	/* initialize timestamp */
 	__touch_watchdog();
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#54 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 14 lines · Raistlin

There sometimes is the need of executing a task as if it would have the maximum possible priority in the entire system, i.e., whenever it gets ready it must run! This is for example the case for some maintainance kernel thread like migration and (sometimes) watchdog or ksoftirq.

Since SCHED_DEADLINE is now the highest priority scheduling class these tasks have to be handled therein, but it is not obvious how to choose a runtime and a deadline that guarantee what explained above. Therefore, we need a mean of recognizing system tasks inside the -deadline class and always run them as soon as possible, without any kind of runtime and bandwidth limitation.

Quoted 8 lines

This patch:
- adds the SF_HEAD flag, which identify a special task that need absolute prioritization among any other task;
- ensures that special tasks always preempt everyone else (and, obviously, are not preempted by non special tasks);
- disables runtime and bandwidth checking for such tasks, hoping that the interference they cause is small enough.

Yet in the previous patch you had this hunk:

Quoted 11 lines

+++ b/kernel/sched_stoptask.c

(quoted diff) +1 -1
@@ -81,7 +81,7 @@ get_rr_interval_stop(struct rq *rq, struct
 task_struct *task)
  * Simple, special scheduling class for the per-CPU stop tasks:
  */
 static const struct sched_class stop_sched_class = {
-       .next                   = &rt_sched_class,
+       .next                   = &dl_sched_class,
 
        .enqueue_task           = enqueue_task_stop,

.dequeue_task = dequeue_task_stop,

#55 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 18 lines · Peter Zijlstra
Quoted 6 lines

Since SCHED_DEADLINE is now the highest priority scheduling class these tasks have to be handled therein, but it is not obvious how to choose a runtime and a deadline that guarantee what explained above. Therefore, we need a mean of recognizing system tasks inside the -deadline class and always run them as soon as possible, without any kind of runtime and bandwidth limitation.

Yet in the previous patch you had this hunk:

Quoted 9 lines

+++ b/kernel/sched_stoptask.c

(quoted diff) +1 -1
@@ -81,7 +81,7 @@ get_rr_interval_stop(struct rq *rq, struct
 task_struct *task)
  * Simple, special scheduling class for the per-CPU stop tasks:
  */
 static const struct sched_class stop_sched_class = {
-       .next                   = &rt_sched_class,
+       .next                   = &dl_sched_class,
 
Quoted 3 lines
Quoted 2 lines
(quoted diff) +0 -0
        .enqueue_task           = enqueue_task_stop,

.dequeue_task = dequeue_task_stop,

Yep. And (as said on IRC) this needs serious cleanup, in favour of stop_task!

I'll completely drop patch 06 for next releases.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#56 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

In reply to Raistlin

kernel/sched.c void sched_idle_next(void) · line 6110

Quoted 9 lines · Raistlin
kernel/sched.c +1 -1
@@ -6071,7 +6104,7 @@ void sched_idle_next(void)
         */
        raw_spin_lock_irqsave(&rq->lock, flags);
 
-       __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
+       __setscheduler_dl_special(rq, p);
 
        activate_task(rq, p, 0);
 

Ingo, happen to know if this is really needed these days? hotplug should have migrated all other tasks away, leaving only the idle task to run.

#57 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Raistlin
kernel/sched.c +0 -0
@@ -6071,7 +6104,7 @@ void sched_idle_next(void)
         */
        raw_spin_lock_irqsave(&rq->lock, flags);
 
Quoted 8 lines

kernel/sched.c void sched_idle_next(void) · line 6110

Quoted 5 lines
kernel/sched.c +1 -1
-       __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
+       __setscheduler_dl_special(rq, p);
 
        activate_task(rq, p, 0);
 

Ingo, happen to know if this is really needed these days? hotplug should have migrated all other tasks away, leaving only the idle task to run.

This is called before CPU_DEAD stage which migrates all tasks away.

Sorry, can't resist, off-topic quiestion. Do we really need migration_call()->migrate_live_tasks() ?

With the recent changes, try_to_wake_up() can never choose the dead (!cpu_online) cpu if the task was deactivated.

Looks like we should only worry about the running tasks, and migrate_dead_tasks()->pick_next_task() loop seems to all work we need.

(Of course, we can't just remove migrate_live_tasks(), at leat
migrate_dead() needs simple changes).

What do you think?

Oleg.

maintainer
#58 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 25 lines · Oleg Nesterov
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Raistlin
kernel/sched.c +0 -0
@@ -6071,7 +6104,7 @@ void sched_idle_next(void)
         */
        raw_spin_lock_irqsave(&rq->lock, flags);
 
Quoted 8 lines

kernel/sched.c void sched_idle_next(void) · line 6110

Quoted 5 lines
kernel/sched.c +1 -1
-       __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
+       __setscheduler_dl_special(rq, p);
 
        activate_task(rq, p, 0);
 

Ingo, happen to know if this is really needed these days? hotplug should have migrated all other tasks away, leaving only the idle task to run.

This is called before CPU_DEAD stage which migrates all tasks away.

Sorry, can't resist, off-topic quiestion. Do we really need migration_call()->migrate_live_tasks() ?

With the recent changes, try_to_wake_up() can never choose the dead (!cpu_online) cpu if the task was deactivated.

Quoted 8 lines

Looks like we should only worry about the running tasks, and migrate_dead_tasks()->pick_next_task() loop seems to all work we need.

(Of course, we can't just remove migrate_live_tasks(), at leat
migrate_dead() needs simple changes).

What do you think?

Yes, I think we can make that work, we could even move that migrate_live_tasks() into CPU_DYING, which is before this point.

#59 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · Oleg Nesterov

Sorry, can't resist, off-topic quiestion. Do we really need migration_call()->migrate_live_tasks() ?

With the recent changes, try_to_wake_up() can never choose the dead (!cpu_online) cpu if the task was deactivated.

Looks like we should only worry about the running tasks, and migrate_dead_tasks()->pick_next_task() loop seems to all work we need.

Quoted 7 lines
Quoted 4 lines

(Of course, we can't just remove migrate_live_tasks(), at leat
migrate_dead() needs simple changes).

What do you think?

Yes, I think we can make that work, we could even move that migrate_live_tasks() into CPU_DYING, which is before this point.

Hmm, I think you are right. In this case we can also simplify migrate-from-dead-cpu paths, we know that nobody can touch rq->lock, every CPU runs stop_machine_cpu_stop() with irqs disabled. No need to get/put task_struct, etc.

Oleg.

maintainer
#60 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 8 lines · Oleg Nesterov
Quoted 3 lines

Yes, I think we can make that work, we could even move that migrate_live_tasks() into CPU_DYING, which is before this point.

Hmm, I think you are right. In this case we can also simplify migrate-from-dead-cpu paths, we know that nobody can touch rq->lock, every CPU runs stop_machine_cpu_stop() with irqs disabled. No need to get/put task_struct, etc.

Something like so?.. hasn't even seen a compiler yet but one's got to do something to keep the worst bore of saturday night telly in check ;-)

---
Subject: sched: Simplify cpu-hot-unplug task migration
From: Peter Zijlstra <[email protected]>
Date: Sat Nov 13 19:32:29 CET 2010

LKML-Reference: <new-submission>

---
 include/linux/sched.h |    3 
 kernel/cpu.c          |    7 -
 kernel/sched.c        |  181 ++++++++++++--------------------------------------
 3 files changed, 46 insertions(+), 145 deletions(-)
include/linux/sched.h +0 -3
Index: linux-2.6/include/linux/sched.h
===================================================================
@@ -1872,14 +1872,11 @@ extern void sched_clock_idle_sleep_event
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
 extern void idle_task_exit(void);
 #else
 static inline void idle_task_exit(void) {}
 #endif
 
-extern void sched_idle_next(void);
-
 #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
 extern void wake_up_idle_cpu(int cpu);
 #else
kernel/cpu.c +0 -7
Index: linux-2.6/kernel/cpu.c
===================================================================
@@ -189,7 +189,6 @@ static inline void check_for_tasks(int c
 }
 
 struct take_cpu_down_param {
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };
@@ -208,11 +207,6 @@ static int __ref take_cpu_down(void *_pa
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();
 	return 0;
 }
 
@@ -223,7 +217,6 @@ static int __ref _cpu_down(unsigned int
 	void *hcpu = (void *)(long)cpu;
 	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
 	struct take_cpu_down_param tcd_param = {
-		.caller = current,
 		.mod = mod,
 		.hcpu = hcpu,
 	};
kernel/sched.c +46 -135

261 lines not on this page · raw message

#61 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 3 lines · Peter Zijlstra

Something like so?.. hasn't even seen a compiler yet but one's got to do something to keep the worst bore of saturday night telly in check ;-)

Yes, I _think_ this all can work (and imho makes a lot of sense if it works).

quick and dirty review below ;)

Quoted 6 lines

struct take_cpu_down_param {

kernel/cpu.c +0 -1
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };

kernel/cpu.c static int __ref take_cpu_down(void *_pa · line 215

Quoted 8 lines
kernel/cpu.c +0 -5
@@ -208,11 +207,6 @@ static int __ref take_cpu_down(void *_pa
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();

Yes. but we should remove "while (!idle_cpu(cpu))" from _cpu_down().

Quoted 16 lines
kernel/sched.c +0 -12
@@ -2381,18 +2381,15 @@ static int select_fallback_rq(int cpu, s
 		return dest_cpu;
 
 	/* No more Mr. Nice Guy. */
-	if (unlikely(dest_cpu >= nr_cpu_ids)) {
-		dest_cpu = cpuset_cpus_allowed_fallback(p);
-		/*
-		 * Don't tell them about moving exiting tasks or
-		 * kernel threads (both mm NULL), since they never
-		 * leave kernel.
-		 */
-		if (p->mm && printk_ratelimit()) {
-			printk(KERN_INFO "process %d (%s) no "
-			       "longer affine to cpu%d\n",
-			       task_pid_nr(p), p->comm, cpu);
-		}

kernel/sched.c static int select_fallback_rq(int cpu, s · line 2393

Quoted 10 lines
kernel/sched.c +9 -0
+	dest_cpu = cpuset_cpus_allowed_fallback(p);
+	/*
+	 * Don't tell them about moving exiting tasks or
+	 * kernel threads (both mm NULL), since they never
+	 * leave kernel.
+	 */
+	if (p->mm && printk_ratelimit()) {
+		printk(KERN_INFO "process %d (%s) no longer affine to cpu%d\n",
+				task_pid_nr(p), p->comm, cpu);
 	}

Hmm. I was really puzzled until I realized this is just cleanup, we can't reach this point if dest_cpu < nr_cpu_ids.

Quoted 6 lines
kernel/sched.c +2 -1
+static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
 {
 	struct rq *rq = cpu_rq(dead_cpu);
+	int needs_cpu, uninitialized_var(dest_cpu);
 
-	/* Must be exiting, otherwise would be on tasklist. */

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5778

Quoted 10 lines
kernel/sched.c +4 -6
-	BUG_ON(!p->exit_state);
-
-	/* Cannot have done final schedule yet: would have vanished. */
-	BUG_ON(p->state == TASK_DEAD);
-
-	get_task_struct(p);
+	needs_cpu = (task_cpu(p) == dead_cpu) && (p->state != TASK_WAKING);
+	if (needs_cpu)
+		dest_cpu = select_fallback_rq(dead_cpu, p);
+	raw_spin_unlock(&rq->lock);

Probably we do not need any checks. This task was picked by ->pick_next_task(), it should have task_cpu(p) == dead_cpu ?

But. I think there is a problem. We should not migrate current task, stop thread, which does the migrating. At least, sched_stoptask.c doesn't implement ->enqueue_task() and we can never wake it up later for kthread_stop().

Perhaps migrate_tasks() should do for_each_class() by hand to ignore stop_sched_class. But then _cpu_down() should somewhow ensure the stop thread on the dead CPU is already parked in schedule().

kernel/sched.c migration_call(struct notifier_block *nf · line 6047

Quoted 10 lines
kernel/sched.c +2 -1
-	case CPU_DYING_FROZEN:
 		/* Update our root-domain */
 		raw_spin_lock_irqsave(&rq->lock, flags);
 		if (rq->rd) {
 			BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
 			set_rq_offline(rq);
 		}
+		migrate_tasks(cpu);
+		BUG_ON(rq->nr_running != 0);
 		raw_spin_unlock_irqrestore(&rq->lock, flags);

Probably we don't really need rq->lock. All cpus run stop threads.

I am not sure about rq->idle, perhaps it should be deactivated. I don't think we should migrate it.

What I never understood is the meaning of play_dead/etc. If we remove sched_idle_next(), who will do that logic? And how the idle thread can call idle_task_exit() ?

Oleg.

maintainer
#62 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 19 lines · Oleg Nesterov
Quoted 3 lines · Peter Zijlstra

Something like so?.. hasn't even seen a compiler yet but one's got to do something to keep the worst bore of saturday night telly in check ;-)

Yes, I _think_ this all can work (and imho makes a lot of sense if it works).

quick and dirty review below ;)

Quoted 9 lines

struct take_cpu_down_param {

kernel/cpu.c +0 -1
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };
@@ -208,11 +207,6 @@ static int __ref take_cpu_down(void *_pa
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
Quoted 7 lines

kernel/cpu.c static int __ref take_cpu_down(void *_pa · line 215

Quoted 5 lines
kernel/cpu.c +0 -5
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();

Yes. but we should remove "while (!idle_cpu(cpu))" from _cpu_down().

Right, I think we should replace that with something like BUG_ON(! idle_cpu(cpu)); Since we migrated everything away during the stop machine, the cpu should be idle after it.

Quoted 21 lines
Quoted 21 lines
kernel/sched.c +5 -12
@@ -2381,18 +2381,15 @@ static int select_fallback_rq(int cpu, s
 		return dest_cpu;
 
 	/* No more Mr. Nice Guy. */
-	if (unlikely(dest_cpu >= nr_cpu_ids)) {
-		dest_cpu = cpuset_cpus_allowed_fallback(p);
-		/*
-		 * Don't tell them about moving exiting tasks or
-		 * kernel threads (both mm NULL), since they never
-		 * leave kernel.
-		 */
-		if (p->mm && printk_ratelimit()) {
-			printk(KERN_INFO "process %d (%s) no "
-			       "longer affine to cpu%d\n",
-			       task_pid_nr(p), p->comm, cpu);
-		}
+	dest_cpu = cpuset_cpus_allowed_fallback(p);
+	/*
+	 * Don't tell them about moving exiting tasks or
+	 * kernel threads (both mm NULL), since they never
+	 * leave kernel.
Quoted 8 lines

kernel/sched.c static int select_fallback_rq(int cpu, s · line 2393

Quoted 5 lines
kernel/sched.c +4 -0
+	 */
+	if (p->mm && printk_ratelimit()) {
+		printk(KERN_INFO "process %d (%s) no longer affine to cpu%d\n",
+				task_pid_nr(p), p->comm, cpu);
 	}

Hmm. I was really puzzled until I realized this is just cleanup, we can't reach this point if dest_cpu < nr_cpu_ids.

Right.. Noticed that when I read that code, though I might as well fix it up.

Quoted 5 lines
Quoted 5 lines
kernel/sched.c +2 -0
+static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
 {
 	struct rq *rq = cpu_rq(dead_cpu);
+	int needs_cpu, uninitialized_var(dest_cpu);
Quoted 14 lines

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5778

Quoted 11 lines
kernel/sched.c +4 -7
-	/* Must be exiting, otherwise would be on tasklist. */
-	BUG_ON(!p->exit_state);
-
-	/* Cannot have done final schedule yet: would have vanished. */
-	BUG_ON(p->state == TASK_DEAD);
-
-	get_task_struct(p);
+	needs_cpu = (task_cpu(p) == dead_cpu) && (p->state != TASK_WAKING);
+	if (needs_cpu)
+		dest_cpu = select_fallback_rq(dead_cpu, p);
+	raw_spin_unlock(&rq->lock);

Probably we do not need any checks. This task was picked by ->pick_next_task(), it should have task_cpu(p) == dead_cpu ?

Right, we can drop those checks, its unconditionally true.

Quoted 4 lines

But. I think there is a problem. We should not migrate current task, stop thread, which does the migrating. At least, sched_stoptask.c doesn't implement ->enqueue_task() and we can never wake it up later for kthread_stop().

Hrm, right, so while the migration thread isn't actually on any rq structure as such, pick_next_task() will return it.. need to come up with a way to skip it.

As to current, take_cpu_down() is actually migrating current away before this patch, so I simply included current in the CPU_DYING->migrate_tasks() loop and removed the special case from take_cpu_down().

Quoted 4 lines

Perhaps migrate_tasks() should do for_each_class() by hand to ignore stop_sched_class. But then _cpu_down() should somewhow ensure the stop thread on the dead CPU is already parked in schedule().

Well, since we're in stop_machine all cpus but the cpu that is executing is stuck in the stop_machine_cpu_stop() loop, in both cases we could simply fudge the pick_next_task_stop() condition (eg. set rq->stop = NULL) while doing that loop, and restore it afterwards, nothing will hit schedule() while we're there.

Quoted 4 lines
Quoted 4 lines
kernel/sched.c +0 -1
-	case CPU_DYING_FROZEN:
 		/* Update our root-domain */
 		raw_spin_lock_irqsave(&rq->lock, flags);
 		if (rq->rd) {
Quoted 8 lines

kernel/sched.c migration_call(struct notifier_block *nf · line 6047

Quoted 6 lines
kernel/sched.c +2 -0
 			BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
 			set_rq_offline(rq);
 		}
+		migrate_tasks(cpu);
+		BUG_ON(rq->nr_running != 0);
 		raw_spin_unlock_irqrestore(&rq->lock, flags);

Probably we don't really need rq->lock. All cpus run stop threads.

Right, but I was worried about stuff that relied on lockdep state like the rcu lockdep stuff.. and taking the lock doesn't hurt.

Quoted 2 lines

I am not sure about rq->idle, perhaps it should be deactivated. I don't think we should migrate it.

Ah, I think the !nr_running check will bail before we end up selecting the idle thread.

Quoted 3 lines

What I never understood is the meaning of play_dead/etc. If we remove sched_idle_next(), who will do that logic? And how the idle thread can call idle_task_exit() ?

Well, since we'll have migrated every task on that runqueue (except the migration thread), the only runnable task left (once the migration thread stops running) is the idle thread, so it should be implicit.

As to play_dead():

  cpu_idle()
    if (cpu_is_offline(smp_processor_id()))
      play_dead()
        native_play_dead() /* did I already say I detest paravirt? */
          play_dead_common()
            idle_task_exit();
            local_irq_disable();
          tboot/mwait/hlt

It basically puts the cpu to sleep with IRQs disabled, needs special magic to wake it back up.

maintainer
#63 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Latest version, I actually compiled it too !

---
Subject: sched: Simplify cpu-hot-unplug task migration
From: Peter Zijlstra <[email protected]>
Date: Sat Nov 13 19:32:29 CET 2010

---
 include/linux/sched.h |    3 
 kernel/cpu.c          |   17 +---
 kernel/sched.c        |  201 ++++++++++++++------------------------------------
 3 files changed, 63 insertions(+), 158 deletions(-)
include/linux/sched.h +0 -3
Index: linux-2.6/include/linux/sched.h
===================================================================
@@ -1872,14 +1872,11 @@ extern void sched_clock_idle_sleep_event
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
 extern void idle_task_exit(void);
 #else
 static inline void idle_task_exit(void) {}
 #endif
 
-extern void sched_idle_next(void);
-
 #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
 extern void wake_up_idle_cpu(int cpu);
 #else
kernel/cpu.c +6 -11
Index: linux-2.6/kernel/cpu.c
===================================================================
@@ -189,7 +189,6 @@ static inline void check_for_tasks(int c
 }
 
 struct take_cpu_down_param {
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };
@@ -198,7 +197,6 @@ struct take_cpu_down_param {
 static int __ref take_cpu_down(void *_param)
 {
 	struct take_cpu_down_param *param = _param;
-	unsigned int cpu = (unsigned long)param->hcpu;
 	int err;
 
 	/* Ensure this CPU doesn't handle any more interrupts. */
@@ -208,11 +206,6 @@ static int __ref take_cpu_down(void *_pa
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();
 	return 0;
 }
 
@@ -223,7 +216,6 @@ static int __ref _cpu_down(unsigned int
 	void *hcpu = (void *)(long)cpu;
 	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
 	struct take_cpu_down_param tcd_param = {
-		.caller = current,
 		.mod = mod,
 		.hcpu = hcpu,
 	};
@@ -253,9 +245,12 @@ static int __ref _cpu_down(unsigned int
 	}
 	BUG_ON(cpu_online(cpu));
 
-	/* Wait for it to sleep (leaving idle task). */
-	while (!idle_cpu(cpu))
-		yield();
+	/*
+	 * The migration_call() CPU_DYING callback will have removed all
+	 * runnable tasks from the cpu, there's only the idle task left now
+	 * that the migration thread is done doing the stop_machine thing.
+	 */
+	BUG_ON(!idle_cpu(cpu));
 
 	/* This actually kills the CPU. */
 	__cpu_die(cpu);
kernel/sched.c +57 -144

277 lines not on this page · raw message

maintainer
#64 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

Quoted 1 line · Peter Zijlstra

Latest version, I actually compiled it too !

Locks up solid though,.. even the NMI watchdog doesn't seem to trigger anymore (or its broken too)...

/me goes prod at it a bit more

maintainer
#65 lore raw

PATCH 1/1 sched: Simplify cpu-hot-unplug task migration

Subject: sched: Simplify cpu-hot-unplug task migration
From: Peter Zijlstra <[email protected]>
Date: Sat Nov 13 19:32:29 CET 2010

While discussing the need for sched_idle_next(), Oleg remarked that since try_to_wake_up() ensures sleeping tasks will end up running on a sane cpu, we can do away with migrate_live_tasks().

If we then extend the existing hack of migrating current from CPU_DYING to migrating the full rq worth of tasks from CPU_DYING, the need for the sched_idle_next() abomination disappears as well, since idle will be the only possible thread left after the migration thread stops.

This greatly simplifies the hot-unplug task migration path, as can be seen from the resulting code reduction (and about half the new lines are comments).

---
 include/linux/sched.h |    3 
 kernel/cpu.c          |   16 +--
 kernel/sched.c        |  210 +++++++++++++++-----------------------------------
 3 files changed, 69 insertions(+), 160 deletions(-)
include/linux/sched.h +0 -3
Index: linux-2.6/include/linux/sched.h
===================================================================
@@ -1872,14 +1872,11 @@ extern void sched_clock_idle_sleep_event
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
 extern void idle_task_exit(void);
 #else
 static inline void idle_task_exit(void) {}
 #endif
 
-extern void sched_idle_next(void);
-
 #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
 extern void wake_up_idle_cpu(int cpu);
 #else
kernel/cpu.c +6 -10
Index: linux-2.6/kernel/cpu.c
===================================================================
@@ -189,7 +189,6 @@ static inline void check_for_tasks(int c
 }
 
 struct take_cpu_down_param {
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };
@@ -208,11 +207,6 @@ static int __ref take_cpu_down(void *_pa
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();
 	return 0;
 }
 
@@ -223,7 +217,6 @@ static int __ref _cpu_down(unsigned int 
 	void *hcpu = (void *)(long)cpu;
 	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
 	struct take_cpu_down_param tcd_param = {
-		.caller = current,
 		.mod = mod,
 		.hcpu = hcpu,
 	};
@@ -253,9 +246,12 @@ static int __ref _cpu_down(unsigned int 
 	}
 	BUG_ON(cpu_online(cpu));
 
-	/* Wait for it to sleep (leaving idle task). */
-	while (!idle_cpu(cpu))
-		yield();
+	/*
+	 * The migration_call() CPU_DYING callback will have removed all
+	 * runnable tasks from the cpu, there's only the idle task left now
+	 * that the migration thread is done doing the stop_machine thing.
+	 */
+	BUG_ON(!idle_cpu(cpu));
 
 	/* This actually kills the CPU. */
 	__cpu_die(cpu);
kernel/sched.c +63 -147

283 lines not on this page · raw message

#66 lore raw

Re: [PATCH] sched: Simplify cpu-hot-unplug task migration

Peter, sorry for delay.

I was going to read this patch carefully today, but due to the holiday in the Czech Republic I have to drink (too much) beer instead ;)

This means you should probably ignore my question, but can't resist...

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5790

Quoted 5 lines
kernel/sched.c +1 -4
-static void migrate_dead_tasks(unsigned int dead_cpu)
-{
-	struct rq *rq = cpu_rq(dead_cpu);
-	struct task_struct *next;
+	rq->stop = NULL;

(or we could do current->state = TASK_INTERRUPTIPLE, afaics)

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5798

Quoted 8 lines
kernel/sched.c +5 -1
 	for ( ; ; ) {
-		if (!rq->nr_running)
+		/*
+		 * There's this thread running, bail when that's the only
+		 * remaining thread.
+		 */
+		if (rq->nr_running == 1)
 			break;

I was very much confused, and I was going to say this is wrong. However, now I think this is correct, just the comment is not right.

There is another running thread we should not migrate, rq->idle. If nothing else, dequeue_task_idle() should be never called.

But, if I understand correctly, ->nr_running does not account the idle thread, and this is what makes this correct.

Correct?

Oleg.

maintainer
#67 lore raw

Re: [PATCH] sched: Simplify cpu-hot-unplug task migration

Quoted 7 lines · Oleg Nesterov

Peter, sorry for delay.

I was going to read this patch carefully today, but due to the holiday in the Czech Republic I have to drink (too much) beer instead ;)

This means you should probably ignore my question, but can't resist...

Quoted 7 lines

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5790

Quoted 5 lines
kernel/sched.c +1 -4
-static void migrate_dead_tasks(unsigned int dead_cpu)
-{
-	struct rq *rq = cpu_rq(dead_cpu);
-	struct task_struct *next;
+	rq->stop = NULL;

(or we could do current->state = TASK_INTERRUPTIPLE, afaics)

Ah, you missed a patch that made pick_next_task_stop() look like:

static struct task_struct *pick_next_task_stop(struct rq *rq)

{
        struct task_struct *stop = rq->stop;

        if (stop && stop->se.on_rq)
                return stop;

        return NULL;
}
Quoted 13 lines

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5798

Quoted 8 lines
kernel/sched.c +5 -1
 	for ( ; ; ) {
-		if (!rq->nr_running)
+		/*
+		 * There's this thread running, bail when that's the only
+		 * remaining thread.
+		 */
+		if (rq->nr_running == 1)
 			break;

I was very much confused, and I was going to say this is wrong. However, now I think this is correct, just the comment is not right.

Quoted 2 lines

There is another running thread we should not migrate, rq->idle. If nothing else, dequeue_task_idle() should be never called.

In fact, dequeue_task_idle() will yell if you try that ;-)

Quoted 4 lines

But, if I understand correctly, ->nr_running does not account the idle thread, and this is what makes this correct.

Correct?

Right, I can add: (the idle thread is not counted in nr_running), if that makes things clearer for you; however its a quite fundamental property, we don't consider the idle task a proper runnable entity, its simply the thing we do when there's nothing else to do.

#68 lore raw

Re: [PATCH] sched: Simplify cpu-hot-unplug task migration

Quoted 11 lines · Peter Zijlstra
Quoted 7 lines · Oleg Nesterov

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5790

Quoted 5 lines
kernel/sched.c +1 -4
-static void migrate_dead_tasks(unsigned int dead_cpu)
-{
-	struct rq *rq = cpu_rq(dead_cpu);
-	struct task_struct *next;
+	rq->stop = NULL;

(or we could do current->state = TASK_INTERRUPTIPLE, afaics)

Quoted 7 lines

Ah, you missed a patch that made pick_next_task_stop() look like:

static struct task_struct *pick_next_task_stop(struct rq *rq)

{
        struct task_struct *stop = rq->stop;

        if (stop && stop->se.on_rq)

Yes, thanks.

Quoted 18 lines
Quoted 13 lines

kernel/sched.c void move_task_off_dead_cpu(int dead_cpu · line 5798

Quoted 8 lines
kernel/sched.c +5 -1
 	for ( ; ; ) {
-		if (!rq->nr_running)
+		/*
+		 * There's this thread running, bail when that's the only
+		 * remaining thread.
+		 */
+		if (rq->nr_running == 1)
 			break;

I was very much confused, and I was going to say this is wrong. However, now I think this is correct, just the comment is not right.

Quoted 2 lines

There is another running thread we should not migrate, rq->idle. If nothing else, dequeue_task_idle() should be never called.

In fact, dequeue_task_idle() will yell if you try that ;-)

Quoted 8 lines
Quoted 4 lines

But, if I understand correctly, ->nr_running does not account the idle thread, and this is what makes this correct.

Correct?

Right, I can add: (the idle thread is not counted in nr_running), if that makes things clearer for you; however its a quite fundamental property,

Yes, I see now.

OK, this also explains my previous questions. I greatly misunderstood this "small detail", starting from your initial patch. Every time I thought you are trying to migrate rq->idle as well.

Thanks Peter. Only one question,

kernel/cpu.c static int __ref _cpu_down(unsigned int · line 254

Quoted 13 lines
kernel/cpu.c +6 -3
@@ -253,9 +246,12 @@ static int __ref _cpu_down(unsigned int
 	}
 	BUG_ON(cpu_online(cpu));
 
-	/* Wait for it to sleep (leaving idle task). */
-	while (!idle_cpu(cpu))
-		yield();
+	/*
+	 * The migration_call() CPU_DYING callback will have removed all
+	 * runnable tasks from the cpu, there's only the idle task left now
+	 * that the migration thread is done doing the stop_machine thing.
+	 */
+	BUG_ON(!idle_cpu(cpu));

I am not sure.

Yes, we know for sure rhat the only runnable task is rq->idle. But only after migration thread calls schedule() and switches to the idle thread.

However, I see nothing which can guarantee this. Migration thread running on the dead cpu wakes up the caller of stop_cpus() before it calls schedule(), _cpu_down() can check rq->curr before it was changed.

No?

Hmm. In fact, I think it is possible that cpu_stopper_thread() can have more cpu_stop_work's queued when __stop_machine() returns. This has nothing to do with this patch, but I think it makes sense to clear stopper->enabled at CPU_DYING stage as well (of course, this needs a separate patch).

Oleg.

maintainer
#69 lore raw

Re: [PATCH] sched: Simplify cpu-hot-unplug task migration

Quoted 25 lines · Oleg Nesterov

kernel/cpu.c static int __ref _cpu_down(unsigned int · line 254

Quoted 9 lines
kernel/cpu.c +6 -3
-     /* Wait for it to sleep (leaving idle task). */
-     while (!idle_cpu(cpu))
-             yield();
+     /*
+      * The migration_call() CPU_DYING callback will have removed all
+      * runnable tasks from the cpu, there's only the idle task left now
+      * that the migration thread is done doing the stop_machine thing.
+      */
+     BUG_ON(!idle_cpu(cpu));

I am not sure.

Yes, we know for sure rhat the only runnable task is rq->idle. But only after migration thread calls schedule() and switches to the idle thread.

However, I see nothing which can guarantee this. Migration thread running on the dead cpu wakes up the caller of stop_cpus() before it calls schedule(), _cpu_down() can check rq->curr before it was changed.

No?

Quoted 5 lines

Hmm. In fact, I think it is possible that cpu_stopper_thread() can have more cpu_stop_work's queued when __stop_machine() returns. This has nothing to do with this patch, but I think it makes sense to clear stopper->enabled at CPU_DYING stage as well (of course, this needs a separate patch).

Hmm, I think you're right, although I haven't hit that case during testing.

There is no firm guarantee the dying cpu actually got to running the idle thread (there's a guarantee it will at some point), so we ought to maintain that wait-loop, possibly using cpu_relax(), I don't see the point in calling yield() here.

#70 lore raw

Re: [PATCH] sched: Simplify cpu-hot-unplug task migration

Quoted 5 lines · Peter Zijlstra

There is no firm guarantee the dying cpu actually got to running the idle thread (there's a guarantee it will at some point), so we ought to maintain that wait-loop, possibly using cpu_relax(), I don't see the point in calling yield() here.

Agreed. But do we need to wait at all?

With or without this change, even if we know that rq->idle is running we can't know if it (say) already started play_dead_common() or not.

We are going to call __cpu_die(), afaics it should do the necessary synchronization in any case.

For example, native_cpu_die() waits for cpu_state == CPU_DEAD in a loop. Of course it should work in practice (it also does msleep), but in theory there is no guarantee.

So. Can't we just remove this wait-loop? We know that rq->idle will be scheduled "soon", I don't understand why it is necessary to ensure that context_switch() has already happened.

Oleg.

#71 lore raw

[tip:sched/core] sched: Simplify cpu-hot-unplug task migration

In reply to Peter Zijlstra
Commit-ID:  48c5ccae88dcd989d9de507e8510313c6cbd352b
Gitweb:     http://git.kernel.org/tip/48c5ccae88dcd989d9de507e8510313c6cbd352b
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Sat, 13 Nov 2010 19:32:29 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 18 Nov 2010 13:27:46 +0100

sched: Simplify cpu-hot-unplug task migration

While discussing the need for sched_idle_next(), Oleg remarked that since try_to_wake_up() ensures sleeping tasks will end up running on a sane cpu, we can do away with migrate_live_tasks().

If we then extend the existing hack of migrating current from CPU_DYING to migrating the full rq worth of tasks from CPU_DYING, the need for the sched_idle_next() abomination disappears as well, since idle will be the only possible thread left after the migration thread stops.

This greatly simplifies the hot-unplug task migration path, as can be seen from the resulting code reduction (and about half the new lines are comments).

LKML-Reference: <1289851597.2109.547.camel@laptop>

---
 include/linux/sched.h |    3 -
 kernel/cpu.c          |   16 ++---
 kernel/sched.c        |  206 +++++++++++++++----------------------------------
 3 files changed, 67 insertions(+), 158 deletions(-)
include/linux/sched.h +0 -3
index 3cd70cf..29d953a 100644
@@ -1871,14 +1871,11 @@ extern void sched_clock_idle_sleep_event(void);
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
 extern void idle_task_exit(void);
 #else
 static inline void idle_task_exit(void) {}
 #endif
 
-extern void sched_idle_next(void);
-
 #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
 extern void wake_up_idle_cpu(int cpu);
 #else
kernel/cpu.c +6 -10
index f6e726f..8615aa6 100644
@@ -189,7 +189,6 @@ static inline void check_for_tasks(int cpu)
 }
 
 struct take_cpu_down_param {
-	struct task_struct *caller;
 	unsigned long mod;
 	void *hcpu;
 };
@@ -208,11 +207,6 @@ static int __ref take_cpu_down(void *_param)
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
 
-	if (task_cpu(param->caller) == cpu)
-		move_task_off_dead_cpu(cpu, param->caller);
-	/* Force idle task to run as soon as we yield: it should
-	   immediately notice cpu is offline and die quickly. */
-	sched_idle_next();
 	return 0;
 }
 
@@ -223,7 +217,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	void *hcpu = (void *)(long)cpu;
 	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
 	struct take_cpu_down_param tcd_param = {
-		.caller = current,
 		.mod = mod,
 		.hcpu = hcpu,
 	};
@@ -253,9 +246,12 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	}
 	BUG_ON(cpu_online(cpu));
 
-	/* Wait for it to sleep (leaving idle task). */
-	while (!idle_cpu(cpu))
-		yield();
+	/*
+	 * The migration_call() CPU_DYING callback will have removed all
+	 * runnable tasks from the cpu, there's only the idle task left now
+	 * that the migration thread is done doing the stop_machine thing.
+	 */
+	BUG_ON(!idle_cpu(cpu));
 
 	/* This actually kills the CPU. */
 	__cpu_die(cpu);
kernel/sched.c +61 -145

281 lines not on this page · raw message

maintainer
#72 lore raw

Re: [RFC][PATCH 06/22] sched: SCHED_DEADLINE handles spacial kthreads

In reply to Raistlin
Quoted 9 lines · Raistlin
kernel/softirq.c +0 -1
index d4d918a..9c4c967 100644
@@ -853,13 +853,9 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
                             cpumask_any(cpu_online_mask));
        case CPU_DEAD:
        case CPU_DEAD_FROZEN: {
-               static struct sched_param param = {

kernel/softirq.c static int __cpuinit cpu_callback(struct notifier_block *nfb, · line 861

Quoted 10 lines
kernel/softirq.c +1 -4
-                       .sched_priority = MAX_RT_PRIO-1
-               };
-
                p = per_cpu(ksoftirqd, hotcpu);
                per_cpu(ksoftirqd, hotcpu) = NULL;
-               sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+               setscheduler_dl_special(p);
                kthread_stop(p);
                takeover_tasklets(hotcpu);
                break;

So this comes from 1c6b4aa94576, which is something I wouldn't have bothered merging in the first place, if you pin a cpu with RT tasks like that you get to keep the pieces, hotplug isn't the only thing that will go wonky.

Anyway, if you leave the code as is you'll be fine, it'll me above any FIFO task, but still below deadline tasks and the stop task, neither of which should be hogging the system like that anyway.

Quoted 6 lines
kernel/watchdog.c +0 -0
index 94ca779..2b7f259 100644
@@ -307,10 +307,9 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
  */

kernel/watchdog.c static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) · line 315

Quoted 10 lines
kernel/watchdog.c +1 -2
 static int watchdog(void *unused)
 {
-       static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
        struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
 
-       sched_setscheduler(current, SCHED_FIFO, &param);
+       setscheduler_dl_special(current);
 
        /* initialize timestamp */
        __touch_watchdog(); 

I'd be inclined to drop this too, if people get watchdog timeouts it means the system is really over-commited on deadline tasks and the watchdog FIFO thread didn't get around to running, something which I think we both agree shouldn't be happening.

author
#73 lore raw

RFC PATCH 7/22 sched: SCHED_DEADLINE push and pull logic

In reply to Raistlin

Add dynamic migrations to SCHED_DEADLINE, so that tasks can be moved among CPUs when necessary. It is also possible to bind a task to a (set of) CPU(s), thus restricting its capability of migrating, or forbidding migrations at all.

The very same approach used in sched_rt is utilised:
- -deadline tasks are kept into CPU-specific runqueues,
- -deadline tasks are migrated among runqueues to achieve the following:
* on an M-CPU system the M earliest deadline ready tasks are always running;
* affinity/cpusets settings of all the -deadline tasks is always respected.

Therefore, this very special form of "load balancing" is done with an active method, i.e., the scheduler pushes or pulls tasks between runqueues when they are woken up and/or (de)scheduled.
IOW, every time a preemption occurs, the descheduled task might be sent to some other CPU (depending on its deadline) to continue executing (push). On the other hand, every time a CPU becomes idle, it might pull the second earliest deadline ready task from some other CPU.

To enforce this, a pull operation is always attempted before taking any scheduling decision (pre_schedule()), as well as a push one after each scheduling decision (post_schedule()). In addition, when a task arrives or wakes up, the best CPU where to resume it is selected taking into account its affinity mask, the system topology, but also its deadline. E.g., from the scheduling point of view, the best CPU where to wake up (and also where to push) a task is the one which is running the task with the latest deadline among the M executing ones.

In order to facilitate these decisions, per-runqueue "caching" of the deadlines of the currently running and of the first ready task is used. Queued but not running tasks are also parked in another rb-tree to speed-up pushes.

---
 kernel/sched_dl.c |  888 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 kernel/sched_rt.c |    2 +-
 2 files changed, 866 insertions(+), 24 deletions(-)
kernel/sched_dl.c +865 -23
index 17973aa..26126a6 100644
@@ -10,6 +10,7 @@
  * miss some of their deadlines), and won't affect any other task.
  *
  * Copyright (C) 2010 Dario Faggioli <[email protected]>,
+ *                    Juri Lelli <[email protected]>,
  *                    Michael Trimarchi <[email protected]>,
  *                    Fabio Checconi <[email protected]>
  */
@@ -52,6 +53,151 @@ static inline struct dl_rq *dl_rq_of_se(struct sched_dl_entity *dl_se)
 	return &rq->dl;
 }
 
+#ifdef CONFIG_SMP
+
+static inline int dl_overloaded(struct rq *rq)
+{
+	return atomic_read(&rq->rd->dlo_count);
+}
+
+static inline void dl_set_overload(struct rq *rq)
+{
+	if (!rq->online)
+		return;
+
+	cpumask_set_cpu(rq->cpu, rq->rd->dlo_mask);
+	/*
+	 * Must be visible before the overload count is
+	 * set (as in sched_rt.c).
+	 */
+	wmb();
+	atomic_inc(&rq->rd->dlo_count);
+}
+
+static inline void dl_clear_overload(struct rq *rq)
+{
+	if (!rq->online)
+		return;
+
+	atomic_dec(&rq->rd->dlo_count);
+	cpumask_clear_cpu(rq->cpu, rq->rd->dlo_mask);
+}
+
+static void update_dl_migration(struct dl_rq *dl_rq)
+{
+	if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_total > 1) {
+		if (!dl_rq->overloaded) {
+			dl_set_overload(rq_of_dl_rq(dl_rq));
+			dl_rq->overloaded = 1;
+		}
+	} else if (dl_rq->overloaded) {
+		dl_clear_overload(rq_of_dl_rq(dl_rq));
+		dl_rq->overloaded = 0;
+	}
+}
+
+static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+	dl_rq = &rq_of_dl_rq(dl_rq)->dl;
+
+	dl_rq->dl_nr_total++;
+	if (dl_se->nr_cpus_allowed > 1)
+		dl_rq->dl_nr_migratory++;
+
+	update_dl_migration(dl_rq);
+}
+
+static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+	dl_rq = &rq_of_dl_rq(dl_rq)->dl;
+
+	dl_rq->dl_nr_total--;
+	if (dl_se->nr_cpus_allowed > 1)
+		dl_rq->dl_nr_migratory--;
+
+	update_dl_migration(dl_rq);
+}
+
+/*
+ * The list of pushable -deadline task is not a plist, like in
+ * sched_rt.c, it is an rb-tree with tasks ordered by deadline.
+ */
+static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
+{
+	struct dl_rq *dl_rq = &rq->dl;
+	struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_node;
+	struct rb_node *parent = NULL;
+	struct task_struct *entry;
+	int leftmost = 1;
+
+	BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks));
+
+	while (*link) {
+		parent = *link;
+		entry = rb_entry(parent, struct task_struct,
+				 pushable_dl_tasks);
+		if (!dl_entity_preempt(&entry->dl, &p->dl))
+			link = &parent->rb_left;
+		else {
+			link = &parent->rb_right;
+			leftmost = 0;
+		}
+	}
+
+	if (leftmost)
+		dl_rq->pushable_dl_tasks_leftmost = &p->pushable_dl_tasks;
+
+	rb_link_node(&p->pushable_dl_tasks, parent, link);
+	rb_insert_color(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
+}
+
+static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
+{
+	struct dl_rq *dl_rq = &rq->dl;
+
+	if (RB_EMPTY_NODE(&p->pushable_dl_tasks))
+		return;
+
+	if (dl_rq->pushable_dl_tasks_leftmost == &p->pushable_dl_tasks) {
+		struct rb_node *next_node;
+
+		next_node = rb_next(&p->pushable_dl_tasks);
+		dl_rq->pushable_dl_tasks_leftmost = next_node;
+	}
+
+	rb_erase(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
+	RB_CLEAR_NODE(&p->pushable_dl_tasks);
+}
+
+static inline int has_pushable_dl_tasks(struct rq *rq)
+{
+	return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root);
+}
+
+#else
+
+static inline
+void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
+{
+}
+
+static inline
+void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
+{
+}
+
+static inline
+void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+}
+
+static inline
+void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+}
+
+#endif /* CONFIG_SMP */
+
 static inline int on_dl_rq(struct sched_dl_entity *dl_se)
 {
 	return !RB_EMPTY_NODE(&dl_se->rb_node);
@@ -61,6 +207,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags);
 static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags);
 static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
 				  int flags);
+static int push_dl_task(struct rq *rq);
 
 /*
  * We are being explicitly informed that a new instance is starting,
@@ -280,6 +427,13 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
 	if (p->se.on_rq) {
 		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
 		check_preempt_curr_dl(rq, p, 0);
+
+		/*
+		 * Queueing this task back might have overloaded rq,
+		 * check if we need to kick someone away.
+		 */
+		if (rq->dl.overloaded)
+			push_dl_task(rq);
 	}
 unlock:
 	task_rq_unlock(rq, &flags);
@@ -367,6 +521,100 @@ static void update_curr_dl(struct rq *rq)
 	}
 }
 
+#ifdef CONFIG_SMP
+
+static struct task_struct *pick_next_earliest_dl_task(struct rq *rq, int cpu);
+
+static inline int next_deadline(struct rq *rq)
+{
+	struct task_struct *next = pick_next_earliest_dl_task(rq, rq->cpu);
+
+	if (next && dl_prio(next->prio))
+		return next->dl.deadline;
+	else
+		return 0;
+}
+
+static void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
+{
+	struct rq *rq = rq_of_dl_rq(dl_rq);
+
+	if (dl_rq->earliest_dl.curr == 0 ||
+	    dl_time_before(deadline, dl_rq->earliest_dl.curr)) {
+		/*
+		 * If the dl_rq had no -deadline tasks, or if the new task
+		 * has shorter deadline than the current one on dl_rq, we
+		 * know that the previous earliest becomes our next earliest,
+		 * as the new task becomes the earliest itself.
+		 */
+		dl_rq->earliest_dl.next = dl_rq->earliest_dl.curr;
+		dl_rq->earliest_dl.curr = deadline;
+	} else if (dl_rq->earliest_dl.next == 0 ||
+		   dl_time_before(deadline, dl_rq->earliest_dl.next)) {
+		/*
+		 * On the other hand, if the new -deadline task has a
+		 * a later deadline than the earliest one on dl_rq, but
+		 * it is earlier than the next (if any), we must
+		 * recompute the next-earliest.
+		 */
+		dl_rq->earliest_dl.next = next_deadline(rq);
+	}
+}
+
+static void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
+{
+	struct rq *rq = rq_of_dl_rq(dl_rq);
+
+	/*
+	 * Since we may have removed our earliest (and/or next earliest)
+	 * task we must recompute them.
+	 */
+	if (!dl_rq->dl_nr_running) {
+		dl_rq->earliest_dl.curr = 0;
+		dl_rq->earliest_dl.next = 0;
+	} else {
+		struct rb_node *leftmost = dl_rq->rb_leftmost;
+		struct sched_dl_entity *entry;
+
+		entry = rb_entry(leftmost, struct sched_dl_entity, rb_node);
+		dl_rq->earliest_dl.curr = entry->deadline;
+		dl_rq->earliest_dl.next = next_deadline(rq);
+	}
+}
+
+#else
+
+static inline void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
+static inline void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
+
+#endif /* CONFIG_SMP */
+
+static inline
+void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+	int prio = dl_task_of(dl_se)->prio;
+	u64 deadline = dl_se->deadline;
+
+	WARN_ON(!dl_prio(prio));
+	dl_rq->dl_nr_running++;
+
+	inc_dl_deadline(dl_rq, deadline);
+	inc_dl_migration(dl_se, dl_rq);
+}
+
+static inline
+void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
+{
+	int prio = dl_task_of(dl_se)->prio;
+
+	WARN_ON(!dl_prio(prio));
+	WARN_ON(!dl_rq->dl_nr_running);
+	dl_rq->dl_nr_running--;
+
+	dec_dl_deadline(dl_rq, dl_se->deadline);
+	dec_dl_migration(dl_se, dl_rq);
+}
+
 static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
 {
 	struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
@@ -394,7 +642,7 @@ static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
 	rb_link_node(&dl_se->rb_node, parent, link);
 	rb_insert_color(&dl_se->rb_node, &dl_rq->rb_root);
 
-	dl_rq->dl_nr_running++;
+	inc_dl_tasks(dl_se, dl_rq);
 }
 
 static void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
@@ -414,7 +662,7 @@ static void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
 	rb_erase(&dl_se->rb_node, &dl_rq->rb_root);
 	RB_CLEAR_NODE(&dl_se->rb_node);
 
-	dl_rq->dl_nr_running--;
+	dec_dl_tasks(dl_se, dl_rq);
 }
 
 static void
@@ -452,11 +700,15 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 		return;
 
 	enqueue_dl_entity(&p->dl, flags);
+
+	if (!task_current(rq, p) && p->dl.nr_cpus_allowed > 1)
+		enqueue_pushable_dl_task(rq, p);
 }
 
 static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
 	dequeue_dl_entity(&p->dl);
+	dequeue_pushable_dl_task(rq, p);
 }
 
 static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
@@ -488,12 +740,80 @@ static void yield_task_dl(struct rq *rq)
 	update_curr_dl(rq);
 }
 
+#ifdef CONFIG_SMP
+static int find_later_rq(struct task_struct *task);
+static int latest_cpu_find(struct cpumask *span,
+			   struct task_struct *task,
+			   struct cpumask *later_mask);
+
+static int
+select_task_rq_dl(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
+{
+	if (sd_flag != SD_BALANCE_WAKE)
+		return smp_processor_id();
+
+	/*
+	 * If we are dealing with a -deadline task, we must
+	 * decide where to wake it up.
+	 * If it has a later deadline and the current task
+	 * on this rq can't move (provided the waking task
+	 * can!) we prefer to send it somewhere else. On the
+	 * other hand, if it has a shorter deadline, we
+	 * try to make it stay here, it might be important.
+	 */
+	if (unlikely(dl_task(rq->curr)) &&
+	    (rq->curr->dl.nr_cpus_allowed < 2 ||
+	     dl_entity_preempt(&rq->curr->dl, &p->dl)) &&
+	    (p->dl.nr_cpus_allowed > 1)) {
+		int cpu = find_later_rq(p);
+
+		return (cpu == -1) ? task_cpu(p) : cpu;
+	}
+
+	return task_cpu(p);
+}
+
+static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
+{
+	/*
+	 * Current can't be migrated, useles to reschedule,
+	 * let's hope p can move out.
+	 */
+	if (rq->curr->dl.nr_cpus_allowed == 1 ||
+	    latest_cpu_find(rq->rd->span, rq->curr, NULL) == -1)
+		return;
+
+	/*
+	 * p is migratable, so let's not schedule it and
+	 * see if it is pushed or pulled somewhere else.
+	 */
+	if (p->dl.nr_cpus_allowed != 1 &&
+	    latest_cpu_find(rq->rd->span, p, NULL) != -1)
+		return;
+
+	resched_task(rq->curr);
+}
+
+#endif /* CONFIG_SMP */
+
 static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
 				  int flags)
 {
 	if (!dl_task(rq->curr) || (dl_task(p) &&
-	    dl_entity_preempt(&p->dl, &rq->curr->dl)))
+	    dl_entity_preempt(&p->dl, &rq->curr->dl))) {
 		resched_task(rq->curr);
+		return;
+	}
+
+#ifdef CONFIG_SMP
+	/*
+	 * In the unlikely case current and p have the same deadline
+	 * let us try to decide what's the best thing to do...
+	 */
+	if ((s64)(p->dl.deadline - rq->curr->dl.deadline) == 0 &&
+	    !need_resched())
+		check_preempt_equal_dl(rq, p);
+#endif /* CONFIG_SMP */
 }
 
 #ifdef CONFIG_SCHED_HRTICK
@@ -537,10 +857,20 @@ struct task_struct *pick_next_task_dl(struct rq *rq)
 
 	p = dl_task_of(dl_se);
 	p->se.exec_start = rq->clock;
+
+	/* Running task will never be pushed. */
+	if (p)
+		dequeue_pushable_dl_task(rq, p);
+
 #ifdef CONFIG_SCHED_HRTICK
 	if (hrtick_enabled(rq))
 		start_hrtick_dl(rq, p);
 #endif
+
+#ifdef CONFIG_SMP
+	rq->post_schedule = has_pushable_dl_tasks(rq);
+#endif /* CONFIG_SMP */
+
 	return p;
 }
 
@@ -548,6 +878,9 @@ static void put_prev_task_dl(struct rq *rq, struct task_struct *p)
 {
 	update_curr_dl(rq);
 	p->se.exec_start = 0;
+
+	if (on_dl_rq(&p->dl) && p->dl.nr_cpus_allowed > 1)
+		enqueue_pushable_dl_task(rq, p);
 }
 
 static void task_tick_dl(struct rq *rq, struct task_struct *p, int queued)
@@ -586,41 +919,409 @@ static void set_curr_task_dl(struct rq *rq)
 	struct task_struct *p = rq->curr;
 
 	p->se.exec_start = rq->clock;
+
+	/* You can't push away the running task */
+	dequeue_pushable_dl_task(rq, p);
 }
 
-static void switched_from_dl(struct rq *rq, struct task_struct *p,
-			     int running)
+#ifdef CONFIG_SMP
+
+/* Only try algorithms three times */
+#define DL_MAX_TRIES 3
+
+static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu)
 {
-	if (hrtimer_active(&p->dl.dl_timer))
-		hrtimer_try_to_cancel(&p->dl.dl_timer);
+	if (!task_running(rq, p) &&
+	    (cpu < 0 || cpumask_test_cpu(cpu, &p->cpus_allowed)) &&
+	    (p->dl.nr_cpus_allowed > 1))
+		return 1;
+
+	return 0;
 }
 
-static void switched_to_dl(struct rq *rq, struct task_struct *p,
-			   int running)
+/* Returns the second earliest -deadline task, NULL otherwise */
+static struct task_struct *pick_next_earliest_dl_task(struct rq *rq, int cpu)
+{
+	struct rb_node *next_node = rq->dl.rb_leftmost;
+	struct sched_dl_entity *dl_se;
+	struct task_struct *p = NULL;
+
+next_node:
+	next_node = rb_next(next_node);
+	if (next_node) {
+		dl_se = rb_entry(next_node, struct sched_dl_entity, rb_node);
+		p = dl_task_of(dl_se);
+
+		if (pick_dl_task(rq, p, cpu))
+			return p;
+
+		goto next_node;
+	}
+
+	return NULL;
+}
+
+static int latest_cpu_find(struct cpumask *span,
+			   struct task_struct *task,
+			   struct cpumask *later_mask)
+{
+	const struct sched_dl_entity *dl_se = &task->dl;
+	int cpu, found = -1, best = 0;
+	u64 max_dl = 0;
+
+	for_each_cpu(cpu, span) {
+		struct rq *rq = cpu_rq(cpu);
+		struct dl_rq *dl_rq = &rq->dl;
+
+		if (cpumask_test_cpu(cpu, &task->cpus_allowed) &&
+		    (!dl_rq->dl_nr_running || dl_time_before(dl_se->deadline,
+		     dl_rq->earliest_dl.curr))) {
+			if (later_mask)
+				cpumask_set_cpu(cpu, later_mask);
+			if (!best && !dl_rq->dl_nr_running) {
+				best = 1;
+				found = cpu;
+			} else if (!best &&
+				   dl_time_before(max_dl,
+						  dl_rq->earliest_dl.curr)) {
+				max_dl = dl_rq->earliest_dl.curr;
+				found = cpu;
+			}
+		} else if (later_mask)
+			cpumask_clear_cpu(cpu, later_mask);
+	}
+
+	return found;
+}
+
+static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl);
+
+static int find_later_rq(struct task_struct *task)
 {
+	struct sched_domain *sd;
+	struct cpumask *later_mask = __get_cpu_var(local_cpu_mask_dl);
+	int this_cpu = smp_processor_id();
+	int best_cpu, cpu = task_cpu(task);
+
+	if (task->dl.nr_cpus_allowed == 1)
+		return -1;
+
+	best_cpu = latest_cpu_find(task_rq(task)->rd->span, task, later_mask);
+	if (best_cpu == -1)
+		return -1;
+
 	/*
-	 * If p is throttled, don't consider the possibility
-	 * of preempting rq->curr, the check will be done right
-	 * after its runtime will get replenished.
+	 * If we are here, some target has been found,
+	 * the most suitable of which is cached in best_cpu.
+	 * This is, among the runqueues where the current tasks
+	 * have later deadlines than the task's one, the rq
+	 * with the latest possible one.
+	 *
+	 * Now we check how well this matches with task's
+	 * affinity and system topology.
+	 *
+	 * The last cpu where the task run is our first
+	 * guess, since it is most likely cache-hot there.
 	 */
-	if (unlikely(p->dl.dl_throttled))
-		return;
+	if (cpumask_test_cpu(cpu, later_mask))
+		return cpu;
 
-	if (!running)
-		check_preempt_curr_dl(rq, p, 0);
+	/*
+	 * Check if this_cpu is to be skipped (i.e., it is
+	 * not in the mask) or not.
+	 */
+	if (!cpumask_test_cpu(this_cpu, later_mask))
+		this_cpu = -1;
+
+	for_each_domain(cpu, sd) {
+		if (sd->flags & SD_WAKE_AFFINE) {
+
+			/*
+			 * If possible, preempting this_cpu is
+			 * cheaper than migrating.
+			 */
+			if (this_cpu != -1 &&
+			    cpumask_test_cpu(this_cpu, sched_domain_span(sd)))
+				return this_cpu;
+
+			/*
+			 * Last chance: if best_cpu is valid and is
+			 * in the mask, that becomes our choice.
+			 */
+			if (best_cpu < nr_cpu_ids &&
+			    cpumask_test_cpu(best_cpu, sched_domain_span(sd)))
+				return best_cpu;
+		}
+	}
+
+	/*
+	 * At this point, all our guesses failed, we just return
+	 * 'something', and let the caller sort the things out.
+	 */
+	if (this_cpu != -1)
+		return this_cpu;
+
+	cpu = cpumask_any(later_mask);
+	if (cpu < nr_cpu_ids)
+		return cpu;
+
+	return -1;
 }
 
-static void prio_changed_dl(struct rq *rq, struct task_struct *p,
-			    int oldprio, int running)
+/* Locks the rq it finds */
+static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
 {
-	switched_to_dl(rq, p, running);
+	struct rq *later_rq = NULL;
+	int tries;
+	int cpu;
+
+	for (tries = 0; tries < DL_MAX_TRIES; tries++) {
+		cpu = find_later_rq(task);
+
+		if ((cpu == -1) || (cpu == rq->cpu))
+			break;
+
+		later_rq = cpu_rq(cpu);
+
+		/* Retry if something changed. */
+		if (double_lock_balance(rq, later_rq)) {
+			if (unlikely(task_rq(task) != rq ||
+				     !cpumask_test_cpu(later_rq->cpu,
+						       &task->cpus_allowed) ||
+				     task_running(rq, task) ||
+				     !task->se.on_rq)) {
+				raw_spin_unlock(&later_rq->lock);
+				later_rq = NULL;
+				break;
+			}
+		}
+
+		/*
+		 * If the rq we found has no -deadline task, or
+		 * its earliest one has a later deadline than our
+		 * task, the rq is a good one.
+		 */
+		if (!later_rq->dl.dl_nr_running ||
+		    dl_time_before(task->dl.deadline,
+				   later_rq->dl.earliest_dl.curr))
+			break;
+
+		/* Otherwise we try again. */
+		double_unlock_balance(rq, later_rq);
+		later_rq = NULL;
+	}
+
+	return later_rq;
 }
 
-#ifdef CONFIG_SMP
-static int
-select_task_rq_dl(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
+static struct task_struct *pick_next_pushable_dl_task(struct rq *rq)
 {
-	return task_cpu(p);
+	struct task_struct *p;
+
+	if (!has_pushable_dl_tasks(rq))
+		return NULL;
+
+	p = rb_entry(rq->dl.pushable_dl_tasks_leftmost,
+		     struct task_struct, pushable_dl_tasks);
+
+	BUG_ON(rq->cpu != task_cpu(p));
+	BUG_ON(task_current(rq, p));
+	BUG_ON(p->dl.nr_cpus_allowed <= 1);
+
+	BUG_ON(!p->se.on_rq);
+	BUG_ON(!dl_task(p));
+
+	return p;
+}
+
+/*
+ * See if the non running -deadline tasks on this rq
+ * can be sent to some other CPU where they can preempt
+ * and start executing.
+ */
+static int push_dl_task(struct rq *rq)
+{
+	struct task_struct *next_task;
+	struct rq *later_rq;
+
+	if (!rq->dl.overloaded)
+		return 0;
+
+	next_task = pick_next_pushable_dl_task(rq);
+	if (!next_task)
+		return 0;
+
+retry:
+	if (unlikely(next_task == rq->curr)) {
+		WARN_ON(1);
+		return 0;
+	}
+
+	/*
+	 * If next_task preempts rq->curr, and rq->curr
+	 * can move away, it makes sense to just reschedule
+	 * without going further in pushing next_task.
+	 */
+	if (dl_task(rq->curr) &&
+	    dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) &&
+	    rq->curr->dl.nr_cpus_allowed > 1) {
+		resched_task(rq->curr);
+		return 0;
+	}
+
+	/* We might release rq lock */
+	get_task_struct(next_task);
+
+	/* Will lock the rq it'll find */
+	later_rq = find_lock_later_rq(next_task, rq);
+	if (!later_rq) {
+		struct task_struct *task;
+
+		/*
+		 * We must check all this again, since
+		 * find_lock_later_rq releases rq->lock and it is
+		 * then possible that next_task has migrated.
+		 */
+		task = pick_next_pushable_dl_task(rq);
+		if (task_cpu(next_task) == rq->cpu && task == next_task) {
+			/*
+			 * The task is still there. We don't try
+			 * again, some other cpu will pull it when ready.
+			 */
+			dequeue_pushable_dl_task(rq, next_task);
+			goto out;
+		}
+
+		if (!task)
+			/* No more tasks */
+			goto out;
+
+		put_task_struct(next_task);
+		next_task = task;
+		goto retry;
+	}
+
+	deactivate_task(rq, next_task, 0);
+	set_task_cpu(next_task, later_rq->cpu);
+	activate_task(later_rq, next_task, 0);
+
+	resched_task(later_rq->curr);
+
+	double_unlock_balance(rq, later_rq);
+
+out:
+	put_task_struct(next_task);
+
+	return 1;
+}
+
+static void push_dl_tasks(struct rq *rq)
+{
+	/* Terminates as it moves a -deadline task */
+	while (push_dl_task(rq))
+		;
+}
+
+static int pull_dl_task(struct rq *this_rq)
+{
+	int this_cpu = this_rq->cpu, ret = 0, cpu;
+	struct task_struct *p;
+	struct rq *src_rq;
+	u64 dmin = LONG_MAX;
+
+	if (likely(!dl_overloaded(this_rq)))
+		return 0;
+
+	for_each_cpu(cpu, this_rq->rd->dlo_mask) {
+		if (this_cpu == cpu)
+			continue;
+
+		src_rq = cpu_rq(cpu);
+
+		/*
+		 * It looks racy, abd it is! However, as in sched_rt.c,
+		 * we are fine with this.
+		 */
+		if (this_rq->dl.dl_nr_running &&
+		    dl_time_before(this_rq->dl.earliest_dl.curr,
+				   src_rq->dl.earliest_dl.next))
+			continue;
+
+		/* Might drop this_rq->lock */
+		double_lock_balance(this_rq, src_rq);
+
+		/*
+		 * If there are no more pullable tasks on the
+		 * rq, we're done with it.
+		 */
+		if (src_rq->dl.dl_nr_running <= 1)
+			goto skip;
+
+		p = pick_next_earliest_dl_task(src_rq, this_cpu);
+
+		/*
+		 * We found a task to be pulled if:
+		 *  - it preempts our current (if there's one),
+		 *  - it will preempt the last one we pulled (if any).
+		 */
+		if (p && dl_time_before(p->dl.deadline, dmin) &&
+		    (!this_rq->dl.dl_nr_running ||
+		     dl_time_before(p->dl.deadline,
+				    this_rq->dl.earliest_dl.curr))) {
+			WARN_ON(p == src_rq->curr);
+			WARN_ON(!p->se.on_rq);
+
+			/*
+			 * Then we pull iff p has actually an earlier
+			 * deadline than the current task of its runqueue.
+			 */
+			if (dl_time_before(p->dl.deadline,
+					   src_rq->curr->dl.deadline))
+				goto skip;
+
+			ret = 1;
+
+			deactivate_task(src_rq, p, 0);
+			set_task_cpu(p, this_cpu);
+			activate_task(this_rq, p, 0);
+			dmin = p->dl.deadline;
+
+			/* Is there any other task even earlier? */
+		}
+skip:
+		double_unlock_balance(this_rq, src_rq);
+	}
+
+	return ret;
+}
+
+static void pre_schedule_dl(struct rq *rq, struct task_struct *prev)
+{
+	/* Try to pull other tasks here */
+	if (dl_task(prev))
+		pull_dl_task(rq);
+}
+
+static void post_schedule_dl(struct rq *rq)
+{
+	push_dl_tasks(rq);
+}
+
+/*
+ * Since the task is not running and a reschedule is not going to happen
+ * anytime soon on its runqueue, we try pushing it away now.
+ */
+static void task_woken_dl(struct rq *rq, struct task_struct *p)
+{
+	if (!task_running(rq, p) &&
+	    !test_tsk_need_resched(rq->curr) &&
+	    has_pushable_dl_tasks(rq) &&
+	    p->dl.nr_cpus_allowed > 1 &&
+	    dl_task(rq->curr) &&
+	    (rq->curr->dl.nr_cpus_allowed < 2 ||
+	     dl_entity_preempt(&rq->curr->dl, &p->dl))) {
+		push_dl_tasks(rq);
+	}
 }
 
 static void set_cpus_allowed_dl(struct task_struct *p,
@@ -630,10 +1331,146 @@ static void set_cpus_allowed_dl(struct task_struct *p,
 
 	BUG_ON(!dl_task(p));
 
+	/*
+	 * Update only if the task is actually running (i.e.,
+	 * it is on the rq AND it is not throttled).
+	 */
+	if (on_dl_rq(&p->dl) && (weight != p->dl.nr_cpus_allowed)) {
+		struct rq *rq = task_rq(p);
+
+		if (!task_current(rq, p)) {
+			/*
+			 * If the task was on the pushable list,
+			 * make sure it stays there only if the new
+			 * mask allows that.
+			 */
+			if (p->dl.nr_cpus_allowed > 1)
+				dequeue_pushable_dl_task(rq, p);
+
+			if (weight > 1)
+				enqueue_pushable_dl_task(rq, p);
+		}
+
+		if ((p->dl.nr_cpus_allowed <= 1) && (weight > 1)) {
+			rq->dl.dl_nr_migratory++;
+		} else if ((p->dl.nr_cpus_allowed > 1) && (weight <= 1)) {
+			BUG_ON(!rq->dl.dl_nr_migratory);
+			rq->dl.dl_nr_migratory--;
+		}
+
+		update_dl_migration(&rq->dl);
+	}
+
 	cpumask_copy(&p->cpus_allowed, new_mask);
 	p->dl.nr_cpus_allowed = weight;
 }
+
+/* Assumes rq->lock is held */
+static void rq_online_dl(struct rq *rq)
+{
+	if (rq->dl.overloaded)
+		dl_set_overload(rq);
+}
+
+/* Assumes rq->lock is held */
+static void rq_offline_dl(struct rq *rq)
+{
+	if (rq->dl.overloaded)
+		dl_clear_overload(rq);
+}
+
+static inline void init_sched_dl_class(void)
+{
+	unsigned int i;
+
+	for_each_possible_cpu(i)
+		zalloc_cpumask_var_node(&per_cpu(local_cpu_mask_dl, i),
+					GFP_KERNEL, cpu_to_node(i));
+}
+#endif /* CONFIG_SMP */
+
+static void switched_from_dl(struct rq *rq, struct task_struct *p,
+			     int running)
+{
+	if (hrtimer_active(&p->dl.dl_timer) && !dl_policy(p->policy))
+		hrtimer_try_to_cancel(&p->dl.dl_timer);
+
+#ifdef CONFIG_SMP
+	/*
+	 * Since this might be the only -deadline task on the rq,
+	 * this is the right place to try to pull some other one
+	 * from an overloaded cpu, if any.
+	 */
+	if (!rq->dl.dl_nr_running)
+		pull_dl_task(rq);
 #endif
+}
+
+/*
+ * When switching to -deadline, we may overload the rq, then
+ * we try to push someone off, if possible.
+ */
+static void switched_to_dl(struct rq *rq, struct task_struct *p,
+			   int running)
+{
+	int check_resched = 1;
+
+	/*
+	 * If p is throttled, don't consider the possibility
+	 * of preempting rq->curr, the check will be done right
+	 * after its runtime will get replenished.
+	 */
+	if (unlikely(p->dl.dl_throttled))
+		return;
+
+	if (!running) {
+#ifdef CONFIG_SMP
+		if (rq->dl.overloaded && push_dl_task(rq) && rq != task_rq(p))
+			/* Only reschedule if pushing failed */
+			check_resched = 0;
+#endif /* CONFIG_SMP */
+		if (check_resched)
+			check_preempt_curr_dl(rq, p, 0);
+	}
+}
+
+/*
+ * If the scheduling parameters of a -deadline task changed,
+ * a push or pull operation might be needed.
+ */
+static void prio_changed_dl(struct rq *rq, struct task_struct *p,
+			    int oldprio, int running)
+{
+	if (running) {
+#ifdef CONFIG_SMP
+		/*
+		 * This might be too much, but unfortunately
+		 * we don't have the old deadline value, and
+		 * we can't argue if the task is increasing
+		 * or lowering its prio, so...
+		 */
+		if (!rq->dl.overloaded)
+			pull_dl_task(rq);
+
+		/*
+		 * If we now have a earlier deadline task than p,
+		 * then reschedule, provided p is still on this
+		 * runqueue.
+		 */
+		if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline) &&
+		    rq->curr == p)
+			resched_task(p);
+#else
+		/*
+		 * Again, we don't know if p has a earlier
+		 * or later deadline, so let's blindly set a
+		 * (maybe not needed) rescheduling point.
+		 */
+		resched_task(p);
+#endif /* CONFIG_SMP */
+	} else
+		switched_to_dl(rq, p, running);
+}
 
 static const struct sched_class dl_sched_class = {
 	.next			= &rt_sched_class,
@@ -650,6 +1487,11 @@ static const struct sched_class dl_sched_class = {
 	.select_task_rq		= select_task_rq_dl,
 
 	.set_cpus_allowed       = set_cpus_allowed_dl,
+	.rq_online              = rq_online_dl,
+	.rq_offline             = rq_offline_dl,
+	.pre_schedule		= pre_schedule_dl,
+	.post_schedule		= post_schedule_dl,
+	.task_woken		= task_woken_dl,
 #endif
 
 	.set_curr_task		= set_curr_task_dl,
kernel/sched_rt.c +1 -1
index 56c00fa..9a8422d 100644
@@ -1498,7 +1498,7 @@ static void task_woken_rt(struct rq *rq, struct task_struct *p)
 	    !test_tsk_need_resched(rq->curr) &&
 	    has_pushable_tasks(rq) &&
 	    p->rt.nr_cpus_allowed > 1 &&
-	    rt_task(rq->curr) &&
+	    (dl_task(rq->curr) || rt_task(rq->curr)) &&
 	    (rq->curr->rt.nr_cpus_allowed < 2 ||
 	     rq->curr->prio < p->prio))
 		push_rt_tasks(rq);
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#74 lore raw

Re: [RFC][PATCH 07/22] sched: SCHED_DEADLINE push and pull logic

Quoted 5 lines · Raistlin

Add dynamic migrations to SCHED_DEADLINE, so that tasks can be moved among CPUs when necessary. It is also possible to bind a task to a (set of) CPU(s), thus restricting its capability of migrating, or forbidding migrations at all.

Quoted 8 lines

The very same approach used in sched_rt is utilised:
- -deadline tasks are kept into CPU-specific runqueues,
- -deadline tasks are migrated among runqueues to achieve the following:
* on an M-CPU system the M earliest deadline ready tasks are always running;
* affinity/cpusets settings of all the -deadline tasks is always respected.

I haven't fully digested the patch, I keep getting side-tracked and its a large patch.. however, I thought we would only allow 2 affinities, strict per-cpu and full root-domain?

Since there are no existing applications using this, this won't break anything except maybe some expectations :-)

The advantage of restricting the sched_setaffinity() calls like this is that we can make the schedulability tests saner.

Keep 2 per-cpu utilization counts, a hard-rt and a soft-rt, and ensure the sum stays <= 1. Use the hard-rt one for the planned SF_HARD_RT flag, use the soft-rt one for !SF_HARD_RT with nr_cpus_allowed == 1, and use \Sum (1-h-s) over the root domain for nr_cpus_allowed != 1.

Once you start allowing masks in between its nearly impossible to guarantee anything.

author
#75 lore raw

Re: [RFC][PATCH 07/22] sched: SCHED_DEADLINE push and pull logic

Quoted 15 lines · Peter Zijlstra
Quoted 5 lines · Raistlin

Add dynamic migrations to SCHED_DEADLINE, so that tasks can be moved among CPUs when necessary. It is also possible to bind a task to a (set of) CPU(s), thus restricting its capability of migrating, or forbidding migrations at all.

Quoted 8 lines

The very same approach used in sched_rt is utilised:
- -deadline tasks are kept into CPU-specific runqueues,
- -deadline tasks are migrated among runqueues to achieve the following:
* on an M-CPU system the M earliest deadline ready tasks are always running;
* affinity/cpusets settings of all the -deadline tasks is always respected.

Quoted 3 lines

I haven't fully digested the patch, I keep getting side-tracked and its a large patch..

Yeah, I know, take your time. :-)

Quoted 3 lines

however, I thought we would only allow 2 affinities, strict per-cpu and full root-domain?

Yes, we do! Writing a better changelog for this already noted for next version.

Quoted 5 lines

Keep 2 per-cpu utilization counts, a hard-rt and a soft-rt, and ensure the sum stays <= 1. Use the hard-rt one for the planned SF_HARD_RT flag, use the soft-rt one for !SF_HARD_RT with nr_cpus_allowed == 1, and use \Sum (1-h-s) over the root domain for nr_cpus_allowed != 1.

As agreed during LPC, that's exactly what I'll do. Let's hope to don't screw up while trying to do the math! :-P

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#76 lore raw

Re: [RFC][PATCH 07/22] sched: SCHED_DEADLINE push and pull logic

In reply to Peter Zijlstra
Quoted 15 lines · Peter Zijlstra
Quoted 5 lines · Raistlin

Add dynamic migrations to SCHED_DEADLINE, so that tasks can be moved among CPUs when necessary. It is also possible to bind a task to a (set of) CPU(s), thus restricting its capability of migrating, or forbidding migrations at all.

Quoted 8 lines

The very same approach used in sched_rt is utilised:
- -deadline tasks are kept into CPU-specific runqueues,
- -deadline tasks are migrated among runqueues to achieve the following:
* on an M-CPU system the M earliest deadline ready tasks are always running;
* affinity/cpusets settings of all the -deadline tasks is always respected.

Quoted 3 lines

I haven't fully digested the patch, I keep getting side-tracked and its a large patch..

BTW, I was thinking about your suggestion of adding a *debugging* knob for achieving a "lock everything while I'm migrating" behaviour... :-)

Something like locking the root_domain during pushes and pulls won't probably work, since both of them do a double_lock_balance, taking two rq, which might race with this new "global" lock.
Something like we (CPU#1) hold rq1->lock, we take rd->lock, and then we try to take rq2->lock. CPU#2 holds rq2->lock and try to take rd->lock. Stuck! :-(
This should be possible if both CPU#1 and CPU#2 are into a push or a pull which, on each one, involves some task on the other. Do you agree, or I'm missing/mistaking something? :-)

Something we can probably do is locking the root_domain for _each_and_every_ scheduling decision, having all the rq->locks nesting inside our new root_domain->lock. This would emulate some sort of unique global rq implementation, since also local decisions on a CPU will affect all the others, as if they were sharing a single rq... But it's going to be very slow on large machines (but I guess we can afford that... It's debugging!), and will probably affect other scheduling class.
I'm not sure we want the latter... But maybe it could be useful for debugging others too (at least for FIFO/RR, it should be!).

Let me know what you think...

Thanks and Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#77 lore raw

Re: [RFC][PATCH 07/22] sched: SCHED_DEADLINE push and pull logic

Quoted 43 lines · Raistlin
Quoted 15 lines · Peter Zijlstra
Quoted 5 lines · Raistlin

Add dynamic migrations to SCHED_DEADLINE, so that tasks can be moved among CPUs when necessary. It is also possible to bind a task to a (set of) CPU(s), thus restricting its capability of migrating, or forbidding migrations at all.

Quoted 8 lines

The very same approach used in sched_rt is utilised:
- -deadline tasks are kept into CPU-specific runqueues,
- -deadline tasks are migrated among runqueues to achieve the following:
* on an M-CPU system the M earliest deadline ready tasks are always running;
* affinity/cpusets settings of all the -deadline tasks is always respected.

Quoted 3 lines

I haven't fully digested the patch, I keep getting side-tracked and its a large patch..

BTW, I was thinking about your suggestion of adding a *debugging* knob for achieving a "lock everything while I'm migrating" behaviour... :-)

Something like locking the root_domain during pushes and pulls won't probably work, since both of them do a double_lock_balance, taking two rq, which might race with this new "global" lock.
Something like we (CPU#1) hold rq1->lock, we take rd->lock, and then we try to take rq2->lock. CPU#2 holds rq2->lock and try to take rd->lock. Stuck! :-(
This should be possible if both CPU#1 and CPU#2 are into a push or a pull which, on each one, involves some task on the other. Do you agree, or I'm missing/mistaking something? :-)

Something we can probably do is locking the root_domain for _each_and_every_ scheduling decision, having all the rq->locks nesting inside our new root_domain->lock. This would emulate some sort of unique global rq implementation, since also local decisions on a CPU will affect all the others, as if they were sharing a single rq... But it's going to be very slow on large machines (but I guess we can afford that... It's debugging!), and will probably affect other scheduling class.
I'm not sure we want the latter... But maybe it could be useful for debugging others too (at least for FIFO/RR, it should be!).

Quoted 1 line

Let me know what you think...

Ugh!.. lock ordering sucks :-)

I think we can cheat since double_rq_lock() and double_lock_balance() can already unlock both locks, so you can simply: unlock both, lock rd, then lock both.

author
#78 lore raw

RFC PATCH 8/22 sched: SCHED_DEADLINE avg_update accounting

In reply to Raistlin

Make the core scheduler and load balancer aware of the load produced by -deadline tasks, by updating the moving average like for sched_rt.

---
 kernel/sched.c      |   13 ++++++++++++-
 kernel/sched_dl.c   |    2 ++
 kernel/sched_fair.c |    4 ++--
 3 files changed, 16 insertions(+), 3 deletions(-)
kernel/sched.c +12 -1
index 79e7c1c..7f0780c 100644
@@ -571,7 +571,7 @@ struct rq {
 
 	unsigned long avg_load_per_task;
 
-	u64 rt_avg;
+	u64 dl_avg, rt_avg;
 	u64 age_stamp;
 	u64 idle_stamp;
 	u64 avg_idle;
@@ -1346,10 +1346,17 @@ static void sched_avg_update(struct rq *rq)
 		 */
 		asm("" : "+rm" (rq->age_stamp));
 		rq->age_stamp += period;
+		rq->dl_avg /= 2;
 		rq->rt_avg /= 2;
 	}
 }
 
+static void sched_dl_avg_update(struct rq *rq, u64 dl_delta)
+{
+	rq->dl_avg += dl_delta;
+	sched_avg_update(rq);
+}
+
 static void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
 {
 	rq->rt_avg += rt_delta;
@@ -1363,6 +1370,10 @@ static void resched_task(struct task_struct *p)
 	set_tsk_need_resched(p);
 }
 
+static void sched_dl_avg_update(struct rq *rq, u64 dl_delta)
+{
+}
+
 static void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
 {
 }
kernel/sched_dl.c +2 -0
index 26126a6..1bb4308 100644
@@ -509,6 +509,8 @@ static void update_curr_dl(struct rq *rq)
 	curr->se.exec_start = rq->clock;
 	cpuacct_charge(curr, delta_exec);
 
+	sched_dl_avg_update(rq, delta_exec);
+
 	dl_se->runtime -= delta_exec;
 	if (dl_runtime_exceeded(rq, dl_se)) {
 		__dequeue_task_dl(rq, curr, 0);
kernel/sched_fair.c +2 -2
index 54c869c..2afe280 100644
@@ -2276,11 +2276,11 @@ unsigned long scale_rt_power(int cpu)
 
 	total = sched_avg_period() + (rq->clock - rq->age_stamp);
 
-	if (unlikely(total < rq->rt_avg)) {
+	if (unlikely(total < rq->dl_avg + rq->rt_avg)) {
 		/* Ensures that power won't end up being negative */
 		available = 0;
 	} else {
-		available = total - rq->rt_avg;
+		available = total - rq->dl_avg - rq->rt_avg;
 	}
 
 	if (unlikely((s64)total < SCHED_LOAD_SCALE))
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#79 lore raw

Re: [RFC][PATCH 08/22] sched: SCHED_DEADLINE avg_update accounting

Quoted 3 lines · Raistlin

Make the core scheduler and load balancer aware of the load produced by -deadline tasks, by updating the moving average like for sched_rt.

I think you can simply add your dl time to sched_rt_avg_update(), no need to track a second avg, its about !fair anyway.

author
#80 lore raw

RFC PATCH 9/22 sched: add period support for -deadline tasks

In reply to Raistlin

Make it possible to specify a period (different or equal than deadline) for -deadline tasks.

---
 include/linux/sched.h |    1 +
 kernel/sched.c        |   12 +++++++++++-
 kernel/sched_dl.c     |    8 ++++++--
 3 files changed, 18 insertions(+), 3 deletions(-)
include/linux/sched.h +1 -0
index f25d3a6..83fa2b5 100644
@@ -1251,6 +1251,7 @@ struct sched_dl_entity {
 	 */
 	u64 dl_runtime;		/* maximum runtime for each instance 	*/
 	u64 dl_deadline;	/* relative deadline of each instance	*/
+	u64 dl_period;		/* separation of two instances (period) */
 
 	/*
 	 * Actual scheduling parameters. Initialized with the values above,
kernel/sched.c +11 -1
index 7f0780c..4491f7d 100644
@@ -2708,6 +2708,7 @@ static void __sched_fork(struct task_struct *p)
 	hrtimer_init(&p->dl.dl_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	p->dl.dl_runtime = p->dl.runtime = 0;
 	p->dl.dl_deadline = p->dl.deadline = 0;
+	p->dl.dl_period = 0;
 	p->dl.flags = 0;
 
 	INIT_LIST_HEAD(&p->rt.run_list);
@@ -4789,6 +4790,10 @@ __setparam_dl(struct task_struct *p, const struct sched_param_ex *param_ex)
 	init_dl_task_timer(dl_se);
 	dl_se->dl_runtime = timespec_to_ns(&param_ex->sched_runtime);
 	dl_se->dl_deadline = timespec_to_ns(&param_ex->sched_deadline);
+	if (timespec_to_ns(&param_ex->sched_period) != 0)
+		dl_se->dl_period = timespec_to_ns(&param_ex->sched_period);
+	else
+		dl_se->dl_period = dl_se->dl_deadline;
 	dl_se->flags = param_ex->sched_flags;
 	dl_se->dl_throttled = 0;
 	dl_se->dl_new = 1;
@@ -4802,6 +4807,7 @@ __getparam_dl(struct task_struct *p, struct sched_param_ex *param_ex)
 	param_ex->sched_priority = p->rt_priority;
 	param_ex->sched_runtime = ns_to_timespec(dl_se->dl_runtime);
 	param_ex->sched_deadline = ns_to_timespec(dl_se->dl_deadline);
+	param_ex->sched_period = ns_to_timespec(dl_se->dl_period);
 	param_ex->sched_flags = dl_se->flags;
 	param_ex->curr_runtime = ns_to_timespec(dl_se->runtime);
 	param_ex->curr_deadline = ns_to_timespec(dl_se->deadline);
@@ -4810,7 +4816,8 @@ __getparam_dl(struct task_struct *p, struct sched_param_ex *param_ex)
 /*
  * This function validates the new parameters of a -deadline task.
  * We ask for the deadline not being zero, and greater or equal
- * than the runtime.
+ * than the runtime, as well as the period of being zero or
+ * not greater than deadline.
  */
 static bool
 __checkparam_dl(const struct sched_param_ex *prm, bool kthread)
@@ -4822,6 +4829,9 @@ __checkparam_dl(const struct sched_param_ex *prm, bool kthread)
 		return kthread;
 
 	return timespec_to_ns(&prm->sched_deadline) != 0 &&
+	       (timespec_to_ns(&prm->sched_period) == 0 ||
+		timespec_compare(&prm->sched_period,
+				 &prm->sched_deadline) >= 0) &&
 	       timespec_compare(&prm->sched_deadline,
 				&prm->sched_runtime) >= 0;
 }
kernel/sched_dl.c +6 -2
index 1bb4308..31fb771 100644
@@ -263,7 +263,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 	 * arbitrary large.
 	 */
 	while (dl_se->runtime <= 0) {
-		dl_se->deadline += dl_se->dl_deadline;
+		dl_se->deadline += dl_se->dl_period;
 		dl_se->runtime += dl_se->dl_runtime;
 	}
 
@@ -290,7 +290,11 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
  * assigned (function returns true if it can).
  *
  * For this to hold, we must check if:
- *   runtime / (deadline - t) < dl_runtime / dl_deadline .
+ *   runtime / (deadline - t) < dl_runtime / dl_period .
+ *
+ * Notice that the bandwidth check is done against the period. For
+ * task with deadline equal to period this is the same of using
+ * dl_deadline instead of dl_period in the equation above.
  */
 static bool dl_entity_overflow(struct sched_dl_entity *dl_se, u64 t)
 {
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#81 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Quoted 3 lines · Raistlin

Make it possible to specify a period (different or equal than deadline) for -deadline tasks.

I would expect it to be:

runtime <= deadline <= period

author
#82 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Raistlin

Make it possible to specify a period (different or equal than deadline) for -deadline tasks.

I would expect it to be:

runtime <= deadline <= period

Well, apart from that really unhappy comment/changelog, it should be like that in the code, and if it's not, it is what I meant and I'll change to that as soon as I can! :-)

Since you spotted it... The biggest issue here is admission control test. Right now this is done against task's bandwidth, i.e., sum_i(runtime_i/period_i)<=threshold, but it is unfortunately wrong... Or at least very, very loose, to the point of being almost useless! :-(

The more correct --in the sense that it at least yield a sufficient (not necessary!) condition-- thing to do would be sum_i(runtime_i/min{deadline_i,period_i})<=threshold.

So, what you think we should do? Can I go for this latter option?

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#83 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Quoted 9 lines · Raistlin
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Raistlin

Make it possible to specify a period (different or equal than deadline) for -deadline tasks.

I would expect it to be:

runtime <= deadline <= period

Quoted 8 lines

Well, apart from that really unhappy comment/changelog, it should be like that in the code, and if it's not, it is what I meant and I'll change to that as soon as I can! :-)

Since you spotted it... The biggest issue here is admission control test. Right now this is done against task's bandwidth, i.e., sum_i(runtime_i/period_i)<=threshold, but it is unfortunately wrong... Or at least very, very loose, to the point of being almost useless! :-(

Right, I have some recollection on that.

Quoted 5 lines

The more correct --in the sense that it at least yield a sufficient (not necessary!) condition-- thing to do would be sum_i(runtime_i/min{deadline_i,period_i})<=threshold.

So, what you think we should do? Can I go for this latter option?

I remember we visited this subject last time, but I seem to have forgotten most details.

So sufficient (but not necessary) means its still a pessimistic approach but better than the one currently employed, or does it mean its optimistic and allows for unschedulable sets to be allowed in?

#84 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Il 11/11/2010 20:43, Peter Zijlstra ha scritto:

Quoted 8 lines
Quoted 5 lines

The more correct --in the sense that it at least yield a sufficient (not necessary!) condition-- thing to do would be sum_i(runtime_i/min{deadline_i,period_i})<=threshold.

So, what you think we should do? Can I go for this latter option?

So sufficient (but not necessary) means its still a pessimistic approach but better than the one currently employed, or does it mean its optimistic and allows for unschedulable sets to be allowed in?

It means that, if the new task passes the test, then it has its guaranteed runtime_i over each time horizon as long as min{deadline_i, period_i} (and all of the other tasks already admitted have their guarantees as well of course). From the perspective of analyzing capability of the attached task to meet its own deadlines, if the task has a WCET of runtime_i, a minimum inter-arrival period of period_i, and a relative deadline of deadline_i, then it is guaranteed to meet all of its deadlines.

Therefore, this kind of test is sufficient for ensuring schedulability of all of the tasks, but it is not actually necessary, because it is too pessimistic. In fact, consider a task with a period of 10ms, a runtime of 3ms and a relative deadline of 5ms. After the test passed, you have actually allocated a "share" of the CPU capable of handling 3ms of workload every 5ms. Instead, we actually know that (or, we may actually force it to), after the deadline at 5ms, this task will actually be idle for further 5ms, till its new period. There are more complex tests which account for this, in the analysis.

Generally speaking, with deadlines different from periods, a tighter test (for partitioned EDF) is one making use of the demand-bound function, which unfortunately is far more heavyweight than a mere utilization check (for example, you should perform a number of checks along a time horizon that can go as far as the hyper-period [LCM of the periods] of the considered task-set -- something that may require arbitrary precision arithmetics in the worst-case). However, you can check the *RT* conferences in the last 10 years in order to see all the possible trade-offs between accuracy of the test and the imposed computation requirement/overhead.

Summarizing, the test suggested by Dario is sufficient to ensure the correct behavior of the accepted tasks, under the assumption that they stick to the "sporadic RT task model", it is very simple to implement in the kernel, but it is somewhat pessimistic. Also, it actually uses only 2 parameters, the runtime and the min{deadline_i, period_i}.
This clarifies also why I was raising the issue of whether to have at all the specification of a deadline \neq period, in my other e-mail. If the first implementation will just use the minimum of 2 of the supplied parameters, then let them be specified as 1 parameter only: it will be easier for developers to understand and use. If we identify later a proper test we want to use, then we can exploit the "extensibility" of the sched_params.

My 2 cents.

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
author
#85 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines

Since you spotted it... The biggest issue here is admission control test. Right now this is done against task's bandwidth, i.e., sum_i(runtime_i/period_i)<=threshold, but it is unfortunately wrong... Or at least very, very loose, to the point of being almost useless! :-(

Right, I have some recollection on that.

:-)

Quoted 4 lines

So sufficient (but not necessary) means its still a pessimistic approach but better than the one currently employed, or does it mean its optimistic and allows for unschedulable sets to be allowed in?

Tommaso already gave the best possible explanation of this! :-P

So, trying to recap:
- using runtime/min(deadline,period) _does_ guarantee schedulability, but also rejects schedulable situations in UP/partitioning. Quite sure it _does_not_ guarantee schedulability in SMP/global, but *should* enable bounded tardiness;
- using runtime/period _does_not_ guarantee schedulability nor in UP/partitioning neither in SMP/global, but *should* enable bounded tardiness for _both_.

The *should*-s come from the fact that I feel like I read it somewhere, but right now I can't find the paper(s), not even following the references indicated by Bjorn and Jim in previous e-mails and threads (i.e., I can't find anything _explicitly_ considering deadline!=period, but it might be my fault)... :-(

Thus, all this being said, what do you want me to do? :-D

Since we care about bounded tardiness more than 100%-guaranteed schedulability (which, BTW, neither min{} could give us, at least for SMPs), should we stay with runtime/period? Tommaso, Luca, do you think it would be so bad?

Thanks and Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#86 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Quoted 25 lines · Raistlin
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines

Since you spotted it... The biggest issue here is admission control test. Right now this is done against task's bandwidth, i.e., sum_i(runtime_i/period_i)<=threshold, but it is unfortunately wrong... Or at least very, very loose, to the point of being almost useless! :-(

Right, I have some recollection on that.

:-)

Quoted 4 lines

So sufficient (but not necessary) means its still a pessimistic approach but better than the one currently employed, or does it mean its optimistic and allows for unschedulable sets to be allowed in?

Tommaso already gave the best possible explanation of this! :-P

So, trying to recap:
- using runtime/min(deadline,period) _does_ guarantee schedulability, but also rejects schedulable situations in UP/partitioning. Quite sure it _does_not_ guarantee schedulability in SMP/global, but *should* enable bounded tardiness;
- using runtime/period _does_not_ guarantee schedulability nor in UP/partitioning neither in SMP/global, but *should* enable bounded tardiness for _both_.

Quoted 1 line

Thus, all this being said, what do you want me to do? :-D

runtime/min(deadline,period) sounds fine, as its more useful than runtime/period.

#87 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

In reply to Raistlin
Quoted 9 lines · Raistlin
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Raistlin

Make it possible to specify a period (different or equal than deadline) for -deadline tasks.

I would expect it to be:

runtime<= deadline<= period

Quoted 8 lines

Well, apart from that really unhappy comment/changelog, it should be like that in the code, and if it's not, it is what I meant and I'll change to that as soon as I can! :-)

Since you spotted it... The biggest issue here is admission control test. Right now this is done against task's bandwidth, i.e., sum_i(runtime_i/period_i)<=threshold, but it is unfortunately wrong... Or at least very, very loose, to the point of being almost useless! :-(

The point is that when the relative deadline is different from the period, the concept of "task utilisation", or "bandwidth" becomes fuzzy at least (I would say it becomes almost meaningless, but...).

The test with min{D,P} is technically more correct (meaning that it will never accept unschedulable tasks), but it rejects some schedulable tasks. As Tommaso pointed out, a more complex admission test would be needed.

Quoted 5 lines

The more correct --in the sense that it at least yield a sufficient (not necessary!) condition-- thing to do would be sum_i(runtime_i/min{deadline_i,period_i})<=threshold.

So, what you think we should do? Can I go for this latter option?

The one with min{} is at lest correct :)

Luca

author
#88 lore raw

Re: [RFC][PATCH 09/22] sched: add period support for -deadline tasks

Quoted 3 lines · Luca Abeni
Quoted 1 line

So, what you think we should do? Can I go for this latter option?

The one with min{} is at lest correct :)

Seems that Peter agrees (and I'm Tommaso would agree too) so, copy that! ;-P

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#89 lore raw

RFC PATCH 10/22 sched: add a syscall to wait for the next instance

In reply to Raistlin

Introduce sched_wait_interval() syscall (and scheduling class interface call). In general, this aims at providing each scheduling class with a mean of making one of its own task sleep for some time according to some specific rule of the scheduling class itself.

As of now, the sched_dl scheduling class is the only one that needs this kind of service, and thus the only one that implements the class-specific logic. For other classes, calling it will result in the same effect than calling clock_nanosleep with CLOCK_MONOTONIC clockid and the TIMER_ABSTIME flag on.

For -deadline task, the idea is to give them the possibility of notifying the scheduler a periodic/sporadic instance just ended and ask it to wake up them at the beginning of the next one, with:
- fully replenished runtime and
- the absolute deadline set just one relative deadline interval away from the wakeup time.
This is an effective mean of synchronizing the task's behaviour with the scheduler one, which might be useful in some situations.

This patch:
- adds the new syscall (x83-32, x86-64 and ARM, but extension to all archs is strightforward);
- implements the class-specific logic for -deadline tasks, making it impossible for them to exploit this call to use more bandwidth than they are given.

---
 arch/arm/include/asm/unistd.h      |    1 +
 arch/arm/kernel/calls.S            |    1 +
 arch/x86/ia32/ia32entry.S          |    1 +
 arch/x86/include/asm/unistd_32.h   |    3 +-
 arch/x86/include/asm/unistd_64.h   |    2 +
 arch/x86/kernel/syscall_table_32.S |    1 +
 include/linux/sched.h              |    2 +
 include/linux/syscalls.h           |    2 +
 kernel/sched.c                     |   39 ++++++++++++++++++++++
 kernel/sched_dl.c                  |   63 ++++++++++++++++++++++++++++++++++++
 10 files changed, 114 insertions(+), 1 deletions(-)
arch/arm/include/asm/unistd.h +1 -0
index 6f18f72..56513bb 100644
@@ -399,6 +399,7 @@
 #define __NR_sched_setscheduler_ex	(__NR_SYSCALL_BASE+370)
 #define __NR_sched_setparam_ex		(__NR_SYSCALL_BASE+371)
 #define __NR_sched_getparam_ex		(__NR_SYSCALL_BASE+372)
+#define __NR_sched_wait_interval	(__NR_SYSCALL_BASE+373)
 
 /*
  * The following SWIs are ARM private.
arch/arm/kernel/calls.S +1 -0
index c131615..c18e1e4 100644
@@ -382,6 +382,7 @@
 /* 370 */	CALL(sys_sched_setscheduler_ex)
 		CALL(sys_sched_setparam_ex)
 		CALL(sys_sched_getparam_ex)
+		CALL(sys_sched_wait_interval)
 #ifndef syscalls_counted
 .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
 #define syscalls_counted
arch/x86/ia32/ia32entry.S +1 -0
index 0c6f451..32821df 100644
@@ -854,4 +854,5 @@ ia32_sys_call_table:
 	.quad sys_sched_setscheduler_ex
 	.quad sys_sched_setparam_ex
 	.quad sys_sched_getparam_ex
+	.quad sys_sched_wait_interval
 ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +2 -1
index 437383b..684bf79 100644
@@ -349,10 +349,11 @@
 #define __NR_sched_setscheduler_ex	341
 #define __NR_sched_setparam_ex		342
 #define __NR_sched_getparam_ex		343
+#define __NR_sched_wait_interval	344
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 344
+#define NR_syscalls 345
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +2 -0
index fc4618b..932b094 100644
@@ -675,6 +675,8 @@ __SYSCALL(__NR_sched_setscheduler_ex, sys_sched_setscheduler_ex)
 __SYSCALL(__NR_sched_setparam_ex, sys_sched_setparam_ex)
 #define __NR_sched_getparam_ex			305
 __SYSCALL(__NR_sched_getparam_ex, sys_sched_getparam_ex)
+#define __NR_sched_wait_interval		306
+__SYSCALL(__NR_sched_wait_interval, sys_sched_wait_interval)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +1 -0
index 7d4ed62..c77e82c 100644
@@ -343,3 +343,4 @@ ENTRY(sys_call_table)
 	.long sys_sched_setscheduler_ex
 	.long sys_sched_setparam_ex
 	.long sys_sched_getparam_ex
+	.long sys_sched_wait_interval
include/linux/sched.h +2 -0
index 83fa2b5..e301eea 100644
@@ -1116,6 +1116,8 @@ struct sched_class {
 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
 	void (*yield_task) (struct rq *rq);
+	long (*wait_interval) (struct task_struct *p, struct timespec *rqtp,
+			       struct timespec __user *rmtp);
 
 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
 
include/linux/syscalls.h +2 -0
index 46b461e..b6e04db 100644
@@ -339,6 +339,8 @@ asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
 asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
 					unsigned long __user *user_mask_ptr);
 asmlinkage long sys_sched_yield(void);
+asmlinkage long sys_sched_wait_interval(const struct timespec __user *rqtp,
+					struct timespec *rmtp);
 asmlinkage long sys_sched_get_priority_max(int policy);
 asmlinkage long sys_sched_get_priority_min(int policy);
 asmlinkage long sys_sched_rr_get_interval(pid_t pid,
kernel/sched.c +39 -0
index 4491f7d..619d091 100644
@@ -5504,6 +5504,45 @@ SYSCALL_DEFINE0(sched_yield)
 	return 0;
 }
 
+/**
+ * sys_sched_wait_interval - sleep according to the scheduling class rules.
+ *
+ * This function is implemented inside each scheduling class, in case it
+ * wants to provide its tasks a mean of waiting a specific instant in
+ * time, while also honouring some specific rule of itself.
+ */
+SYSCALL_DEFINE2(sched_wait_interval,
+	const struct timespec __user *, rqtp,
+	struct timespec __user *, rmtp)
+{
+	struct timespec lrq, lrm;
+	int ret;
+
+	if (rqtp != NULL) {
+		if (copy_from_user(&lrq, rqtp, sizeof(struct timespec)))
+			return -EFAULT;
+		if (!timespec_valid(&lrq))
+			return -EINVAL;
+	}
+
+	if (current->sched_class->wait_interval)
+		ret = current->sched_class->wait_interval(current,
+							  rqtp ? &lrq : NULL,
+							  &lrm);
+	else {
+		if (!rqtp)
+			return -EINVAL;
+
+		ret = hrtimer_nanosleep(&lrq, &lrm, HRTIMER_MODE_ABS,
+					CLOCK_MONOTONIC);
+	}
+
+	if (rmtp && copy_to_user(rmtp, &lrm, sizeof(struct timespec)))
+		return -EFAULT;
+
+	return ret;
+}
+
 static inline int should_resched(void)
 {
 	return need_resched() && !(preempt_count() & PREEMPT_ACTIVE);
kernel/sched_dl.c +63 -0

75 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#90 lore raw

Re: [RFC][PATCH 10/22] sched: add a syscall to wait for the next instance

Quoted 6 lines · Raistlin

Introduce sched_wait_interval() syscall (and scheduling class interface call). In general, this aims at providing each scheduling class with a mean of making one of its own task sleep for some time according to some specific rule of the scheduling class itself.

Did we have an actual use case for this? I seem to remember that the last time we seemed to thing job wakeups are due to external events, in which case we don't need this.

I think we should try without this patch first and only consider this once we merged the base functionality and have a solid use-case for this.

author
#91 lore raw

Re: [RFC][PATCH 10/22] sched: add a syscall to wait for the next instance

Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Raistlin

Introduce sched_wait_interval() syscall (and scheduling class interface call). In general, this aims at providing each scheduling class with a mean of making one of its own task sleep for some time according to some specific rule of the scheduling class itself.

Did we have an actual use case for this? I seem to remember that the last time we seemed to thing job wakeups are due to external events, in which case we don't need this.

Might find out something, but I mostly agree with what you're saying.

Quoted 4 lines

I think we should try without this patch first and only consider this once we merged the base functionality and have a solid use-case for this.

Consider it as already dropped! :-)

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#92 lore raw

RFC PATCH 11/22 sched: add schedstats for -deadline tasks

In reply to Raistlin

Add some typical sched-debug output to dl_rq(s) and some schedstats to -deadline tasks.

---
 include/linux/sched.h |   13 +++++++++++++
 kernel/sched.c        |    2 ++
 kernel/sched_debug.c  |   43 +++++++++++++++++++++++++++++++++++++++++++
 kernel/sched_dl.c     |   42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 0 deletions(-)
include/linux/sched.h +13 -0
index e301eea..8ae947b 100644
@@ -1242,6 +1242,15 @@ struct sched_rt_entity {
 #endif
 };
 
+#ifdef CONFIG_SCHEDSTATS
+struct sched_stats_dl {
+	u64			last_dmiss;
+	u64			last_rorun;
+	u64			dmiss_max;
+	u64			rorun_max;
+};
+#endif
+
 struct sched_dl_entity {
 	struct rb_node	rb_node;
 	int nr_cpus_allowed;
@@ -1282,6 +1291,10 @@ struct sched_dl_entity {
 	 * own bandwidth to be enforced, thus we need one timer per task.
 	 */
 	struct hrtimer dl_timer;
+
+#ifdef CONFIG_SCHEDSTATS
+	struct sched_stats_dl stats;
+#endif
 };
 
 struct rcu_node;
kernel/sched.c +2 -0
index 619d091..63a33f6 100644
@@ -425,6 +425,8 @@ struct dl_rq {
 
 	unsigned long dl_nr_running;
 
+	u64 exec_clock;
+
 #ifdef CONFIG_SMP
 	/*
 	 * Deadline values of the currently executing and the
kernel/sched_debug.c +43 -0

61 lines not on this page · raw message

kernel/sched_dl.c +42 -0

63 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#93 lore raw

RFC PATCH 12/22 sched: add runtime reporting for -deadline tasks

In reply to Raistlin

Make it available for the user-space the total amount of runtime time it has used from since it became a -deadline task.

This is something that is typically useful for monitoring from user-space the task CPU usage, and maybe implementing at that level some more sophisticated scheduling behaviour.

One example is feedback scheduling, where you try to adapt the scheduling parameters of a task by looking at its behaviour in a certain interval of time, applying concepts coming from control engineering.

---
 include/linux/sched.h |    7 +++----
 kernel/sched.c        |    3 +++
 kernel/sched_debug.c  |    1 +
 kernel/sched_dl.c     |    1 +
 4 files changed, 8 insertions(+), 4 deletions(-)
include/linux/sched.h +3 -4
index 8ae947b..b6f0635 100644
@@ -1242,14 +1242,15 @@ struct sched_rt_entity {
 #endif
 };
 
-#ifdef CONFIG_SCHEDSTATS
 struct sched_stats_dl {
+#ifdef CONFIG_SCHEDSTATS
 	u64			last_dmiss;
 	u64			last_rorun;
 	u64			dmiss_max;
 	u64			rorun_max;
-};
 #endif
+	u64			tot_rtime;
+};
 
 struct sched_dl_entity {
 	struct rb_node	rb_node;
@@ -1292,9 +1293,7 @@ struct sched_dl_entity {
 	 */
 	struct hrtimer dl_timer;
 
-#ifdef CONFIG_SCHEDSTATS
 	struct sched_stats_dl stats;
-#endif
 };
 
 struct rcu_node;
kernel/sched.c +3 -0
index 63a33f6..19c8c25 100644
@@ -4799,6 +4799,8 @@ __setparam_dl(struct task_struct *p, const struct sched_param_ex *param_ex)
 	dl_se->flags = param_ex->sched_flags;
 	dl_se->dl_throttled = 0;
 	dl_se->dl_new = 1;
+
+	dl_se->stats.tot_rtime = 0;
 }
 
 static void
@@ -4812,6 +4814,7 @@ __getparam_dl(struct task_struct *p, struct sched_param_ex *param_ex)
 	param_ex->sched_period = ns_to_timespec(dl_se->dl_period);
 	param_ex->sched_flags = dl_se->flags;
 	param_ex->curr_runtime = ns_to_timespec(dl_se->runtime);
+	param_ex->used_runtime = ns_to_timespec(dl_se->stats.tot_rtime);
 	param_ex->curr_deadline = ns_to_timespec(dl_se->deadline);
 }
 
kernel/sched_debug.c +1 -0
index f685f18..9bec524 100644
@@ -472,6 +472,7 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 		PN(dl.stats.dmiss_max);
 		PN(dl.stats.last_rorun);
 		PN(dl.stats.rorun_max);
+		PN(dl.stats.tot_rtime);
 	}
 
 	{
kernel/sched_dl.c +1 -0
index b01aa2a..c4091c9 100644
@@ -535,6 +535,7 @@ static void update_curr_dl(struct rq *rq)
 
 	sched_dl_avg_update(rq, delta_exec);
 
+	dl_se->stats.tot_rtime += delta_exec;
 	dl_se->runtime -= delta_exec;
 	if (dl_runtime_exceeded(rq, dl_se)) {
 		__dequeue_task_dl(rq, curr, 0);
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#94 lore raw

Re: [RFC][PATCH 12/22] sched: add runtime reporting for -deadline tasks

Quoted 30 lines · Raistlin

Make it available for the user-space the total amount of runtime time it has used from since it became a -deadline task.

This is something that is typically useful for monitoring from user-space the task CPU usage, and maybe implementing at that level some more sophisticated scheduling behaviour.

One example is feedback scheduling, where you try to adapt the scheduling parameters of a task by looking at its behaviour in a certain interval of time, applying concepts coming from control engineering.

---
 include/linux/sched.h |    7 +++----
 kernel/sched.c        |    3 +++
 kernel/sched_debug.c  |    1 +
 kernel/sched_dl.c     |    1 +
 4 files changed, 8 insertions(+), 4 deletions(-)
include/linux/sched.h +0 -1
index 8ae947b..b6f0635 100644
@@ -1242,14 +1242,15 @@ struct sched_rt_entity {
 #endif
 };
 
-#ifdef CONFIG_SCHEDSTATS
 struct sched_stats_dl {

include/linux/sched.h struct sched_rt_entity { · line 1254

Quoted 10 lines
include/linux/sched.h +3 -1
+#ifdef CONFIG_SCHEDSTATS
 	u64			last_dmiss;
 	u64			last_rorun;
 	u64			dmiss_max;
 	u64			rorun_max;
-};
 #endif
+	u64			tot_rtime;
+};
 

I know we agreed to pull this from the sched_param2 structure and delay exposing this information for a while until the base patches got merged and came up with a solid use-case, but reading this patch makes me wonder why tsk->se.sum_exec_runtime isn't good enough?

author
#95 lore raw

Re: [RFC][PATCH 12/22] sched: add runtime reporting for -deadline tasks

Quoted 8 lines · Peter Zijlstra
Quoted 8 lines
include/linux/sched.h +1 -2
-#ifdef CONFIG_SCHEDSTATS
 struct sched_stats_dl {
+#ifdef CONFIG_SCHEDSTATS
 	u64			last_dmiss;
 	u64			last_rorun;
 	u64			dmiss_max;
 	u64			rorun_max;
-};
Quoted 9 lines

include/linux/sched.h struct sched_rt_entity { · line 1253

Quoted 4 lines

#endif

include/linux/sched.h +2 -0
+	u64			tot_rtime;
+};

I know we agreed to pull this from the sched_param2 structure and delay exposing this information for a while until the base patches got merged and came up with a solid use-case,

Sure! :-)

Quoted 3 lines

but reading this patch makes me
wonder why tsk->se.sum_exec_runtime isn't good enough?

Might be, but what you usually want is something reporting you total runtime from when you became a -deadline task, which may not be the case of sum_exec_runtime, is it?

BTW, again, let's postpone this.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#96 lore raw

Re: [RFC][PATCH 12/22] sched: add runtime reporting for -deadline tasks

Quoted 6 lines · Raistlin
Quoted 3 lines

but reading this patch makes me
wonder why tsk->se.sum_exec_runtime isn't good enough?

Might be, but what you usually want is something reporting you total runtime from when you became a -deadline task, which may not be the case of sum_exec_runtime, is it?

Correct, it wouldn't be. However since I expect a user to be mostly interested in deltas between two readings, in which case it really doesn't matter, does it?

author
#97 lore raw

Re: [RFC][PATCH 12/22] sched: add runtime reporting for -deadline tasks

Quoted 8 lines · Peter Zijlstra
Quoted 3 lines

Might be, but what you usually want is something reporting you total runtime from when you became a -deadline task, which may not be the case of sum_exec_runtime, is it?

Correct, it wouldn't be. However since I expect a user to be mostly interested in deltas between two readings, in which case it really doesn't matter, does it?

Good point. So we won't need this new stat anyway.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#98 lore raw

RFC PATCH 13/22 sched: add resource limits for -deadline tasks

In reply to Raistlin

Add resource limits for non-root tasks in using the SCHED_DEADLINE policy, very similarly to what already exists for RT policies.

In fact, this patch:
- adds the resource limit RLIMIT_DLDLINE, which is the minimum value a user task can use as its own deadline;
- adds the resource limit RLIMIT_DLRTIME, which is the maximum value a user task can use as it own runtime.

Notice that to exploit these, a modified version of the ulimit utility and a modified resource.h header file are needed. They both will be available on the website of the project.

---
 include/asm-generic/resource.h |    7 ++++++-
 kernel/sched.c                 |   25 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletions(-)
include/asm-generic/resource.h +6 -1
index 587566f..4a1d0e2 100644
@@ -45,7 +45,10 @@
 					   0-39 for nice level 19 .. -20 */
 #define RLIMIT_RTPRIO		14	/* maximum realtime priority */
 #define RLIMIT_RTTIME		15	/* timeout for RT tasks in us */
-#define RLIM_NLIMITS		16
+
+#define RLIMIT_DLDLINE		16	/* minimum deadline in us */
+#define RLIMIT_DLRTIME		17	/* maximum runtime in us */
+#define RLIM_NLIMITS		18
 
 /*
  * SuS says limits have to be unsigned.
@@ -87,6 +90,8 @@
 	[RLIMIT_NICE]		= { 0, 0 },				\
 	[RLIMIT_RTPRIO]		= { 0, 0 },				\
 	[RLIMIT_RTTIME]		= {  RLIM_INFINITY,  RLIM_INFINITY },	\
+	[RLIMIT_DLDLINE]	= { ULONG_MAX, ULONG_MAX },		\
+	[RLIMIT_DLRTIME]	= { 0, 0 },				\
 }
 
 #endif	/* __KERNEL__ */
kernel/sched.c +25 -0
index 19c8c25..9165c5e 100644
@@ -4903,6 +4903,31 @@ recheck:
 	 * Allow unprivileged RT tasks to decrease priority:
 	 */
 	if (user && !capable(CAP_SYS_NICE)) {
+		if (dl_policy(policy)) {
+			u64 rlim_dline, rlim_rtime;
+			u64 dline, rtime;
+
+			if (!lock_task_sighand(p, &flags))
+				return -ESRCH;
+			rlim_dline = p->signal->rlim[RLIMIT_DLDLINE].rlim_cur;
+			rlim_rtime = p->signal->rlim[RLIMIT_DLRTIME].rlim_cur;
+			unlock_task_sighand(p, &flags);
+
+			/* can't set/change -deadline policy */
+			if (policy != p->policy && !rlim_rtime)
+				return -EPERM;
+
+			/* can't decrease the deadline */
+			rlim_dline *= NSEC_PER_USEC;
+			dline = timespec_to_ns(&param_ex->sched_deadline);
+			if (dline < p->dl.dl_deadline && dline < rlim_dline)
+				return -EPERM;
+			/* can't increase the runtime */
+			rlim_rtime *= NSEC_PER_USEC;
+			rtime = timespec_to_ns(&param_ex->sched_runtime);
+			if (rtime > p->dl.dl_runtime && rtime > rlim_rtime)
+				return -EPERM;
+		}
 		if (rt_policy(policy)) {
 			unsigned long rlim_rtprio =
 					task_rlimit(p, RLIMIT_RTPRIO);
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#99 lore raw

Re: [RFC][PATCH 13/22] sched: add resource limits for -deadline tasks

Quoted 9 lines · Raistlin

Add resource limits for non-root tasks in using the SCHED_DEADLINE policy, very similarly to what already exists for RT policies.

In fact, this patch:
- adds the resource limit RLIMIT_DLDLINE, which is the minimum value a user task can use as its own deadline;
- adds the resource limit RLIMIT_DLRTIME, which is the maximum value a user task can use as it own runtime.

Quoted 3 lines

Notice that to exploit these, a modified version of the ulimit utility and a modified resource.h header file are needed. They both will be available on the website of the project.

We might also want to add an additional !SYS_CAP_ADMIN global bandwidth cap much like the existing sysctl bandwidth cap.

author
#100 lore raw

Re: [RFC][PATCH 13/22] sched: add resource limits for -deadline tasks

Quoted 10 lines · Peter Zijlstra
Quoted 6 lines

In fact, this patch:
- adds the resource limit RLIMIT_DLDLINE, which is the minimum value a user task can use as its own deadline;
- adds the resource limit RLIMIT_DLRTIME, which is the maximum value a user task can use as it own runtime.

We might also want to add an additional !SYS_CAP_ADMIN global bandwidth cap much like the existing sysctl bandwidth cap.

Mmm... I think we've never discussed much about that before, so here I am. I'm currently asking one to be root to set SCHED_DEADLINE as his policy. Normal users are allowed to do so, but just under the rlimits restrictions provided by this patch.

So, first of all, are we cool with this? Or do we want normal users to be able to give their tasks SCHED_DEADLINE policy by default? Maybe we want that but up to a certain bandwidth? Is this that you mean here, having two bandwidth limits, one of which !SYS_ADMINs could not cross?

Sorry for being annoying, but I've never got any feedback on this, while I think it's something really important.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#101 lore raw

Re: [RFC][PATCH 13/22] sched: add resource limits for -deadline tasks

Quoted 11 lines · Raistlin
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines

In fact, this patch:
- adds the resource limit RLIMIT_DLDLINE, which is the minimum value a user task can use as its own deadline;
- adds the resource limit RLIMIT_DLRTIME, which is the maximum value a user task can use as it own runtime.

We might also want to add an additional !SYS_CAP_ADMIN global bandwidth cap much like the existing sysctl bandwidth cap.

Quoted 7 lines

Mmm... I think we've never discussed much about that before, so here I am. I'm currently asking one to be root to set SCHED_DEADLINE as his policy. Normal users are allowed to do so, but just under the rlimits restrictions provided by this patch.

So, first of all, are we cool with this? Or do we want normal users to be able to give their tasks SCHED_DEADLINE policy by default?

I think so, it would make it much more useful to people.

Quoted 1 line

Maybe we want that but up to a certain bandwidth?

Exactly.

Quoted 2 lines

Is this that you mean here,
having two bandwidth limits, one of which !SYS_ADMINs could not cross?

Yep. A bandwidth cap for !SYS_CAP_ADMIN and a these two constraints already introduced by this patch, a min period to avoid very fast timer programming and a max runtime to avoid incurring large latencies on the rest of the system.

author
#102 lore raw

RFC PATCH 14/22 sched: add latency tracing for -deadline tasks.

In reply to Raistlin

It is very likely that systems that wants/needs to use the new SCHED_DEADLINE policy also want to have the scheduling latency of the -deadline tasks under control.

For this reason a new version of the scheduling wakeup latency, called "wakeup_dl", is introduced.

As a consequence of applying this patch there will be three wakeup latency tracer:
* "wakeup", that deals with all tasks in the system;
* "wakeup_rt", that deals with -rt and -deadline tasks only;
* "wakeup_dl", that deals with -deadline tasks only.

---
 kernel/trace/trace_sched_wakeup.c |   44 +++++++++++++++++++++++++++++++++---
 kernel/trace/trace_selftest.c     |   31 ++++++++++++++++----------
 2 files changed, 59 insertions(+), 16 deletions(-)
kernel/trace/trace_sched_wakeup.c +40 -4
index 7319559..8cee7b0 100644
@@ -27,6 +27,7 @@ static int			wakeup_cpu;
 static int			wakeup_current_cpu;
 static unsigned			wakeup_prio = -1;
 static int			wakeup_rt;
+static int			wakeup_dl;
 
 static arch_spinlock_t wakeup_lock =
 	(arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
@@ -414,9 +415,17 @@ probe_wakeup(void *ignore, struct task_struct *p, int success)
 	tracing_record_cmdline(p);
 	tracing_record_cmdline(current);
 
-	if ((wakeup_rt && !rt_task(p)) ||
-			p->prio >= wakeup_prio ||
-			p->prio >= current->prio)
+	/*
+	 * Semantic is like this:
+	 *  - wakeup tracer handles all tasks in the system, independently
+	 *    from their scheduling class;
+	 *  - wakeup_rt tracer handles tasks belonging to sched_dl and
+	 *    sched_rt class;
+	 *  - wakeup_dl handles tasks belonging to sched_dl class only.
+	 */
+	if ((wakeup_dl && !dl_task(p)) ||
+	    (wakeup_rt && !dl_task(p) && !rt_task(p)) ||
+	    (p->prio >= wakeup_prio || p->prio >= current->prio))
 		return;
 
 	pc = preempt_count();
@@ -428,7 +437,7 @@ probe_wakeup(void *ignore, struct task_struct *p, int success)
 	arch_spin_lock(&wakeup_lock);
 
 	/* check for races. */
-	if (!tracer_enabled || p->prio >= wakeup_prio)
+	if (!tracer_enabled || (!dl_task(p) && p->prio >= wakeup_prio))
 		goto out_locked;
 
 	/* reset the trace */
@@ -536,16 +545,25 @@ static int __wakeup_tracer_init(struct trace_array *tr)
 
 static int wakeup_tracer_init(struct trace_array *tr)
 {
+	wakeup_dl = 0;
 	wakeup_rt = 0;
 	return __wakeup_tracer_init(tr);
 }
 
 static int wakeup_rt_tracer_init(struct trace_array *tr)
 {
+	wakeup_dl = 0;
 	wakeup_rt = 1;
 	return __wakeup_tracer_init(tr);
 }
 
+static int wakeup_dl_tracer_init(struct trace_array *tr)
+{
+	wakeup_dl = 1;
+	wakeup_rt = 0;
+	return __wakeup_tracer_init(tr);
+}
+
 static void wakeup_tracer_reset(struct trace_array *tr)
 {
 	stop_wakeup_tracer(tr);
@@ -608,6 +626,20 @@ static struct tracer wakeup_rt_tracer __read_mostly =
 	.use_max_tr	= 1,
 };
 
+static struct tracer wakeup_dl_tracer __read_mostly =
+{
+	.name		= "wakeup_dl",
+	.init		= wakeup_dl_tracer_init,
+	.reset		= wakeup_tracer_reset,
+	.start		= wakeup_tracer_start,
+	.stop		= wakeup_tracer_stop,
+	.wait_pipe	= poll_wait_pipe,
+	.print_max	= 1,
+#ifdef CONFIG_FTRACE_SELFTEST
+	.selftest    = trace_selftest_startup_wakeup,
+#endif
+};
+
 __init static int init_wakeup_tracer(void)
 {
 	int ret;
@@ -620,6 +652,10 @@ __init static int init_wakeup_tracer(void)
 	if (ret)
 		return ret;
 
+	ret = register_tracer(&wakeup_dl_tracer);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 device_initcall(init_wakeup_tracer);
kernel/trace/trace_selftest.c +19 -12
index 562c56e..c4f3580 100644
@@ -557,11 +557,18 @@ trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
 #ifdef CONFIG_SCHED_TRACER
 static int trace_wakeup_test_thread(void *data)
 {
-	/* Make this a RT thread, doesn't need to be too high */
-	static struct sched_param param = { .sched_priority = 5 };
+	/* Make this a -deadline thread */
+	struct sched_param param = { .sched_priority = 0 };
+	struct sched_param_ex paramx = {
+		.sched_priority = 0,
+		.sched_runtime = { .tv_sec = 0, .tv_nsec = 100000 },
+		.sched_deadline = { .tv_sec = 0, .tv_nsec = 10000000 },
+		.sched_period = { .tv_sec = 0, tv_nsec = 10000000 }
+		.sched_flags = 0
+	};
 	struct completion *x = data;
 
-	sched_setscheduler(current, SCHED_FIFO, &param);
+	sched_setscheduler_ex(current, SCHED_DEADLINE, &param, &paramx);
 
 	/* Make it know we have a new prio */
 	complete(x);
@@ -573,8 +580,8 @@ static int trace_wakeup_test_thread(void *data)
 	/* we are awake, now wait to disappear */
 	while (!kthread_should_stop()) {
 		/*
-		 * This is an RT task, do short sleeps to let
-		 * others run.
+		 * This will likely be the system top priority
+		 * task, do short sleeps to let others run.
 		 */
 		msleep(100);
 	}
@@ -587,21 +594,21 @@ trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
 {
 	unsigned long save_max = tracing_max_latency;
 	struct task_struct *p;
-	struct completion isrt;
+	struct completion is_ready;
 	unsigned long count;
 	int ret;
 
-	init_completion(&isrt);
+	init_completion(&is_ready);
 
-	/* create a high prio thread */
-	p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test");
+	/* create a -deadline thread */
+	p = kthread_run(trace_wakeup_test_thread, &is_ready, "ftrace-test");
 	if (IS_ERR(p)) {
 		printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
 		return -1;
 	}
 
-	/* make sure the thread is running at an RT prio */
-	wait_for_completion(&isrt);
+	/* make sure the thread is running at -deadline policy */
+	wait_for_completion(&is_ready);
 
 	/* start the tracing */
 	ret = tracer_init(trace, tr);
@@ -613,7 +620,7 @@ trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
 	/* reset the max latency */
 	tracing_max_latency = 0;
 
-	/* sleep to let the RT thread sleep too */
+	/* sleep to let the thread sleep too */
 	msleep(100);
 
 	/*
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#103 lore raw

RFC PATCH 15/22 sched: add traceporints for -deadline tasks

In reply to Raistlin

Add tracepoints for the most notable events related to -deadline tasks scheduling (new task arrival, context switch, runtime accounting, bandwidth enforcement timer, etc.).

---
 include/trace/events/sched.h |  203 +++++++++++++++++++++++++++++++++++++++++-
 kernel/sched.c               |    2 +
 kernel/sched_dl.c            |   21 +++++
 3 files changed, 225 insertions(+), 1 deletions(-)
include/trace/events/sched.h +202 -1
index f633478..03baa17 100644
@@ -304,7 +304,6 @@ DECLARE_EVENT_CLASS(sched_stat_template,
 			(unsigned long long)__entry->delay)
 );
 
-
 /*
  * Tracepoint for accounting wait time (time the task is runnable
  * but not actually running due to scheduler contention).
@@ -363,6 +362,208 @@ TRACE_EVENT(sched_stat_runtime,
 );
 
 /*
+ * Tracepoint for task switches involving -deadline tasks:
+ */
+TRACE_EVENT(sched_switch_dl,
+
+	TP_PROTO(u64 clock,
+		 struct task_struct *prev,
+		 struct task_struct *next),
+
+	TP_ARGS(clock, prev, next),
+
+	TP_STRUCT__entry(
+		__array(	char,	prev_comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	prev_pid			)
+		__field(	u64,	clock				)
+		__field(	s64,	prev_rt				)
+		__field(	u64,	prev_dl				)
+		__field(	long,	prev_state			)
+		__array(	char,	next_comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	next_pid			)
+		__field(	s64,	next_rt				)
+		__field(	u64,	next_dl				)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
+		__entry->prev_pid	= prev->pid;
+		__entry->clock		= clock;
+		__entry->prev_rt	= prev->dl.runtime;
+		__entry->prev_dl	= prev->dl.deadline;
+		__entry->prev_state	= __trace_sched_switch_state(prev);
+		memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
+		__entry->next_pid	= next->pid;
+		__entry->next_rt	= next->dl.runtime;
+		__entry->next_dl	= next->dl.deadline;
+	),
+
+	TP_printk("prev_comm=%s prev_pid=%d prev_rt=%Ld [ns] prev_dl=%Lu [ns] prev_state=%s ==> "
+		  "next_comm=%s next_pid=%d next_rt=%Ld [ns] next_dl=%Lu [ns] clock=%Lu [ns]",
+		  __entry->prev_comm, __entry->prev_pid, (long long)__entry->prev_rt,
+		  (unsigned long long)__entry->prev_dl, __entry->prev_state ?
+		    __print_flags(__entry->prev_state, "|",
+				{ 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
+				{ 16, "Z" }, { 32, "X" }, { 64, "x" },
+				{ 128, "W" }) : "R",
+		  __entry->next_comm, __entry->next_pid, (long long)__entry->next_rt,
+		  (unsigned long long)__entry->next_dl, (unsigned long long)__entry->clock)
+);
+
+/*
+ * Tracepoint for starting of the throttling timer of a -deadline task:
+ */
+TRACE_EVENT(sched_start_timer_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock,
+		 s64 now, s64 act, unsigned long range),
+
+	TP_ARGS(p, clock, now, act, range),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	s64,	now			)
+		__field(	s64,	act			)
+		__field(	unsigned long,	range		)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->now		= now;
+		__entry->act		= act;
+		__entry->range		= range;
+	),
+
+	TP_printk("comm=%s pid=%d clock=%Lu [ns] now=%Ld [ns] soft=%Ld [ns] range=%lu",
+		  __entry->comm, __entry->pid, (unsigned long long)__entry->clock,
+		  (long long)__entry->now, (long long)__entry->act,
+		  (unsigned long)__entry->range)
+);
+
+/*
+ * Tracepoint for the throttling timer of a -deadline task:
+ */
+TRACE_EVENT(sched_timer_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock, int on_rq, int running),
+
+	TP_ARGS(p, clock, on_rq, running),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	int,	on_rq			)
+		__field(	int,	running			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->on_rq		= on_rq;
+		__entry->running	= running;
+	),
+
+	TP_printk("comm=%s pid=%d clock=%Lu_rq=%d running=%d",
+		  __entry->comm, __entry->pid, (unsigned long long)__entry->clock,
+		  __entry->on_rq, __entry->running)
+);
+
+/*
+ * sched_stat tracepoints for -deadline tasks:
+ */
+DECLARE_EVENT_CLASS(sched_stat_template_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock, int flags),
+
+	TP_ARGS(p, clock, flags),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	s64,	rt			)
+		__field(	u64,	dl			)
+		__field(	int,	flags			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->rt		= p->dl.runtime;
+		__entry->dl		= p->dl.deadline;
+		__entry->flags		= flags;
+	),
+
+	TP_printk("comm=%s pid=%d clock=%Lu [ns] rt=%Ld dl=%Lu [ns] flags=0x%x",
+		  __entry->comm, __entry->pid, (unsigned long long)__entry->clock,
+		  (long long)__entry->rt, (unsigned long long)__entry->dl,
+		  __entry->flags)
+);
+
+/*
+ * Tracepoint for a new instance of a -deadline task:
+ */
+DEFINE_EVENT(sched_stat_template_dl, sched_stat_new_dl,
+	     TP_PROTO(struct task_struct *tsk, u64 clock, int flags),
+	     TP_ARGS(tsk, clock, flags));
+
+/*
+ * Tracepoint for a replenishment of a -deadline task:
+ */
+DEFINE_EVENT(sched_stat_template_dl, sched_stat_repl_dl,
+	     TP_PROTO(struct task_struct *tsk, u64 clock, int flags),
+	     TP_ARGS(tsk, clock, flags));
+
+/*
+ * Tracepoint for parameters recalculation of -deadline tasks:.
+ */
+DEFINE_EVENT(sched_stat_template_dl, sched_stat_updt_dl,
+	     TP_PROTO(struct task_struct *tsk, u64 clock, int flags),
+	     TP_ARGS(tsk, clock, flags));
+
+/*
+ * Tracepoint for accounting stats of -deadline tasks:.
+ */
+TRACE_EVENT(sched_stat_runtime_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock, u64 last),
+
+	TP_ARGS(p, clock, last),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	u64,	last			)
+		__field(	s64,	rt			)
+		__field(	u64,	dl			)
+		__field(	u64,	start			)
+        ),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->last		= last;
+		__entry->rt		= p->dl.runtime - last;
+		__entry->dl		= p->dl.deadline;
+		__entry->start		= p->se.exec_start;
+	),
+
+	TP_printk("comm=%s pid=%d clock=%Lu [ns] delta_exec=%Lu [ns] rt=%Ld [ns] dl=%Lu [ns] exec_start=%Lu [ns]",
+		  __entry->comm, __entry->pid, (unsigned long long)__entry->clock,
+		  (unsigned long long)__entry->last, (long long)__entry->rt,
+		  (unsigned long long)__entry->dl, (unsigned long long)__entry->start)
+);
+
+/*
  * Tracepoint for showing priority inheritance modifying a tasks
  * priority.
  */
kernel/sched.c +2 -0
index 9165c5e..060d0c9 100644
@@ -3061,6 +3061,8 @@ context_switch(struct rq *rq, struct task_struct *prev,
 
 	prepare_task_switch(rq, prev, next);
 	trace_sched_switch(prev, next);
+	if (unlikely(dl_task(prev) || dl_task(next)))
+		trace_sched_switch_dl(rq->clock, prev, next);
 	mm = next->mm;
 	oldmm = prev->active_mm;
 	/*
kernel/sched_dl.c +21 -0
index c4091c9..229814a 100644
@@ -231,6 +231,9 @@ static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se)
 	dl_se->deadline = rq->clock + dl_se->dl_deadline;
 	dl_se->runtime = dl_se->dl_runtime;
 	dl_se->dl_new = 0;
+#ifdef CONFIG_SCHEDSTATS
+	trace_sched_stat_new_dl(dl_task_of(dl_se), rq->clock, dl_se->flags);
+#endif
 }
 
 /*
@@ -255,6 +258,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 {
 	struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
 	struct rq *rq = rq_of_dl_rq(dl_rq);
+	int reset = 0;
 
 	/*
 	 * We Keep moving the deadline away until we get some
@@ -280,7 +284,11 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
 		WARN_ON_ONCE(1);
 		dl_se->deadline = rq->clock + dl_se->dl_deadline;
 		dl_se->runtime = dl_se->dl_runtime;
+		reset = 1;
 	}
+#ifdef CONFIG_SCHEDSTATS
+	trace_sched_stat_repl_dl(dl_task_of(dl_se), rq->clock, reset);
+#endif
 }
 
 /*
@@ -332,6 +340,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)
 {
 	struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
 	struct rq *rq = rq_of_dl_rq(dl_rq);
+	int overflow = 0;
 
 	/*
 	 * The arrival of a new instance needs special treatment, i.e.,
@@ -346,7 +355,11 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)
 	    dl_entity_overflow(dl_se, rq->clock)) {
 		dl_se->deadline = rq->clock + dl_se->dl_deadline;
 		dl_se->runtime = dl_se->dl_runtime;
+		overflow = 1;
 	}
+#ifdef CONFIG_SCHEDSTATS
+	trace_sched_stat_updt_dl(dl_task_of(dl_se), rq->clock, overflow);
+#endif
 }
 
 /*
@@ -394,6 +407,10 @@ static int start_dl_timer(struct sched_dl_entity *dl_se)
 	__hrtimer_start_range_ns(&dl_se->dl_timer, soft,
 				 range, HRTIMER_MODE_ABS, 0);
 
+	trace_sched_start_timer_dl(dl_task_of(dl_se), rq->clock,
+				   ktime_to_ns(now), ktime_to_ns(soft),
+				   range);
+
 	return hrtimer_active(&dl_se->dl_timer);
 }
 
@@ -427,6 +444,8 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
 	if (!dl_task(p))
 		goto unlock;
 
+	trace_sched_timer_dl(p, rq->clock, p->se.on_rq, task_current(rq, p));
+
 	dl_se->dl_throttled = 0;
 	if (p->se.on_rq) {
 		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
@@ -439,6 +458,7 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
 		if (rq->dl.overloaded)
 			push_dl_task(rq);
 	}
+
 unlock:
 	task_rq_unlock(rq, &flags);
 
@@ -529,6 +549,7 @@ static void update_curr_dl(struct rq *rq)
 	curr->se.sum_exec_runtime += delta_exec;
 	schedstat_add(&rq->dl, exec_clock, delta_exec);
 	account_group_exec_runtime(curr, delta_exec);
+	trace_sched_stat_runtime_dl(curr, rq->clock, delta_exec);
 
 	curr->se.exec_start = rq->clock;
 	cpuacct_charge(curr, delta_exec);
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#104 lore raw

Re: [RFC][PATCH 15/22] sched: add traceporints for -deadline tasks

Quoted 25 lines · Raistlin

Add tracepoints for the most notable events related to -deadline tasks scheduling (new task arrival, context switch, runtime accounting, bandwidth enforcement timer, etc.).

---
 include/trace/events/sched.h |  203 +++++++++++++++++++++++++++++++++++++++++-
 kernel/sched.c               |    2 +
 kernel/sched_dl.c            |   21 +++++
 3 files changed, 225 insertions(+), 1 deletions(-)
include/trace/events/sched.h +0 -1
index f633478..03baa17 100644
@@ -304,7 +304,6 @@ DECLARE_EVENT_CLASS(sched_stat_template,
 			(unsigned long long)__entry->delay)
 );
 
-
 /*
  * Tracepoint for accounting wait time (time the task is runnable
  * but not actually running due to scheduler contention).

include/trace/events/sched.h TRACE_EVENT(sched_stat_runtime, · line 367

Quoted 6 lines
include/trace/events/sched.h +3 -0
@@ -363,6 +362,208 @@ TRACE_EVENT(sched_stat_runtime,
 );
 
 /*
+ * Tracepoint for task switches involving -deadline tasks:
+ */
+TRACE_EVENT(sched_switch_dl,

We've already got sched_switch(), better extend that. Same for the next patch, we already have a migration tracepoint, extend that.

And I recently rejected a fifo push/pull tracepoint patch from Steve because the migration tracepoint was able to provide the same information.

author
#105 lore raw

Re: [RFC][PATCH 15/22] sched: add traceporints for -deadline tasks

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Raistlin

Add tracepoints for the most notable events related to -deadline tasks scheduling (new task arrival, context switch, runtime accounting, bandwidth enforcement timer, etc.).

Quoted 7 lines

We've already got sched_switch(), better extend that. Same for the next patch, we already have a migration tracepoint, extend that.

And I recently rejected a fifo push/pull tracepoint patch from Steve because the migration tracepoint was able to provide the same information.

Perfectly fine. I'll see how do that without spamming too much the trace with data that are meaningless for non-deadline tasks.

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#106 lore raw

RFC PATCH 16/22 sched: add SMP traceporints for -deadline tasks

In reply to Raistlin

Add tracepoints for the events involved in -deadline task migration (mainly push, pull and migrate-task).

---
 include/trace/events/sched.h |  109 ++++++++++++++++++++++++++++++++++++++++++
 kernel/sched.c               |    3 +
 kernel/sched_dl.c            |    7 +++
 3 files changed, 119 insertions(+), 0 deletions(-)
include/trace/events/sched.h +109 -0
index 03baa17..f1d805f 100644
@@ -475,6 +475,115 @@ TRACE_EVENT(sched_timer_dl,
 );
 
 /*
+ *
+ */
+TRACE_EVENT(sched_push_task_dl,
+
+	TP_PROTO(struct task_struct *n, u64 clock, int later_cpu),
+
+	TP_ARGS(n, clock, later_cpu),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	s64,	rt			)
+		__field(	u64,	dl			)
+		__field(	int,	cpu			)
+		__field(	int,	later_cpu		)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, n->comm, TASK_COMM_LEN);
+		__entry->pid		= n->pid;
+		__entry->clock		= clock;
+		__entry->rt		= n->dl.runtime;
+		__entry->dl		= n->dl.deadline;
+		__entry->cpu		= task_cpu(n);
+		__entry->later_cpu	= later_cpu;
+	),
+
+	TP_printk("comm=%s pid=%d rt=%Ld [ns] dl=%Lu [ns] clock=%Lu [ns] cpu=%d later_cpu=%d",
+		  __entry->comm, __entry->pid, (long long)__entry->rt,
+		  (unsigned long long)__entry->dl, (unsigned long long)__entry->clock,
+		  __entry->cpu, __entry->later_cpu)
+);
+
+/*
+ *
+ */
+TRACE_EVENT(sched_pull_task_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock, int src_cpu),
+
+	TP_ARGS(p, clock, src_cpu),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	s64,	rt			)
+		__field(	u64,	dl			)
+		__field(	int,	cpu			)
+		__field(	int,	src_cpu			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->rt		= p->dl.runtime;
+		__entry->dl		= p->dl.deadline;
+		__entry->cpu		= task_cpu(p);
+		__entry->src_cpu	= src_cpu;
+	),
+
+	TP_printk("comm=%s pid=%d rt=%Ld [ns] dl=%Lu [ns] clock=%Lu [ns] cpu=%d later_cpu=%d",
+		  __entry->comm, __entry->pid, (long long)__entry->rt,
+		  (unsigned long long)__entry->dl, (unsigned long long)__entry->clock,
+		  __entry->cpu, __entry->src_cpu)
+);
+
+/*
+ * Tracepoint for migrations involving -deadline tasks:
+ */
+TRACE_EVENT(sched_migrate_task_dl,
+
+	TP_PROTO(struct task_struct *p, u64 clock, int dest_cpu, u64 dclock),
+
+	TP_ARGS(p, clock, dest_cpu, dclock),
+
+	TP_STRUCT__entry(
+		__array(	char,	comm,	TASK_COMM_LEN	)
+		__field(	pid_t,	pid			)
+		__field(	u64,	clock			)
+		__field(	s64,	rt			)
+		__field(	u64,	dl			)
+		__field(	int,	orig_cpu		)
+		__field(	int,	dest_cpu		)
+		__field(	u64,	dclock			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+		__entry->pid		= p->pid;
+		__entry->clock		= clock;
+		__entry->rt		= p->dl.runtime;
+		__entry->dl		= p->dl.deadline;
+		__entry->orig_cpu	= task_cpu(p);
+		__entry->dest_cpu	= dest_cpu;
+		__entry->dclock		= dclock;
+	),
+
+	TP_printk("comm=%s pid=%d rt=%Ld [ns] dl=%Lu [ns] orig_cpu=%d orig_clock=%Lu [ns] "
+		  "dest_cpu=%d dest_clock=%Lu [ns]",
+		  __entry->comm, __entry->pid, (long long)__entry->rt,
+		  (unsigned long long)__entry->dl, __entry->orig_cpu,
+		  (unsigned long long)__entry->clock, __entry->dest_cpu,
+		  (unsigned long long)__entry->dclock)
+);
+
+/*
  * sched_stat tracepoints for -deadline tasks:
  */
 DECLARE_EVENT_CLASS(sched_stat_template_dl,
kernel/sched.c +3 -0
index 060d0c9..79cac6e 100644
@@ -2235,6 +2235,9 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
 #endif
 
 	trace_sched_migrate_task(p, new_cpu);
+	if (unlikely(dl_task(p)))
+		trace_sched_migrate_task_dl(p, task_rq(p)->clock,
+					    new_cpu, cpu_rq(new_cpu)->clock);
 
 	if (task_cpu(p) != new_cpu) {
 		p->se.nr_migrations++;
kernel/sched_dl.c +7 -0
index 229814a..cc87949 100644
@@ -1294,6 +1294,10 @@ retry:
 
 	/* Will lock the rq it'll find */
 	later_rq = find_lock_later_rq(next_task, rq);
+
+	trace_sched_push_task_dl(next_task, rq->clock,
+				 later_rq ? later_rq->cpu : -1);
+
 	if (!later_rq) {
 		struct task_struct *task;
 
@@ -1378,6 +1382,9 @@ static int pull_dl_task(struct rq *this_rq)
 			goto skip;
 
 		p = pick_next_earliest_dl_task(src_rq, this_cpu);
+		if (p)
+			trace_sched_pull_task_dl(p, this_rq->clock,
+						 src_rq->cpu);
 
 		/*
 		 * We found a task to be pulled if:
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#107 lore raw

RFC PATCH 17/22 sched: add signaling overrunning -deadline tasks.

In reply to Raistlin

Add to the scheduler the capability of notifying when -deadline tasks overrun their maximum runtime and/or overcome their scheduling deadline.

Runtime overruns might be quite common, e.g., due to coarse granularity execution time accounting resolution or wrong assignment of tasks' parameters (especially runtime). However, since the scheduler enforces bandwidth isolation among tasks, this is not at all a threat to other tasks' schedulability. For this reason, it is not common that a task wants to be notified about that. Moreover, if we are using the SCHED_DEADLINE policy with sporadic tasks, or to limit the bandwidth of not periodic nor sporadic ones, runtime overruns are very likely to occur at each and every instance, and again they should not be considered a problem.

On the other hand, a deadline miss in any task means that, even if we are trying at our best to keep each task isolated and to avoid reciprocal interference among them, something went very, very bad, and one task did not manage in consuming its runtime by its deadline. This is something that should happen only on an oversubscribed system, and thus being notified when it occurs could be very useful.

The user can specify the signal(s) he wants to be sent to his task during sched_setscheduler_ex(), raising two specific flags in the sched_flags field of struct sched_param_ex:
* SF_SIG_RORUN (if he wants to be signaled on runtime overrun),
* SF_SIG_DMISS (if he wants to be signaled on deadline misses).

This patch:
- adds the logic needed to send SIGXCPU signal to a -deadline task in case its actual runtime becomes negative;
- adds the logic needed to send SIGXCPU signal to a -deadline task in case it is still being scheduled while its absolute deadline passes.

This all happens in the POSIX cpu-timers code, we need to take t->sighand->siglock, and it can't be done within the scheduler, under task_rq(t)->lock.

---
 include/linux/sched.h     |   14 ++++++++++-
 kernel/posix-cpu-timers.c |   55 +++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched_debug.c      |    2 +
 kernel/sched_dl.c         |    8 +++++-
 4 files changed, 76 insertions(+), 3 deletions(-)
include/linux/sched.h +13 -1
index b6f0635..b729f83 100644
@@ -163,8 +163,19 @@ struct sched_param_ex {
  *              of the highest priority scheduling class. In case it
  *              it sched_deadline, the task also ignore runtime and
  *              bandwidth limitations.
+ *
+ * These flags here below are meant to be used by userspace tasks to affect
+ * the scheduler behaviour and/or specifying that they want to be informed
+ * of the occurrence of some events.
+ *
+ *  @SF_SIG_RORUN       tells us the task wants to be notified whenever
+ *                      a runtime overrun occurs;
+ *  @SF_SIG_DMISS       tells us the task wants to be notified whenever
+ *                      a scheduling deadline is missed.
  */
 #define SF_HEAD		1
+#define SF_SIG_RORUN	2
+#define SF_SIG_DMISS	4
 
 struct exec_domain;
 struct futex_pi_state;
@@ -1243,9 +1254,10 @@ struct sched_rt_entity {
 };
 
 struct sched_stats_dl {
-#ifdef CONFIG_SCHEDSTATS
+	int			dmiss, rorun;
 	u64			last_dmiss;
 	u64			last_rorun;
+#ifdef CONFIG_SCHEDSTATS
 	u64			dmiss_max;
 	u64			rorun_max;
 #endif
kernel/posix-cpu-timers.c +55 -0

73 lines not on this page · raw message

kernel/sched_debug.c +2 -0
index 9bec524..4949a21 100644
@@ -468,8 +468,10 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 	P(se.statistics.nr_wakeups_passive);
 	P(se.statistics.nr_wakeups_idle);
 	if (dl_task(p)) {
+		P(dl.stats.dmiss);
 		PN(dl.stats.last_dmiss);
 		PN(dl.stats.dmiss_max);
+		P(dl.stats.rorun);
 		PN(dl.stats.last_rorun);
 		PN(dl.stats.rorun_max);
 		PN(dl.stats.tot_rtime);
kernel/sched_dl.c +6 -2
index cc87949..eff183a 100644
@@ -491,14 +491,18 @@ int dl_runtime_exceeded(struct rq *rq, struct sched_dl_entity *dl_se)
 	if (dmiss) {
 		u64 damount = rq->clock - dl_se->deadline;
 
-		schedstat_set(dl_se->stats.last_dmiss, damount);
+		dl_se->stats.dmiss = 1;
+		dl_se->stats.last_dmiss = damount;
+
 		schedstat_set(dl_se->stats.dmiss_max,
 			      max(dl_se->stats.dmiss_max, damount));
 	}
 	if (rorun) {
 		u64 ramount = -dl_se->runtime;
 
-		schedstat_set(dl_se->stats.last_rorun, ramount);
+		dl_se->stats.rorun = 1;
+		dl_se->stats.last_rorun = ramount;
+
 		schedstat_set(dl_se->stats.rorun_max,
 			      max(dl_se->stats.rorun_max, ramount));
 	}
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#108 lore raw

Re: [RFC][PATCH 17/22] sched: add signaling overrunning -deadline tasks.

Quoted 9 lines · Raistlin
kernel/posix-cpu-timers.c +9 -0
+static inline void __dl_signal(struct task_struct *tsk, int which)
+{
+       struct siginfo info;
+       long long amount = which == SF_SIG_DMISS ? tsk->dl.stats.last_dmiss :
+                          tsk->dl.stats.last_rorun;
+
+       info.si_signo = SIGXCPU;
+       info.si_errno = which;
+       info.si_code = SI_KERNEL;

kernel/posix-cpu-timers.c void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) · line 932

Quoted 10 lines
kernel/posix-cpu-timers.c +10 -0
+       info.si_pid = 0;
+       info.si_uid = 0;
+       info.si_value.sival_int = (int)amount;
+
+       /* Correctly take the locks on task's sighand */
+       __group_send_sig_info(SIGXCPU, &info, tsk);
+       /* Log what happened to dmesg */
+       printk(KERN_INFO "SCHED_DEADLINE: 0x%4x by %Ld [ns] in %d (%s)\n",
+              which, amount, task_pid_nr(tsk), tsk->comm);
+} 

This being a G-EDF like scheduler with a u<=1 schedulability test, we're firmly in soft-rt territory which means the above will be very easy to trigger.. Maybe not spam dmesg?

author
#109 lore raw

Re: [RFC][PATCH 17/22] sched: add signaling overrunning -deadline tasks.

Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Raistlin
kernel/posix-cpu-timers.c +15 -0
+static inline void __dl_signal(struct task_struct *tsk, int which)
+{
+       struct siginfo info;
+       long long amount = which == SF_SIG_DMISS ? tsk->dl.stats.last_dmiss :
+                          tsk->dl.stats.last_rorun;
+
+       info.si_signo = SIGXCPU;
+       info.si_errno = which;
+       info.si_code = SI_KERNEL;
+       info.si_pid = 0;
+       info.si_uid = 0;
+       info.si_value.sival_int = (int)amount;
+
+       /* Correctly take the locks on task's sighand */
+       __group_send_sig_info(SIGXCPU, &info, tsk);
Quoted 9 lines

kernel/posix-cpu-timers.c void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) · line 932

Quoted 4 lines
kernel/posix-cpu-timers.c +4 -0
+       /* Log what happened to dmesg */
+       printk(KERN_INFO "SCHED_DEADLINE: 0x%4x by %Ld [ns] in %d (%s)\n",
+              which, amount, task_pid_nr(tsk), tsk->comm);
+} 

This being a G-EDF like scheduler with a u<=1 schedulability test, we're firmly in soft-rt territory which means the above will be very easy to trigger.. Maybe not spam dmesg?

Ok, right. Maybe, if I add the SF_HARD_RT flag (and force the hard tasks to run on a single CPU they must specify) I can keep the notification for those tasks only. What do you think?

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#110 lore raw

Re: [RFC][PATCH 17/22] sched: add signaling overrunning -deadline tasks.

Quoted 26 lines · Raistlin
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Raistlin
kernel/posix-cpu-timers.c +15 -0
+static inline void __dl_signal(struct task_struct *tsk, int which)
+{
+       struct siginfo info;
+       long long amount = which == SF_SIG_DMISS ? tsk->dl.stats.last_dmiss :
+                          tsk->dl.stats.last_rorun;
+
+       info.si_signo = SIGXCPU;
+       info.si_errno = which;
+       info.si_code = SI_KERNEL;
+       info.si_pid = 0;
+       info.si_uid = 0;
+       info.si_value.sival_int = (int)amount;
+
+       /* Correctly take the locks on task's sighand */
+       __group_send_sig_info(SIGXCPU, &info, tsk);
Quoted 9 lines

kernel/posix-cpu-timers.c void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) · line 932

Quoted 4 lines
kernel/posix-cpu-timers.c +4 -0
+       /* Log what happened to dmesg */
+       printk(KERN_INFO "SCHED_DEADLINE: 0x%4x by %Ld [ns] in %d (%s)\n",
+              which, amount, task_pid_nr(tsk), tsk->comm);
+} 

This being a G-EDF like scheduler with a u<=1 schedulability test, we're firmly in soft-rt territory which means the above will be very easy to trigger.. Maybe not spam dmesg?

Quoted 3 lines

Ok, right. Maybe, if I add the SF_HARD_RT flag (and force the hard tasks to run on a single CPU they must specify) I can keep the notification for those tasks only. What do you think?

Sure.. that makes sense.

author
#111 lore raw

RFC PATCH 18/22 sched: add reclaiming logic to -deadline tasks

In reply to Raistlin

The bandwidth enforcing mechanism implemented inside the SCHED_DEADLINE policy ensures that overrunning tasks are slowed down without interfering with well behaving ones. This, however, comes at the price of limiting the capability of a task to exploit more bandwidth than it is asigned.

The current implementation always stops a task that is trying to use more than its runtime (every deadline). Something else that could be done is to let it continue running, but with a "decreased priority". This way, we can exploit full CPU bandwidth and still avoid interferences.

In order of "decreasing the priority" of a deadline task, we can:
- let it stay SCHED_DEADLINE and postpone its deadline. This way it will always be scheduled before -rt and -other tasks but it won't affect other -deadline tasks;
- put it in SCHED_FIFO with some priority. This way it will always be scheduled before -other tasks but it won't affect -deadline tasks, nor other -rt tasks with higher priority;
- put it in SCHED_OTHER.

Notice also that this can be done on a per-task basis, e.g., each task can specify what kind of reclaiming mechanism it wants to use by means of the sched_flags field of sched_param_ex.

Therefore, this patch:
- adds the flags for specyfing DEADLINE, RT or OTHER reclaiming behaviour;
- adds the logic that changes the scheduling class of a task when it overruns, according to the requested policy.

---
 include/linux/sched.h |   25 ++++++++++++++
 kernel/hrtimer.c      |    2 +-
 kernel/sched.c        |   86 ++++++++++++++++++++++++++++++++-----------------
 kernel/sched_debug.c  |    2 +-
 kernel/sched_dl.c     |   44 +++++++++++++++++++++++--
 5 files changed, 123 insertions(+), 36 deletions(-)
include/linux/sched.h +25 -0
index b729f83..8806c1f 100644
@@ -172,10 +172,26 @@ struct sched_param_ex {
  *                      a runtime overrun occurs;
  *  @SF_SIG_DMISS       tells us the task wants to be notified whenever
  *                      a scheduling deadline is missed.
+ *  @SF_BWRECL_DL       tells us that the task doesn't stop when exhausting
+ *                      its runtime, and it remains a -deadline task, even
+ *                      though its deadline is postponed. This means it
+ *                      won't affect the scheduling of the other -deadline
+ *                      tasks, but if it is a CPU-hog, lower scheduling
+ *                      classes will starve!
+ *  @SF_BWRECL_RT       tells us that the task doesn't stop when exhausting
+ *                      its runtime, and it becomes a -rt task, with the
+ *                      priority specified in the sched_priority field of
+ *                      struct shced_param_ex.
+ *  @SF_BWRECL_OTH      tells us that the task doesn't stop when exhausting
+ *                      its runtime, and it becomes a normal task, with
+ *                      default priority.
  */
 #define SF_HEAD		1
 #define SF_SIG_RORUN	2
 #define SF_SIG_DMISS	4
+#define SF_BWRECL_DL	8
+#define SF_BWRECL_RT	16
+#define SF_BWRECL_NR	32
 
 struct exec_domain;
 struct futex_pi_state;
@@ -1694,6 +1710,15 @@ static inline int dl_task(struct task_struct *p)
 	return dl_prio(p->prio);
 }
 
+/*
+ * We might have temporarily dropped -deadline policy,
+ * but still be a -deadline task!
+ */
+static inline int __dl_task(struct task_struct *p)
+{
+	return dl_task(p) || p->policy == SCHED_DEADLINE;
+}
+
 static inline int rt_prio(int prio)
 {
 	if (unlikely(prio >= MAX_DL_PRIO && prio < MAX_RT_PRIO))
kernel/hrtimer.c +1 -1
index 9cd8564..54277be 100644
@@ -1574,7 +1574,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
 	unsigned long slack;
 
 	slack = current->timer_slack_ns;
-	if (dl_task(current) || rt_task(current))
+	if (__dl_task(current) || rt_task(current))
 		slack = 0;
 
 	hrtimer_init_on_stack(&t.timer, clockid, mode);
kernel/sched.c +56 -30

142 lines not on this page · raw message

kernel/sched_debug.c +1 -1
index 4949a21..2bf4e72 100644
@@ -467,7 +467,7 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 	P(se.statistics.nr_wakeups_affine_attempts);
 	P(se.statistics.nr_wakeups_passive);
 	P(se.statistics.nr_wakeups_idle);
-	if (dl_task(p)) {
+	if (__dl_task(p)) {
 		P(dl.stats.dmiss);
 		PN(dl.stats.last_dmiss);
 		PN(dl.stats.dmiss_max);
kernel/sched_dl.c +40 -4

97 lines not on this page · raw message

Signature · 11 lines
1.7.2.3



-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#112 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 25 lines · Raistlin

The bandwidth enforcing mechanism implemented inside the SCHED_DEADLINE policy ensures that overrunning tasks are slowed down without interfering with well behaving ones. This, however, comes at the price of limiting the capability of a task to exploit more bandwidth than it is asigned.

The current implementation always stops a task that is trying to use more than its runtime (every deadline). Something else that could be done is to let it continue running, but with a "decreased priority". This way, we can exploit full CPU bandwidth and still avoid interferences.

In order of "decreasing the priority" of a deadline task, we can:
- let it stay SCHED_DEADLINE and postpone its deadline. This way it will always be scheduled before -rt and -other tasks but it won't affect other -deadline tasks;
- put it in SCHED_FIFO with some priority. This way it will always be scheduled before -other tasks but it won't affect -deadline tasks, nor other -rt tasks with higher priority;
- put it in SCHED_OTHER.

Notice also that this can be done on a per-task basis, e.g., each task can specify what kind of reclaiming mechanism it wants to use by means of the sched_flags field of sched_param_ex.

Quoted 5 lines

Therefore, this patch:
- adds the flags for specyfing DEADLINE, RT or OTHER reclaiming behaviour;
- adds the logic that changes the scheduling class of a task when it overruns, according to the requested policy.

The first two definitely should require SYS_CAP_ADMIN because it allows silly while(1) loops again.. but can we postpone this fancy feature as well?

I'd much rather have the stochastic thing implemented that allows limited temporal overrun.

author
#113 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 9 lines · Peter Zijlstra
Quoted 5 lines

Therefore, this patch:
- adds the flags for specyfing DEADLINE, RT or OTHER reclaiming behaviour;
- adds the logic that changes the scheduling class of a task when it overruns, according to the requested policy.

The first two definitely should require SYS_CAP_ADMIN because it allows silly while(1) loops again..

Sure, good point!

Quoted 3 lines

but can we postpone this fancy feature as
well?

As you wish, I'll keep backing it in my private tree...

Quoted 3 lines

I'd much rather have the stochastic thing implemented that allows limited temporal overrun.

... But at this point I can't avoid asking. That model aims at _pure_ hard real-time scheduling *without* resource reservation capabilities, provided it deals with temporal overruns by means of a probabilistic analysis, right?
In this scheduler, we do have resource reservations to deal with overruns, provided it can guarantee bandwidth isolation among tasks even in case of overrun (which is very typical soft real-time solution, but can provide hard guarantees as well, if the analysis is careful enough).

Are we sure the two approaches matches, and/or can live together?

That's because I'm not sure what we would do, at that point, while facing a runtime overrun... Enforce the bandwidth by stopping the task until its next deadline (as we do now)? Or allows it to overrun basing of the statistical information we have? Or do we want somehow try to do both?

I know we can discuss and decide the details later, after merging all this... But I still think it's worth trying to have at least a basic idea of how to do that, just to avoid doing something now that we will regret then. :-)

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#114 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 6 lines · Raistlin

But at this point I can't avoid asking. That model aims at _pure_ hard real-time scheduling *without* resource reservation capabilities, provided it deals with temporal overruns by means of a probabilistic analysis, right?

From what I understood from it, its a soft real-time scheduling

algorithm with resource reservation. It explicitly allows for deadline misses, but requires the tardiness of those misses to be bounded, ie. the UNC soft real-time definition.

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

By using the average CET (much more easily obtained) we get a much higher system utilization, but since its an average we need to deal with deadline overruns due to temporal overload scenarios.

Their reasoning goes that since its an average, an overrun must be compensated by a short run in the near future. The variance parameter provides a measure of 'near'. Once we've 'consumed' this short run and are back to the average case our tardiness is back to 0 as well (considering an otherwise tight scheduler, say P-EDF), since then we've met the bandwidth requirements placed by this scheduler.

And since the pure statistics allow for an arbitrary large deviation from the average it also requires a max runtime in order to be able to place a bound on tardiness.

So for G-EDF with stochastic ET we still get a bounded tardiness, its a simple sum of bounds, one due to the G in G-EDF and one due to the stochastic ET.

#115 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Raistlin

But at this point I can't avoid asking. That model aims at _pure_ hard real-time scheduling *without* resource reservation capabilities, provided it deals with temporal overruns by means of a probabilistic analysis, right?

Quoted 8 lines
Quoted 1 line

From what I understood from it, its a soft real-time scheduling

algorithm with resource reservation. It explicitly allows for deadline misses, but requires the tardiness of those misses to be bounded, ie. the UNC soft real-time definition.

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

[...]
BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET. You can use some stochastic analysis, providing probabilistic deadline guarantees. See (for example) "QoS Guarantee Using Probabilistic Deadlines"
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.7683&rep=rep1&type=pdf
and "Stochastic analysis of a reservation based system"
http://www.computer.org/portal/web/csdl/doi?doc=doi/10.1109/IPDPS.2001.925049
(sorry, this is not easy to download... But I can provide a copy if you are interested).

Luca

maintainer
#116 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 7 lines · Luca Abeni
Quoted 3 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

[...]
BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET.

Yes you are, it pushes the deadline back on overrun. The idea it to maintain the deadline despite overrunning your budget (up to a point).

The paper we're all talking about is:

A. Mills and J. Anderson, " A Stochastic Framework for Multiprocessor Soft Real-Time Scheduling", Proceedings of the 16th IEEE Real-Time and Embedded Technology and Applications Symposium, pp. 311-320, April 2010.
http://www.cs.unc.edu/~anderson/papers/rtas10brevised.pdf

And I see they've got a new stochastic paper out:

A. Mills and J. Anderson, " Scheduling Stochastically-Executing Soft Real-Time Tasks: A Multiprocessor Approach Without Worst-Case Execution Times", in submission.
http://www.cs.unc.edu/~anderson/papers/rtas11b.pdf

#117 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 10 lines · Peter Zijlstra
Quoted 7 lines · Luca Abeni
Quoted 3 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

[...]
BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET.

Yes you are, it pushes the deadline back on overrun.

I think in case of overrun it postpones the deadline (by a period P), avoiding to execute the task until the end of the current period, right?

Quoted 9 lines

The idea it to
maintain the deadline despite overrunning your budget (up to a point).

The paper we're all talking about is:

A. Mills and J. Anderson, " A Stochastic Framework for Multiprocessor Soft Real-Time Scheduling", Proceedings of the 16th IEEE Real-Time and Embedded Technology and Applications Symposium, pp. 311-320, April 2010.
http://www.cs.unc.edu/~anderson/papers/rtas10brevised.pdf

I see... This is a different approach to stochastic analysis, which requires modifications to the scheduler.

In the analysis I mentioned, you still enforce a maximum runtime C every period P, but C can be smaller than the WCET of the task. If C is larger than the average execution time, you can use queuing theory to find the probability to miss a deadline (or, the probability to finish a job in a time x * P).

Luca

author
#118 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines

BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET.

Yes you are, it pushes the deadline back on overrun. The idea it to maintain the deadline despite overrunning your budget (up to a point).

BTW, although I share most of Luca's and Tommaso's viewpoints, triggering bandwidth enforcement at runtime+something instead than just at runtime doesn't look all that bad, and should fit nicely in what we have now, without much twisting.

It's just another way to interpret the runtime, and it seems feasible (or at least plan-able as future feature! :-P) to me... Actually this was exactly what I was asking and what I wanted to know. :-)

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
#119 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to Luca Abeni

Il 12/11/2010 18:41, Luca Abeni ha scritto:

Quoted 9 lines
Quoted 8 lines

algorithm with resource reservation. It explicitly allows for deadline misses, but requires the tardiness of those misses to be bounded, ie. the UNC soft real-time definition.

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

Quoted 8 lines

[...]
BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET. You can use some stochastic analysis, providing probabilistic deadline guarantees. See (for example) "QoS Guarantee Using Probabilistic Deadlines"
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.7683&rep=rep1&type=pdf

and "Stochastic analysis of a reservation based system"
http://www.computer.org/portal/web/csdl/doi?doc=doi/10.1109/IPDPS.2001.925049

(sorry, this is not easy to download... But I can provide a copy if you are interested).

Thanks, Luca, for supporting the viewpoint. I also repeated this multiple times, during the LPC as well.

Let me underline a few key points, also about the technique suggested by Zijlstra:

-) the specification of a budget every period may be exploited for providing deterministic guarantees to applications, if the budget = WCET, as well as probabilistic guarantees, if the budget < WCET. For example, what we do in many of our papers is to set budget = to some percentile/quantile of the observed computation time distribution, especially in those cases in which there are isolated peaks of computation times which would cause an excessive under-utilization of the system (these are ruled out by the percentile-based allocation); I think this is a way of reasoning that can be easily understood and used by developers;

-) setting a budget equal to (or too close to) the average computation time is *bad*, because the is almost in a meta-stable condition in which its response-time may easily grow uncontrolled;

-) same thing applies to admitting tasks in the system: if you only ensure that the sum of average/expected bandwidths < system capacity, then the whole system is at risk of having uncontrolled and arbitrarily high peak delays, but from a theoretical viewpoint it is still a "stable" system; this is not a condition you want to have in a sane real-time scenario;

-) if you want to apply the Mills & Anderson's rule for controlling the bound on the tardiness percentiles, as in that paper (A Stochastic Framework for Multiprocessor
Soft Real-Time Scheduling), then I can see 2 major drawbacks:
a) you need to compute the "\psi" in order to use the "Corollary 10"
of that paper, but that quantity needs to solve a LP optimization problem (see also the example in Section 6); the \psi can be used in Eq. (36) in order to compute the *expected tardiness*;
b) unfortunately, the expected tardiness is hardly the quantity of
interest for any concrete real-time application, where some percentile of the tardiness distribution may be much more important; therefore, you are actually interested in Eq. (37) for computing the q-th percentile of the tardiness. Unfortunately, such last bound is provided through the Chebychev (or Markov, or whatever it is called) inequality simply from the expected average, and this bound is well-known to be so conservative (a 99% percentile is basically hundred times the average). The consequence is that you would end-up to actually admit very few tasks as compared to what actually fits into the system.

Please, understand me: I don't want to say that that particular technique is not useful, but I'd like simply to stress that such policies might just belong to the user-space. If you really want, you can disable *any* type of admission control at the kernel-level, and you can disable *any* kind of budget enforcement, and just trust the user-space to have deployed the proper/correct number & type of tasks into your embedded RT platform.

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
author
#120 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 5 lines · Tommaso Cucinotta

Let me underline a few key points, also about the technique suggested by Zijlstra:

[...]

Quoted 8 lines

I can see 2 major drawbacks:
a) you need to compute the "\psi" in order to use the "Corollary 10"
of that paper, but that quantity needs to solve a LP optimization problem (see also the example in Section 6); the \psi can be used in Eq.
(36) in order to compute the *expected tardiness*;

[...]

Wow man! You really know what "give us details" means, don't you? :-PP

Thanks and regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#121 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to Tommaso Cucinotta
Quoted 29 lines · Tommaso Cucinotta

Il 12/11/2010 18:41, Luca Abeni ha scritto:

Quoted 17 lines
Quoted 8 lines

algorithm with resource reservation. It explicitly allows for deadline misses, but requires the tardiness of those misses to be bounded, ie. the UNC soft real-time definition.

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

[...]
BTW, sorry for the shameless plug, but even with the current SCHED_DEADLINE you are not forced to dimension the runtime using the WCET. You can use some stochastic analysis, providing probabilistic deadline guarantees. See (for example) "QoS Guarantee Using Probabilistic Deadlines"
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.7683&rep=rep1&type=pdf

Quoted 5 lines

and "Stochastic analysis of a reservation based system"
http://www.computer.org/portal/web/csdl/doi?doc=doi/10.1109/IPDPS.2001.925049

(sorry, this is not easy to download... But I can provide a copy if you are interested).

Thanks, Luca, for supporting the viewpoint. I also repeated this multiple times, during the LPC as well.

Let me underline a few key points, also about the technique suggested by Zijlstra:

Quoted 10 lines

-) the specification of a budget every period may be exploited for providing deterministic guarantees to applications, if the budget = WCET, as well as probabilistic guarantees, if the budget < WCET. For example, what we do in many of our papers is to set budget = to some percentile/quantile of the observed computation time distribution, especially in those cases in which there are isolated peaks of computation times which would cause an excessive under-utilization of the system (these are ruled out by the percentile-based allocation); I think this is a way of reasoning that can be easily understood and used by developers;

Maybe, but I'm clearly not one of them because I'm not getting it.

Quoted 3 lines

-) setting a budget equal to (or too close to) the average computation time is *bad*, because the is almost in a meta-stable condition in which its response-time may easily grow uncontrolled;

How so? Didn't the paper referenced just prove that the response time stays bounded?

Setting it lower will of course wreak havoc, but that's what we have bandwidth control for (implementing stochastic bandwidth control is a whole separate fun topic though -- although I've been thinking we could do something by lowering the max runtime every time a job overruns the average, and limit it at 2*avg - max, if you take a simple parametrized reduction function and compute the variability of th resulting series you can invert that and find the reduction parameter to a given variability).

Quoted 6 lines

-) same thing applies to admitting tasks in the system: if you only ensure that the sum of average/expected bandwidths < system capacity, then the whole system is at risk of having uncontrolled and arbitrarily high peak delays, but from a theoretical viewpoint it is still a "stable" system; this is not a condition you want to have in a sane real-time scenario;

I'm not seeing where the unbounded comes from.

I am seeing that if you place your budget request slightly higher than the actual average (say 1 stdev) your variability in the response time will decrease, but at a cost of lower utilization.

Quoted 8 lines

-) if you want to apply the Mills & Anderson's rule for controlling the bound on the tardiness percentiles, as in that paper (A Stochastic Framework for Multiprocessor
Soft Real-Time Scheduling), then I can see 2 major drawbacks:
a) you need to compute the "\psi" in order to use the "Corollary 10"
of that paper, but that quantity needs to solve a LP optimization problem (see also the example in Section 6); the \psi can be used in Eq.
(36) in order to compute the *expected tardiness*;

Right, but do we ever actually want to compute the bound? G-EDF also incurs tardiness but we don't calculate it either. Both depend on the full task set parameters which is not stable (nor accessible to user-space in a meaningful manner).

Quoted 7 lines

Please, understand me: I don't want to say that that particular technique is not useful, but I'd like simply to stress that such policies might just belong to the user-space. If you really want, you can disable *any* type of admission control at the kernel-level, and you can disable *any* kind of budget enforcement, and just trust the user-space to have deployed the proper/correct number & type of tasks into your embedded RT platform.

I'm very much against disabling everything and letting the user sort it, that's basically what SCHED_FIFO does too and its a frigging nightmare.

The whole admission control and schedulability test is what makes this thing usable. People who build closed systems can already hack their kernel and do as they please, but for anything other than a closed system this approach is useless.

#122 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Il 13/11/2010 01:43, Peter Zijlstra ha scritto:

Quoted 11 lines · Tommaso Cucinotta
Quoted 10 lines

-) the specification of a budget every period may be exploited for providing deterministic guarantees to applications, if the budget = WCET, as well as probabilistic guarantees, if the budget< WCET. For example, what we do in many of our papers is to set budget = to some percentile/quantile of the observed computation time distribution, especially in those cases in which there are isolated peaks of computation times which would cause an excessive under-utilization of the system (these are ruled out by the percentile-based allocation); I think this is a way of reasoning that can be easily understood and used by developers;

Quoted 1 line

Maybe, but I'm clearly not one of them because I'm not getting it.

My fault for not having explained. Let me see if I can clarify. Let's just consider the simple case in which application instances do not enqueue (i.e., as soon as the application detects to have missed a deadline, it discards the current job, as opposed to keep computing the current job), and consider a reservation period == application period.

In such a case, if 'C' represents the (probabilistically modeled) computation time of a job, then:

Prob{deadline hit} = Prob{enough runtime for a job instance} = Prob{C
<= runtime}.

So, if runtime is set as the q-th quantile of the `C' probability distribution, then:

Prob{deadline hit} = Prob{C <= runtime} = q

This is true independently of what else is admitted into the system, as far as I get my runtime guaranteed from the scheduler.

Does this now make sense ?

If, on the other hand, task instances enqueue (e.g., I keep decoding the current frame even if I know a new frame arrived), then the probability of deadline-hit will be lower than q, and generally speaking one can use stochastic analysis & queueing theory techniques in order to figure out what it actually is.

Quoted 5 lines
Quoted 3 lines

-) setting a budget equal to (or too close to) the average computation time is *bad*, because the is almost in a meta-stable condition in which its response-time may easily grow uncontrolled;

How so? Didn't the paper referenced just prove that the response time stays bounded?

Here I was not referring to GEDF, but simply to the case in which we are reserved from the kernel a budget every period (whatever the scheduling algorithm): as the reserved budget moves from the WCET down towards the average computation time, the response time distribution moves from a shape entirely contained below the deadline, to a more and more flat shape, where the probability of missing the deadline for the task increases over and over. Roughly speaking, if the application instances do not enqueue, then with a budget = average computation time, I would expect a ~50% deadline miss, something which hardly is acceptable even for soft RT applications. If instances instead enqueue, then the situation may go much worse, because the response-time distribution flattens with a long tail beyond the deadline. The maximum value of it approaches +\infty with the reserved budget approaching the average computation time.

Quoted 8 lines

Setting it lower will of course wreak havoc, but that's what we have bandwidth control for (implementing stochastic bandwidth control is a whole separate fun topic though -- although I've been thinking we could do something by lowering the max runtime every time a job overruns the average, and limit it at 2*avg - max, if you take a simple parametrized reduction function and compute the variability of th resulting series you can invert that and find the reduction parameter to a given variability).

I'd need some more explanation, sorry, I couldn't understand what you're proposing.

Quoted 10 lines
Quoted 8 lines

-) if you want to apply the Mills& Anderson's rule for controlling the bound on the tardiness percentiles, as in that paper (A Stochastic Framework for Multiprocessor
Soft Real-Time Scheduling), then I can see 2 major drawbacks:
a) you need to compute the "\psi" in order to use the "Corollary 10"
of that paper, but that quantity needs to solve a LP optimization problem (see also the example in Section 6); the \psi can be used in Eq.
(36) in order to compute the *expected tardiness*;

Right, but do we ever actually want to compute the bound? G-EDF also incurs tardiness but we don't calculate it either.

I was assuming you were proposing to keep an admission test based on providing the parameters needed for checking whether or not a given tardiness bound were respected. I must have misunderstood. Would you please detail what is the test (and result in the paper) you are thinking of using ?

Quoted 7 lines
Quoted 5 lines

If you really want, you
can disable *any* type of admission control at the kernel-level, and you can disable *any* kind of budget enforcement, and just trust the user-space to have deployed the proper/correct number& type of tasks into your embedded RT platform.

I'm very much against disabling everything and letting the user sort it, that's basically what SCHED_FIFO does too and its a frigging nightmare.

Sure, I agree. I was simply suggesting it as a last-resort option (possibly usable by exploiting a compile-time option of the scheduler compiling out the admission test), useful in those cases in which you do have a user-space complex admission test that you made (or even an off-line static analysis of your system) but the simple admission test into the kernel would actually reject the task set, being the test merely sufficient.

Bye,

    T.
Signature · 4 lines
Tommaso Cucinotta, Computer Engineering PhD, Researcher
ReTiS Lab, Scuola Superiore Sant'Anna, Pisa, Italy
Tel +39 050 882 024, Fax +39 050 882 003
http://retis.sssup.it/people/tommaso
author
#123 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Raistlin

But at this point I can't avoid asking. That model aims at _pure_ hard real-time scheduling *without* resource reservation capabilities, provided it deals with temporal overruns by means of a probabilistic analysis, right?

From what I understood from it, its a soft real-time scheduling algorithm with resource reservation.

Mmm... I've gone through it (again!) quickly, and you're right, it mentions soft real-time, and I agree that for those systems average CET is better than worst CET. However, I'm not sure resource reservation is there... Not in the paper I have at least, but I may be wrong.

Quoted 4 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

I know, and it's very reasonable. The point I'm trying to make is that resource reservation tries to address the very same issue.
I am all but against this model, just want to be sure it's not too much in conflict to the other features we have, especially with resource reservation. Especially considering that --if I got the whole thing about this scheduler right-- resource reservation is something we really want, and I think UNC people would agree here, since I heard Bjorn stating this very clear both in Dresden and in Dublin. :-)

BTW, I'm adding them to the Cc, seems fair, and more useful than all this speculation! :-P

Bjorn, Jim, sorry for bothering. If you're interested, this is the very beginning of the whole thread:
http://lkml.org/lkml/2010/10/29/67

And these should be from where this specific discussion starts (I hope, the mirror is not updated yet I guess :-( ):
http://lkml.org/lkml/2010/10/29/49
http://groups.google.com/group/linux.kernel/msg/1dadeca435631b60

Thanks and Regards,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#125 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Sorry for the delayed response... I think I must have inadvertently deleted this email last week and Bjoern just mentioned it to me...

Quoted 40 lines · Peter Zijlstra
Quoted 12 lines · Raistlin
Quoted 6 lines

But at this point I can't avoid asking. That model aims at _pure_ hard real-time scheduling *without* resource reservation capabilities, provided it deals with temporal overruns by means of a probabilistic analysis, right?

From what I understood from it, its a soft real-time scheduling algorithm with resource reservation.

Mmm... I've gone through it (again!) quickly, and you're right, it mentions soft real-time, and I agree that for those systems average CET is better than worst CET. However, I'm not sure resource reservation is there... Not in the paper I have at least, but I may be wrong.

Quoted 5 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

I know, and it's very reasonable. The point I'm trying to make is that resource reservation tries to address the very same issue.
I am all but against this model, just want to be sure it's not too much in conflict to the other features we have, especially with resource reservation. Especially considering that --if I got the whole thing about this scheduler right-- resource reservation is something we really want, and I think UNC people would agree here, since I heard Bjorn stating this very clear both in Dresden and in Dublin. :-)

BTW, I'm adding them to the Cc, seems fair, and more useful than all this speculation! :-P

Bjorn, Jim, sorry for bothering. If you're interested, this is the very beginning of the whole thread:
http://lkml.org/lkml/2010/10/29/67

Quoted 8 lines

And these should be from where this specific discussion starts (I hope, the mirror is not updated yet I guess :-( ):
http://lkml.org/lkml/2010/10/29/49
http://groups.google.com/group/linux.kernel/msg/1dadeca435631b60

Thanks and Regards,
Dario

If you're talking about our most recent "stochastic" paper, it is about supporting soft real-time task systems on a multiprocessor where resource reservations are used. The main result of the paper is that if you provision the reservation for a task slightly higher than it's average-case execution time, and if you use a scheduling algorithm (like global EDF) that ensures bounded tardiness (w.r.t. these reservations), then the task's expected tardiness will be bounded and the expected bound does not depend on worst-case execution times. I'm not sure if slack-reallocation methods have come up in this discussion (sorry, I'm really pressed for time and didn't look), but we didn't get into that in our paper. However, such methods would be easy to incorporate. I think one of the most beautiful aspects of this paper (which we didn't say enough about) is that the analysis completely separates all the stochastic stuff from the reasoning needed to derive tardiness bounds under a given scheduler. In other words, you can simply ignore all stochastic issues when reasoning about tardiness. I gathered there was some confusion about whether we were using resource reservations. Such reservations are actually crucial for our analysis as they allow independence to be assumed across tasks. And oh yeah: this work has nothing to do with hard real-time and worst-case execution times are not used at all.

Just to make sure I don't end up creating more confusion, the paper I'm talking about is this one:
http://www.cs.unc.edu/~anderson/papers/rtas11b.pdf

I hope this helps.

-Jim Anderson

#126 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Hi James,

On 15/11/10 19:37, James H. Anderson wrote:
[...]

Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

I know, and it's very reasonable. The point I'm trying to make is that resource reservation tries to address the very same issue.
I am all but against this model, just want to be sure it's not too much in conflict to the other features we have, especially with resource reservation. Especially considering that --if I got the whole thing about this scheduler right-- resource reservation is something we really want, and I think UNC people would agree here, since I heard Bjorn stating this very clear both in Dresden and in Dublin. :-)

BTW, I'm adding them to the Cc, seems fair, and more useful than all this speculation! :-P

Bjorn, Jim, sorry for bothering. If you're interested, this is the very beginning of the whole thread:
http://lkml.org/lkml/2010/10/29/67

[...]

Quoted 10 lines

If you're talking about our most recent "stochastic" paper, it is about supporting
soft real-time task systems on a multiprocessor where resource reservations are
used. The main result of the paper is that if you provision the reservation for a
task slightly higher than it's average-case execution time, and if you use a
scheduling algorithm (like global EDF) that ensures bounded tardiness (w.r.t.

Quoted 8 lines

these reservations), then the task's expected tardiness will be bounded and the
expected bound does not depend on worst-case execution times. I'm not sure if
slack-reallocation methods have come up in this discussion (sorry, I'm really
pressed for time and didn't look), but we didn't get into that in our paper.

So, if I understand well (sorry, I am just trying to make a short summary to check if we are aligned) your analysis is similar to the one presented in the papers I mentioned earlier in this thread (different stochastic modelling, but similar approach): you analyse a reservation in isolation and you provide some stochastic tardiness guarantees based on an (e_i, p_i) service model.... Right?

If my understanding is correct (please, correct me if I am wrong), your analysis can be applied even with the current version of Dario's patch (I mean: no modifications to the patch are needed for removing assumptions about WCET knowledge... Your paper uses a sporadic server for the reservation mechanism, but I think a CBS can work too...).

Thanks,
Luca

#127 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

Quoted 42 lines · Luca Abeni

Hi James,

On 15/11/10 19:37, James H. Anderson wrote:
[...]

Quoted 19 lines
Quoted 19 lines
Quoted 4 lines

The problem the stochastic execution time model tries to address is the WCET computation mess, WCET computation is hard and often overly pessimistic, resulting in under-utilized systems.

I know, and it's very reasonable. The point I'm trying to make is that resource reservation tries to address the very same issue.
I am all but against this model, just want to be sure it's not too much in conflict to the other features we have, especially with resource reservation. Especially considering that --if I got the whole thing about this scheduler right-- resource reservation is something we really want, and I think UNC people would agree here, since I heard Bjorn stating this very clear both in Dresden and in Dublin. :-)

BTW, I'm adding them to the Cc, seems fair, and more useful than all this speculation! :-P

Bjorn, Jim, sorry for bothering. If you're interested, this is the very beginning of the whole thread:
http://lkml.org/lkml/2010/10/29/67

[...]

Quoted 10 lines

If you're talking about our most recent "stochastic" paper, it is about supporting
soft real-time task systems on a multiprocessor where resource reservations are
used. The main result of the paper is that if you provision the reservation for a
task slightly higher than it's average-case execution time, and if you use a
scheduling algorithm (like global EDF) that ensures bounded tardiness (w.r.t.

Quoted 8 lines

these reservations), then the task's expected tardiness will be bounded and the
expected bound does not depend on worst-case execution times. I'm not sure if
slack-reallocation methods have come up in this discussion (sorry, I'm really
pressed for time and didn't look), but we didn't get into that in our paper.

Quoted 1 line

So, if I understand well (sorry, I am just trying to make a short summary to check if we are aligned) your analysis is similar to the one presented in the papers I mentioned earlier in this thread (different stochastic modelling, but similar approach): you analyse a reservation in isolation and you provide some stochastic tardiness guarantees based on an (e_i, p_i) service model.... Right?

Sorry, I don't have time right now to check these papers, but what you are saying sounds correct.

Quoted 2 lines

If my understanding is correct (please, correct me if I am wrong), your analysis can be applied even with the current version of Dario's patch (I mean: no modifications to the patch are needed for removing assumptions about WCET knowledge... Your paper uses a sporadic server for the reservation mechanism, but I think a CBS can work too...).

This sounds correct a well. We assume that if a job of a task overruns its current budget allocation (which will likely happen, provisioning reservations on the average case), then the remainder of that job will be executed using future allocations for the same task. The analysis doesn't (I think) depend too much on the exact way reservations are supported.

-Jim

#128 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to James H. Anderson

On 15/11/10 19:37, James H. Anderson wrote:
[...]

Quoted 7 lines

If you're talking about our most recent "stochastic" paper, it is about supporting
soft real-time task systems on a multiprocessor where resource reservations are
used. The main result of the paper is that if you provision the reservation for a
task slightly higher than it's average-case execution time

[...]
BTW, I think we are aligned on this.

I was a little bit surprised when Peter mentioned allocating a runtime equal to the average execution time (because of the meta-stability considerations that Tommaso also mentioned), but I fully agree that if the allocated runtime is higher than the average execution time then the queue is stable and it's possible to find a bound for the expected tardiness (or even its probability distribution... This is similar to my "probabilistic deadlines").

Luca

author
#129 lore raw

Re: [RFC][PATCH 18/22] sched: add reclaiming logic to -deadline tasks

In reply to James H. Anderson
Quoted 3 lines · James H. Anderson

Sorry for the delayed response... I think I must have inadvertently deleted this

NP. Hope it's not my fault, due to GPG and stuff... :-)

Quoted 6 lines

If you're talking about our most recent "stochastic" paper, it is about supporting
soft real-time task systems on a multiprocessor where resource reservations are
used.

Actually, we were talking about the previous one, which (if I got it well) didn't include reservations, and that's why we were wondering how to integrate it in the scheduler (which _is_ reservation based).

Now that this one is out, going for it simply solves all our issues, also considering that it says something very similar to what we (Pisa guys :-D) are familiar with, since we investigated this stuff too sometime ago (actually, Luca did).

Quoted 2 lines

However, such methods would be easy to incorporate.

I think it really should be... Actually, I'm under the impression that we don't even need variance/std-dev of the execution time to be part of the interface, do we?

Quoted 5 lines

I gathered there was
some confusion about whether we were using resource reservations. Such reservations are actually crucial for our analysis as they allow independence to be assumed across tasks.

Yes, as I said, this was because we were looking at first paper. Now we got it, thanks a lot for clarifying! :-)

Quoted 2 lines

I hope this helps.

A lot, thanks again.

Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#130 lore raw

RFC PATCH 19/22 rtmutex: turn the plist into an rb-tree

In reply to Raistlin

Turn the pi-chains from plist to rb-tree, in the rt_mutex code, and provide a proper comparison function for -deadline and -priority tasks.

This is done mainly because:
- classical prio field of the plist is just an int, which might not be enough for representing a deadline;
- manipulating such a list would become O(nr_deadline_tasks), which might be to much, as the number of -deadline task increses.

Therefore, an rb-tree is used, and tasks are queued in it according to the following logic:
- among two -priority (i.e., SCHED_BATCH/OTHER/RR/FIFO) tasks, the one with the higher (lower, actually!) prio wins;
- among a -priority and a -deadline task, the latter always wins;
- among two -deadline tasks, the one with the earliest deadline wins.

Queueing and dequeueing functions are chenged accordingly, for both the list of a task's pi-waiters and the list of tasks blocked on a pi-lock.

---
 include/linux/init_task.h |   10 +++
 include/linux/rtmutex.h   |   13 +---
 include/linux/sched.h     |    4 +-
 kernel/fork.c             |    3 +-
 kernel/rtmutex-debug.c    |    8 +--
 kernel/rtmutex.c          |  135 +++++++++++++++++++++++++++++++++++----------
 kernel/rtmutex_common.h   |   22 ++++----
 kernel/sched.c            |    4 -
 8 files changed, 137 insertions(+), 62 deletions(-)
include/linux/init_task.h +10 -0
index 1f8c06c..f4f7567 100644
@@ -10,6 +10,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/user_namespace.h>
 #include <linux/securebits.h>
+#include <linux/rbtree.h>
 #include <net/net_namespace.h>
 
 extern struct files_struct init_files;
@@ -110,6 +111,14 @@ extern struct cred init_cred;
 # define INIT_PERF_EVENTS(tsk)
 #endif
 
+#ifdef CONFIG_RT_MUTEXES
+# define INIT_RT_MUTEXES						\
+	.pi_waiters = RB_ROOT,						\
+	.pi_waiters_leftmost = NULL,
+#else
+# define INIT_RT_MUTEXES
+#endif
+
 /*
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -178,6 +187,7 @@ extern struct cred init_cred;
 	INIT_FTRACE_GRAPH						\
 	INIT_TRACE_RECURSION						\
 	INIT_TASK_RCU_PREEMPT(tsk)					\
+	INIT_RT_MUTEXES							\
 }
 
 
include/linux/rtmutex.h +3 -10
index 8d522ff..bd7cd02 100644
@@ -13,7 +13,7 @@
 #define __LINUX_RT_MUTEX_H
 
 #include <linux/linkage.h>
-#include <linux/plist.h>
+#include <linux/rbtree.h>
 #include <linux/spinlock_types.h>
 
 extern int max_lock_depth; /* for sysctl */
@@ -27,7 +27,8 @@ extern int max_lock_depth; /* for sysctl */
  */
 struct rt_mutex {
 	raw_spinlock_t		wait_lock;
-	struct plist_head	wait_list;
+	struct rb_root          waiters;
+	struct rb_node          *waiters_leftmost;
 	struct task_struct	*owner;
 #ifdef CONFIG_DEBUG_RT_MUTEXES
 	int			save_state;
@@ -98,12 +99,4 @@ extern int rt_mutex_trylock(struct rt_mutex *lock);
 
 extern void rt_mutex_unlock(struct rt_mutex *lock);
 
-#ifdef CONFIG_RT_MUTEXES
-# define INIT_RT_MUTEXES(tsk)						\
-	.pi_waiters	= PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock),	\
-	INIT_RT_MUTEX_DEBUG(tsk)
-#else
-# define INIT_RT_MUTEXES(tsk)
-#endif
-
 #endif
include/linux/sched.h +3 -1
index 8806c1f..c3d1f17b 100644
@@ -56,6 +56,7 @@ struct sched_param {
 #include <linux/types.h>
 #include <linux/timex.h>
 #include <linux/jiffies.h>
+#include <linux/plist.h>
 #include <linux/rbtree.h>
 #include <linux/thread_info.h>
 #include <linux/cpumask.h>
@@ -1530,7 +1531,8 @@ struct task_struct {
 
 #ifdef CONFIG_RT_MUTEXES
 	/* PI waiters blocked on a rt_mutex held by this task */
-	struct plist_head pi_waiters;
+	struct rb_root pi_waiters;
+	struct rb_node *pi_waiters_leftmost;
 	/* Deadlock detection and priority inheritance handling */
 	struct rt_mutex_waiter *pi_blocked_on;
 #endif
kernel/fork.c +2 -1
index 3b159c5..aceb248 100644
@@ -935,7 +935,8 @@ static void rt_mutex_init_task(struct task_struct *p)
 {
 	raw_spin_lock_init(&p->pi_lock);
 #ifdef CONFIG_RT_MUTEXES
-	plist_head_init_raw(&p->pi_waiters, &p->pi_lock);
+	p->pi_waiters = RB_ROOT;
+	p->pi_waiters_leftmost = NULL;
 	p->pi_blocked_on = NULL;
 #endif
 }
kernel/rtmutex-debug.c +2 -6
index ddabb54..7cc8376 100644
@@ -23,7 +23,7 @@
 #include <linux/kallsyms.h>
 #include <linux/syscalls.h>
 #include <linux/interrupt.h>
-#include <linux/plist.h>
+#include <linux/rbtree.h>
 #include <linux/fs.h>
 #include <linux/debug_locks.h>
 
@@ -111,7 +111,7 @@ static void printk_lock(struct rt_mutex *lock, int print_owner)
 
 void rt_mutex_debug_task_free(struct task_struct *task)
 {
-	WARN_ON(!plist_head_empty(&task->pi_waiters));
+	WARN_ON(!RB_EMPTY_ROOT(&task->pi_waiters));
 	WARN_ON(task->pi_blocked_on);
 }
 
@@ -205,16 +205,12 @@ void debug_rt_mutex_proxy_unlock(struct rt_mutex *lock)
 void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
 {
 	memset(waiter, 0x11, sizeof(*waiter));
-	plist_node_init(&waiter->list_entry, MAX_PRIO);
-	plist_node_init(&waiter->pi_list_entry, MAX_PRIO);
 	waiter->deadlock_task_pid = NULL;
 }
 
 void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
 {
 	put_pid(waiter->deadlock_task_pid);
-	TRACE_WARN_ON(!plist_node_empty(&waiter->list_entry));
-	TRACE_WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
 	TRACE_WARN_ON(waiter->task);
 	memset(waiter, 0x22, sizeof(*waiter));
 }
kernel/rtmutex.c +106 -29

251 lines not on this page · raw message

kernel/rtmutex_common.h +11 -11
index 97a2f81..84b9eea 100644
@@ -40,13 +40,13 @@ extern void schedule_rt_mutex_test(struct rt_mutex *lock);
  * This is the control structure for tasks blocked on a rt_mutex,
  * which is allocated on the kernel stack on of the blocked task.
  *
- * @list_entry:		pi node to enqueue into the mutex waiters list
- * @pi_list_entry:	pi node to enqueue into the mutex owner waiters list
+ * @tree_entry:		pi node to enqueue into the mutex waiters tree
+ * @pi_tree_entry:	pi node to enqueue into the mutex owner waiters tree
  * @task:		task reference to the blocked task
  */
 struct rt_mutex_waiter {
-	struct plist_node	list_entry;
-	struct plist_node	pi_list_entry;
+	struct rb_node          tree_entry;
+	struct rb_node          pi_tree_entry;
 	struct task_struct	*task;
 	struct rt_mutex		*lock;
 #ifdef CONFIG_DEBUG_RT_MUTEXES
@@ -57,11 +57,11 @@ struct rt_mutex_waiter {
 };
 
 /*
- * Various helpers to access the waiters-plist:
+ * Various helpers to access the waiters-tree:
  */
 static inline int rt_mutex_has_waiters(struct rt_mutex *lock)
 {
-	return !plist_head_empty(&lock->wait_list);
+	return !RB_EMPTY_ROOT(&lock->waiters);
 }
 
 static inline struct rt_mutex_waiter *
@@ -69,8 +69,8 @@ rt_mutex_top_waiter(struct rt_mutex *lock)
 {
 	struct rt_mutex_waiter *w;
 
-	w = plist_first_entry(&lock->wait_list, struct rt_mutex_waiter,
-			       list_entry);
+	w = rb_entry(lock->waiters_leftmost, struct rt_mutex_waiter,
+		     tree_entry);
 	BUG_ON(w->lock != lock);
 
 	return w;
@@ -78,14 +78,14 @@ rt_mutex_top_waiter(struct rt_mutex *lock)
 
 static inline int task_has_pi_waiters(struct task_struct *p)
 {
-	return !plist_head_empty(&p->pi_waiters);
+	return !RB_EMPTY_ROOT(&p->pi_waiters);
 }
 
 static inline struct rt_mutex_waiter *
 task_top_pi_waiter(struct task_struct *p)
 {
-	return plist_first_entry(&p->pi_waiters, struct rt_mutex_waiter,
-				  pi_list_entry);
+	return rb_entry(p->pi_waiters_leftmost, struct rt_mutex_waiter,
+			pi_tree_entry);
 }
 
 /*
kernel/sched.c +0 -4
index 4d291e3..853473a 100644
@@ -8504,10 +8504,6 @@ void __init sched_init(void)
 	open_softirq(SCHED_SOFTIRQ, run_rebalance_domains);
 #endif
 
-#ifdef CONFIG_RT_MUTEXES
-	plist_head_init_raw(&init_task.pi_waiters, &init_task.pi_lock);
-#endif
-
 	/*
 	 * The boot idle thread does lazy MMU switching as well:
 	 */
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#131 lore raw

RFC PATCH 20/22 sched: drafted deadline inheritance logic

In reply to Raistlin

Some method to deal with rt-mutexes and make sched_dl interact with the current PI-coded is needed, raising all but trivial issues, that needs (according to us) to be solved with some restructuring of the pi-code (i.e., going toward a proxy execution-ish implementation).

This is under development, in the meanwhile, as a temporary solution, what this commits does is:
- ensure a pi-lock owner with waiters is never throttled down. Instead, when it runs out of runtime, it immediately gets replenished and it's deadline is postponed (as in SF_BWRECL_DL reclaiming policy);
- the scheduling parameters (relative deadline and default runtime) used for that replenishments --during the whole period it holds the pi-lock-- are the ones of the waiting task with earliest deadline.

Acting this way, we provide some kind of boosting to the lock-owner, still by using the existing (actually, slightly modified by the previous commit) pi-architecture.

---
 include/linux/sched.h |    3 ++
 kernel/fork.c         |    1 +
 kernel/rtmutex.c      |   13 ++++++++-
 kernel/sched.c        |    3 +-
 kernel/sched_dl.c     |   65 +++++++++++++++++++++++++++++++------------------
 5 files changed, 58 insertions(+), 27 deletions(-)
include/linux/sched.h +3 -0
index c3d1f17b..7cf78e2 100644
@@ -1535,6 +1535,8 @@ struct task_struct {
 	struct rb_node *pi_waiters_leftmost;
 	/* Deadlock detection and priority inheritance handling */
 	struct rt_mutex_waiter *pi_blocked_on;
+	/* */
+	struct task_struct *pi_top_task;
 #endif
 
 #ifdef CONFIG_DEBUG_MUTEXES
@@ -2118,6 +2120,7 @@ extern unsigned int sysctl_sched_compat_yield;
 
 #ifdef CONFIG_RT_MUTEXES
 extern int rt_mutex_getprio(struct task_struct *p);
+extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task);
 extern void rt_mutex_setprio(struct task_struct *p, int prio);
 extern void rt_mutex_adjust_pi(struct task_struct *p);
 #else
kernel/fork.c +1 -0
index aceb248..c8f2555 100644
@@ -938,6 +938,7 @@ static void rt_mutex_init_task(struct task_struct *p)
 	p->pi_waiters = RB_ROOT;
 	p->pi_waiters_leftmost = NULL;
 	p->pi_blocked_on = NULL;
+	p->pi_top_task = NULL;
 #endif
 }
 
kernel/rtmutex.c +11 -2
index 2e9c0dc..84ea165 100644
@@ -196,6 +196,14 @@ int rt_mutex_getprio(struct task_struct *task)
 		   task->normal_prio);
 }
 
+struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
+{
+	if (likely(!task_has_pi_waiters(task)))
+		return NULL;
+
+	return task_top_pi_waiter(task)->task;
+}
+
 /*
  * Adjust the priority of a task, after its pi_waiters got modified.
  *
@@ -205,7 +213,7 @@ static void __rt_mutex_adjust_prio(struct task_struct *task)
 {
 	int prio = rt_mutex_getprio(task);
 
-	if (task->prio != prio)
+	if (task->prio != prio || dl_prio(prio))
 		rt_mutex_setprio(task, prio);
 }
 
@@ -671,7 +679,8 @@ void rt_mutex_adjust_pi(struct task_struct *task)
 	raw_spin_lock_irqsave(&task->pi_lock, flags);
 
 	waiter = task->pi_blocked_on;
-	if (!waiter || waiter->task->prio == task->prio) {
+	if (!waiter || (waiter->task->prio == task->prio &&
+	    !dl_prio(task->prio))) {
 		raw_spin_unlock_irqrestore(&task->pi_lock, flags);
 		return;
 	}
kernel/sched.c +2 -1
index 853473a..97db370 100644
@@ -4611,10 +4611,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
 	unsigned long flags;
 	struct rq *rq;
 
-	BUG_ON(prio < 0 || prio > MAX_PRIO);
+	BUG_ON(prio > MAX_PRIO);
 
 	rq = task_rq_lock(p, &flags);
 	trace_sched_pi_setprio(p, prio);
+	p->pi_top_task = rt_mutex_get_top_task(p);
 	__setprio(rq, p, prio);
 	task_rq_unlock(rq, &flags);
 }
kernel/sched_dl.c +41 -24

172 lines not on this page · raw message

Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
maintainer
#132 lore raw

Re: [RFC][PATCH 20/22] sched: drafted deadline inheritance logic

Quoted 14 lines · Raistlin

Some method to deal with rt-mutexes and make sched_dl interact with the current PI-coded is needed, raising all but trivial issues, that needs (according to us) to be solved with some restructuring of the pi-code (i.e., going toward a proxy execution-ish implementation).

This is under development, in the meanwhile, as a temporary solution, what this commits does is:
- ensure a pi-lock owner with waiters is never throttled down. Instead, when it runs out of runtime, it immediately gets replenished and it's deadline is postponed (as in SF_BWRECL_DL reclaiming policy);
- the scheduling parameters (relative deadline and default runtime) used for that replenishments --during the whole period it holds the pi-lock-- are the ones of the waiting task with earliest deadline.

Quoted 3 lines

Acting this way, we provide some kind of boosting to the lock-owner, still by using the existing (actually, slightly modified by the previous commit) pi-architecture.

Right, so this is the trivial priority ceiling protocol extended to bandwidth inheritance and we basically let the owner overrun its runtime to release the shared resource.

Didn't look at it too closely, but yeah, that is a sensible first approximation band-aid to keep stuff working.

author
#133 lore raw

Re: [RFC][PATCH 20/22] sched: drafted deadline inheritance logic

Quoted 8 lines · Peter Zijlstra
Quoted 3 lines

Acting this way, we provide some kind of boosting to the lock-owner, still by using the existing (actually, slightly modified by the previous commit) pi-architecture.

Right, so this is the trivial priority ceiling protocol extended to bandwidth inheritance and we basically let the owner overrun its runtime to release the shared resource.

We can call it that way. Basically, what we do is scheduling the lock-owner with the parameters, i.e., runtime and deadline, of the earliest deadline task blocked on it. As soon as such runtime depletes, we (1) _do_ postpone that deadline (again, according to earliest deadline lock-owner's relative deadline), but we also (2) immediately replenish the runtime _immediately_.

Acting like this we ensure the lock-owner won't hurt the guarantees provided to tasks with deadline earlier than all the tasks in its blocking chains (by means of (1)), and we also enable a quicker release of the lock (by means of (2)).

Quoted 3 lines

Didn't look at it too closely, but yeah, that is a sensible first approximation band-aid to keep stuff working.

I'll keep going this way then. :-)

Thanks,
Dario

Signature · 6 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#134 lore raw

RFC PATCH 21/22 sched: add bandwidth management for sched_dl

In reply to Raistlin

In order of -deaadline scheduling to be effective and useful, it is important that some method of having the allocation of the available CPU bandwidth to tasks and task groups under control.
This is usually called "admission control" and if it is not performed at all, no guarantee can be given on the actual scheduling of the -deadline tasks.

Since when RT-throttling has been introduced each task group have a bandwidth associated to itself, calculated as a certain amount of runtime over a period. Moreover, to make it possible to manipulate such bandwidth, readable/writable controls have been added to both procfs (for system wide settings) and cgroupfs (for per-group settings).
Therefore, the same interface is being used for controlling the bandwidth distrubution to -deadline tasks and task groups, i.e., new controls but with similar names, equivalent meaning and with the same usage paradigm are added.

However, more discussion is needed in order to figure out how we want to manage SCHED_DEADLINE bandwidth at the task group level. Therefore, this patch adds a less sophisticated, but actually very sensible, machanism to ensure that a certain utilization cap is not overcome per each root_domain.

Another main difference between deadline bandwidth management and RT-throttling is that -deadline tasks have bandwidth on their own (while -rt ones doesn't!), and thus we don't need an higher level throttling mechanism to enforce the desired bandwidth.

This patch, therefore:
- adds system wide deadline bandwidth management by means of:
* /proc/sys/kernel/sched_dl_runtime_us,
* /proc/sys/kernel/sched_dl_period_us,
that determine (i.e., runtime / period) the total bandwidth available on each CPU of each root_domain for -deadline tasks;
- couples the RT and deadline bandwidth management, i.e., enforces that the sum of how much bandwidth is being devoted to -rt -deadline tasks to stay below 100%.

This means that, for a root_domain comprising M CPUs, -deadline tasks can be created until the sum of their bandwidths stay below:

M * (sched_dl_runtime_us / sched_dl_period_us)

It is also possible to disable this bandwidth management logic, and be thus free of oversubscribing the system up to any arbitrary level.

---
 include/linux/sched.h |    8 +
 kernel/sched.c        |  480 ++++++++++++++++++++++++++++++++++++++++++++++--
 kernel/sched_dl.c     |   10 +
 kernel/sysctl.c       |   14 ++
 4 files changed, 492 insertions(+), 20 deletions(-)
include/linux/sched.h +8 -0
index 7cf78e2..03f8a8a 100644
@@ -1293,6 +1293,7 @@ struct sched_dl_entity {
 	u64 dl_runtime;		/* maximum runtime for each instance 	*/
 	u64 dl_deadline;	/* relative deadline of each instance	*/
 	u64 dl_period;		/* separation of two instances (period) */
+	u64 dl_bw;		/* dl_runtime / dl_deadline		*/
 
 	/*
 	 * Actual scheduling parameters. Initialized with the values above,
@@ -2116,6 +2117,13 @@ int sched_rt_handler(struct ctl_table *table, int write,
 		void __user *buffer, size_t *lenp,
 		loff_t *ppos);
 
+extern unsigned int sysctl_sched_dl_period;
+extern int sysctl_sched_dl_runtime;
+
+int sched_dl_handler(struct ctl_table *table, int write,
+		void __user *buffer, size_t *lenp,
+		loff_t *ppos);
+
 extern unsigned int sysctl_sched_compat_yield;
 
 #ifdef CONFIG_RT_MUTEXES
kernel/sched.c +460 -20

616 lines not on this page · raw message

kernel/sched_dl.c +10 -0
index 991a4f2..69324ae 100644
@@ -1084,7 +1084,17 @@ static void task_fork_dl(struct task_struct *p)
 
 static void task_dead_dl(struct task_struct *p)
 {
+	struct dl_bw *dl_b = &task_rq(p)->rd->dl_bw;
+
+	/*
+	 * Since we are TASK_DEAD we won't slip out of the domain!
+	 */
+	raw_spin_lock_irq(&dl_b->lock);
+	dl_b->total_bw -= p->dl.dl_bw;
+	raw_spin_unlock_irq(&dl_b->lock);
+
 	/*
+	 * We are no longer holding any lock here, so it is safe to
 	 * We are not holding any lock here, so it is safe to
 	 * wait for the bandwidth timer to be removed.
 	 */
kernel/sysctl.c +14 -0
index c33a1ed..eb975be 100644
@@ -376,6 +376,20 @@ static struct ctl_table kern_table[] = {
 		.proc_handler	= sched_rt_handler,
 	},
 	{
+		.procname	= "sched_dl_period_us",
+		.data		= &sysctl_sched_dl_period,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= sched_dl_handler,
+	},
+	{
+		.procname	= "sched_dl_runtime_us",
+		.data		= &sysctl_sched_dl_runtime,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= sched_dl_handler,
+	},
+	{
 		.procname	= "sched_compat_yield",
 		.data		= &sysctl_sched_compat_yield,
 		.maxlen		= sizeof(unsigned int),
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]
author
#135 lore raw

RFC PATCH 22/22 sched: add sched_dl documentation

In reply to Raistlin

Add in Documentation/scheduler/ some hints about the design choices, the usage and the future possible developments of the sched_dl scheduling class and of the SCHED_DEADLINE policy.

---
 Documentation/scheduler/sched-deadline.txt |  147 ++++++++++++++++++++++++++++
 1 files changed, 147 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/scheduler/sched-deadline.txt
Documentation/scheduler/sched-deadline.txt new file +147 -0
new file mode 100644
index 0000000..e795968
@@ -0,0 +1,147 @@
+			Deadline Task and Group Scheduling
+			----------------------------------
+
+CONTENTS
+========
+
+0. WARNING
+1. Overview
+2. Task scheduling
+2. The interface
+3. Bandwidth management
+  3.1 System wide settings
+  2.2 Task interface
+  2.4 Default behavior
+3. Future plans
+
+
+0. WARNING
+==========
+
+ Fiddling with these settings can result in an unpredictable or even unstable
+ system behavior. As for -rt (group) scheduling, it is assumed that root
+ knows what he is doing.
+
+
+1. Overview
+===========
+
+ The SCHED_DEADLINE policy contained inside the sched_dl scheduling class is
+ basically an implementation of the Earliest Deadline First (EDF) scheduling
+ algorithm, augmented with a mechanism (called Constant Bandwidth Server, CBS)
+ that make it possible to isolate the behaviour of tasks between each other.
+
+
+2. Task scheduling
+==================
+
+ The typical -deadline task will be made up of a computation phase (instance)
+ which is activated on a periodic or sporadic fashion. The expected (maximum)
+ duration of such computation is called the task's runtime; the time interval
+ by which each instance need to be completed is called the task's relative
+ deadline. The task's absolute deadline is dynamically calculated as the
+ time instant a task (better, an instance) activates plus the relative
+ deadline.
+
+ The EDF algorithms selects the task with the smallest absolute deadline as
+ the one to be executed first, while the CBS ensures each task to run for
+ at most the its runtime every (relative) deadline length time interval,
+ avoiding any interference between different tasks (bandwidth isolation).
+ Thanks to this feature, also tasks that do not strictly comply with the
+ computational model sketched above can effectively use the new policy.
+ IOW, there are no limitations on what kind of task can exploit this new
+ scheduling discipline, even if it must be said that it is particularly
+ suited for periodic or sporadic tasks that need guarantees on their
+ timing behaviour, e.g., multimedia, streaming, control applications, etc.
+
+
+3. Bandwidth management
+=======================
+
+ In order of -deaadline scheduling to be effective and useful, it is important
+ that some method of having the allocation of the available CPU bandwidth to
+ the tasks under control.
+ This is usually called "admission control" and if it is not performed at all,
+ no guarantee can be given on the actual scheduling of the -deadline tasks.
+
+ Since when RT-throttling has been introduced each task group have a bandwidth
+ associated to itself, calculated as a certain amount of runtime over a period.
+ Moreover, to make it possible to manipulate such bandwidth, readable/writable
+ controls have been added to both procfs (for system wide settings) and cgroupfs
+ (for per-group settings).
+ Therefore, the same interface is being used for controlling the bandwidth
+ distrubution to -deadline tasks and task groups, i.e., new controls but with
+ similar names, equivalent meaning and with the same usage paradigm are added.
+
+ However, more discussion is needed in order to figure out how we want to manage
+ SCHED_DEADLINE bandwidth at the task group level. Therefore, SCHED_DEADLINE uses
+ (for now) a less sophisticated, but actually very sensible, machanism to ensure
+ that a certain utilization cap is not overcome per each root_domain.
+
+ Another main difference between deadline bandwidth management and RT-throttling
+ is that -deadline tasks have bandwidth on their own (while -rt ones doesn't!),
+ and thus we don't need an higher level throttling mechanism to enforce the
+ desired bandwidth.
+
+3.1 System wide settings
+------------------------
+
+The system wide settings are configured under the /proc virtual file system:
+
+ The per-group controls that are added to the cgroupfs virtual file system are:
+  * /proc/sys/kernel/sched_dl_runtime_us,
+  * /proc/sys/kernel/sched_dl_period_us,
+
+ They accepts (if written) and provides (if read) the new runtime and period,
+ respectively, for each CPU in each root_domain.
+
+ This means that, for a root_domain comprising M CPUs, -deadline tasks
+ can be created until the sum of their bandwidths stay below:
+
+   M * (sched_dl_runtime_us / sched_dl_period_us)
+
+ It is also possible to disable this bandwidth management logic, and
+ be thus free of oversubscribing the system up to any arbitrary level.
+ This is done by writing -1 in /proc/sys/kernel/sched_dl_runtime_us.
+
+
+2.2 Task interface
+------------------
+
+ Specifying a periodic/sporadic task that executes for a given amount of
+ runtime at each instance, and that is scheduled according to the usrgency of
+ their own timing constraints needs, in general, a way of declaring:
+  - a (maximum/typical) instance execution time,
+  - a minimum interval between consecutive instances,
+  - a time constraint by which each instance must be completed.
+
+ Therefore:
+  * a new struct sched_param_ex, containing all the necessary fields is
+    provided;
+  * the new scheduling related syscalls that manipulate it, i.e.,
+    sched_setscheduler_ex(), sched_setparam_ex() and sched_getparam_ex()
+    are implemented.
+
+
+2.4 Default behavior
+---------------------
+
+The default values for SCHED_DEADLINE bandwidth is to have dl_runtime and
+dl_period equal to 500000 and 1000000, respectively. This means -deadline
+tasks can use at most 5%, multiplied by the number of CPUs that compose the
+root_domain, for each root_domain.
+
+When a -deadline task fork a child, its dl_runtime is set to 0, which means
+someone must call sched_setscheduler_ex() on it, or it won't even start.
+
+
+3. Future plans
+===============
+
+Still Missing parts:
+
+ - refinements in deadline inheritance, especially regarding the possibility
+   of retaining bandwidth isolation among non-interacting tasks. This is
+   being studied from both theoretical and practical point of views, and
+   hopefully we can have some demonstrative code soon.
+
Signature · 10 lines
1.7.2.3


-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
----------------------------------------------------------------------
Dario Faggioli, ReTiS Lab, Scuola Superiore Sant'Anna, Pisa  (Italy)

http://blog.linux.it/raistlin / [email protected] /
[email protected]