0% found this document useful (0 votes)
12 views

schedule

The document outlines the fundamentals of CPU scheduling, including its objectives, various algorithms, and evaluation criteria. It distinguishes between non-preemptive and preemptive scheduling, detailing specific algorithms and their applications, such as First Come First Served and Earliest Deadline First. Additionally, it discusses task classifications, scheduling criteria, and the importance of understanding turnaround and waiting times in the context of CPU scheduling efficiency.

Uploaded by

son.cvh.eng2110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

schedule

The document outlines the fundamentals of CPU scheduling, including its objectives, various algorithms, and evaluation criteria. It distinguishes between non-preemptive and preemptive scheduling, detailing specific algorithms and their applications, such as First Come First Served and Earliest Deadline First. Additionally, it discusses task classifications, scheduling criteria, and the importance of understanding turnaround and waiting times in the context of CPU scheduling efficiency.

Uploaded by

son.cvh.eng2110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

CPU SCHEDULING

OBJECTIVES

• To introduce CPU scheduling, which is the basis for multi-programmed


operating systems

• To describe various cpu-scheduling algorithms

• To discuss evaluation criteria for selecting a cpu-scheduling algorithm for a


particular system
CPU SCHEDULER

• Short-term scheduler selects from among the processes in ready


queue, and allocates the CPU to one of them
• Queue may be ordered in various ways
• CPU scheduling decisions may take place when a process:
• Switches from running to waiting state
• Switches from running to ready state
• Switches from waiting to ready
• Terminates
• Scheduling under 1 and 4 is non-preemptive
• All other scheduling is preemptive
• Consider access to shared data
• Consider preemption while in kernel mode
• Consider interrupts occurring during crucial OS activities
DISPATCHER

• Dispatcher module gives control of the CPU to the process selected by the
short-term scheduler; this involves:
• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that program

• Dispatch latency – time it takes for the dispatcher to stop one process and
start another running
SCHEDULING CRITERIA

• CPU utilization – keep the CPU as busy as possible


• Throughput – # of processes that complete their execution per time unit
• Turnaround time – amount of time to execute a particular process
• Waiting time – amount of time a process has been waiting in the ready
queue
• Response time – amount of time it takes from when a request was
submitted until the first response is produced, not output (for time-
sharing environment)
SCHEDULING ALGORITHM OPTIMIZATION CRITERIA

• Max CPU utilization


• Max throughput
• Min turn-around time
• Min waiting time
• Min response time
TASK CLASSIFICATION

1. Fixed-instance

2. Periodic

3. Aperiodic

4. Sporadic
FIXED-INSTANCE TASKS
PERIODIC TASKS

• Periodic tasks are those that must be run with a fixed


cycle
• A task k can be represented as
a pair (Ck, Tk)
Ck: the worst-case computation time
Tk: the period
Tasks (2, 6), (1, 4), (4, 12)

• Processor utilization
U > 1 : CPU is overloaded
U ≤ 1 : not overload
APERIODIC TASKS

Tasks that respond to events that occur at irregular intervals

• No minimum time interval between two events requiring


the same response

• Difficult to require such responses to be hard real-time

• Too many of such events would overload the system

=> Such tasks must be scheduled in such a way to never


cause a firm or hard real-time task to miss its deadline
SPORADIC TASKS
Tasks are aperiodic tasks that usually require a firm or hard
real-time response.

• Task k can be represented as a pair (Ck, Tk)


Ck: the worst-case computation time required to respond to the event
Tk: the minimum interval between such events

• Sporadic task may overload the system by their nature


=> must be decided which firm and hard real-time tasks will miss their
deadlines

• When a sporadic task is ready => be treated as periodic


task
GANTT CHART

- visualize and analyze CPU scheduling algorithms


- understanding and comparing different CPU
scheduling algorithms
Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU
Scheduling

• Turn Around Time (TAT) is the total time taken for a process to complete its
execution from the moment it enters the system until it finishes. It includes
both the time the process spends executing on the CPU and the time it spends
waiting for CPU time. TAT is measured from the start of the process to its
completion and is often used to evaluate the overall efficiency of a scheduling
algorithm.

