0% found this document useful (0 votes)
17 views12 pages

OS Scheduling

The document discusses CPU scheduling in operating systems, focusing on the differentiation between interactive and conventional processes based on their average sleep time and static priority. It explains how the Linux scheduler manages active and expired processes to prevent starvation and ensure fair CPU time distribution. Additionally, it covers real-time process scheduling, the role of system calls in adjusting process priorities, and the structure of the runqueue for managing runnable processes.

Uploaded by

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

OS Scheduling

The document discusses CPU scheduling in operating systems, focusing on the differentiation between interactive and conventional processes based on their average sleep time and static priority. It explains how the Linux scheduler manages active and expired processes to prevent starvation and ensure fair CPU time distribution. Additionally, it covers real-time process scheduling, the role of system calls in adjusting process priorities, and the structure of the runqueue for managing runnable processes.

Uploaded by

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

OPERATING SYSTEMS CS F372

BIJU K RAVEENDRAN & TEAM

LECT #23: CPU SCHEDULING


• Average sleep time is also used by the scheduler to
determine whether a given process should be
considered interactive or branch process
• Interactive process
– Dynamic priority <= 3 X static priority / 4 + 28
– Which is equivalent to Bonus – 5 >= static priority / 4 – 28
– static priority / 4 – 28 is called the interactive delta
• varies from -3 (highest priority) to +6 (lowest priority)
– It is far easier for a high priority process to become interactive
than low priority process
• Process with priority 100 is considered interactive if bonus >2
(when its average sleep time exceeds 200ms)
• Process with priority 139 is never considered interactive because
bonus value required is 11 which is not achievable

Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 2


Average Sleep Time Bonus Granularity
Greater than or equal to 0 but smaller than 100ms 0 5120
Greater than or equal to 100ms but smaller than 200ms 1 2560
Greater than or equal to 200ms but smaller than 300ms 2 1280
Greater than or equal to 300ms but smaller than 400ms 3 640
Greater than or equal to 400ms but smaller than 500ms 4 320
Greater than or equal to 500ms but smaller than 600ms 5 160
Greater than or equal to 600ms but smaller than 700ms 6 80
Greater than or equal to 700ms but smaller than 800ms 7 40
Greater than or equal to 800ms but smaller than 900ms 8 20
Greater than or equal to 900ms but smaller than 1000ms 9 10
1 second
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 10 103
• Conventional processes with higher static priorities get
larger slices of the CPU
– They should not completely lock out the processes
having lower static priority
• To avoid process starvation, when a process finishes its
time quantum, it can be replaced by a lower priority
process whose time quantum has not yet been
exhausted
• To achieve this, in Linux scheduler maintains 2 disjoint
set of runnable processes
– Active Processes
– Expired processes
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 4
Reality
• Scheduler tries to boost the performance of interactive processes
– An active batch process finishes its time quantum always becomes
expired
– An active interactive process finishes its time quantum usually remains
active
• Scheduler refills its time quantum and leaves it in the set of active
processes
– However, scheduler moves an interactive process that finishes its time
quantum to expired process if
• The eldest expired process has already waited for long time
• An expired process has higher static priority (lower value) than the
interactive process
– The active processes will become empty & expired processes will get a
chance to run

Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 5


Scheduling Real-time Processes
• Every real time process is associated with a real time priority
ranging from 1 (highest) to 99 (lowest)
• Scheduler always favors a higher priority runnable process over a
lower priority one
• Real time processes are always considered active
• User can change the real-time priority of a process by
sched_setparam() and sched_setscheduler() system calls
• If several real time runnable processes have the same highest
priority, the scheduler chooses the process that occurs first in the
corresponding list of the local CPU’s run queue

Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 6


• A real time process is replaced by another only when
one of the following events occur
– Process is preempted by a higher real time priority
process
– Process performs blocking operation (TASK_
INTERRUPTABLE or TASK_UNINTERRUPTABLE)
– Process is stopped (TASK_STOPPED or TASK_TRACED)
– Process is killed (EXIT_ZOMBIE or EXIT_DEAD)
– Process voluntarily relinquishes the CPU by invoking
sched_yield() system call
– The process is Round Robin real time (SCHED_RR)
and it has exhausted its time quantum
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 7
• The nice() and setpriority() system calls, when
applied to a RR real time process, do not change
the real time priority
– Changes the duration of the base time
quantum
• Duration of the base time quantum in RR does
not depend on real time priority
– Depends on the static priority of the process

Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 8


• The arrays field of the runqueue is an array consisting of
two prio_array_t structures
– Each data structure represents
• A set of runnable processes and includes 140 doubly linked
list heads (one list for each possible process priority),
• A priority bit map and
• A counter of the processes included in the set
– The active field of the runqueue structure points to
one of the two prio_array_t data structure in arrays
• Exchange of active and expired data structures is
achieved by exchanging the contents of the active and
expired fields of the runqueue
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 9
List of Tasks Indexed According to Priorities

139 139
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 10
• schedule()
– Selects a process from the runqueue list and
assign CPU to it.
– Invoked directly or lazy (deferred) way
• Direct
– The current process is blocked right away because the
resource it needs is not available.
• Lazy invocation
– By setting the TIF_NEED_RESCHED flag of current
process to 1
– Check on the value of this flag is made before resuming
the execution of a User Mode Process
Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 11
• Examples of lazy invocation
– When current process has used up its quantum time
(done by scheduler_tick() function)
– When a process is woken up and its priority is higher
than that of the current process (done by
try_to_wake_up() function)
– When a sched_setscheduler() system call is issued
• load_balance()
– Keeps the runqueues of a multiprocessor system
balanced

Monday, February 24, 2025 Biju K Raveendran @ BITS Pilani Goa 12

You might also like