Download cmps 270 lecture 6 . and more Lecture notes Computer Science in PDF only on Docsity!
CMPS 240 - Operating Systems
Lecture 8: Process Scheduling
Maurice Khabbaz, Ph.D. – Edited by Mohamad Zalghout, Ph.D.
Last Time
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
Critical Section Problem
Hardware-based Solutions
Software-based Solutions
Semaphores
Classical Problems of Synchronization
Monitors
Basic Concepts
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Single-CPU System: only one process can run at a time.
- Other processes must wait until CPU is freed and can be rescheduled.
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Single-CPU System: only one process can run at a time.
- Other processes must wait until CPU is freed and can be rescheduled.
- Multitasking OS can simultaneously interleave execution of multiple processes.
- Several processes may be found in memory at any point in time.
- On single-CPU machines → illusion of multiple processes running concurrently.
- On multi-CPU machines → enable process concurrency and parallelism on different CPUs.
- Scheduling: main OS function that schedules all computer resources before use:
- CPU is one of the primary computer resources.
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Single-CPU System: only one process can run at a time.
- Other processes must wait until CPU is freed and can be rescheduled.
- Multitasking OS can simultaneously interleave execution of multiple processes.
- Several processes may be found in memory at any point in time.
- On single-CPU machines → illusion of multiple processes running concurrently.
- On multi-CPU machines → enable process concurrency and parallelism on different CPUs.
- Scheduling: main OS function that schedules all computer resources before use:
- CPU is one of the primary computer resources.
- Whenever CPU is idle:
- CPU scheduler (STS(short-term scheduler)) selects a process from ready queue for execution.^ AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Single-CPU System: only one process can run at a time.
- Other processes must wait until CPU is freed and can be rescheduled.
- Multitasking OS can simultaneously interleave execution of multiple processes.
- Several processes may be found in memory at any point in time.
- On single-CPU machines → illusion of multiple processes running concurrently.
- On multi-CPU machines → enable process concurrency and parallelism on different CPUs.
- Scheduling: main OS function that schedules all computer resources before use:
- CPU is one of the primary computer resources.
- Whenever CPU is idle:
- CPU scheduler (STS(short-term scheduler)) selects a process from ready queue for execution.
- CPU scheduling decisions take place when a process:
- Switches from running to waiting state.
- Switches from running to ready state.
- Switches from waiting to ready state.
- Terminates.
Ready^ AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
Waiting
start scheduler dispatch
interrupt I/O event or wait() I/O or event completion
Terminated exit() Running
New
- Single-CPU System: only one process can run at a time.
- Other processes must wait until CPU is freed and can be rescheduled.
- Multitasking OS can simultaneously interleave execution of multiple processes.
- Several processes may be found in memory at any point in time.
- On single-CPU machines → illusion of multiple processes running concurrently.
- On multi-CPU machines → enable process concurrency and parallelism on different CPUs.
- Scheduling: main OS function that schedules all computer resources before use:
- CPU is one of the primary computer resources.
- Whenever CPU is idle:
- CPU scheduler (STS(short-term scheduler)) selects a process from ready queue for execution.
- CPU scheduling decisions take place when a process:
- Switches from running to waiting state.
- Switches from running to ready state.
- Switches from waiting to ready state.
- Terminates.
Ready^ AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
Waiting
start scheduler dispatch
interrupt I/O event or wait() I/O or event completion
Terminated exit() Running
New
5
- REMARK:
- Scheduling under (1.) and (4.) is non-preemptive ( i.e. , cooperative ).
- Otherwise, scheduling is preemptive.
Definitions
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Non-Preemptive Scheduling:
- Process keeps CPU until either it terminates or it switches to waiting state.
- Used on some HW platforms → does not require any special HW ( e.g. timer).
- Preemptive Scheduling:
Definitions
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
- Non-Preemptive Scheduling:
- Process keeps CPU until either it terminates or it switches to waiting state.
- Used on some HW platforms → does not require any special HW ( e.g. timer).
- Preemptive Scheduling:
- Process releases CPU before terminating or willingly switching to waiting state.
- When an interrupt arises, it preempts a process to handle the interrupt.
Dispatcher Module
- Component involved in CPU scheduling.
- Gives control of CPU to process selected by STS (short-term scheduler).
- Dispatching involves:
- Switching context.
- Switching to user mode.
- Jumping to proper location in the user program to restart that program.
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D. 7
Dispatcher Module
- Component involved in CPU scheduling.
- Gives control of CPU to process selected by STS (short-term scheduler).
- Dispatching involves:
- Switching context.
- Switching to user mode.
- Jumping to proper location in the user program to restart that program.
- Dispatcher should be as fast as possible:
- It is invoked during every process switch.
AUB - CMPS 240 - M. J. KHABBAZ, Ph.D. 7
Burst Cycles
- CPU Burst Cycle (CPU-BC): cycle of CPU execution.
- I/O Burst Cycle (I/O-BC): wait for I/O. AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
add store
- When executing a process alternates between two burst cycles: read from file
Burst Cycles
- CPU Burst Cycle (CPU-BC): cycle of CPU execution.
- I/O Burst Cycle (I/O-BC): wait for I/O. AUB - CMPS 240 - M. J. KHABBAZ, Ph.D.
add store
- When executing a process alternates between two burst cycles: read from file
time