SCHED DEADLINE

From Automotive Grade Linux
Jump to: navigation, search

Introduction

SCHED_DEADLINE is the name of a patch proposed to add a resource-reservation real-time CPU scheduler to the Linux kernel.

The Linux kernel contains different scheduler classes. By default the kernel uses a scheduler mechanism called Completely Fair Scheduler, introduced in the 2.6.23 version of the kernel. Internally this default-scheduler class is also known as SCHED_OTHER. The standard Linux kernel also contains two real-time scheduling classes named SCHED_FIFO (realtime first-in-first-out) and SCHED_RR (realtime round-robin) both of which take precedence over the default class. The SCHED_DEADLINE patch adds a new scheduling class to the modular Linux scheduler, and implements the well-known Earliest Deadline First (EDF) algorithm.


Motivation

The need of an EDF scheduler in Linux has been for a long time in the mind of a part of the Linux community. The file Documentation/scheduler/sched-rt-group.txt, for example, says

"The next project will be SCHED_EDF (Earliest Deadline First scheduling) to bring full deadline scheduling to the linux kernel."

The existing scheduling classes (i.e., sched_fair and sched_rt), in fact, perform very well in their own domain of application. However,

  1. They cannot provide the guarantees a time-sensitive application may require.

    Using SCHED_OTHER, no concept of timing constraint (e.g., deadline) can be associated to tasks. In fact, although it is possible to assign a share of the processor time to a task (or a group of tasks), there is no way to specify that a task must execute for 20msec within 100msec, unlike using a real-time scheduling algorithm, such as EDF.
    As a proof of concept, we implemented a very simple test to run two tasks that need to execute for 20msec every 50msec. We scheduled them using CFS with the same CPU share, and we observed that even if there is enough spare CPU time (the system is idle), the tasks occasionally experience some deadline miss. The test is available here (otherwiise the RT-APP application can be used for similar tests).
    Using SCHED_FIFO/SCHED_RR, instead, we can give that kind of guarantee only using a global period, with the constraint that "a subgroup must have a smaller or equal period to its parent".
  2. The latency experienced by a task (i.e., the time between two consecutive executions of a task) is not deterministic and cannot be bound, since it highly depends on the number of tasks running in the system at that time.

    Using EDF, instead, this time is deterministic, bounded and known at any instant of time.

These issues are particularly critical when running time-sensitive or control applications. Without a real-time scheduler, in fact, it is not possible to make any feasibility study of the system under development, and developers cannot be sure that the timing requirements will be met under any circumstance. And we feel that this prevents the usage of Linux in industrial contexts.

A key feature of our scheduling class is that "temporal isolation" is ensured. This means that the temporal behavior of each task (i.e., its ability to meet its deadlines) is not affected by the behavior of any other task in the system. In other words, even if a task misbehaves, it is not able to exploit larger execution times than the amount it has been allocated.

Each task is characterized by a "budget" sched_runtime and a "period" sched_period, equal to its deadline. At any instant of time, the system schedules the (ready) task having earliest deadline. During execution, task's budget is decreased by an amount equal to the time executed. When task's budget reaches zero (i.e., the task executed for a time equal to its budget), it is stopped until the time instant of its next deadline. At that time, the task is made runnable again, its budget is refilled and a new deadline is computed. This means that the task is guaranteed a share of processor time equal to sched_runtime/sched_period every sched_period.

Of course, the sum of sched_runtime/sched_period of all tasks cannot be higher than the total throughput available on the system (i.e., 100% on uniprocessor systems), otherwise the system is overloaded and task deadlines cannot be guaranteed. When a task tries to execute more than its budget, it is slowed down, by stopping it until the time instant of its next deadline. When, at that time, it is made runnable again, its budget is refilled and a new deadline is computed.

Some notes about the implementation:

  • It implements the well-known Earliest Deadline First (EDF) algorithm
  • It is aligned with the current mainstream kernel
  • It does not make any restrictive assumption about the characteristics of the tasks: it can handle periodic, sporadic or aperiodic tasks
  • On-going effort for integration with the cgroups filesystem, which will let to assign a reservation to a group of tasks and make hierarchical scheduling.

History of the project

The initial idea of a Linux scheduling class based on the Earliest Deadline First (EDF) algorithm is born in the small context of the Real-Time Systems (ReTiS) Lab of Scuola Superiore Sant'Anna and its Spin-Off company Evidence Srl. Then, Evidence Srl leveraged the funding of the ACTORS project, supported by the European Commission through the FP7 framework programme, for financing and promoting the development of the first versions of the patch. The code has been developed by Dario Faggioli (for the first three versions) and Juri Lelli (since the fourth version) with sporadic help from Michael Trimarchi and Fabio Checconi. Claudio Scordino has been in charge of the initial coordination, supporting and project advertisement. Johan Eker has been in charge of coordination within ACTORS and supporting from Ericsson. The patch has been periodically released to the kernel community through the Linux kernel mailing list (LKML). Each release aligned the code to the latest version of the kernel and took into account comments received at the previous submission. As the popularity of the scheduler increased, a higher number of kernel developers started providing their feedback and their contribution.

The original version of the patch was called SCHED_EDF and presented to the Linux kernel community in 2009. With this name was also presented to the Real-Time Linux Workshop after a few weeks. The name has been then changed to SCHED_DEADLINE after the request of the Linux kernel community.

The following versions have been released:

The project has been already integrated in the Yocto distribution. Moreover, there has been some interest for inclusion in Linaro as well.

An article on the popular Linux Weekly News site argued that SCHED_DEADLINE may be merged into the mainline kernel in the very next releases.

The code has been merged into the mainline kernel (commit number a0fa1dd3cdbccec9597fe53b6177a9aa6e20f2f8) and therefore will be available from kernel release 3.14.

Academic conferences and events

The project has been presented through some academic workshops, conferences and journals:

The project has been also presented at the Kernel Summit in 2010, at the Linux Plumbers Conference 2012, and at the Embedded Linux Conference 2013.

Recently, a video has been uploaded on youtube.

Web pages

Several websites (e.g., OSNews, Slashdot, Linux Today, Phoronix, etc.) have talked about the project in the course of the years.

Among the various websites, the best resources are:

Download and usage

The project has an official page.

The code is publicly available on a GitHub website.

To download a Linux kernel with SCHED_DEADLINE integrated, type

    git clone git://github.org/jlelli/sched_deadline.git

The documentation is available inside the Documentation/scheduler/sched-deadline.txt file.