Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Operating Systems

CS F372

CPU Scheduling

Biju K Raveendran
Linux Schedulers
• Every linux process is always scheduled
according to one of the following classes
– SCHED_FIFO
– SCHED_RR
– SCHED_NORMAL or SCHED_OTHER

Monday, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 2


Scheduling of Conventional Processes
• Every conventional process has its own static priority
– Used to rate the process with respect to other
conventional processes in the system
– Static priority ranges from 100 (highest priority) to
139 (lowest priority)
– A new process will always inherit the static priority
of its parent
– User can change the static priority of the process by
nice() system call

Monday, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 3


nice() or setpriority() system calls
– Changes the static priority of the process
– /*Convert user-nice values [ -20 ... 0 ... 19 ]
to static priority [ MAX_RT_PRIO..MAX_PRIO-
1 ], and back */
– #define NICE_TO_PRIO(nice)
(MAX_RT_PRIO + (nice) + 20)
– #define PRIO_TO_NICE(prio)
((prio) - MAX_RT_PRIO - 20)

Monday, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 4


Linux Scheduling
• Static priority determines the base time quantum of a process
• Base time quantum (in milliseconds)
– (140 – static priority) X 20 if static priority <120
– (140 – static priority) X 5 if static priority >=120
– The higher the static priority (lower value), the longer the base
time quantum
– Example
Description static priority base time quantum
Highest static priority 100 800ms
Default static priority 120 100ms
Lowest static priority 139 5ms
Monday, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 5
Dynamic Priority
• Dynamic priority value ranges from 100 (highest priority) to 139
(lowest priority)
• Dynamic priority is the one scheduler looks at when selecting a
new process to run
– Dynamic priority = max (100,
min(static priority – bonus + 5, 139))
– Bonus is ranging from 0 to 10
• Less than 5 (is a penalty that) lowers dynamic priority
• Greater than 5 raises dynamic priority
– Value of bonus depends on the past history of the process
(related to average sleep time of the process)
• Average sleep time reduces when process is running
• Average sleep can never become larger than 1 second
• Average sleep time increases when process is in I/O
Monday, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 6
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, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 10 107
• 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, October 21, 2019 Biju K Raveendran @ BITS Pilani Goa 8

You might also like