Presentation is loading. Please wait.

Presentation is loading. Please wait.

RTOS task scheduling models

Similar presentations


Presentation on theme: "RTOS task scheduling models"— Presentation transcript:

1 RTOS task scheduling models

2 Scheduling Definition:
It is the method by which threads, processes or data flows are given access to system resources (e.g. processor time, communications bandwidth). By use of Proper algorithm of scheduling, we can perform multiple task in a given time. The scheduler is concerned mainly with: Throughput - The total number of processes that complete their execution per time unit. Response time - amount of time it takes from when a request was submitted until the first response is produced. Waiting Time - Equal CPU time to each process (or more generally appropriate times according to each process' priority). It is the time for which the process remains in the ready queue.

3 Preemptive vs. Non-Preemptive
A scheduling algorithm is: Preemptive: if the active process or task or thread can be temporarily suspended to execute a more important process or task or thread . Non-Preemptive: if the active process or task or thread cannot be suspended, i.e., always runs to completion.

4 RTOS task scheduling models
Cooperative Scheduling of ready tasks in a queue. Cyclic and round robin (time slicing) Scheduling. Preemptive Scheduling. Rate-Monotonic Scheduling (RMS). Scheduling using “Earliest deadline first” (EDF).

5 Cooperative Scheduling of ready tasks in a queue.
Dis-advantages:  Longer execution time of a low priority task makes a higher priority task wait until it finishes.

6 Cyclic and round robin (time slicing) Scheduling.
Cyclic Scheduling

7 Round Robin (time slicing) Scheduling
Round robin means that each ready task runs turn by turn only in a cyclic queue for a limited time slice Where 𝑻 𝒔𝒍𝒊𝒄𝒆 =𝑳𝒊𝒎𝒊𝒕𝒆𝒅 𝒕𝒊𝒎𝒆 𝒔𝒍𝒊𝒄𝒆 𝑻 𝒄𝒚𝒄𝒍𝒆 =𝑻𝒊𝒎𝒆 𝒄𝒚𝒄𝒍𝒆 𝑵=𝑵𝒖𝒎𝒃𝒆𝒓 𝒐𝒇 𝒕𝒂𝒔𝒌𝒔 Round robin is a hybrid model of clock-driven model (for example cyclic model) as well as event driven (for example, pre-emptive) A real time system responds to the event within a bound time limit and within an explicit time. 𝑻 𝒔𝒍𝒊𝒄𝒆 = 𝑻 𝒄𝒚𝒄𝒍𝒆 𝑵

8 Example So we 𝑻 𝒄𝒚𝒄𝒍𝒆 =20msec & 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑇𝑎𝑠𝑘𝑠=𝟓
Supposed after every 20ms, there is a stream of coded messages reaching at port A of an embedded system, it is then decrypted and retransmitted to the port after encoding each decrypted message. The multiple processes consist of five tasks: C1, C2, C3, C4 and C5 as follow: Task 1 C1: Check for a message at port A every 20ms Task 2 C2: Read port A and put the message in a message queue. Task 3 C3: Decrypt the message from the message queue. Task 4 C4: Encode the message from the queue. Task 5 C5: Transmit the encoded message from the queue to port B So we 𝑻 𝒄𝒚𝒄𝒍𝒆 =20msec & 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑇𝑎𝑠𝑘𝑠=𝟓 𝑻 𝒔𝒍𝒊𝒄𝒆 = 𝑻 𝒄𝒚𝒄𝒍𝒆 𝑵 = 𝟐𝟎𝒎𝒔𝒆𝒄 𝟓 =𝟒𝒎𝒔𝒆𝒄

9 So we have five tasks , C1 to C5 that are to be scheduled
So we have five tasks , C1 to C5 that are to be scheduled. Now Five time schedules between 0 and 4 ms, 4 ms and 8 ms , 8 and 12 ms, 12 and 16ms & 16 and 20ms respectively. ( 𝐓 𝐬𝐥𝐢𝐜𝐞 =𝟒𝐦𝐬) Tasks programs contexts at the five instances in the Time Scheduling Scheduler for C1 to C5

10 Priority-based Scheduling
Typical RTOS based on fixed-priority preemptive scheduler Assign each process a priority At any time, scheduler runs highest priority process ready to run Process runs to completion unless preempted

11 Typical RTOS Task Model
Each task a triplet: (execution time, period, deadline) Usually, deadline = period Can be initiated any time during the period Execution time Period Deadline Time Initiation

12 Priority-based Preemptive Scheduling
Always run the highest-priority runnable process Priorities Initiation Deadline 1 P1 P1 P1 P1 2 P2 P2 P2 3 P3 P3 P3 t t Scheduling After completing other high priority process, switch to next interrupted low priority process

13 RMS Scheduling

14 Rate-Monotonic Scheduling
Common way to assign priorities Result from Liu & Lay-land, 1973 (JACM) Processes with shorter period given higher priority a set of n independent tasks scheduled by the rate monotonic algorithm. will always meet its deadlines, for all task phasings, if Where 𝑪 𝒊 = deterministic computation time of each task Ti = period of particular task 𝑼 𝒏 = Scheduling bound, the maximum fraction of processor utilization allowable for n tasks: 𝑪 𝟏 𝑻 𝟏 + 𝑪 𝟐 𝑻 𝟐 + …………… 𝑪 𝒏 𝑻 𝒏 ≤𝑼 𝒏 𝑼 𝒏 = 𝟏 or 100%

15 The utilization bound (UB) test allows schedulability analysis by comparing the calculated utilization for a set of tasks and comparing that total to the theoretical utilization for that number of tasks: If this equality is satisfied, all of the tasks will always meet their deadlines. If the total utilization calculates to greater than 100%, the system will have scheduling problems. 𝑪 𝟏 𝑻 𝟏 + 𝑪 𝟐 𝑻 𝟐 + …………… 𝑪 𝒏 𝑻 𝒏 ≤𝑼 𝒏 =𝟏

16 Utilization Bound Test
Assumes rate monotonic priority assignment Task with smaller period is assigned higher priority Guaranteed to be schedulable if test succeeds. 𝐔 𝐧 ≡ 𝐢=𝟏 𝐧 𝐂 𝐢 𝐓 𝐢 ≤𝟏

17 Utilization Bound Test Example
No. Tasks Utilization Bound (in % ) 1 100% 2 82.8% 3 78.0% 4 75.7% 5 74.3% 10 71.8%

18 Computation/ Execution Time (Ci)
Example: Checking for Schedulability using of RMS. And Time period P1 process = 4 secs. Means P1 repeat after every 4 secs Solution: Golden Rule : Shortest test period = Highest Priority Check for Schedulability Processes Computation/ Execution Time (Ci) Time Period (Ti) P1 1 4 P2 2 6 P3 3 12

19 Deciding Priority Level
Processes Computation/ Execution Time Time Period Priority P1 1 4 High(1) P2 2 6 Medium(2) P3 3 12 Low(3) Checking for Schedulability 𝐔 𝐧 ≡ 𝐢=𝟏 𝐧 𝐂 𝐢 𝐓 𝐢 ≤𝟏 𝐔 𝐧 = 𝐢=𝟏 𝟑 𝐂 𝐢 𝐓 𝐢 = 𝐂 𝟏 𝐓 𝟏 + 𝐂 𝟐 𝐓 𝟐 + 𝐂 𝟑 𝐓 𝟑 = 𝟏 𝟒 + 𝟐 𝟔 + 𝟑 𝟏𝟐 =𝟎.𝟖𝟑≤𝟏 Here U(n) < 1, so we can schedule the process by using RMS scheduling algorithm

20 Computation/ Execution Time
Scheduling Timing Diagram Total time = take LCM of Period of Process = 12 Processes Computation/ Execution Time Time Period P1 1 4 P2 2 6 P3 3 12 Processes 1st period continue 1 2 3 4 5 6 7 8 9 10 11 12 P3 P3 P3 P3 Next period P2 P2 P2 Next period Next period P1 P1 P1 P1 Time----->

21 Computation/ Execution Time (Ci)
Example: Checking for Schedulability using of RMS. Solution Here clearly the CPU Utilization is more than 1 (i.e. 1.25). So these is not Scheduled. Processes Computation/ Execution Time (Ci) Time Period (Ti) P1 2 4 P2 3 6 P3 12

22 Earliest deadline first Scheduling
RMS assumes fixed priorities First check for Schedulability by using Utilization formulae Earliest deadline first: Processes with soonest deadline given highest priority

23 Computation/ Execution Time (Ci)
Example: Checking for Schedulability using of EDF. Solution Step 1: Check for Schedulability U = 1/3 + 1/4 + 2/5 = 0.98 which is less than 1 So we can schedule the given task Processes Computation/ Execution Time (Ci) Time Period (Ti) P1 1 3 P2 4 P3 2 5

24 Computation/ Execution Time (Ci)
Processes Computation/ Execution Time (Ci) Time Period (Ti) P1 1 3 P2 4 P3 2 5 Solutions Period (UPTO 60) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 d(1) d(2) d(3) P1 P2 P3 Scheduled Process according to their Execution time

25 OS SECURITY ISSUES SELF STUDY!!!!


Download ppt "RTOS task scheduling models"

Similar presentations


Ads by Google