You are on page 1of 23

Real-Time Embedded Systems

Task Scheduling

Presented by:
Siraj Q. Mahdi
Outline
➔ Introduction

➔ Sec1: Tasks

➔ Sec2: Clock driven scheduling

➔ Sec3: Round robin approach

➔ Conclusion

➔ summary

TASK SCHEDULING IN EMBEDDED SYSTEMS 2


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

Task management and scheduling are some of the core functions of any RTOS kernel. Part of the
kernel is a scheduler that is responsible for allocating and scheduling tasks on processors to
ensure that deadlines are met.
• Task: unit of work scheduled for execution on the CPU.
• real-time application that uses an RTOS can be structured as a set of independent tasks.
• Periodic tasks are repeated once a period

TASK SCHEDULING IN EMBEDDED SYSTEMS 3


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• Periodic tasks arise from:


1. sensory data acquisition
2. control law computation
3. action planning
4. system monitoring
❖ Periodic tasks have hard deadlines

• Aperiodic tasks are one-shot tasks.


• Sporadic tasks are also event-driven

TASK SCHEDULING IN EMBEDDED SYSTEMS 4


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• In a real-time system, a task can be specified by the following temporal parameters:


1. Release time
2. Deadline.
3. Relative deadline.
4. Execution time
5. Response time.
• a periodic task has the following
two parameters:
1. Period
2. phase

TASK SCHEDULING IN EMBEDDED SYSTEMS 5


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• For a periodic task, the task execution time, release time, deadline, relative deadline, and
response time are all referring to its instances
• we specify a periodic task as follows: 𝑇𝐼 = (𝜙𝐼 , 𝑃𝐼, 𝑒𝐼 . 𝐷𝐼 )
• we can calculate their hyperperiod, denoted by H. H is the least common multiple
(LCM)
(prime factorization)
• Example 4.1
• When we compute the schedule for a set of periodic tasks, we only need to compute its
schedule for its first hyperperiod

TASK SCHEDULING IN EMBEDDED SYSTEMS 6


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

Example 4.1 Calculation of Hyperperiod of Periodic Tasks


Consider a system of three periodic tasks:
T1 = (5, 1), T2 = (12, 2), T3 = (40, 1).
Number 5 is a prime and is not decomposable. Number 12 is a composite number and can be expressed as
12 = 2 ⋅ 6 = 2 ⋅ 2 ⋅ 3 = 2^2 ⋅ 3.
Number 40 is also a composite number and can be decomposed as 40 = 2 ⋅ 20 = 2 ⋅ 2 ⋅ 10 = 2 ⋅ 2 ⋅
2 ⋅ 5 = 2^3 ⋅ 5.
The LCM of 5, 12, and 20 is the product of the highest power of each prime number combined. That is,

H = LCM(5, 12, 40)


= 2^3 ⋅ 3 ⋅ 5
= 120

TASK SCHEDULING IN EMBEDDED SYSTEMS 7


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• Criticality: Tasks in a system are not equally important.


• Preemptivity: Execution of tasks can be interleaved.
• Task States… In real-time systems, a task can exist in one of the following three
states:
1. Running
2. Ready
3. Blocked.
• When a new task is created, it is placed in the ready state queue. The task can be
scheduled for execution immediately or later, depending on it priority and the priority
of other tasks in the ready state

TASK SCHEDULING IN EMBEDDED SYSTEMS 8


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• Task States… In real-time systems, a task can exist in one of the following
three states:

TASK SCHEDULING IN EMBEDDED SYSTEMS 9


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

• Precedence Constraints. A precedence constraint specifies the execution order of two


or more tasks.
• Example 4.2 Precedence Graph (There are seven tasks. Dependency constraints)

TASK SCHEDULING IN EMBEDDED SYSTEMS 10


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

❖ Task Assignment and Scheduling:


• Only one task within the application can be executing at any point in time on a
processor. A schedule is an assignment of tasks to available processors.The
scheduler of an RTOS is a module that implements the assignment (scheduling)
algorithms.
• A schedule is said to be valid if all precedence and resource usage constraints are
met and no task is underscheduled or overscheduled
• schedule is said to be feasible if every task scheduled completes before its deadline.
A system (a set of tasks) is said to be schedulable if a feasible schedule exists for the
system. The bulk of real-time scheduling work deals with finding feasible schedules.

TASK SCHEDULING IN EMBEDDED SYSTEMS 11


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

❑ 4.2 clock-driven scheduling, scheduling decisions are made at specific


time instants, which are typically chosen a priori before the system
begins execution. It usually works for deterministic systems where tasks
have hard deadlines and all task parameters are not changing during
system operation.

• In Example 4.3 there are two feasible schedules for the system of three
periodic tasks: T1 = (4, 1), T2 = (6, 1), T3 = (12, 2).

TASK SCHEDULING IN EMBEDDED SYSTEMS 12


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

TASK SCHEDULING IN EMBEDDED SYSTEMS 13


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

TASK SCHEDULING IN EMBEDDED SYSTEMS 19


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

TASK SCHEDULING IN EMBEDDED SYSTEMS 20


Clock_driven Round_robin
Introduction tasks Conclusion summary
scheduling approach

TASK SCHEDULING IN EMBEDDED SYSTEMS 21


Thank you for Listening

You might also like