Introduction to Scheduling
Scheduling is simpler in personal computers because (1) there is only one active process, (2) CPU is more faster than I/O.
Compute-bound: long CPU bursts and thus infrequent I/O waits. I/O-bound: short CPU bursts and thus frequent I/O waits.
When to Schedule
- A new process is created
- A process exits
- A process blocks on I/O
- I/O interrupt occurs
Types of schedule algorithm
- nonpreemptive scheduling algorithm: picks a process to run until it blocks, exit, or voluntarily release the CPU.
- preemptive scheduling algorithm: picks a process and lets it run for a maximum of some fixed time.
Goals of Scheduling Algorithms
- Fainess - giving each process a fair share of the CPU
- Policy enforcement - seeing that stated policy is carried out
- Balance - keeping all parts of the system busy
- Throughput - maximize jobs per hour
- Turnaround tiem - minimize time between submission and termination
- CPU utilization - keep the CPU busy all the time
- Response time - respond to requests quickly
- Propertionality - meets user’s expectations
- Meeting deadlines - avoid losing data
- Predictability - avoid quality degradation in multimedia systems
Scheduling in Batch Systems
Shortest Job First
Reduce the mean turnaround time.
Shortest Remaining Time Next
When new process enterd, its executime is compared with the remaining time of current process.
Scheduling in Interactive Systems
Each process is assigned a time interval, called its quantum , during which it is allowed to run. The CPU switches when the process blocks, of course.
Setting the quantum too short causes too many process switches and lowers the CPU efficiency, but setting it too long may cause poor response to short interactive requests. A quantum arount 20-50 msec is often a resnable compromise.
Each process is assigned a priority, and the runable process with the highest priority is allowed to run. The priority of the running process decreases at each clock tick.
A simple algorithm for giving a good service to I/O bound processes is to set the priority to 1/f, where f is the fraction of the last quantum that a process used.
Set up priority classes, a group of processes sorted by priority in each class.
Whenever a process used up all the quanta allocted to it, it was moved down one class, saving the CPU for short, interactive processes.
Whenever a carriage return was typed at a terminal, the process belonging to that terminal was moved to the highest priority class.
This prevents a process that needed to run for a long time when it first started but became interactive later, from being punished forever.
Shorted Process Next
To a certain extent, it would be nice if this algorithm used in batch systems could be used for interactive processes.
Estimating running time as $t = aT_0 + (1-a)T_1$
Make real promises to the users about performance ahd then live up to those promises.
- Compute the ratio of actual CPU time consumed to CPU time entitled.
- Run the process with the lowest ratio until its ratio is no longer the lowest.
Give processes lottery tickets for various system resources. Whenever a scheduling decision has to be made, a lottery ticket is chosen at random, and the process holding that ticket gets the resource.
- lottery scheduling is highly responsive, the process have more lottery tickets is more likely to get the turn.
- processes can exchange lottery tickets, the server and the client for example.
Each user is allocated some fraction of the CPU and the scheduler picks processes in such a way to enforce it.
For example, user 1 created process A B C D, while user 2 only created process E, the scheduling sequence should be:
A E B E C E …
If user 1 is entitled to twice as much CPU time as user 2, the sequence should be:
A B E C D E …
Scheduling in Real-Time Systems
The events that a real-time system may have to respond to can be categorized as periodic (occurring at regular intevals) or aperiodic (occurring unpredictably).
Depending on how much time each event requires for processing, it may not even be possible to handle them all. A real-time system that meets this requirement is said to be schedulable .
Policy versus Mechanism
Separate the scheduling mechanism from the scheduling policy to alow more flexible scheduling. What this means is that the scheduling algorithm is parameterized in some way.
- Kernel-level thread doesn’t block the entire process when blocking sys-calls are made, unlike user-level thread.
- Since the kernel knows that switching from a thread in process A to a thread in process B is more expensive than running a second thread in process A, it can take this into account when making a decision.
- User-level threads can employ an application-specific thread scheduler.
转载请注明来源： http://harttle.com/2013/12/03/morden-os-scheduling.html 欢迎对文章中的引用来源进行考证，欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论（可能需要在能访问 disqus 服务的网络），也可以邮件至 firstname.lastname@example.org。