co2101 processes and multi tasking
play

CO2101 Processes and Multi-tasking Tom Ridge (tr61) 7th October - PowerPoint PPT Presentation

CO2101 Processes and Multi-tasking Tom Ridge (tr61) 7th October 2019 tr61 Multi-tasking 7th October 2019 1 / 33 How to implement multi-tasking Why multi-tasking? Simple Fetch-Execute Cycle CPU operates in a Fetch-Execute cycle it


  1. How to implement multi-tasking Programs and processes Aside about Kernel Mode vs User Mode OS needs to protect processes from each other for security If a user’s process had access to all machine instructions, then the user could do anything the OS can. tr61 Multi-tasking 7th October 2019 11 / 33

  2. How to implement multi-tasking Programs and processes Aside about Kernel Mode vs User Mode OS needs to protect processes from each other for security If a user’s process had access to all machine instructions, then the user could do anything the OS can. The solution is for the CPU to have a special operating mode, kernel or supervisor mode, which can only be invoked by the OS. tr61 Multi-tasking 7th October 2019 11 / 33

  3. How to implement multi-tasking Programs and processes Aside about Kernel Mode vs User Mode OS needs to protect processes from each other for security If a user’s process had access to all machine instructions, then the user could do anything the OS can. The solution is for the CPU to have a special operating mode, kernel or supervisor mode, which can only be invoked by the OS. In kernel mode, certain privileged instructions, e.g , interrupt processing, dispatcher, memory allocation, are possible; normal processes run in user mode tr61 Multi-tasking 7th October 2019 11 / 33

  4. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). tr61 Multi-tasking 7th October 2019 12 / 33

  5. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). Is the current process still the most suitable to run? If so, resume 1 execution; otherwise . . . tr61 Multi-tasking 7th October 2019 12 / 33

  6. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). Is the current process still the most suitable to run? If so, resume 1 execution; otherwise . . . Save the state of the current process in its PCB 2 tr61 Multi-tasking 7th October 2019 12 / 33

  7. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). Is the current process still the most suitable to run? If so, resume 1 execution; otherwise . . . Save the state of the current process in its PCB 2 3 Retrieve the state of the most suitable process from its PCB tr61 Multi-tasking 7th October 2019 12 / 33

  8. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). Is the current process still the most suitable to run? If so, resume 1 execution; otherwise . . . Save the state of the current process in its PCB 2 3 Retrieve the state of the most suitable process from its PCB Transfer control to the new process, at the point indicated in the PCB 4 tr61 Multi-tasking 7th October 2019 12 / 33

  9. How to implement multi-tasking The Dispatcher The Dispatcher After an interrupt has been handled, control is passed to the Dispatcher (or Low Level Scheduler). Is the current process still the most suitable to run? If so, resume 1 execution; otherwise . . . Save the state of the current process in its PCB 2 3 Retrieve the state of the most suitable process from its PCB Transfer control to the new process, at the point indicated in the PCB 4 The action of storing the state of current process and (re-)starting another process is called a context switch tr61 Multi-tasking 7th October 2019 12 / 33

  10. How to implement multi-tasking The Dispatcher States of processes The running process is in the RUNNING state; only one RUNNING process on a processor at a time. tr61 Multi-tasking 7th October 2019 13 / 33

  11. How to implement multi-tasking The Dispatcher States of processes The running process is in the RUNNING state; only one RUNNING process on a processor at a time. Clock interrupt: Initiated by a clock within the CPU. Gives the dispatcher an opportunity to context switch. A process stopped by clock interrupt goes to READY state. tr61 Multi-tasking 7th October 2019 13 / 33

  12. How to implement multi-tasking The Dispatcher States of processes The running process is in the RUNNING state; only one RUNNING process on a processor at a time. Clock interrupt: Initiated by a clock within the CPU. Gives the dispatcher an opportunity to context switch. A process stopped by clock interrupt goes to READY state. I/O interrupt: Initiated by CPU when an I/O instruction occurs in the running process or by an I/O device signalling completion of an I/O operation When a process starts an I/O operation it goes to the BLOCKED state When an I/O operation completes for a process, it goes to READY state tr61 Multi-tasking 7th October 2019 13 / 33

  13. How to implement multi-tasking The Dispatcher States of processes The running process is in the RUNNING state; only one RUNNING process on a processor at a time. Clock interrupt: Initiated by a clock within the CPU. Gives the dispatcher an opportunity to context switch. A process stopped by clock interrupt goes to READY state. I/O interrupt: Initiated by CPU when an I/O instruction occurs in the running process or by an I/O device signalling completion of an I/O operation When a process starts an I/O operation it goes to the BLOCKED state When an I/O operation completes for a process, it goes to READY state The dispatcher can select a process to run only if it is READY. tr61 Multi-tasking 7th October 2019 13 / 33

  14. How to implement multi-tasking The Dispatcher Diagram of process states Process entry I/O completion READY BLOCKED Dispatch Timeout I/O wait RUNNING Termination tr61 Multi-tasking 7th October 2019 14 / 33

  15. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). tr61 Multi-tasking 7th October 2019 15 / 33

  16. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). tr61 Multi-tasking 7th October 2019 15 / 33

  17. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). tr61 Multi-tasking 7th October 2019 15 / 33

  18. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). Interrupts are used to stop the currently RUNNING process. tr61 Multi-tasking 7th October 2019 15 / 33

  19. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). Interrupts are used to stop the currently RUNNING process. A clock interrupt causes the current process to become READY. tr61 Multi-tasking 7th October 2019 15 / 33

  20. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). Interrupts are used to stop the currently RUNNING process. A clock interrupt causes the current process to become READY. An I/O interrupt causes the current process to become BLOCKED, upon completion of the I/O it becomes READY tr61 Multi-tasking 7th October 2019 15 / 33

  21. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). Interrupts are used to stop the currently RUNNING process. A clock interrupt causes the current process to become READY. An I/O interrupt causes the current process to become BLOCKED, upon completion of the I/O it becomes READY The Dispatcher chooses the next process to run from the queue of READY processes. tr61 Multi-tasking 7th October 2019 15 / 33

  22. How to implement multi-tasking The Dispatcher Summary of the story and what next A process can be RUNNING (currently running), READY (ready to run) or BLOCKED (waiting on I/O). Interrupts are used to stop the currently RUNNING process. A clock interrupt causes the current process to become READY. An I/O interrupt causes the current process to become BLOCKED, upon completion of the I/O it becomes READY The Dispatcher chooses the next process to run from the queue of READY processes. Scheduling: is the policy for choosing among the READY processes. tr61 Multi-tasking 7th October 2019 15 / 33

  23. How to implement multi-tasking The Dispatcher Types of Scheduling policy Scheduling policy determines: Which READY process to run next. How long a process is given to use the CPU. tr61 Multi-tasking 7th October 2019 16 / 33

  24. How to implement multi-tasking The Dispatcher Types of Scheduling policy Scheduling policy determines: Which READY process to run next. How long a process is given to use the CPU. Non-preemptive scheduling: A process releases CPU only if it BLOCKS on I/O (or it finishes). i.e. the process cannot be stopped during regular operation. tr61 Multi-tasking 7th October 2019 16 / 33

  25. How to implement multi-tasking The Dispatcher Types of Scheduling policy Scheduling policy determines: Which READY process to run next. How long a process is given to use the CPU. Non-preemptive scheduling: A process releases CPU only if it BLOCKS on I/O (or it finishes). i.e. the process cannot be stopped during regular operation. Preemptive scheduling: A process can be stopped at any point by a clock interrupt. tr61 Multi-tasking 7th October 2019 16 / 33

  26. How to implement multi-tasking The Dispatcher Efficiency measures of scheduling policies There are many possible ways to measure efficiency of scheduling policies. We consider the following 3: Turnaround time. CPU usage. Response time. tr61 Multi-tasking 7th October 2019 17 / 33

  27. How to implement multi-tasking The Dispatcher Efficiency measures of scheduling policies There are many possible ways to measure efficiency of scheduling policies. We consider the following 3: Turnaround time. CPU usage. Response time. tr61 Multi-tasking 7th October 2019 17 / 33

  28. How to implement multi-tasking The Dispatcher Efficiency measures of scheduling policies There are many possible ways to measure efficiency of scheduling policies. We consider the following 3: Turnaround time. CPU usage. Response time. tr61 Multi-tasking 7th October 2019 17 / 33

  29. How to implement multi-tasking The Dispatcher Turnaround time Turnaround time of a particular process is its duration in real time, i.e. the difference between the time it is submitted for execution and the time execution is complete. tr61 Multi-tasking 7th October 2019 18 / 33

  30. How to implement multi-tasking The Dispatcher Turnaround time Turnaround time of a particular process is its duration in real time, i.e. the difference between the time it is submitted for execution and the time execution is complete. Turnaround time of a group of processes is the average of their individual turnaround times. tr61 Multi-tasking 7th October 2019 18 / 33

  31. How to implement multi-tasking The Dispatcher Turnaround time Turnaround time of a particular process is its duration in real time, i.e. the difference between the time it is submitted for execution and the time execution is complete. Turnaround time of a group of processes is the average of their individual turnaround times. Example: We have 3 processes with respective start (submitted) and end times ( 100 , 200 ) , ( 150 , 300 ) and ( 200 , 400 ) . The individual turnaround times are 100, 150, 200. The average turnaround time is 150 tr61 Multi-tasking 7th October 2019 18 / 33

  32. How to implement multi-tasking The Dispatcher Turnaround time Turnaround time of a particular process is its duration in real time, i.e. the difference between the time it is submitted for execution and the time execution is complete. Turnaround time of a group of processes is the average of their individual turnaround times. Example: We have 3 processes with respective start (submitted) and end times ( 100 , 200 ) , ( 150 , 300 ) and ( 200 , 400 ) . The individual turnaround times are 100, 150, 200. The average turnaround time is 150 Generally a scheduling policy aims to keep average turnaround time as low as possible . tr61 Multi-tasking 7th October 2019 18 / 33

  33. How to implement multi-tasking The Dispatcher CPU Usage If all the processes are blocked waiting for completion of their I/O operations, the CPU stays idle. tr61 Multi-tasking 7th October 2019 19 / 33

  34. How to implement multi-tasking The Dispatcher CPU Usage If all the processes are blocked waiting for completion of their I/O operations, the CPU stays idle. A good scheduling policy minimises the idleness time. tr61 Multi-tasking 7th October 2019 19 / 33

  35. How to implement multi-tasking The Dispatcher CPU Usage If all the processes are blocked waiting for completion of their I/O operations, the CPU stays idle. A good scheduling policy minimises the idleness time. CPU usage: given some amount of time, the percentage of time during which the CPU is busy. tr61 Multi-tasking 7th October 2019 19 / 33

  36. How to implement multi-tasking The Dispatcher CPU Usage If all the processes are blocked waiting for completion of their I/O operations, the CPU stays idle. A good scheduling policy minimises the idleness time. CPU usage: given some amount of time, the percentage of time during which the CPU is busy. Generally a scheduling policy aims to maximise CPU usage. tr61 Multi-tasking 7th October 2019 19 / 33

  37. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. tr61 Multi-tasking 7th October 2019 20 / 33

  38. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. E.g , in Linux, user requests are commands like cp, cd, ls, etc. or applications. tr61 Multi-tasking 7th October 2019 20 / 33

  39. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. E.g , in Linux, user requests are commands like cp, cd, ls, etc. or applications. The response time is average turnaround time of user requests. tr61 Multi-tasking 7th October 2019 20 / 33

  40. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. E.g , in Linux, user requests are commands like cp, cd, ls, etc. or applications. The response time is average turnaround time of user requests. The turnaround time of other processes (“batch processes”) is ignored. tr61 Multi-tasking 7th October 2019 20 / 33

  41. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. E.g , in Linux, user requests are commands like cp, cd, ls, etc. or applications. The response time is average turnaround time of user requests. The turnaround time of other processes (“batch processes”) is ignored. For interactive users response time should be minimised. tr61 Multi-tasking 7th October 2019 20 / 33

  42. How to implement multi-tasking The Dispatcher Response time The OS (or something else) classifies some processes as user commands. E.g , in Linux, user requests are commands like cp, cd, ls, etc. or applications. The response time is average turnaround time of user requests. The turnaround time of other processes (“batch processes”) is ignored. For interactive users response time should be minimised. NOTE The terminology “response time” is not completely standardized (like lots of CS terminology) tr61 Multi-tasking 7th October 2019 20 / 33

  43. How to implement multi-tasking The Dispatcher Types of operating systems Batch systems: Run a series of programs without human intervention. Examples: scientific computing, salary calculation in big companies. Turnaround time and CPU usage are more important measures than response time. Example: recoding a video tr61 Multi-tasking 7th October 2019 21 / 33

  44. How to implement multi-tasking The Dispatcher Types of operating systems Batch systems: Run a series of programs without human intervention. Examples: scientific computing, salary calculation in big companies. Turnaround time and CPU usage are more important measures than response time. Example: recoding a video Interactive systems: Designed to continuously communicate with the user. Examples: desktop workstations/laptops, etc ; mobile phones, tablets . . . Response time is more important measure than general average turnaround time or CPU utilisation. Users often don’t care if a background task takes a little bit longer, provided the thing they clicked on shows some sort of response almost immediately (i.e., without noticable delay) tr61 Multi-tasking 7th October 2019 21 / 33

  45. How to implement multi-tasking Scheduling policies Generalisations I/O is not relevant when comparing different scheduling policies — when a process blocks on I/O it is no longer available for scheduling. tr61 Multi-tasking 7th October 2019 22 / 33

  46. How to implement multi-tasking Scheduling policies Generalisations I/O is not relevant when comparing different scheduling policies — when a process blocks on I/O it is no longer available for scheduling. Consider each long running process to be split into short bursts that require no I/O; treat these bursts as separate processes as far as the scheduler is concerned. tr61 Multi-tasking 7th October 2019 22 / 33

  47. How to implement multi-tasking Scheduling policies First come first served (FCFS) policy This policy is non-preemptive. tr61 Multi-tasking 7th October 2019 23 / 33

  48. How to implement multi-tasking Scheduling policies First come first served (FCFS) policy This policy is non-preemptive. The first READY process in the queue is started. tr61 Multi-tasking 7th October 2019 23 / 33

  49. How to implement multi-tasking Scheduling policies First come first served (FCFS) policy This policy is non-preemptive. The first READY process in the queue is started. The process releases the CPU when it finishes or it BLOCK s on I/O tr61 Multi-tasking 7th October 2019 23 / 33

  50. How to implement multi-tasking Scheduling policies First come first served (FCFS) policy This policy is non-preemptive. The first READY process in the queue is started. The process releases the CPU when it finishes or it BLOCK s on I/O When a BLOCKed process returns to READY state, it goes to the back of the READY queue. tr61 Multi-tasking 7th October 2019 23 / 33

  51. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the FCFS policy Advantages: Easy to implement. No indefinite waiting (when a process can potentially wait forever to be run). tr61 Multi-tasking 7th October 2019 24 / 33

  52. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the FCFS policy Advantages: Easy to implement. No indefinite waiting (when a process can potentially wait forever to be run). Disadvantage: likely to be un-responsive; because turnaround time of short processes can be much longer than their actual execution time. tr61 Multi-tasking 7th October 2019 24 / 33

  53. How to implement multi-tasking Scheduling policies Shortest job first (SJF) policy The policy is non-preemptive. tr61 Multi-tasking 7th October 2019 25 / 33

  54. How to implement multi-tasking Scheduling policies Shortest job first (SJF) policy The policy is non-preemptive. Requires knowledge about the runtime of processes before they actually execute. tr61 Multi-tasking 7th October 2019 25 / 33

  55. How to implement multi-tasking Scheduling policies Shortest job first (SJF) policy The policy is non-preemptive. Requires knowledge about the runtime of processes before they actually execute. From the queue of READY processes choose the one whose (expected) runtime is smallest. tr61 Multi-tasking 7th October 2019 25 / 33

  56. How to implement multi-tasking Scheduling policies Shortest job first (SJF) policy The policy is non-preemptive. Requires knowledge about the runtime of processes before they actually execute. From the queue of READY processes choose the one whose (expected) runtime is smallest. Otherwise, as for FCFS. tr61 Multi-tasking 7th October 2019 25 / 33

  57. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the SJF policy Advantage: favourable to processes with short runtimes. tr61 Multi-tasking 7th October 2019 26 / 33

  58. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the SJF policy Advantage: favourable to processes with short runtimes. Disadvantages: Requires advance knowledge about runtimes. Indefinite waiting is possible: a long process can wait a long time if multiple new short processes arrive. tr61 Multi-tasking 7th October 2019 26 / 33

  59. How to implement multi-tasking Scheduling policies Shortest remaining time first (SRTF) policy This is a preemptive policy. tr61 Multi-tasking 7th October 2019 27 / 33

  60. How to implement multi-tasking Scheduling policies Shortest remaining time first (SRTF) policy This is a preemptive policy. For every process, requires knowledge of the remaining runtime . tr61 Multi-tasking 7th October 2019 27 / 33

  61. How to implement multi-tasking Scheduling policies Shortest remaining time first (SRTF) policy This is a preemptive policy. For every process, requires knowledge of the remaining runtime . Very similar to SJF . The differences are: Arrival of a process in the READY queue leads to an interrupt. Chooses process with the shortest remaining time instead of shortest overall time. So if a process with shorter remaining time than the current one arrives in the READY queue, then the current process is preempted. tr61 Multi-tasking 7th October 2019 27 / 33

  62. How to implement multi-tasking Scheduling policies Shortest remaining time first (SRTF) policy This is a preemptive policy. For every process, requires knowledge of the remaining runtime . Very similar to SJF . The differences are: Arrival of a process in the READY queue leads to an interrupt. Chooses process with the shortest remaining time instead of shortest overall time. So if a process with shorter remaining time than the current one arrives in the READY queue, then the current process is preempted. tr61 Multi-tasking 7th October 2019 27 / 33

  63. How to implement multi-tasking Scheduling policies Shortest remaining time first (SRTF) policy This is a preemptive policy. For every process, requires knowledge of the remaining runtime . Very similar to SJF . The differences are: Arrival of a process in the READY queue leads to an interrupt. Chooses process with the shortest remaining time instead of shortest overall time. So if a process with shorter remaining time than the current one arrives in the READY queue, then the current process is preempted. tr61 Multi-tasking 7th October 2019 27 / 33

  64. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the SRTF policy. Advantage: even more sensitive to the short processes than SJF . tr61 Multi-tasking 7th October 2019 28 / 33

  65. How to implement multi-tasking Scheduling policies Advantages and disadvantages of the SRTF policy. Advantage: even more sensitive to the short processes than SJF . Disadvantages: requires advance knowledge of runtimes; indefinite waiting is still possible. tr61 Multi-tasking 7th October 2019 28 / 33

  66. How to implement multi-tasking Scheduling policies Round-Robin scheduling policy This is a preemptive policy used in interactive systems. tr61 Multi-tasking 7th October 2019 29 / 33

  67. How to implement multi-tasking Scheduling policies Round-Robin scheduling policy This is a preemptive policy used in interactive systems. Each process in turn gets the CPU for a fixed time quantum (typically 10–100 ms). tr61 Multi-tasking 7th October 2019 29 / 33

  68. How to implement multi-tasking Scheduling policies Round-Robin scheduling policy This is a preemptive policy used in interactive systems. Each process in turn gets the CPU for a fixed time quantum (typically 10–100 ms). When the quantum finishes: a timeout interrupt occurs and the process goes to the back of the READY queue. tr61 Multi-tasking 7th October 2019 29 / 33

  69. How to implement multi-tasking Scheduling policies Round-Robin scheduling policy This is a preemptive policy used in interactive systems. Each process in turn gets the CPU for a fixed time quantum (typically 10–100 ms). When the quantum finishes: a timeout interrupt occurs and the process goes to the back of the READY queue. New processes join the back of the READY queue. tr61 Multi-tasking 7th October 2019 29 / 33

  70. How to implement multi-tasking Scheduling policies Quantum duration for round-robin Context switch: is the procedure of replacing the currently running process by another one. This takes a non-zero amount of time. tr61 Multi-tasking 7th October 2019 30 / 33

  71. How to implement multi-tasking Scheduling policies Quantum duration for round-robin Context switch: is the procedure of replacing the currently running process by another one. This takes a non-zero amount of time. tr61 Multi-tasking 7th October 2019 30 / 33

  72. How to implement multi-tasking Scheduling policies Quantum duration for round-robin Context switch: is the procedure of replacing the currently running process by another one. This takes a non-zero amount of time. If the quantum is too short (similar to the time taken for a context switch), the CPU spends a large proportion of its time just context switching. tr61 Multi-tasking 7th October 2019 30 / 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend