Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scheduling Classes and Real-Time Scheduling in Linux

Similar presentations


Presentation on theme: "Scheduling Classes and Real-Time Scheduling in Linux"— Presentation transcript:

1 Scheduling Classes and Real-Time Scheduling in Linux
David Ferry, Chris Gill, Brian Kocoloski CSE 422S - Operating Systems Organization Washington University in St. Louis

2 Real-Time Applications
Have repeating functions that must execute within a precise period of time Within the next 10 ms, do something, or else bad things could happen Examples Air traffic control systems Video/audio communication systems Web serving Stock Trading CSE 422S – Operating Systems Organization

3 CSE 422S – Operating Systems Organization
Real-Time Scheduling Real-time tasks execute repeatedly (usually are periodic) under some time constraint Task Time 0ms 5ms 10ms E.g., a task is released to execute every 5 msec, and each invocation has a deadline of 5 msec Separate priority range from the nice priorities for CFS: Priorities are from 1 (low) to 99 (high), highest ones need root CSE 422S – Operating Systems Organization

4 CSE 422S – Operating Systems Organization
Real-Time OS Support Why might supporting such applications be challenging, given our understanding of Linux’ CFS scheduler? For example, if a user accessed the kernel: ”can you guarantee my task will run for 1 second at every 5 second interval?” Challenges: CFS uses proportional sharing – so the answer is highly dependent on other system activity What if another process boosts its priority? What if another process is starved? vruntime is designed to achieve proportionality – not to give guarantees on deadlines or speak in terms of fixed time quantities CSE 422S – Operating Systems Organization

5 CSE 422S – Operating Systems Organization
Real-Time OS Support Goal is to achieve predictable execution: Other sources of uncertainty (and solutions): Interrupts (can mask some interrupts) Migrations (can pin tasks to cores) OS latency, jitter, and kernel non-preemptibility (real-time scheduling) Ideal: Real world: Preempt Migrate CSE 422S – Operating Systems Organization

6 CSE 422S – Operating Systems Organization
Kernel Preemption Before the 2.6 kernel (2003), Linux did not have a pre-emptible kernel If a process was executing in the kernel, it could hog the CPU indefinitely User-level process in a system-call Kernel threads Major issue for interactive/latency-sensitive + real-time applications Starting in 2.6, the kernel became fully1 preemptible 1 there are ways to selectively disable preemption, for example, during interrupt handlers, or when taking special locks; more on this in a few weeks CSE 422S – Operating Systems Organization

7 Three real-time scheduling classes
SCHED_FIFO First-in, First-out scheduling SCHED_RT Round robin scheduling SCHED_DEADLINE Earliest deadline first CSE 422S – Operating Systems Organization

8 CSE 422S – Operating Systems Organization
SCHED_FIFO First-in, First-out scheduling The first enqueued task of highest priority executes to completion A task will only relinquish a processor when it completes, yields, or blocks Only a higher priority SCHED_FIFO or SCHED_RR task can preempt a SCHED_FIFO task – all others will be starved as it runs Task 1 Task 2 Task 3 Time CSE 422S – Operating Systems Organization

9 CSE 422S – Operating Systems Organization
SCHED_RR Round-robin scheduling Same as SCHED_FIFO but with timeslices Among tasks of equal priority: Rotate through all tasks Each task gets a fixed time slice Only a higher priority SCHED_FIFO or SCHED_RR task can preempt a SCHED_FIFO Tasks of equal priority preempt each other after timeslice expiration Task 1 Task 2 Task 3 Time CSE 422S – Operating Systems Organization

10 CSE 422S – Operating Systems Organization
SCHED_DEADLINE Earliest Deadline First (EDF) scheduling (only available with rt-preempt patch) Whichever task has next deadline gets to run Theory exists to analyze such systems Linux implements bandwidth reservation to prevent deadline abuse Task 3 Deadline: 12 Exec time: 2 Task 2 Deadline: 8 Exec time: 3 Task 1 Deadline: 5 Exec time: 4 Time 0 Task 1 Task 2 Task 3 5 8 12 CSE 422S – Operating Systems Organization

11 CSE 422S – Operating Systems Organization
Scheduling Classes Multiple schedulers are implemented as different scheduling classes. Normal: SCHED_NORMAL: regular, interactive CFS tasks SCHED_BATCH: low priority, non-interactive CFS tasks SCHED_IDLE: very low priority tasks Real-time: SCHED_RR: round-robin SCHED_FIFO: first-in, first-out SCHED_DEADLINE: earliest deadline first (rt-preempt) CSE 422S – Operating Systems Organization

12 CSE 422S – Operating Systems Organization
struct sched_class A few major functions: Other functions: Task migration Task state queries Task yielding Other utilities CSE 422S – Operating Systems Organization

13 Current Scheduling Classes and Ordering
stop_sched_class //for halting processors dl_sched_class // (rt-preempt patch only) rt_sched_class // SCHED_RR, SCHED_FIFO fair_sched_class // SCHED_OTHER idle_sched_class Declared in /kernel/sched/sched.h CSE 422S – Operating Systems Organization

14 Example sched_class Definition
From: /kernel/sched/rt.c CSE 422S – Operating Systems Organization

15 How the Next Runnable Task is Picked
Function pick_next_task() from /kernel/sched/core.c Have all scheduling classes try to pick a new task The last class, SCHED_IDLE, should always return some idle task CSE 422S – Operating Systems Organization


Download ppt "Scheduling Classes and Real-Time Scheduling in Linux"

Similar presentations


Ads by Google