CPU Scheduling
Objectives
We would like to :
- Discuss the basics of cpu scheduling
Notes
- Keeping processes running on the CPU or CPUS or cores or ... is the fundamental operating system function.
- They change the description of a process slightly for these discussions
- Most processes start out with a CPU Burst or a period of time when the process is active on the cpu.
- This is followed by a I/O Burst or a period when the process is waiting for I/O.
- This cycle repeats, see Figure 5.1 page 200.
- You can be sure that this has been studied in depth
- On simulations
- In the real world.
- The burst time of individual processes will vary but
- Research shows that a pattern emerges in the long run.
- See the figure on page 201.
- Most processes fall into a small range of CPU bursts.
- Very few have exceedingly long bursts.
- This information is important when discussing process behavior WRT scheduling.
- Scheduling
- This occurs when the/a processor(s) becomes idle (process blocked or times out)
- The Scheduler selects the next task to run from the runtime queue/queues
- We may have one, or multiple run time queues.
- Different process priorities
- Real time, normal and batch queue.
- Or other situations.
- We will definitely have different goals for the scheduler as well (discussed soon)
- In the queue, the process is represented by the Process Control Block (PCB)
- We have discussed this.
- In linux sched.h struct task_struct
- All the information necessary to load the task into memory.
- A context switch then (114 -115 if you need to re-read it)
- Is moving relevant information from the registers/memory/... to the PCB for the process that is being removed from the core
- Loading the relevant information from the new process' PCB
- Switching back to user mode
- See figure 5.3 page 203
- Context switches are performed by the Dispatcher.
- Since many of these occur, this needs to be efficient.
- The time to perform context switch is called dispatcher latency.
- grep ctxt /proc/pid/status will show the context switches for a process
- Voluntary - switch because of resource request
- involuntary - times out.
- Take a look at reader and pi.
- Scheduling Terms
- Scheduling is based on process switching
- from running to waiting due to service request
- from running to ready due to timeout interrupt
- from waiting to ready due to service finished
- from running to termination
- They label 1 and 4 as cooperative or nonpreemptive
- They label 2 and 3 as preemptive
- In a nonpreemptive system, a process runs until it is terminated or needs a service.
- And this can lead to poor performance.
- Most modern os's are preemptive.
- They state kernels can be preemptive or non-preemptive.
- In an nonpreemeptive kernel, the kernel is allowed to complete tasks on behalf of the process without interruption.
- But this leads to poor real-time performance.
- So most modern kernels are preemptive