| Current Path : /var/www/html/bibhas.ghoshal/lecture_slides/lect6/ |
| Current File : /var/www/html/bibhas.ghoshal/lecture_slides/lect6/lect6.tex.backup |
% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
% This file is a template using the "beamer" package to create slides for a talk or presentation
% - Talk at a conference/colloquium.
% - Talk length is about 20min.
% - Style is ornate.
% MODIFIED by Jonathan Kew, 2008-07-06
% The header comments and encoding in this file were modified for inclusion with TeXworks.
% The content is otherwise unchanged from the original distributed with the beamer package.
\documentclass{beamer}
% Copyright 2004 by Till Tantau <tantau@users.sourceforge.net>.
%
% In principle, this file can be redistributed and/or modified under
% the terms of the GNU Public License, version 2.
%
% However, this file is supposed to be a template to be modified
% for your own needs. For this reason, if you use this file as a
% template and not specifically distribute it as part of a another
% package/program, I grant the extra permission to freely copy and
% modify this file as you see fit and even to delete this copyright
% notice.
% \mode<presentation>
% {
% \usetheme{Warsaw}
% % or ...
%
% \setbeamercovered{transparent}
% % or whatever (possibly just delete it)
% }
\usetheme{CambridgeUS}
\usecolortheme{beaver}
\usepackage[english]{babel}
% or whatever
\usepackage[utf8]{inputenc}
% or whatever
\usepackage{times}
%\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\usepackage{color}
\beamertemplateshadingbackground{yellow}{blue}
%\usepackage{}
\title[IOSY 332C \& IOPS 332C: OS] % (optional, use only with long paper titles)
{ Lecture 6- CPU Scheduling Continued}
%\subtitle
%{Include Only If Paper Has a Subtitle}
\author [Bibhas Ghoshal]% (optional, use only with lots of authors)
{ Instructor : Bibhas Ghoshal (\textcolor{black}{bibhas.ghoshal@iiita.ac.in})}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
% affiliation.
%\institute % (optional, but mostly needed)
%{
%\inst{1}%
% Department of Computer Science and Engineering\\
% Indian Institute of Technology, Kharagpur}
% \and
% \inst{2}%
%Department of Theoretical Philosophy\\
%University of Elsewhere}
% - Use the \inst command only if there are several affiliations.
% - Keep it simple, no one is interested in your street address.
\date% (optional, should be abbreviation of conference name)
{Autumn Semester, 2015}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
% yourself) who are reading the slides online
%\subject{Theoretical Computer Science}
% This is only inserted into the PDF information catalog. Can be left
% out.
% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:
\pgfdeclareimage[height=0.75cm]{university-logo}{IIIT_logo.jpg}
\logo{\pgfuseimage{university-logo}}
% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
% \AtBeginSubsection[]
% {
% \begin{frame}<beamer>{Outline}
% \tableofcontents[currentsection,currentsubsection]
% \end{frame}
% }
% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:
%\beamerdefaultoverlayspecification{<+->}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Shortest Remaining Job First (SRJF)}
\begin{itemize}
\item Preemptive version of SJF
\item While a job A is running, if a new job B comes whose length is shorter than the remaining time of job A, then B preempts A and B is started to run.
\end{itemize}
\end{frame}
\begin{frame}{SRJF-Example}
\begin{figure}
\centering
\includegraphics[width=0.70\textwidth]{SRF.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Numerical Example}
\begin{itemize}
\item Assume we have the following processes. Find out the finish time, waiting time and turnaround time of each process for the following scheduling algorithms: FCFS, SJF, SRJF.
\end{itemize}
\begin{center}
\begin{tabular}{|c|c|c|}\hline
Process &Arrival Time &CPU Burst\\\hline
A&0 &30\\\hline
B& 5 & 20\\\hline
C &10 & 12\\\hline
D & 15 & 10\\\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}{Numerical Example - FCFS}
\begin{itemize}
\item FCFS : Processes will run in the order they arrive. The following is the completion,
turnaround, waiting time of each process.
\end{itemize}
AT : Arrival Time ; BT : Burst Time\\
CT : Completion Time; TAT : Turnaround Time\\
WT : Waiting Time
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}\hline
&AT &BT &CT&TAT&WT\\\hline
A&0 &30&30&30&0\\\hline
B&5 &20&50&45&25\\\hline
C&10 &12&62&52&40\\\hline
D&15 &10&72&57&47\\\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}{Numerical Example - SJF}
\begin{itemize}
\item SJF: running order will be: A(30) D(10) C(12) B(20)
\end{itemize}
AT : Arrival Time ; BT : Burst Time\\
CT : Completion Time; TAT : Turnaround Time\\
WT : Waiting Time
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}\hline
&AT &BT &CT&TAT&WT\\\hline
A&0 &30&30&30&0\\\hline
B&5 &20&40&35&15\\\hline
C&10 &12&52&42&30\\\hline
D&15 &10&72&57&47\\\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}{Numerical Example - SRJF}
\begin{itemize}
\item SRJF: running order will be: A(5) B(5) C(12) D(10) B(15) A(25)
\end{itemize}
AT : Arrival Time ; BT : Burst Time\\
CT : Completion Time; TAT : Turnaround Time\\
WT : Waiting Time
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}\hline
&AT &BT &CT&TAT&WT\\\hline
A&0 &30&72&72&42\\\hline
B&5 &20&47&42&22\\\hline
C&10 &12&22&12&0\\\hline
D&15 &10&32&17&7\\\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}{Priority Scheduling}
\begin{itemize}
\item A priority number (integer) is associated with each process
\item The CPU is allocated to the process with the highest priority (smallest integer is equivalent to highest priority)
\begin{itemize}
\item Preemptive - higher priority process preempts the running one
\item nonpreemptive
\end{itemize}
\item SJF is a priority scheduling where priority is the predicted next CPU burst time
\item Problem : Starvation – low priority processes may never execute
\item Solution : Aging – as time progresses increase the priority of the process
\end{itemize}
\end{frame}
\begin{frame}{Priority Scheduling - Example}
\begin{center}
\begin{tabular}{|c|c|c|c|}\hline
&AT &CPU Burst &Priority\\\hline
A&0 &20&3\\\hline
B&5 &15&2\\\hline
C&10 &20&0\\\hline
D&25 &15&1\\\hline
E&30 &20&1\\\hline
\end{tabular}
\end{center}
\textbf{Nonpreemptive priority scheduling: AAAACCCCDDDEEEEBBB} \\
assuming each letter is 5 time units\\
Completion times: A: 20, B: 90, C: 40, D: 55, E: 75
\textbf{Preemptive priority scheduling: ABCCCCDDDEEEEBBAAA}\\
Completion times: A: 90, B: 75, C:30, D: 45, E: 65
\end{frame}
\begin{frame}{Round Robin (RR)}
\begin{itemize}
\item Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue
\item If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units
\item Performance
\begin{itemize}
\item q large $\implies$ FIFO
\item q small $\implies$ q must be large with respect to context switch, otherwise overhead is too high
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Example of RR with Time Quantum = 4}
\begin{figure}
\centering
\includegraphics[width=0.70\textwidth]{rr_tq_4.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Example of RR with Time Quantum = 20}
\begin{figure}
\centering
\includegraphics[width=0.70\textwidth]{round_robin.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Time Quantum and Context Switch Time}
\begin{figure}
\centering
\includegraphics[width=0.70\textwidth]{time_quantum.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Turnaround Time Varies With The Time Quantum}
\begin{figure}
\centering
\includegraphics[width=0.65\textwidth]{turnaround.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Multilevel Queue}
\begin{itemize}
\item Ready queue is partitioned into separate queues:foreground (interactive) and background (batch)
\item Each queue has its own scheduling algorithm
\begin{itemize}
\item foreground – RR
\item background – FCFS
\end{itemize}
\item Scheduling must be done between the queues
\begin{itemize}
\item Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation
\item Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80\% to foreground in RR
\item 20\% to background in FCFS
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Multilevel Queue}
\begin{figure}
\centering
\includegraphics[width=0.70\textwidth]{multilevel_queue.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Multilevel Feedback Queue}
\begin{itemize}
\item A process can move between the various queues; aging can be implemented this way
\item Multilevel-feedback-queue scheduler defined by the following parameters:
\begin{itemize}
\item number of queues
\item scheduling algorithms for each queue
\item method used to determine when to upgrade a process
\item method used to determine when to demote a process
\item method used to determine which queue a process will enter when that process needs service
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Example of Multilevel Feedback Queue}
\begin{itemize}
\item Three queues:
\begin{itemize}
\item Q0 – RR with time quantum 8 milliseconds
\item Q1 – RR time quantum 16 milliseconds
\item Q2 – FCFS
\end{itemize}
\item Scheduling
\begin{itemize}
\item A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.
\item At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Multilevel Feedback Queue}
\begin{figure}
\centering
\includegraphics[width=0.65\textwidth]{multilevel_feedback_queue.pdf}
%\caption{Process created during execution of a.out}
\end{figure}
\end{frame}
\begin{frame}{Multiple-Processor Scheduling}
\begin{itemize}
\item CPU scheduling more complex when multiple CPUs are available
\item Homogeneous processors within a multiprocessor
\item Load sharing : Preserve locality of data and state
\item Asymmetric multiprocessing – only one processor accesses the operating system data structures, alleviating the need for kernel data sharing among processors
\item Some cooperative processes like to run with n processors or none at all : Gang scheduling to assign group of processors
\end{itemize}
\end{frame}
\begin{frame}{Real Time Scheduling}
\begin{itemize}
\item Hard real-time systems – required to complete a critical task within a guaranteed amount of time
\item Soft real-time computing – requires that critical processes receive priority over less fortunate ones
\item In both cases, RT behaviour is achieved by dividing the program into number of process, each of whose behaviour is predictable. When an external event is detected, it is the job of the scheduler to schedule the processes in such a way that all deadlines are met.
\item The events a RT system has to handle are \textbf{periodic}(occuring at regular intervals) or \textbf{aperiodic}(occuring unpredictably)
\item If there are \emph{m} periodic events and event \emph{i} occurs with period \emph{$P_{i}$} and requires \emph{$C_{i}$} seconds of CPU to handle each event, then the load can be handled if $\sum_{i=1}^{m}{\frac{C_i}{P_i}} \leq 1$ - \textbf{schedulable} RT system
\end{itemize}
\end{frame}
\end{document}