Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that.

Similar presentations


Presentation on theme: "1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that."— Presentation transcript:

1 1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that requests an I/O operation. –e.g. read() The control moves from the user level to kernel level. In general, the use of a system call results in placing user processes in the Blocked state.

2 2 An Architectural View of an OS Inter-process communication Process Scheduling Process Control Subsystem File Subsystem Device Drivers Hardware Control System Call Interface Hardware level Hardware Kernel level User programsLibraries User level Memory Mgt Subsystem

3 3 Process Switch via System Call Running Blocked Running Process 1 Save the process image for P1 Load the process image for P2 System call (I/O operation)Ready Running Ready Process 2 OS Save the process image for P2 Load the process image for P1

4 4 Interrupt –Due to an event that is external to and independent of the currently running process. –Clock interrupt when an OS determines that the currently running process has been executing for the max allowable time period. If so, this process must be switched to Ready state, and another process dispatched to a CPU. –I/O interrupt when an OS determines that an I/O operation is completed. –e.g., Reading a file If the I/O completion constitutes an event for which one or more blocked (or blocked, suspended) processes are waiting, an OS moves all of the processes to the Ready state. –The process will be executed immediately, if there is no running process.

5 5 Process Switch via Interrupt Running Ready Running Process 1 Save the process image for P1 Load the process image for P2 Clock interruptReady Running Ready Process 2 OS Save the process image for P2 Load the process image for P1

6 6 Trap –An error or exception generated within the currently running process. e.g. illegal file access attempt –An OS determines if the error is fatal or not. If so, the currently running process is moved to the Terminated state, and a process switch occurs. If not, the OS may perform some recovery procedure or simply notify a user. A process switch may occur.

7 7Interrupt In interrupt cycle, an OS periodically checks whether any interrupts have occurred. –Indicated by the presence of interrupt signals in a interrupt queue. If an interrupt is pending, an OS does… –Saves a process image of current program being executed. –Sets the program counter to the starting address of the interrupt handler.

8 8 Interrupt Handler A short program that performs a few basic tasks related to an interrupt. –Sends an acknowledgement to the entity that issued the interrupt (I/O device). –Checks any error conditions. If an error has occured, sends a signal to the process that originally requested the I/O operation. –If the interrupt is by the clock, hands control over to the process scheduler.

9 9HW Choose an OS, and describe what kind of interrupts the OS support. Due: 25

10 10Quiz Context switch time is pure overhead, because no processes are executed on a CPU during a switch. –Typically, a few milliseconds. Its speed varies from machine to machine and OS to OS. What does this speed depend on?

11 11 Memory access (read/write) speed –The speed to load/save PCBs from/to memory. The number of CPU registers –The amount of register values to be copied between a CPU and memory. The efficiency of the interrupt handler The complexity of process scheduling algorithm

12 12 Process Scheduling The process to decide which ready process to be executed by the CPU.

13 13 Process Scheduling The process to decide which ready process to be executed by the CPU. More precisely… 3 types of process scheduling –Short-term scheduling Which ready process to be executed? –Medium-term scheduling Which process to be swapped in/out from/to the main memory? –Long-term scheduling Which process to be admitted?

14 14 Ready, Suspended ReadyRunningTerminated Blocked MTS STS Blocked, Suspended MTS New LTS MTS LTS Process Scheduling and State Transition 3 different schedulers

15 15 Long-term Scheduling The process to determine which programs to be admitted. –Once admitted, the programs become processes. When to admit a program (create a new process)? –The more processes are created, the smaller is the percentage of time that each process can be executed. More processes compete for the same amount of processor time. –When the number of admitted processes goes below a threshold. –The fraction of time that the CPU is idle exceeds a threshold. –Each time a process terminates.

16 16 Mid-term Scheduling Mid-term scheduling is a part of the swapping function.

17 17 Short-term Scheduling The process to determine which ready process to be executed on the CPU. The short-term scheduler –works more frequently than the long-term and mid- term schedulers. –makes finer-grained scheduling decision than the long-term and mid-term schedulers.

18 18 Classification of Short-term Scheduling Non-preemptive scheduling –Once a process is in the Running state, it continues to execute until it terminates or blocks itself to wait for I/O completion. Preemptive scheduling –The currently-running process may be interrupted and moved to the Ready state. The preemption decision is performed –is invoked whenever an event occurs that may lead to the suspension of the current process, or may provide an opportunity to preempt a currently-running process in favor of another. e.g., system calls, Interrupts (e.g., clock interrupt and I/O interrupt) and signals (e.g., trap)

19 19 Evaluation Criteria for Short-term Scheduling CPU utilization –How busy the CPU is; the time to execute processes / the total time (0 to 100%) Usually should be from 40% to 90% Throughput –How much work is performed; the number of processes completed per unit of time.


Download ppt "1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that."

Similar presentations


Ads by Google