• Waiting Time (WT) refers to the total amount of time a process spends
waiting in the ready queue before it can be executed on the CPU. It is the time
interval between the process's arrival in the ready queue and the start of its
execution. WT measures the extent to which processes have to wait for CPU
time and is a crucial factor in assessing the efficiency of a CPU scheduling
algorithm.
SCHEDULING ALGORITHMS

• Non-preemptive

• Preemptive
NON-PREEMPTIVE SCHEDULING ALGORITHM

• Timeline:

- Use whatever heuristics the designer chooses to come up with an acceptable schedule
NON-PREEMPTIVE SCHEDULING ALGORITHM

• First come – First served :

Scheduling four tasks using FCFS. Deadlines are marked with stars
NON-PREEMPTIVE SCHEDULING ALGORITHM

• Shortest-job next:

Scheduling four tasks using shortest-task first. Deadlines are marked with stars
NON-PREEMPTIVE SCHEDULING ALGORITHM

• Earliest-deadline first:

Scheduling tasks using earliest-deadline first scheduler. Deadlines are marked with stars
NON-PREEMPTIVE SCHEDULING ALGORITHM

• Least-slack first:

Scheduling tasks using least-slack first scheduler. Latest start times are marked with diamonds.
SCHEDULING ALGORITHMS

• Non-preemptive

• Preemptive
PERIODIC TASK
• execute once per period

• each period can be seen as the deadline of the task

• not possible for periodic tasks to start execution before their period

• Non-preemptive scheduling algorithms cannot work

=> Need preemptive scheduling


POSSIBLE SCHEDULES
• Task A is given priority: if Task A is ready to execute and Task B is currently executing,
Task B is interrupted, and Task A is scheduled.

• A switch is only made if absolutely necessary: we will switch only if not switching will
cause a task to miss a deadline (slack time of a task goes to zero).
PREEMPTIVE SCHEDULING ALGORITHM

• Timeline scheduling:
 A task k can be represented as a pair (Ck, Tk)
Ck: the worst-case computation time
Tk: the period

 Processor utilization

 If U < 1: we can always schedule these tasks over a period of the least
common multiple of the periods (super period)
PREEMPTIVE SCHEDULING ALGORITHM

• Timeline scheduling:
Example of three tasks: Task1 (1, 6) – Task2 (9, 14) and Task3 (4, 21)

processor utilization: U =

Least common multiple(6, 14, 21) = 42 ms

Earliest-deadline-first algorithm
PREEMPTIVE SCHEDULING ALGORITHM

• Timeline scheduling:
Example of three tasks: Task1 (1, 6) – Task2 (9, 14) and Task3 (4, 21)

reduces the number of context switches from 18 to 12 times


PREEMPTIVE SCHEDULING ALGORITHM
• Round-robin:
 It is more of an idea than an algorithm

 Round-robin (RR) idea is that a task is allowed to run at most n units of time
(called a time slice) before it is pre-empted and placed back into the ready
queue.

 Each time a task is scheduled, a timing interrupt is set at the appropriate time
in the future.

 If the task yields the processor early, the associated timing interrupt is
cancelled.

 We cannot, however, use this round robin for real-time systems, as it does
not take into account any deadlines.

 It is a basis for the schedulers used in general-purpose systems


PREEMPTIVE SCHEDULING ALGORITHM
• Dynamic deadline-based preemptive scheduling :

 Earliest-deadline first

o At any time, the task that is executing is the task has the earliest deadline
o If tasks can be scheduled in such a way for all tasks to meet their deadlines

 Least-slack first algorithm

o Task, has less slack time prior to its deadline, will be executed
o Better under certain conditions than earliest-deadline first when dealing with
multiple processing units
PREEMPTIVE SCHEDULING ALGORITHM
• Fixed Priority-based preemptive scheduling :

• Rate monotonic scheduling

• Inverse deadline (or deadline monotonic) algorithm


CPU scheduling exercise

Consider three process, all arriving at time zero, with total execution time of 10, 20 and 30
units respectively.

Each process spends the first 20% of execution time doing I/O, the next 70% of time doing
computation, and the last 10% of time doing I/O again.

The operating system uses a shortest remaining time first scheduling algorithm and schedules a
new process either when the running process gets blocked on I/O or when the running process
finishes its compute burst. Assume that all I/O operations can be overlapped as much as
possible. For what percentage of does the CPU remain idle?

You might also like