linux scheduler © dj foreman 3/8/20091. objectives response time throughput for batch no starvation...

14
Linux Scheduler © DJ Foreman 3/8/2009 1

Upload: monica-fisher

Post on 04-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Linux Scheduler

© DJ Foreman 3/8/2009 1

Page 2: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Objectives• Response time

• Throughput for batch

• No starvation

• Accommodate high AND low priority

© DJ Foreman 3/8/2009 2

Page 3: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

General Process Classifications• Two schemes for classifying:

– Traditional classes• IO bound• CPU bound

– Alternative classes• Interactive• Batch• Real-time

– Video, robotics, sensor-based

How to determine?

© DJ Foreman 3/8/2009 3

Page 4: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Linux Scheduling Classes• FIFO FIFO real-time process

• RR Round Robin real-time process

• Normal non-real-time process

© DJ Foreman 3/8/2009 4

Page 5: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Real-timeDetails

© DJ Foreman 3/8/2009 5

Page 6: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Real-time Rules • Priority 0(highest) - 99(lowest)

– Program adjustable:• sched_setparam() • sched_setscheduler()

• FIFO - non-interruptible except– Higher priority– Blocked– Yields

• RR– Adds a time-slice to each thread– Suspends at end of slice

© DJ Foreman 3/8/2009 6

Page 7: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Non-real-time Scheduling(Conventional processes)

© DJ Foreman 3/8/2009 7

Page 8: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Rules• Every process has a “static” priority

– 100(highest) – 139 (lowest)– Variable via nice() and setpriority()

• Base quantum (not a constant!)– If sp<120

• 20*(140-static priority)

– If sp>=120• 5*(140-static priority)

• Dynamic priority (also 100-139)– Max(100, min(sp-bonus+5,139))– 0<=bonus<=10

© DJ Foreman 3/8/2009 8

Page 9: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Rules (continued)• Bonus

– 0-5 is a penalty– 6-10 is a prize– Related to average sleep time

• OF THIS PROCESS (not of all Processes)• Based on past history• Some sample values:

© DJ Foreman 3/8/2009 9

Average sleep time Bonus

0<=N<100ms 0

300<=N<400ms 3

600<=N<700 6

900<=N<1000 9

Page 10: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Priority Arrays• Two arrays:struct prio_array {

int nr_active;unsigned long bitmap[BITMAP_SIZE];struct list_head queue[MAX_PRIO];}

• With: 140 priority levels (max)wordsize=32 bits

• BITMAP_SIZE is 5 (last 20 bits ignored)

© DJ Foreman 3/8/2009 10

Page 11: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

The Bitmaps• Active queues

• Time-slice-expired queues

• 1 bit/queue (140 queues)

• Based on the Intel “bsfl” instruction– Select least significant 1-bit

© DJ Foreman 3/8/2009 11

Page 12: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Priority arrays – revisited• Two arrays (active/expired):

*listheads prio_array[2][140];

typedef struct listheads {

// 2-way list of PDs @ this priority

PD *next;

PD *prev;}

struct PD {PD *next;

PD*prev;

int PID;

int prio; // etc

}

© DJ Foreman 3/8/2009 12

Page 13: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

Scheduling• Pick highest priority non-empty queue/list

• Tasks in queue/list scheduled

© DJ Foreman 3/8/2009 13

Page 14: Linux Scheduler © DJ Foreman 3/8/20091. Objectives Response time Throughput for batch No starvation Accommodate high AND low priority © DJ Foreman 3/8/2009

References• Lindsey, R., "What's New in the 2.6

Scheduler", Linux Journal, March 2004

• Love, R., Linux Kernel Development, Indianapolis, IN, Sams Publishing, 2004

• Understanding the Linux Kernel, Bovet & Cesati, O’Reilly Press, 2006

© DJ Foreman 3/8/2009 14