aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDario Faggioli <raistlin@linux.it>2013-11-28 05:14:43 -0500
committerIngo Molnar <mingo@kernel.org>2014-01-13 07:41:06 -0500
commitaab03e05e8f7e26f51dee792beddcb5cca9215a5 (patch)
treebae7f6033c849e7ca77a98783c732caea412ae75 /include
parentd50dde5a10f305253cbc3855307f608f8a3c5f73 (diff)
sched/deadline: Add SCHED_DEADLINE structures & implementation
Introduces 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. Adds 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 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. To summarize, this patch: - introduces the data structures, constants and symbols needed; - 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. Signed-off-by: Dario Faggioli <raistlin@linux.it> Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com> Signed-off-by: Fabio Checconi <fchecconi@gmail.com> Signed-off-by: Juri Lelli <juri.lelli@gmail.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1383831828-15501-4-git-send-email-juri.lelli@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/sched.h46
-rw-r--r--include/linux/sched/deadline.h24
-rw-r--r--include/uapi/linux/sched.h1
3 files changed, 70 insertions, 1 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 86025b6c6387..6c196794fc12 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -97,6 +97,10 @@ struct sched_param {
97 * Given this task model, there are a multiplicity of scheduling algorithms 97 * Given this task model, there are a multiplicity of scheduling algorithms
98 * and policies, that can be used to ensure all the tasks will make their 98 * and policies, that can be used to ensure all the tasks will make their
99 * timing constraints. 99 * timing constraints.
100 *
101 * As of now, the SCHED_DEADLINE policy (sched_dl scheduling class) is the
102 * only user of this new interface. More information about the algorithm
103 * available in the scheduling class file or in Documentation/.
100 */ 104 */
101struct sched_attr { 105struct sched_attr {
102 u32 size; 106 u32 size;
@@ -1088,6 +1092,45 @@ struct sched_rt_entity {
1088#endif 1092#endif
1089}; 1093};
1090 1094
1095struct sched_dl_entity {
1096 struct rb_node rb_node;
1097
1098 /*
1099 * Original scheduling parameters. Copied here from sched_attr
1100 * during sched_setscheduler2(), they will remain the same until
1101 * the next sched_setscheduler2().
1102 */
1103 u64 dl_runtime; /* maximum runtime for each instance */
1104 u64 dl_deadline; /* relative deadline of each instance */
1105
1106 /*
1107 * Actual scheduling parameters. Initialized with the values above,
1108 * they are continously updated during task execution. Note that
1109 * the remaining runtime could be < 0 in case we are in overrun.
1110 */
1111 s64 runtime; /* remaining runtime for this instance */
1112 u64 deadline; /* absolute deadline for this instance */
1113 unsigned int flags; /* specifying the scheduler behaviour */
1114
1115 /*
1116 * Some bool flags:
1117 *
1118 * @dl_throttled tells if we exhausted the runtime. If so, the
1119 * task has to wait for a replenishment to be performed at the
1120 * next firing of dl_timer.
1121 *
1122 * @dl_new tells if a new instance arrived. If so we must
1123 * start executing it with full runtime and reset its absolute
1124 * deadline;
1125 */
1126 int dl_throttled, dl_new;
1127
1128 /*
1129 * Bandwidth enforcement timer. Each -deadline task has its
1130 * own bandwidth to be enforced, thus we need one timer per task.
1131 */
1132 struct hrtimer dl_timer;
1133};
1091 1134
1092struct rcu_node; 1135struct rcu_node;
1093 1136
@@ -1124,6 +1167,7 @@ struct task_struct {
1124#ifdef CONFIG_CGROUP_SCHED 1167#ifdef CONFIG_CGROUP_SCHED
1125 struct task_group *sched_task_group; 1168 struct task_group *sched_task_group;
1126#endif 1169#endif
1170 struct sched_dl_entity dl;
1127 1171
1128#ifdef CONFIG_PREEMPT_NOTIFIERS 1172#ifdef CONFIG_PREEMPT_NOTIFIERS
1129 /* list of struct preempt_notifier: */ 1173 /* list of struct preempt_notifier: */
@@ -2099,7 +2143,7 @@ extern void wake_up_new_task(struct task_struct *tsk);
2099#else 2143#else
2100 static inline void kick_process(struct task_struct *tsk) { } 2144 static inline void kick_process(struct task_struct *tsk) { }
2101#endif 2145#endif
2102extern void sched_fork(unsigned long clone_flags, struct task_struct *p); 2146extern int sched_fork(unsigned long clone_flags, struct task_struct *p);
2103extern void sched_dead(struct task_struct *p); 2147extern void sched_dead(struct task_struct *p);
2104 2148
2105extern void proc_caches_init(void); 2149extern void proc_caches_init(void);
diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h
new file mode 100644
index 000000000000..9d303b8847df
--- /dev/null
+++ b/include/linux/sched/deadline.h
@@ -0,0 +1,24 @@
1#ifndef _SCHED_DEADLINE_H
2#define _SCHED_DEADLINE_H
3
4/*
5 * SCHED_DEADLINE tasks has negative priorities, reflecting
6 * the fact that any of them has higher prio than RT and
7 * NORMAL/BATCH tasks.
8 */
9
10#define MAX_DL_PRIO 0
11
12static inline int dl_prio(int prio)
13{
14 if (unlikely(prio < MAX_DL_PRIO))
15 return 1;
16 return 0;
17}
18
19static inline int dl_task(struct task_struct *p)
20{
21 return dl_prio(p->prio);
22}
23
24#endif /* _SCHED_DEADLINE_H */
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index 5a0f945927ac..2d5e49a2a6d2 100644
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -39,6 +39,7 @@
39#define SCHED_BATCH 3 39#define SCHED_BATCH 3
40/* SCHED_ISO: reserved but not implemented yet */ 40/* SCHED_ISO: reserved but not implemented yet */
41#define SCHED_IDLE 5 41#define SCHED_IDLE 5
42#define SCHED_DEADLINE 6
42/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ 43/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
43#define SCHED_RESET_ON_FORK 0x40000000 44#define SCHED_RESET_ON_FORK 0x40000000
44 45