130 likes | 286 Vues
Task scheduling. What are the goals of a modern operating system scheduler, and how does Linux achieve them?. Types of scheduling. Stallings identifies three distinct kinds of process-scheduling decisions: Long-term: which tasks will the system admit? When? And in what order?
E N D
Task scheduling What are the goals of a modern operating system scheduler, and how does Linux achieve them?
Types of scheduling • Stallings identifies three distinct kinds of process-scheduling decisions: • Long-term: which tasks will the system admit? When? And in what order? • Medium-term: which tasks will be temporarily swapped out to disk? And when will they be swapped back in to main memory? • Short-term: which of the ready-to-run tasks will next gain control of the processor?
When are decisions made? • Linux makes its short-term scheduling decisions: • When a timer interrupt occurs • When an I/O request completes • When a system-call is invoked • When a signal is sent • Linux makes its longer-term scheduling decisions: • When a task exits • When CPU’s idle-time exceeds a given threshold
Goals • Specific scheduling policies are chosen to support desired system behaviors • There are multiple goals -- and sometimes they may even appear to be contradictory • So scheduling policies are a “compromise”
User-oriented goals • Rapid response-time • Short turnaround-times • Assured deadlines • Predictable performance
System-oriented goals • Optimum throughput • Maximum CPU utilization • Balanced resource allocation • Enforce priorities • Assure Fairness
Fairness algorithms • One fairness principle is known as FCFS (First-Come, First-Served), though it may not provide optimal throughput • Another way to implement “fairness” is “round-robin” scheduling (“timeslicing”) in which every task gets allocated an equal-size “slice” of the CPUs available time, and all tasks take their turn at executing
Task types • Some tasks are “CPU bound” • They regularly consume the entire amount of processor time that they are allotted • Some tasks are “I/O bound” • They seldom use up their entire timeslice, but instead sleep while awaiting an I/O request
How does kernel distinguish? • If the scheduler repeatedly gets invoked because a task has used up its timeslice, the kernel treats that task as “CPU bound” • If the scheduler repeatedly gets invoked because a task is going to sleep (i.e., it’s awaiting completion of an I/O request), then that task is treated as “I/O bound”
Responsiveness • To achieve improved responsiveness in interactive applications, an OS kernel can assign a higher priority to I/O bound tasks • Tasks that have higher priority will always get scheduled before any tasks that have lower priority get scheduled • However this could result in “starvation”
Dynamic priorities • Linux combines priority-based scheduling with round-robin scheduling • Linux allows priorities to be dynamically recomputed • Separate queues are used for tasks with differing priorities, while tasks that have equal priority are scheduled round-robin • Tasks can migrate between priorities
In-class exercises • Exercise #1: write an application program which exhibits “CPU bound” behavior • Exercise #2: write an application program which exhibits “I/O bound” behavior • Exercise #3: write a program which would exhibit alternating behavior (becoming an I/O bound task for awhile, then becoming a CPU bound task for awhile)