Skip to content

Commit aab03e0

Browse files
dfaggioliingomolnar
authored andcommitted
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>
1 parent d50dde5 commit aab03e0

10 files changed

Lines changed: 882 additions & 20 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ struct sched_param {
9797
* Given this task model, there are a multiplicity of scheduling algorithms
9898
* and policies, that can be used to ensure all the tasks will make their
9999
* 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/.
100104
*/
101105
struct sched_attr {
102106
u32 size;
@@ -1088,6 +1092,45 @@ struct sched_rt_entity {
10881092
#endif
10891093
};
10901094

1095+
struct 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+
};
10911134

10921135
struct rcu_node;
10931136

@@ -1124,6 +1167,7 @@ struct task_struct {
11241167
#ifdef CONFIG_CGROUP_SCHED
11251168
struct task_group *sched_task_group;
11261169
#endif
1170+
struct sched_dl_entity dl;
11271171

11281172
#ifdef CONFIG_PREEMPT_NOTIFIERS
11291173
/* list of struct preempt_notifier: */
@@ -2099,7 +2143,7 @@ extern void wake_up_new_task(struct task_struct *tsk);
20992143
#else
21002144
static inline void kick_process(struct task_struct *tsk) { }
21012145
#endif
2102-
extern void sched_fork(unsigned long clone_flags, struct task_struct *p);
2146+
extern int sched_fork(unsigned long clone_flags, struct task_struct *p);
21032147
extern void sched_dead(struct task_struct *p);
21042148

21052149
extern void proc_caches_init(void);

‎include/linux/sched/deadline.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
12+
static inline int dl_prio(int prio)
13+
{
14+
if (unlikely(prio < MAX_DL_PRIO))
15+
return 1;
16+
return 0;
17+
}
18+
19+
static inline int dl_task(struct task_struct *p)
20+
{
21+
return dl_prio(p->prio);
22+
}
23+
24+
#endif /* _SCHED_DEADLINE_H */

‎include/uapi/linux/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define SCHED_BATCH 3
4040
/* SCHED_ISO: reserved but not implemented yet */
4141
#define SCHED_IDLE 5
42+
#define SCHED_DEADLINE 6
4243
/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
4344
#define SCHED_RESET_ON_FORK 0x40000000
4445

‎kernel/fork.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
13111311
#endif
13121312

13131313
/* Perform scheduler related setup. Assign this task to a CPU. */
1314-
sched_fork(clone_flags, p);
1314+
retval = sched_fork(clone_flags, p);
1315+
if (retval)
1316+
goto bad_fork_cleanup_policy;
13151317

13161318
retval = perf_event_init_task(p);
13171319
if (retval)

‎kernel/hrtimer.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <linux/sched.h>
4747
#include <linux/sched/sysctl.h>
4848
#include <linux/sched/rt.h>
49+
#include <linux/sched/deadline.h>
4950
#include <linux/timer.h>
5051
#include <linux/freezer.h>
5152

@@ -1610,7 +1611,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
16101611
unsigned long slack;
16111612

16121613
slack = current->timer_slack_ns;
1613-
if (rt_task(current))
1614+
if (dl_task(current) || rt_task(current))
16141615
slack = 0;
16151616

16161617
hrtimer_init_on_stack(&t.timer, clockid, mode);

‎kernel/sched/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
1111
CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
1212
endif
1313

14-
obj-y += core.o proc.o clock.o cputime.o idle_task.o fair.o rt.o stop_task.o
14+
obj-y += core.o proc.o clock.o cputime.o
15+
obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
1516
obj-y += wait.o completion.o
1617
obj-$(CONFIG_SMP) += cpupri.o
1718
obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o

0 commit comments

Comments
 (0)