6d832479969711ae6444c9201f5faf28.ppt
- Количество слайдов: 166
BU CAS CS-350 Fundamentals of Computer Systems N M ER SP IO ISS R’ HO T U T OU ITH EA TH Fall 2002 E UT RIB W T IS Prof. Abdelsalam ‘Solom’ Heddaya RD YO E, US T P CO www. cs. bu. edu/fac/heddaya/course/cs 350 NO O E PL ED AS This is a Hypertext Document Click on Icons and Links to View in Full 2002 -10 -29 1
Course Intro M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 2
Today’s Agenda • People – Instructor, TF, students • Resources N – Web site M ER SP – Mailing list • Course description and role • Next O ITH W E UT class: review of computer TRIB system IS D OR PY CO E, US T NO O ED AS LE P 2002 -10 -29 R’ HO T U – Solving practical system problems using maths T U • Course organization and policies IO ISS EA TH organization 3
People • Instructor: Abdelsalam ‘Solom’ Heddaya – Chief Technology Officer and co-founder of Info. Libria, Inc. (www. infolibria. com) – Adjunct Associate Professor, BU CS Dept. – Nine years as full-time professor, and five years as entrepreneur SION IS RM – Helped conceive cs 350 as a new unique course in 1996/97 PE • Teaching fellow: Gali Diamant T – Ph. D. student – Additional info soon E UT RIB • Students… ’S OR H T OU ITH AU HE T W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 4
Resources • Web site – www. cs. bu. edu/fac/heddaya/course/cs 350 • Mailing list N – Will be used for last-minute announcements (e. g. , homework corrections) SIO IS M ER SP – cs 350@cs. bu. edu – Join by following instructions • Office hours • R’ HO T U EA TH T OU TH – Prof. Heddaya: TR 3: 30 -4: 00 pm, or by appointment WI E UT – Gali Diamant: TBA RIB ST I Grades RD YO OP the web site, under a secret ID that you will choose as – Will be posted regularly. Con E, U part of homework. T#1 S NO O ED AS E PL 2002 -10 -29 6
CS-350 in a Nutshell • About – Modeling systems, so as to think about them – Thinking about systems helps us understand existing ones, and design new ones – Focus on most difficult problems • • Performance: how to keep key resources busy and responding quickly. M ER SP • Concurrency: how to keep track of many things happening at OR’ once TH AU NOT about HE T UT O – Programming ITH W – Theory TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 N IO ISS 7
Role of CS-350 (See CS Course Map) • CS-350 builds on – Computer systems organization (CS-210) – Algorithms and data structures (CS-112) N – Discrete Maths (MA-293) M ER SP • CS-350 prepares for – Performance Analysis (CS-470) – Databases (CS-560) – Architecture (CS-450/550) R’ HO T U – Operating Systems (CS-552) – Networking (CS-555/556) IO ISS E UT RIB T OU ITH EA TH W T DIS R YO O • Jobs in which these skills. P come in handy , C SE – System designer, Oarchitect, CTO, etc. TU N O – Researcher, academic, consultant ED S EA PL developer, product manager, performance engineer, etc. – Software – Market analyst, journalist, etc. • Where does CS-350 fit in “The Big Picture™”? 2002 -10 -29 8
Organization of CS-350 • Review of course syllabus – www. cs. bu. edu/fac/heddaya/course/cs 350 N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 10
Extra Stuff M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 12
A Flavor of CS-350 • System – A collection of interacting parts, together with, – A demarcation between system and its environment (an interface) N • Typically represents a narrow interface, but, M • Arbitrary nonetheless ER SP IO ISS • System quality metrics (looking from the outside)THOR’ U – Safe, secure – Available, reliable – Fast • E UT RIB T OU ITH EA TH W T • Throughput (work done per second) DIS • Response time (time required R finish one task) Y O to OP C – Efficient (consumes minimal resources) E, S TU System quality O NO metrics (looking inside) D E – Cheap to AS E build PL – Cheap to maintain – Elegant 2002 -10 -29 13
Where does the System End and “I” Start? • Machine is obedient slave to its human master • An alternative model – • Isaac Asimov’s Three Laws of Robotics (see “I, Robot”, a collection of short stories written in the 1940 s and 50 s and still in print) ION SS MI 1. A robot may not injure a human being, or, through inaction, allow. Ra human being to PE come to harm. ’S OR TH 2. A robot must obey the orders given it by human beings, U except where such orders would EA conflict with the First Law. H TT O 3. A robot must protect its own existence, except. Uwhere such protection would conflict ITH W with the First or Second Law. TE IBU Shouldn’t the human be considered part of the “system”? TR IS RD – Important in designing safe systems, because YO OP – Enables accounting. SE, Chuman error as a sub-system failure to be handled by of U overall system OT N DO – Also, allows for accounting for human response times as part of overall system SE EA PL performance 2002 -10 -29 14
Hurry Up and Wait: Modeling Queues N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 15
Today’s Agenda • Administrivia 1. A simple model: the queue 1. Discover: throughput, response time and waiting capacity N 2. Laws: M ER SP 1. Flow Conservation 2. Little’s Law IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 16
Administrivia • Web site • Mailing list • Policies N – Please read; will be frozen next Friday M ER SP – Email me comments on policy NOW • Section schedule change: EA TH E T IBU R • Mon – 11 -12 (current) – 3 -4 • Fri 2002 -10 -29 R’ HO T U – Instead of 3 sections, we can only have two UT O ITH – Proposed time slots—any two of: W – – – IO ISS P SE 12 -1 T DIS R YO U OT O , C N O 2 -3 (current) ED S 3 -4 A LE (current) P 17
Modeling with Queues • Simple • Widely applicable to quantitative aspects of system performance • Susceptible to easy, back-of-the-envelope analysis N – Yet, extremely robust results that are widely applicable • Can also be analyzed probabilistically – More difficult later in course M ER SP IO ISS R’ HO T U EA TH – Yields more detailed information (probability UT distributions, not just averages) HO – Less robust results (depends on somewhat. IT W fragile assumptions) E T IBU R T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 18
Single Queue System Queue Server Departures at Arrivals at mean rate = N Task • Tasks arrive at an average rate = T OU ITH mean MISSIO rate R PE ’S OR TH U EA TH = . Service rate = W TE • Tasks wait in the queue until it is their. U IB return TR IS – Doesn’t matter how turn is determined RD YO – Average number of tasks waiting = w OP , C – Average number of tasks. Ewaiting and being serviced = q S TU • Server performs O NO work required by the task, at an average = the D – Server is not E AS busy all the time LE P – Average fraction of time server is busy = • Tasks depart, after being serviced, at an average rate = ? – When server is busy, average departure rate = ? – When server is idle, average departure rate = ? 2002 -10 -29 19
Flow Conservation Law Queue Server Departures at mean Arrivals at mean rate = N SIO rate IS . = RM PE ’S R HO T • Flow-conservation law E UT RIB T OU ITH AU HE T = Service rate = W T DIS R YO – Over a sufficiently long COP , period of time, we must have SE E PL 2002 -10 -29 O ED AS N U Mean departure rate = Mean arrival rate =, and OT Mean departure rate Mean service rate = 21
Little’s Law Queue Server Departures at Arrivals at mean rate = T N SIO mean. Mrate IS R PE ’S R HO • Glossary E UT RIB – Mean arrival rate = – Mean service rate = T OU ITH AU HE T = Service rate = W T DIS R YO P C – Mean number of tasks. Oin queue = w E, S U – Mean response OT N time = tq O • Little’s 2002 -10 -29 ED AS law E PL 23
Why Little’s Law is True • We can informally derive Little’s Law as follows 1. The average amount of time that a task can expect to wait is the time it takes for all the tasks that are already waiting ahead of it to depart from the system • • This obviously true of the queuing discipline is FIFO (First-In First-Out) N SIO if the Even if the queue is not FIFO, this would still have to be true on average, since IS RM waiting time for one task is made smaller by the queuing discipline PE selecting it out of FIFO R’S order, then the waiting time for some other task (or tasks) would end up increasing O TH correspondingly AU HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 24
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 25
Today’s Agenda • Administrivia – HW 1 out: electronic hand-in tentative until confirmed by email 1. Computer Organization—a review N 1. Core hardware M ER SP 2. Processor-memory-I/O interactions 2. Improving CPU utilization (efficiency) 1. Using interrupts • T OU TH 2. Using memory caching (probably next class) WI E UT RIB ST I Next class: from program to Dprocess R YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 IO ISS R’ HO T U EA TH 26
The Core Hardware Simplified model • PSR Works only for single straight-line program What’s missing? N • • I/O management • Memory management • M Subroutine support Multi-tasking support ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL O ED AS U OT O , C N PSR = 2002 -10 -29 Program Status Register 27
The Basic Instruction Cycle N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W 1. CPU fetches the next instruction. IST D (with operands) from memory R O 2. Program Counter (PC) incremented PY CO , instruction in memory (assumes sequential program) • To point to subsequent SE TU N instruction 3. CPU executes the O DO SE • Instruction applied to operands stored in registers (after possibly having been fetched from EA PL memory in step 1) • Instruction may be conditioned on the value of certain bits in Program Status Register (PSR) • The instruction may modify the Program counter (PC), so as to cause the CPU to execute an instruction that is out-of-sequence 2002 -10 -29 28
Basic Control & Status Registers • Program Counter (PC) – Contains the address of the next instruction to be fetched • Instruction Register (IR) N – Contains the instruction most recently fetched M ER SP • Program Status Register (PSR) – condition codes and status info bits – Interrupt enable/disable bit – Supervisor(OS)/user mode bit • Data Registers • E UT RIB IO ISS R’ HO T U T OU ITH EA TH W T DIS – Store instruction operands and results R YO – Can be copied from/to COP memory locations , SE Address Registers. OT U N DO – Contain memory address of data and instructions SE EA a portion of an address that is used – May contain PL to calculate the complete address 2002 -10 -29 29
Memory Addressing Modes • Direct – MAR gives the absolute physical memory address of the desired item • Indirect N – MAR contains the absolute address of a memory location that contains the SIO IS RM absolute address of the desired item PE • Indexed • • ’S OR H T AU – MAR provides an index value to be added to a base. Evalue to get the absolute H TT U memory address HO IT EW Segment pointer T IBU R – When address space is divided into segments, memory is referenced by a segment IST D O segment number and an offset in that R PY CO E, Stack pointer US T NO – Points to top of stack O ED – Instruction. S or register provides an offset (usually small) EA PL – For subroutine entry/exit (Appendix 1 B) 2002 -10 -29 30
Must CPU Wait for I/O to Complete? Example • WRITE transfers control to the printer driver (I/O pgm) • I/O pgm prepares I/O module for printing (4) N M ER SP • CPU has to WAIT for I/O command to complete • I/O pgm finishes and reports status of operation • CPU wastes much time waiting E UT RIB IO ISS R’ HO T U T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 31
Interrupts • Invented to allow overlap of input and processing times • CPU launches I/O, returns to processing and then gets interrupted when I/O completed N • The I/O module sends an interrupt request – Via a direct connection, or via a control bus • M ER SP IO ISS R’ HO T Then CPU transfers control to an Interrupt Handler Routine AU E part of the OS) TH T OU TH WI E UT RIB ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 (normally 32
Interrupt Handling • Similar to subroutine call but not controlled by user program N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N User program must restart as if there was no interruption 33
Instruction Cycle with Interrupts N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T • If interrupts are enabled, CPU checks for interrupts after each instruction DIS R O • If no interrupts, then fetch the next instruction for the current program PY O , C • If an interrupt is pending, then suspend execution of the current program, and SE TU execute the interrupt handler (in the OS) NO O ED • Note: AS E PL – Disabling interrupts should be done only when really necessary, because it can cause loss of information. 2002 -10 -29 34
Interrupt Handler • Is a program that determines nature of the interrupt and performs whatever actions are needed • Upon interrupt, control is transferred to this program N – This is done by transferring control to a memory location that is determined by SIO S the type of interruption, according to an interrupt vector (table)I RM E • • P R’S so that it can be – Control must be transferred back to the interrupted program O TH resumed from the point of interruption AU HE T The point of interruption can be anywhere T the program (except where U in O ITH interrupt explicitly inhibited) W TE IBU Thus TR IS R D (content of PC + PSW + registers +. . . ) – Must save the state of the Y O process OP C – Where can this be done? E, S TU NO O ED AS E PL 2002 -10 -29 35
Interrupts improve CPU usage • I/O pgm prepares the I/O module and issues the I/O command (eg, to printer) • Control returns to user pgm N • User code gets executed during I/O operation: no waiting • User pgm gets interrupted (x) when I/O operation is done M ER SP IO ISS R’ HO T U UT O • Control goes to interrupt handler to ITH W check status of I/O module and TE IBU perform necessary processing TR EA TH IS RD • Execution of user code resumes YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 36
Types of Interrupts • Not normalized, but it is a good idea to distinguish between: – traps or exceptions: caused by the pgm as it executes • division by 0 • illegal access N • system calls. . . M ER SP R’ HO T – interruptions: caused by independent events: • end I/O • timers • IO ISS U EA TH T OU TH – faults: term used esp. in connection with paging and segmentation WI E UT But the hardware mechanisms TRIB similar for all are IS D OR PY CO E, US T NO O ED AS LE P 2002 -10 -29 37
Multiple interrupts: sequential order N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T • Disable interrupts during an interrupt DIS R O • Interrupts remain pending until the processor enables interrupts PY O , C E • After interrupt handler. Sroutine completes, the processor checks for additional TU interrupts NO O ED AS E PL 2002 -10 -29 38
Multiple Interrupts: priorities N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T • Higher priority interrupts cause lower-priority interrupts to wait DIS R O • Causes a lower-priority interrupt handler to be interrupted PY • Example O C E, US T N from communication line, it needs to be absorbed quickly to avoid – When input arrives O O E retransmission D AS LE P • This requires a stack mechanism to save registers, etc. 2002 -10 -29 39
Long I/O • Normally I/O is very long with respect to I/O processing • N SIO if In this case, the program and the CPU will have to wait even IS RM PE concurrency between I/O and CPU processing ’S OR TH AU HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 there is 40
Extra Stuff N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 41
Multiprogramming • Allows better use of I/O overlap times • When a program reads a value on an I/O device it may wait long time for the I/O operation to complete – It can be difficult to use this waiting time N M IO ISS ER • So interrupts are mostly effective when a single CPU is Pshared among S R’ several concurrently active processes HO T • AU HE The CPU can then switch to execute another. Tprogram T waits for the result of the read operation. OU TH WI E UT RIB ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 when a program 42
Memory Hierarchy N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 43
Cache Memory • Small fast cache – Interacting with slower but much larger memory • Transparent (invisible) to OS and user programs N M ER SP – But interacts with other memory management hardware T OU ITH – If word referenced is in cache E UT – A block of main memory containing the. RIB T DIS word is moved to the cache R YO P CO E, US T NO O ED AS LE P 2002 -10 -29 R’ HO T U • Processor first checks • If not found in cache IO ISS EA TH W 44
The Hit Ratio • Hit ratio = – Fraction of access where data is in cache • T 1 = – Access time for fast memory N • T 2 = M ER SP R’ HO T – Access time for slow memory U • T 2 >> T 1 • Vertical axis = – Average access time • When hit ratio is close to 1 IO ISS E UT RIB T OU ITH EA TH W T DIS – Average access time is close to T 1 R YO P CO E, US T NO O ED AS LE P 2002 -10 -29 45
Locality of Reference • Memory references for both instruction and data tend to cluster over a long period of time • Example N – Once a loop is entered, there is frequent access to a small set of instructions SIO RM PE S – Similarly, data is usually accessed in sequence • Hence • IS R’ HO T U EA TH T OU – Once a word gets referenced, it is likely WITH nearby words will get referenced that E T often in the near future IBU R IST 1 even for a small cache Thus, the hit ratio will be close to D OR PY CO E, US T NO O ED AS LE P 2002 -10 -29 46
Disk Cache (Same Idea) • A portion of main memory used to temporarily hold data from/to disk • Locality of reference also applies here – Once a record (or portion of a file) gets referenced, it is likely that nearby records will get referenced often in the near future ION SS I RM • If a record referenced is not in the disk cache, the block containing the PE ’S OR record is moved into the disk cache TH U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 47
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 48
Today’s Agenda • Administrivia 1. From program to process 2. Process states and transitions (basic model) 3. • N SIO Swapping processes out of memory improves memory utilization IS RM PE Next class ’S OR TH – My system is better than yours: system quality attributes AU HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 49
From Program to Process • Process – Life is to program as is to DNA N • Processes, their structure, behavior and interactions are. RM PE – The focus of computer system design and analysis • A process is a program execution E UT RIB – A. k. a. task • Types of processes T OU ITH IO ISS ’S OR H T AU HE T W T DIS R YO P SE O , C U – Finite-duration processes (ordinary programs) OT N DO – Infinite processes SE EA • Servers, daemons PL – User processes – OS (kernel) processes 2002 -10 -29 50
When Does a Process Get Created? • Submission of a job • User logs on • Created by OS to provide a service to a user N – Examples: printing M ER SP • Spawned by an existing process IO ISS R’ HO T – A user program can dictate the creation of a number U processes A of E TH T E UT RIB U HO IT W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 51
When Does a Process Get Terminated? • User logs off • Process executes a system call to terminate N M ER SP • Error or fault conditions, timeout IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 52
There Can Be Many Processes • Many processes tend to run “simultaneously”, even on uni-processor machines • Multiple processes could be created from the same program N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 53
How a Process is Created 1. Program R memory image (binary) is stored in a file – Result of compilation 2. Another process asks the OS kernel to execute R N • Via a special system call (exec in Unix) M ER SP 3. Kernel allocates memory for a new process P • Can be physical or virtual memory IO ISS R’ HO T U EA TH 4. Kernel creates Process Control Block (PCB) for P UT • Holds information about P, including 5. 6. O ITH W TE • State (for scheduling purposes) RIBU T D • Identity (for security purposes) IS R YO • Resources (for resource P management purposes) CO E, US Kernel copies R from file to memory of process P T NO O Kernel transfers control to the first instruction in ED AS LE P 2002 -10 -29 P 54
Issues in Process Creation 1. How does the executable program R get created in the first place? 1. What if R belongs to an interpreted language? • Such as PERL, Java, Lisp, etc. 2. What if R doesn’t contain all the code necessary for P? N IO ISS • Typical case; otherwise executables would have to include the huge libraries RM PE that they need to run ’S 3. 4. 5. 6. OR TH What if R can only run correctly if it runs in isolation? AU HE a life-critical device T • For example, R is a real-time program that controls UT O What if N processes are created from ITH same program R? the W TE • Should they consume N times the Imemory? BU TR IS Is it useful to group processes, so that a single program execution RD YO create multiple communicating processes? OP C E, U allowing the proliferation of processes? What is the cost of S OT N 1. Are there light-weight processes with low “overhead”? DO SE EA PL could • For answers, take CS-552 Operating Systems – Prof. Rich West 2002 -10 -29 55
Process States • Running state – The process that is executing on the CPU is in Running state • Blocked state – A process that is waiting for something (e. g. , I/O) to complete is ISSION in Blocked state • Ready state M ER SP ’ OR H(due to limited number of T – A process that is ready to be executed is in Ready state AU E CPUs) TH T OU TH WI E UT RIB ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 56
Other Useful States • New state – OS has performed the necessary actions to create the process • Has created a process identifier • Has created tables needed to manage the process N IO ISS M – But, has not yet committed to execute the process (not yet admitted) ER ’S OR H • Because resources are limited P T U – Long-term scheduler takes this admission control decision EA H T UT O ITH • Exit state – Termination moves the process to this. Tstate EW IBU R – It is no longer eligible for execution IST D OR – Tables and other info are PY temporarily preserved for auxiliary program CO • E. g. , accounting program that cumulates resource usage for billing the users E, US T NO DO E (and its tables) gets deleted when the data is no longer needed – The process AS LE P 2002 -10 -29 57
A Five-state Process Model N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 58
Process State Transitions [1/4] • New Ready (a. k. a admit) – Long-term scheduler decides that the process can be executed N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 59
Process State Transitions [2/4] • Ready Running – The scheduler selects a new process to run (discussed later in course) • Running Ready – The running process is timed out N SIO – The running process gets interrupted because a higher priority process is MIS the ready state in ER P (needs to run) R’S • Or because compute-hungry process exhausted its fair share of CPU THO AU HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 60
Process State Transitions [3/4] • Running Blocked – When a process requests something for which it must wait • A service of the OS that requires a wait • An access to a resource not yet available • Initiates I/O and must wait for the result • Waiting for a process to provide input (IPC) N M ER SP • Blocked Ready R’ HO T U – When the event for which it was waiting occurs E UT RIB IO ISS T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 61
Process State Transitions [4/4] • Running Exit – Process executes system call to exit – Process killed by some external action (user, parent, OS) N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 62
A Queuing Model N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL O ED AS U OT O , C N • Queue Ready: processes waiting to get executed on CPU • When event n occurs, the process that was waiting for it is moved into the Ready queue 2002 -10 -29 63
Variations on the Basic Model • The basic model we have discussed is very widely used • It has a great number of variations, since no two OS’s are alike • An example follows N – Adding swapping states M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 64
Swapping Improves Memory Utilization • So far, all the processes had to be (at least partly) in main memory • Even with virtual memory, keeping too many processes in main memory will deteriorate the system’s performance – E. g. , coexistence of several processes that do not use CPU much SION IS M • The OS may need to suspend some processes to bring S PEothers in R • R’ HO – That is, to swap them out to auxiliary memory (disk) UT EA TH T OU TH We add 2 new states, which double Blocked and Ready: WI E UT – Blocked Suspend RIB ST swapped out to disk • Blocked processes which have R DI been O PY – Ready Suspend CO E, • Ready processes T US have been swapped out to disk which NO O ED AS E PL 2002 -10 -29 65
A Seven-state Process Model N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 66
New State Transitions • Blocked Suspend – When all processes are blocked, the OS may remove a blocked process to bring a ready process in memory • Blocked Suspend Ready Suspend N – When the event for which process has been waiting occurs PERM S • Ready Suspend Ready – When no ready processes in main memory • IO ISS R’ HO T U EA TH T OU --> Blocked suspend for another – Normally, this transition is paired with Blocked TH WI process (memory space must be found)E T IBU R Ready Suspend IST D OR – When there are no blocked. Yprocesses and must free memory for adequate P CO performance E, US T NO O ED AS LE P 2002 -10 -29 67
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 68
Today’s Agenda • Administrivia 1. System quality attributes 1. As black box N 2. As white box M ER SP 2. System quality metrics 1. Measurable, objective, and quantifiable E UT RIB 1. Analysis R’ HO T U 3. System quality determination 1. Modeling IO ISS T OU ITH EA TH W T DIS R YO 2. Simulation P 2. Measurement SE U OT O , C N • Next time: intro to probability DO SE EA PL 2002 -10 -29 69
What is a “System”? • What is the difference between a system and a pile of components? – A jumble of lines of code vs. an OS kernel • System – A collection of interacting parts, together with, N SIO IS – A demarcation between system and its environment (an interface) RM E ’S OR H • Typically represents a narrow interface P T – Each part is itself a system (whose internals we don’t. Ucare about) A • System environment • • • E TH T U HO – Everything that is not inside the system, WIT including human users and other systems TE IBU System behavior (a. k. a. functionality) TR IS RD – Interactions with its environment YO OP – What happens inside the system is not behavior C E, S T System correctness U NO O – System’s behavior falls within specification (or at least expectation) ED AS E PL System failure – System violates its specified (or expected) behavior 2002 -10 -29 70
System Quality Attributes • System as a black box (looking from outside) – Safe, secure, private – Available, reliable N – Fast M ER SP • Throughput (work done per second) • Response time (time required to finish one task) R’ HO T U – Efficient (overhead consumes minimal resources) HE A • IO ISS T UT • Scalable (performance improves with added resources) O ITH W – Domain of cs-350 TE IBU TR System as a white box (looking. ISinside) D OR – Easy to build (i. e. , cheap PY develop) to CO – Easy to maintain (i. e. , , cheap to own and to improve) SE TU NO – Elegant, beautiful (i. e. , pleasing to build and maintain) O ED A – Domain. Lof Ssoftware engineering E P 2002 -10 -29 71
System Quality Metrics [1/4] Attribute Safe Metric Safety Definition System behavior never harms its environment, even when it fails. Examples: Secure, Private E PL 2002 -10 -29 N IO ISS RM PE 1. Application executes an illegal instruction or ’S OR H references protected memory UT EA TH Immunity Each type of attack T yields a different definition. U O against Examples of attacks: ITH W attack (a. k. a. TE 1. Eavesdropping: attacker obtains fully-detailed copy IBU security) TR S of Ivictim’s information RD YO OP 2. Spoofing: attacker tricks victim into accepting C E, information as from a particular source S TU NO 3. Denial-of-service: attacker prevents victim from O D E offering or receiving service AS 4. Timing: attacker detects activity by victim (weaker form of eavesdropping) 72
System Quality Metrics [2/4] Attribute Available Metric Availability Definition Reliable Fraction of time system is up (i. e. , can accept requests for service) ON Reliability SE E PL O ED AS N U OT I ISS • Typically expressed in percentage. M(e. g. , 99. 999%) ER SP • Better expressed as (1 -10 -A), ’i. e. , as the “number of OR TH 9’s” AU HE • More important UT T short-duration services (what for O TH should the availability of the email server be? ) WI E UT RIB ST I RD Length of time system is up (i. e. , can sustain a long O PY -running activity) O , C • Mean Time between Failures (MTBF) is a common statistic for this metric • More important for long-duration services (what should the MTBF of a space probe be? ) • Availability = MTBF/(MTBF+MTTR) 2002 -10 -29 73
System Quality Metrics [3/4] Attribute Fast Metric Throughput Definition Number of units of work completed per unit time Examples N IO ISS 1. A CPU capable of 2, 000 MIPS RM PE ’S 2. A disk capable of 140 MBps (MB/s) OR TH Uof 2, 000 OPS 3. A web server capable EA TH 4. A network link T U capable of 2. 5 Gbps (Gb/s) HO IT Response time Length of E W a unit of work remains in the time T IBU before it is completed system R IST D Examples OR PY CO 1. A disk drive that completes an I/O in 11 , SE U milliseconds OT N O 2. A web server that completes an operation in 20 ED S EA PL milliseconds 3. A network that can transmit a packet in 80 milliseconds from Boston to San Francisco 2002 -10 -29 74
System Quality Metrics [4/4] Attribute Efficient Metric Definition Utilization (a. k. a. efficiency) Fraction of time a resource is busy (doing useful work) Y Scalability. E, US E PL 2002 -10 -29 O ED AS N OT P CO N SIO Alternatively: fraction of theoretical peak capacity IS RM PE that can be utilized ’S OR Examples TH AU HE the CPU busy 80% of the time 1. An OS that can. Tkeep T U O 2. A file system that can keep the disk busy 70% of ITH W the time) TE U RIB Tcommunication protocol that can run a network S 3. DIA R O link at 50% of capacity Utilization as a function of peak theoretical capacity (amount of resources) Examples 1. A database server that can utilize one node at 80%, two nodes at 75%, three nodes at 70% 75
System Modeling Big Picture N M ER SP Workload E UT RIB T OU ITH W T DIS R YO R’ HO T U EA TH System Model IO ISS Metric = f(workload, resources) P SE E PL 2002 -10 -29 O ED AS N U OT O , C Resources 76
System Quality Determination • Modeling 1. Analysis (requires model to be mathematically tractable) • Analyze for the functional forms of the relevant metrics, as functions of N amount of resources and of load characteristics SIO • IS RM • Compute (by software) the value of relevant metrics numerically PE ’S – Can generate functional forms in the form of tables HOR T AU E 2. Simulation TH UT • Measure the value of relevant metrics, HO running the model and then by IT directly measuring the metrics TE W IBU • May use synthetic or real workloads to drive the simulation TR IS RD • Requires model to be Y O effective and efficient, such that experimenting with OP better and cheaper than with the system itself C the simulator is faster, E, S TU O Measurement. N(requires some modeling) O ED A (in 1. In vitro S the lab, under synthetic or real workload) E PL 2. In vivo (in the field, under real workload) 2002 -10 -29 77
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 78
Today’s Agenda • Administrivia – Readings (by A. Bestavros) available via web site (UID and password sent by email) 1. Probability N M 1. What is it? What can it model? ER SP IO ISS ’ 2. An example: what is the probability that two people THOR the same birthday, in have U a class of N students? EA H 2. Definitions T UT O ITH 3. Composing events E UT RIB W 1. A or B (a. k. a. union, disjoint) IST D 4. 5. R Y O joint) 2. A and B (a. k. a. intersection, P CO E, 3. A given B (a. k. a. conditional) US T NO O Random variables ED AS LE Distributions P • Next time: More probability 2002 -10 -29 79
Probability—What is it? • A mathematical construction – Can be studied in total isolation of the real world • Models uncertainty (ignorance), as well as randomness N I • Useful primarily for large populations (the larger the better), Oor long ISS RM histories (the longer the better) PE S • R’ HO to gamble? – What happens if you use probability modeling and analysis T AU E TH Strongly related to counting T OU TH WI E UT RIB ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 80
Example—Probability of Same-day Birthdays • Given a class with N students in it, what is the probability that two students have the same birthday? – The answer, for N = 29, may surprise you • Odds? N – The answer for N = 367, should not surprise you M ER SP • Approach – Solve for N = 2 IO ISS R’ HO T U T EA TH – Count the total number of possible birthday OU H lists IT E W with two or more identical birthdays – Count the number of possible birthday. T lists IBU (call these lists the birthday coincidence, or BC, lists) TR DIS Rbirthday lists is equally likely – Assume that every one of the YO OP , C – Find the frequency of. Ethe event that a list is a BC list S TU NO O ED AS E PL 2002 -10 -29 81
Same-day Birthdays • N=2 – Answer = 1/365 (why? ) • Total number of possible birthday lists N = 365 N RM IO ISS E • Number of possible birthday lists with two or more (up Pto N) repetition ’S = total – number of birthday lists with no repetition = • - 365 x 364 x 363 x … x (365 -N+1) = • 365 N - 365! / (365 -N)! OR H UT EA TH T U HO IT W TE Assume that every one of the birthday lists is equally likely IBU TR IS RD – That is, we assume that there is no self-selection YO OP – Is this assumption true? C E, US T Probability that two (or more) people out of N have the same NO O N - 365! / (365 -N)! ] / 365 N ED = [365 AS LE P 2002 -10 -29 birthday 82
Same-day Birthdays--Results N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE U OT O , C N DO E • See the raw. EAS table for N = 2 to 100 (requires Microsoft Excel) data PL • Probability is much higher than might be guessed • Is it possible that a class of 79 still has no two who share the same birthday? – What about a much larger class? 2002 -10 -29 84
Key Definitions • Event – An assertion about the state of the world that may be true or false – Alternatively (and equivalently) • The set of possible worlds in which the event is true RM PE R’S • (Assertion) “Two or more students have birthdays that fall on. Othe same day” H UT • (Set) “The set of all possible birthday lists in which …”E A H TT U Probability HO IT – A quantity between 0 and 1 (inclusive) E W is attached to every possible event that T IBU R – Subject to some constraints IST D OR – Models PY CO , • The likelihood of the. Eevent US O • The frequency. Nof. Tthe occurrence of worlds in which the event is true (occurs), among the O set of all E D possible worlds AS E PL – Example: • N IO ISS 2002 -10 -29 85
Combining Events • Logically – OR Universe – AND N • Set operations M ER SP – Union – Intersection UT • Conditional – A given B – Also written as (A | B) R’ HO A E UT RIB T OU ITH EA TH IO ISS A and B B W T DIS – Models removal of uncertainty about B R YO • Because we know that B OP true, or because we want to hypothesize that B is true is , C SE – Bayes’ Law TU NO O Pr[A | B] = Pr[A and B] / Pr[B] ED AS E PL 2002 -10 -29 86
Relationship Between Events • A, B are disjoint (mutually exclusive) iff – There is no world in which both A and B are true • I. e. , the sets do not intersect – We have N M Pr[A or B] = Pr[A] + Pr[B] • A, B are mutually exhaustive iff ER SP R’ HO T U – There is no world in which neither A nor B is true HE A T • IO ISS T • I. e. , the sets cover the whole universe of possible worlds OU TH WI E A, B are independent iff UT IB – There is no causal relationship DISTR between A and B R YO – We have P CO Pr[A and B] = Pr[A] x SE, Pr[B] TU Pr[A | B] = Pr[A] O and vice versa N DO SE EA PL 2002 -10 -29 87
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 88
Today’s Agenda • Administrivia – HW 2 out tonight, due next Thursday in class, at the beginning 1. Random variables N 2. Distributions M ER SP 3. Metrics that summarize distributions 4. Common distributions IO ISS R’ HO T U • Next time: Statistics! E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 89
Random Variables • Examples – – A person’s height – • Student birthday The time I have to wait for the T to arrive N Definition – M ER SP A random variable is an ordinary variable such that 1. Its value is unknown – IO ISS R’ HO T AU The value may be unknown either because we are simply ignorant HEit, or because it is unknowable with 100% of T certainty—it doesn’t mater which T U O 2. We want to reason about the probability of individual values ITH • • • Notation By contrast, in most mathematics and software, we W E write expressions involving variables intending the expressions to UT apply to all possible values B R IST D I R YO P – We will use lower-case for. Orandom variables (e. g. , x) and upper-case for ordinary variable C (e. g. , X) E, US T – We will use U to represent the set of all possible values (i. e. , the universe) NO O ED Usage example AS LE P 2002 -10 -29 90
Probability Distributions • Example 1. The last equation in the previous slide 2. Consider the variable c, representing the result of a coin toss • Universe of possible values = {head, tail} • Pr[c = head] = 0. 5 • Pr[c = tail] = 0. 5 • N M ER SP IO ISS ’ 3. Think of the variable d, representing the a roll of a single die HOR T • Universe = {1, 2, 3, 4, 5, 6} AU E TH • Pr[d = D] = 1/6 T OU 4. How about e, capturing the sum of two dice! ITH W TE 1. See next slide IBU TR Types of distributions IS RD – Probability density function PY O O , C SE fx(X) = Pr[x=X] TU NO – Probability distribution function O ED AS E Fx(X) = Pr[x X] PL 2002 -10 -29 91
Example of Probability Distribution N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 92
Types of Random Variables • Discrete – The set of values is finite – Example N • x is a r. v. whose value can be any integer number from 0 to 10 M • Continuous – The set of values is infinite – Example • ER SP IO ISS R’ HO T U EA TH T OU • x is a r. v. whose value can be any real number from 0 and 10 fx(X) = TH I EW T – Pr[x=X] = zero IBU R • Why? IST D OR • fx(X) = ? PY CO E, • F(X) is more meaningful (easier to interpret) for continuous r. v. ’s US T NO Continuous and discrete distributions O ED AS – Just another way of saying that the r. v. is continuous or discrete! LE P 2002 -10 -29 93
Basic Properties of Distributions N M ER SP IO ISS R’ HO T U E UT RIB • Why? T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 94
Relationship Between Density and Distribution Functions N M ER SP IO ISS R’ HO T U E UT RIB • Why? T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 95
Follow-up on Birthday Coincidence Problem • Algorithm to determine if two people have same birthday – Used by Prof. Kanamori 1. A student says their birthday out loud N 2. If anyone else has the same birthday, they say so, and this concludes the SIO IS algorithm RM E 3. If not, then repeat with a different student • Performance? – P T T AU HE T How many students does it take, given a THOU of N students? class I E UT RIB • Minimum? • Maximum? • Average? – ’S OR H W T DIS R YO OP C What is the probability that x X? E, US • I. e. , what is NO(X) = Pr[x X] Fx T O ED AS LE P 2002 -10 -29 96
Paradox! • For a continuous r. v. , if Pr[x = X] = 0, can fx(X) be different from zero? Answer: definition of fx(X) is slightly different for a continuous r. v. N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 97
Key Metrics N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 98
Meaning of Metrics • Mean – Reflects “center of mass” of cloud of values that the random variable can take • Variance N – Captures how “scattered” around the mean, the random variable. IScan be SIO M ER SP • But, … – Mean can be quite unpopular R’ HO T U EA TH T OU • Example, a dice where the “ 6” face is replaced with a “ 60” TH WI E – Mean becomes 12. 5, even though five of the six equally-likely outcomes are 5 or less! UT IB – Variance describes x 2, not x DISTR R • Cannot compare the value Y Othe variance to the value of the mean of P CO E, US T NO O ED AS LE P 2002 -10 -29 99
Additional Metrics • Median – Reflects the “relative popularity” of different values that the r. v. can take – Is itself a popular metric among the digerati (is this is an English word? ) – Definition ON I SS MI Median(x) = A such that Fx(A) = 0. 5 = Pr[x A] ER SP R’ HO – Can be generalized easily to percentiles • 90 th percentile = B such that Fx(B) = 0. 9 = Pr[x B] • Standard deviation – Comparable to mean and median – Definition W T DIS R YO x = sqrt(var[x]) • Nth Moment E UT RIB T OU ITH T AU HE T P O , C SE – Mathematically useful, poor intuition beyond first and second moments TU – Definition DO NO E[x. N] SE EA PL – Examples: • 1 st moment = mean • 2 nd moment = variance + mean squared 2002 -10 -29 100
Popular Distributions • Uniform • Exponential • Poisson N • Normal M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 101
Popular Distributions—Uniform f N 1/(b – a) M ER SP IO ISS R’ HO T U T OU ITH a F W TE b U RIB X b X T DIS R YO P 1 SE E PL O ED AS a 2002 -10 -29 EA TH U OT O , C N 102
Popular Distributions—Exponential N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL O ED AS U OT O , C N See pp. 2 -3 in Bestavros’ lecture notes 2002 -10 -29 103
Popular Distributions—Poisson N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL O ED AS U OT O , C N See pp. 4 in Bestavros’ lecture notes 2002 -10 -29 104
Popular Distributions—Normal N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL O ED AS U OT O , C N See pp. 5 -6 in Bestavros’ lecture notes (note error in exponent in his notes) 2002 -10 -29 105
Normal Distribution’s Key Properties N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 106
Statistics • Statistics is to probability as practice is to theory • Statistics is to probability as reality is to model • Goal: understand accuracy of our probabilistic models – Model is a r. v. with a particular probability distribution N M ER SP IO ISS R’ HO T – We collect a sample multi-set of values for the r. v. , Ahoping that it is U HE representative enough TT U O – We calculate from the sample multi-set, estimates for the distribution’s ITH W TE parameters (e. g. , for Poisson) BU • RI ST – Now we ask the question, how DI accurate are our estimated parameters? R YO OP C E, S A metric of accuracy: “confidence interval” TU NO O – Probability E D our parameter estimate is within a certain distance from the that AS E exact value of the parameter PL – Keep in mind: we could have chosen the wrong distribution! How can we detect that? 2002 -10 -29 107
Sample Mean and Variance • Consider a sample multiset S=(X 1, X 2, …, XN) – Such that the Xi’s are samples of the r. v. x being modeled • Sample mean (a. k. a. average) N s = 1/N x sum(X 1, X 2, …, XN) RM IO ISS • Sample variance (remember that standard deviation is PE square root) ’S its v 2 = 1/N x sum(X 12, X 22, …, XN • Understanding sampling 2) – OR H UT s 2 EA TH T U HO IT W TE U – The number of possible samples is RIB T huge IS R Dvalue for its mean, variance, and any other – Every sample yields a different O PY Oto calculate (such as? ) metrics we might choose C E, S – (This is key!) We. OT U model the sampling process itself as a random process that can N yields random. Ovariables (each metric is a r. v. ) D SE EA a little like cheating? We still haven’t figured out how good our original • Isn’t L P this probability distribution is, and yet we’re now using a fresh probability distribution to model the probability of us making an error in our original model! – What is the probability distribution of s, the sample mean? 2002 -10 -29 108
Central Limit Theorem • Question restated – What is the distribution of s, the sample mean? N • Central Limit Theorem M IO ISS ER – If the individual samples are independent (i. e. , the values Xi Pare obtained in a S ’ OR way that obtaining one sample value doesn’t affect any. Hother), and, T U EA – If the mean and s. d. of the model distribution are. Hfinite (big if), T T U – Then, the r. v. z = [s – mean(x)]/sd(x) follows. Oa standard normal distribution H T I R YO P R IST D W TE IBU O T O E PL 2002 -10 -29 ED AS NO C E, US 109
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 110
Agenda • Administrivia – Mid-term – Friday 10/11 sections N 1. Confidence intervals M ER SP 2. M/M/1 queue analysis using probability 3. Interpreting results of queueing analysis IO ISS R’ HO T U EA TH • Next time: CPU scheduling algorithms and. Tanalysis OU I EW TH T IBU R T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 111
Confidence Interval • Define an interval around the sample mean [Xa-E, Xa+E] such that we can characterize the probability C that the true mean is within T from the sample mean – Our “confidence” is stronger N • The smaller E is, and, M ER SP • The higher the probability C is IO ISS R’ HO T U T OU ITH • Candidates for E? E UT RIB EA TH W T • Would like the probability (“confidence”) as a function of E DIS R YO P O T O E PL 2002 -10 -29 ED AS NO C E, US 112
Estimating Confidence Intervals • 1. 2. 3. Consider a sample S=(X 1, X 2, …, XN) of a r. v. x Calculate the sample mean Xa of S Calculate the sample standard deviation Xsd By the Central Limit Theorem: N IO ISS 1. The mean of the sample-mean (i. e. , over all possible samples)M ER SP = mean of x R’ HO T 2. The standard deviation of the sample-mean AU E TH = standard deviation of x T OU 3. The distribution of the sample mean (over. Hall possible samples) is normally IT EW distributed UT 4. Assume that R R IST D IB O • The standard deviation of the sample-mean = Xsd PY 5. CO (We know that this is SE, true) not U OT N Confidence interval is given by the two parameters DO follows: ASE E PL C = F( X + E ) – F( X – E ) a C, E, and related as a where F is the (Normal) probability distribution function of the sample mean • E. g. , for C = 0. 95, E = 2 Xsd 2002 -10 -29 113
Reminder: Modeling with Queues and Little’s Law • See slides on this topic N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 114
Little’s Law’s Applicability System N M • ER SP IO ISS Applies to any system, regardless of its internal structure. R’ O H UT EA TH 1. Task conservation (i. e. , tasks cannot be created or destroyed inside system) T OU 2. Mean rates are taken over a “sufficiently long ITH period of time” W E UT RIB ST I In particular, RD YO OP C E, S TU NO O ED AS E PL So long as it obeys: • 2002 -10 -29 115
M/M/1 Queue • Notation – Inter-arrival time distribution / service-time distribution / # servers • M/M/1 means N – Inter-arrival time distribution is memoryless M ER SP – Service time distribution is memoryless – One server IO ISS R’ HO T U • A distribution is memoryless iff, for any T T OU ITH EA TH EW T Pr[ x > X+T I|Ux > T ] = Pr[ x > X ] B R IST D OR Y P SE E PL 2002 -10 -29 O ED AS U OT O , C N 116
Analysis of M/M/1 Queue • We’d like to know the probability distribution of q • Let us model this r. v. as a Markov Process (a. k. a. birth-death process) consisting of N – States, and, M – State transitions R’ HO T • Each state represents a value that q can assume U EA TH T – i. e. , {0, 1, 2, …, } • U HO Each state transition is labeled with the probability IT EW T occurring during a very short period of time h IBU R IST D OR PY CO h h USE, h T NO O D q = ASE 0 q=1 q=2 q=3 LE P h 2002 -10 -29 h h ER SP IO ISS of that transition h h 117
Analysis of M/M/1 Queue—Ctd. h h q=0 q=1 h • • • q=2 h h h q=3 h h ERM ’S OR H N IO ISS P T AU We are looking for Pr[q=Q], where Q = 0, 1, E … H 2, TT U Let’s derive some relationships between these quantities HO IT E W exactly T – Hoping to get enough to compute them all IBU R IST – To simplify notation, let PQ= Pr[q=Q] D OR PY We have CO E, US 1. P 0 = P 0 (1 - h) + T 1 ( h) P NO 2. P 1 = P 0 ( h) O P 1 (1 - h- h) + P 2 ( h) E D+ AS 3. P 2 = PLE( h) + P 2 (1 - h- h) + P 3 ( h) P 1 … 4. P 0 + P 1 + P 2 + P 3 + … = 1 2002 -10 -29 118
Analysis of M/M/1 Queue—Ctd. h h q=0 q=1 h q=2 h q=3 1. P 0 = P 0 (1 - h) + P 1 ( h) E UT 2. P 1 = P 0 ( h) + P 1 (1 - h- h) + P 2 RIB ( h) IST Therefore, P 2 = P 1 = 2 P 0 OR D Y 3. P 2 = P 1 ( h) + P 2 (1 - h- P + P 3 ( h) CO h) E, Therefore, P 3 = T US 3 P 0 P 2 = NO … O ED ASP 2 + P 3 + … = 1 4. P 0 + PLE+ P 1 Therefore, P 0 = 1 - Therefore, Pi = i (1 – ) Therefore, E[q]= /(1 – ) 2002 -10 -29 h h N M ER SP IO ISS R’ HO T U • We have Therefore, P 1 = P 0 h h T OU ITH EA TH W 119
New Lecture M ER SP N IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 120
Agenda • Administrivia – Mid-term next Thursday • Covers material through Tuesday – A (short) HW 3 will go out tonight (by email!)—will be due Monday ION SS RM PE S 1. Interpreting results of queueing analysis 2. CPU scheduling algorithms and analysis • Next time: more CPU scheduling E UT RIB T OU ITH I R’ HO T U EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 121
Interpreting M/M/1 Analysis Results • Our Markov model of an M/M/1 queue yielded – The p. d. f. of the number of jobs in the system • Let’s try to interpret our results – What does P 0 mean? – What does E[q] mean? (see pp. 9 in “Notes on Queueing”) • N M ER SP IO ISS R’ HO – Intuition about the distribution Pi (see pp. 8 in “Notes. Uon Queueing”) T A E Now, let’s forget the model and its analysis, TH come back to our and T OU original system TH WI E – What is the capacity of the system that we should buy, given a certain load? What UT RIB ST is load anyway? I RD YO – What should we do if overload occurs? OP C E, as a FIFO queue? S – Should we run the queue TU O • Or maybe give. Npriority to certain jobs? If so, which jobs? O ED • Would. Ethis be fair? What is fairness anyway? We didn’t talk about it before (remember the AS L first. Pweek of the semester!) 2002 -10 -29 122
Fairness vs. Speed • Fairness can be more important than speed – How so? – Can speed (response time) be improved by sacrificing fairness? N • Interesting queuing disciplines – First-In-First-Out (FIFO) • Seems to be the fairest M ER SP IO ISS R’ HO T AU • Easy to analyze (distributions of w and service time yield response time distribution) HE T UT O – Shortest-Job-First (SJF) ITH W • Minimizes response time, but… TE IBU • Can starve jobs (what does this mean? ) TR IS RD – Highest-Priority-First (HPF)Y O OP • Run lower priority jobs C only if there are spare resources E, US T • Priority can be set based on NO – Inverse DO length (in which case HPF = ? ) job SE Awaiting time (in which case HPF = ? ) E – Job PL 2002 -10 -29 123
Design Alternatives • Queueing discipline (see previous slides) • Queueing topology – Consider k-server queueing system: N Should there be k queues, or one queue? M ER SP R’ HO T • M/M/N queue vs. N of the M/M/1 queues? • See “Notes on Multiple-Server Queueing Systems” IO ISS U EA TH T OUthat jobs belonging to the same – Should there be multiple classes of service, Hso IT EW class are assigned to the same server(s)? T IBU R IST D OR PY CO E, US T NO O ED AS LE P 2002 -10 -29 124
Remember Why We’re Doing CS-350 • Answer important questions such as – Computing System Consumer asks: • • Can I depend on this system (is it reliable enough, available enough, fast enough) for my application? N SIO • How much (capacity) should I buy? IS RM PE • If I share this system, will I be treated fairly? ’S OR TH – Computing System Producer asks: AU HE • What should I optimize (response time, throughput, T fairness, availability, reliability, UT O safety, security, …)? ITH • How should I design my system to do so? TE W BU • How can I make promises about my RI T system (that it is better than someone else’s, or that IS it is sufficient for a given application, or that it will not harm anyone, etc. )? RD YO • How can I objectively determine how my system performs (in vitro in an artificial OP , C environment, and in. SE vivo in reality)? U OT N Develop common language for discussing systems DO SE EA – Quality L P metrics and the associated methods of description, measurement, analysis, and interpretation 2002 -10 -29 125
The Big Picture. TM Real World N M ER SP System R’ HO T U • Modeling E UT RIB • Measurement E PL O ED AS N OT E, US W T DIS R YO OP C T OU ITH EA TH IO ISS • Interpretation • Validation • Planning • Design Model World System Model • Analysis • Simulation 2002 -10 -29 126
Scheduling (A New Topic) • A very general problem • Determine – Who gets what N – How much M ER SP – When – Why IO ISS R’ HO T U • Does this remind you of something else? E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 127
Scheduling of Computing Resources • Kinds of work items scheduled – Processes, tasks, jobs, applications, users, network connections (or flows), … • Types of resources to be allocated N – CPU, main memory, disk, network link M ER SP • Quantities to be doled out IO ISS R’ HO T – Period of time, disk quota, bandwidth allocation, … U A E TH T E UT RIB U HO IT W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 128
Scheduling of Computing Resources Why? • Influences the rate a system delivers its various benefits – Different benefits can have varying importance depending on business models and human values • Examples N IO ISS M – Throughput = amount of work done per unit time (maximize. P$$$ revenue) ER ’S • Efficiency = utilization = fraction of time resource is doing useful work (minimize cost) OR H UT – Response time = time elapsed between submission of request and first response EA TH T (maximize customer satisfaction) OU TH • Turn-around time = completion time = time elapsed between submission of request and WI E completion of job UT RIB ST (minimize customer dis-satisfaction) I • Fairness = equal-access to resources RD O – Deadlines met = fraction PY jobs that meet their deadlines O of C E, S TU NO O ED AS E PL 2002 -10 -29 129
CPU Scheduling • Decide which process takes the CPU – For how long; alternatives range widely: • Until completion (batch) • Until I/O request (simplistic multi-tasking) N SIO IS • Until earlier of I/O request or expiration of its time quantum (true multi-tasking) RM PE ’S • Until higher priority process comes along OR TH – When AU HE T • Non-preemption: when process voluntarily relinquishes CPU UT O • Preemption: process can be kicked-out at any H IT time (based on policy) W TE – Why IBU TR S • Different policies and algorithms Ioptimize different metrics RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 130
The Seven-state Process Model N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 131
Queuing Diagram for Scheduling N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 132
Short-Term Scheduling By L. Logrippo, U Ottawa • Determines which process is going to execute next (most common meaning of “CPU scheduling”) • Is the subject of this chapter • The short term scheduler is known as the dispatcher N RM IO ISS • Is invoked on a event that may lead to choose another PE process for R’S O execution: TH U – Timer interrupts – I/O interrupts EA TH T U HO IT W TE IBU TR I • An OS trap is an interrupt handler. Sthat is invoked by a hardware interrupt that is triggered RD based on an action by a user O Y program OP C – Signals (software interrupts) E, S TU NO O ED AS E PL – Operating system calls and traps 2002 -10 -29 135
Short-Tem Scheduling Criteria By L. Logrippo, U Ottawa • User-oriented – Turnaround Time (batch systems): Elapsed time from the submission of a process to its completion – Response Time (interactive systems): Elapsed time from the submission of a N SIO S request to the first response (given that in an interactive system Ithere can be RM PE many requests and many responses) ’S OR H UT – Fairness • System-oriented – CPU utilization EA TH T U HO IT W TE IBU – Throughput: number of process completed per unit time TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 136
Priorities By L. Logrippo, U Ottawa • Implemented by having multiple ready queues to represent each level of priority • Scheduler will always choose a process of higher priority over one of lower priority ION • Lower-priority may suffer starvation • • • SS I RM PE ’S R Then allow a process to change its priority based. UTHO its age or execution on EA history TH T OU use of priorities Our first scheduling algorithms will not. ITH make W E UT We will then present other algorithms that use dynamic priority RIB ST I mechanisms RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 137
Characterization of Scheduling Policies By L. Logrippo, U Ottawa • The selection function: determines which process in the ready queue is selected next for execution • The decision mode: specifies the instants in time at which the selection function is exercised ION – Nonpreemptive SS I RM PE ’S • Once a process is in the running state, it will continue until it terminates or blocks itself OR TH for I/O AU HE T – Preemptive UT O IT and • Currently running process may be interrupted H moved to the Ready state by the OS W TE • Allows for better service since any one. Uprocess cannot monopolize the processor for very RIB long ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 138
The CPU-I/O Cycle By L. Logrippo, U Ottawa • We observe that processes require alternate use of processor and I/O in a repetitive fashion • Typically, each cycle consist of a short CPU burst followed by a (usually) much longer I/O burst ION SS I RM • CPU-bound processes require more CPU time than I/O time, I/O-bound PE ’S R processes are the reverse. HO T E UT RIB T OU ITH AU HE T W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 139
Running Example to Discuss Various Scheduling Policies By L. Logrippo, U Ottawa Burst Arrival Time (to Ready queue) Process Burst Service N Time SIO RM PE S 1 0 2 2 E UT IB R 4 3 P T DIS R YO 4 SE 5 E PL O ED AS N U OT O , C U R’ HO T W T OU ITH EA TH IS 3 6 4 6 5 8 2 • Burst service time = processor time needed in one (CPU-I/O) cycle • Jobs with long burst service times are CPU-bound jobs and are referred to as “long jobs” 2002 -10 -29 140
First Come First Served (FCFS) By L. Logrippo, U Ottawa N M ER SP IO ISS R’ HO T U E UT RIB • • 2002 -10 -29 T OU ITH EA TH W T DIS R Selection function: the process that has been YO the ready queue. COP (hence, FCFS) E, S TU Decision mode: nonpreemptive NO O – a SE D A process runs until it blocks itself (I/O or other) LE P waiting the longest in 141
FCFS drawbacks By L. Logrippo, U Ottawa • Favors CPU-bound processes – A process that does not perform any I/O will monopolize the processor! – I/O-bound processes have to wait until CPU-bound process completes – They may have to wait even when their I/Os have completed (poor ION device ISS M utilization) ER P R’S – We could have kept the I/O devices busy by giving more O priority to I/O bound TH processes AU HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 142
Round-Robin By L. Logrippo, U Ottawa • Ready processes are in a circular queue • Each process is served in turn • When its turn comes, a process is given a fixed quantum of CPU time N – can use it entirely or not M ER SP IO ISS R’ HO T U E UT RIB T DIS R YO P E US O , C T NO currently process O ED S EA PL 2002 -10 -29 being served T OU ITH EA TH W P[0] P[1] P[7] P[2] P[6] P[3] P[5] P[4] 143
Round-Robin By L. Logrippo, U Ottawa N M ER SP IO ISS R’ HO T U E UT RIB • • 2002 -10 -29 T OU ITH EA TH W T DISFCFS (note P 2 before P 3 at time 4) Selection function: same. Ras YO OP Decision mode: preemptive C E, S – a process OT allowed to run until the time slice period (quantum, typically from 10 to is U 100 ms) N expired O has ED S – Lthen a clock interrupt occurs and the running process is put on the ready queue EA P 144
Time Quantum for Round Robin By L. Logrippo, U Ottawa • Must be substantially larger than the time required to handle the timer interrupt and dispatching (context switching time) • Should be larger than the typical burst (but not much more to avoid penalizing I/O bound processes) – A majority of the processes should request I/O before end of quantum N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 145
Round Robin: critique By L. Logrippo, U Ottawa • Still favors CPU-bound processes – A I/O bound process uses the CPU for a time less than the time quantum and then is blocked waiting for I/O – A CPU-bound process run for all its time slice and is put back into the ready queue N SIO IS (thus getting in front of blocked processes) RM ’S OR H • A solution: virtual round robin PE T AU – When an I/O has completed, the blocked process is moved to an auxiliary queue HE T which gets preference over the main ready queue UT HO IT – A process dispatched from the auxiliary queue gets its basic quantum minus the EW T time it ran the last time. IBU R IST D OR Y P SE E PL 2002 -10 -29 O ED AS U OT O , C N 146
Queuing for Virtual Round Robin By L. Logrippo, U Ottawa N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 147
Shortest Process Next (SPN) By L. Logrippo, U Ottawa • Selection function: the process with the shortest expected CPU burst time • Decision mode: nonpreemptive N • I/O bound processes will be picked first RM IO ISS P • We need to estimate the required processing time (CPUEburst time) for R’S O each process: on the basis of past behavior. TH U EA TH T E UT RIB U HO IT W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 148
SPN gives the best turnaround time! By L. Logrippo, U Ottawa • Example: – Three jobs: bursts 1, 2, 3 – If we execute in order of burst length: N • Avg turnaround = [1+(1+2)+(1+2+3)]/3 = 10/3 = 3. 33 M • Is this the best possible time? Why? ER SP IO ISS R’ HO T U • General case: E UT RIB – n jobs: bursts B 1, B 2, B 3, … , Bn – B 1 < B 2 < B 3 < … < Bn T OU ITH EA TH W T DIS R YO – SPN schedule: 1, 2, 3, …, P n O C E, …? – Avg turnaround time. S= U OT N DO SE EA PL 2002 -10 -29 149
Shortest Process Next: critique By L. Logrippo, U Ottawa • Possibility of starvation for longer processes as long as there is a steady supply of shorter processes • Lack of preemption is not suited in a time sharing environment N – CPU bound process gets lower priority (as it should) but a process doing no I/O SIO S could still monopolize the CPU if he is the first one to enter the. MI R system E • P R’S given SPN implicitly incorporates priorities: shortest jobs O are TH AU preferences HE T UT O ITH W TE IBU TR IS RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 150
Highest Response Ratio Next (HRRN) By Patricia Roy 5 0 10 15 20 N M ER SP R’ HO T 1 U 2 3 4 5 E UT RIB SE E PL IO ISS O ED AS N U OT T OU ITH EA TH W T DIS R YO P time spent waiting + expected service time O , C • Choose next process with the highest response ratio 2002 -10 -29 151
Multilevel Feedback Scheduling By L. Logrippo, U Ottawa • Preemptive scheduling with dynamic priorities • Several ready to execute queues with decreasing priorities: – P(RQ 0) > P(RQ 1) >. . . > P(RQn) • New process are placed in RQ 0 • • N IO ISS RM PE When they reach the time quantum, they are placed. R’in RQ 1. If they S O H reach it again, they are place in RQ 2. . . until they Treach RQn U EA TH queues. CPU-bound jobs I/O-bound processes will stay in higher priority T OU TH will drift downward. WI E UT Dispatcher chooses a process for. Rexecution in RQi only if RQi-1 to RQ 0 IB ST I are empty RD YO OP Hence long jobs may starve C E, S TU NO O ED AS E PL 2002 -10 -29 152
Algorithm Comparison By L. Logrippo, U Ottawa • Which one is best? • The answer depends on: – on the system workload (extremely variable) N – hardware support for the dispatcher M IO ISS ER – relative weighting of performance criteria (response time, CPU utilization, SP R’ throughput. . . ) HO T U EA – The evaluation method used (each has its limitations. . . ) TH • T • in some systems it may be important to satisfy the average user OU TH WI • in others, it may be important to keep the machine busy E UT • or to satisfy users who are paying for. IB R priority. . . IST D Hence the answer depends OR too many factors to give on PY CO E, US T NO O ED AS LE P 2002 -10 -29 any. . . 153
In practice. . . By L. Logrippo, U Ottawa • Large mainframe computers have a programmable algorithm • Most of the algorithms just discussed can be chosen, sometimes in combination • Coefficients can also be chosen manually N RM IO ISS • Systems programmers keep observing system behavior PE can change and R’S O algorithm and coefficients according to current load mix TH U • Exceptional programs SE E PL 2002 -10 -29 O ED AS U OT EA TH can be scheduled manually, T OU TH WI E UT RIB ST I RD YO OP , C or even aborted N 154
Fair Share Scheduling (see book for details) By L. Logrippo, U Ottawa • In a multi-user system, each user can own several processes • Users belong to groups and each group should have its fair share of the CPU IO • Ex: if there are 4 equally important departments (groups) and. None ISS RM department has more processes than the others, degradation of response PE ’S time should be more pronounced for that department OR H T E UT RIB T OU ITH AU HE T W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 155
Important concepts of Chapter 9 By L. Logrippo, U Ottawa • Scheduling, dispatching, different types of schedulers, criteria • Response time, turnaround time, throughput • Different algorithms, evaluation criteria N • Preemption M ER SP IO ISS • Shortest job first has the best performance, but the R’ info may not be HO T available AU – estimation: exponential averaging • • E TH T U HO IT Round-robin: choice of quantum, adjustment EW T IBU Priority and priority adjustment R T DIS R YO P CO E, US T NO O ED AS LE P 2002 -10 -29 of quantum 156
Clocks! N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 157
Clocks in History • First computing devices – A clock computes and displays a variable must change at a constant rate – Extremely difficult to do! N • Ancient clocks – Sun dials M ER SP IO ISS R’ • Problem is that the sun’s angular velocity at a point on the surface of the earth varies a HO T AU lot during the day (very slow at sunrise and sunset, fastest at noon) E TH T – Water clocks OU TH • Problem is to ensure that flow is constant, WI even though the height of the water is not E UT RIB – Pendulums ST I RD • Problem is that period changes based on length of pendulum YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 158
Einstein’s Special Relativity • Time dilates or contracts if observed from a distance that changes rapidly relative the speed of light – Why? • If the speed of the observer is known, we can correct for the. ON SI effect RM PE S – What if the speed is variable and unpredictable? IS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 159
The Problem of Mutual Knowledge • P knows X • Q knows Y • P needs to know that Q knows Y – And vice-versa – So that they can cooperate • • • N M ER SP IO ISS R’ HO – Does P also need to know that (Q knows that (P knows T U X))? EA H P and Q need to communicate TT U HO – P sends a message to Q saying “I know X” IT W TE IBU – And vice-versa TR IS R D go about their work (thinking, But, X and Y change as P and Q YO OP sensing environment, E, C etc. ) US P and Q need to NOT communicate frequently O ED AS LE P 2002 -10 -29 computing, 160
The Problem of Global Knowledge • P knows X • Q knows Y • R knows Z • Each of them needs to know what the others know • N IO ISS RM PE – So that each can make a decision that is informed by the global ’S OR H UT Again, X, Y and Z change and therefore communication should EA TH frequent T OU TH WI E UT RIB ST I RD YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 be 161
A Simple Solution: Shared Memory • If P, Q and R have direct access to each other’s memory – They can simply read the whole memory to discover the global state • In reality, it is impossible to construct such a memory N – So that it can be accessed quickly enough from geographically-distant processes SIO IS RM PE • We must solve the problems of mutual and global knowledge in the ’S OR context of a distributed system TH U EA TH T E UT RIB U HO IT W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 162
Distributed System • A simple model – A set of (sequential) processes executing concurrently – Processes communicate by sending and receiving messages N – Messages take a variable, unpredictable and potentially unbounded. Oamount of SI IS time to reach their destinations RM E • P R’S – Events occur inside a process (an event is either a computational step like a CPU O TH instruction, or a communication step like a send or. E a U A receive) H T UT The history problem O ITH W – Processes need to agree on an ordering. Eof events so that, for any two events, A T IBU and B, TR IS • [Condition H] If A caused (or influenced) B, then A must be known to have happened RD YO before B OP C E, and B could not cause A, then • If A could not cause SB, TU – It’s OK if A NO B’s ordering is left ambiguous and O ED – It’s also OK if A is known to have happened before B or vice versa. AS LE P 2002 -10 -29 163
Perfect Physical Clocks • Perfect physical clocks can solve the history problem – Each process maintains a clock – All clocks are perfectly synchronized – Each process assigns a timestamp (a number) to every event that it. ON SI “experiences” • IS RM condition H – These timestamps provide an ordering of all events that satisfies PE ’S OR TH AU HE But, perfect clocks cannot exist T UT O – Why? ITH W TE – Synchronization signal arrives after Iunpredictable delay BU TR – Clocks drift at different rates. R DIS YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 164
Logical Clocks • Happens-before relation: A B if – A, B belong to the same process and A sequentially executes before B, – A is a send event and B is the corresponding receive event, or, N – There exists a E, such that A E, and E B M IO ISS ER • Logical clock problem: assign a numerical timestamp C(A) to each event SP R’ such that HO T U – Condition C(A) < C(B) if A B – C(A) = C(B) implies A = B E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 165
Logical Clocks are Considered Important • Leslie Lamport’s 1978 paper that you’re reading won the first Influential Paper Award in distributed computing – See http: //www. podc. org/influential/2000. html N • The award was granted for (among other things) M ER SP IO ISS R’ – “A precise characterization of causality in distributed systems (called the clock HO T condition) and a framework (similar to Minkowski diagrams of special relativity) AU E T for explaining and reasoning about event ordering. Hin distributed protocols…” T U HO answering the question of ‘what is – “The logical clock abstraction […] enabled. IT[…] W a state in a distributed system’…” IBUTE R IST – “… among the very first papers. Dto show distributed systems were R YO fundamentally different from other concurrent systems and was the first paper to P CO show a rigorous SE, mathematical basis (the "happens before" relation) could be U used to talk about. Tsuch differences. ” NO O ED AS E PL 2002 -10 -29 166
• Lamport’s statement in response said: – “I happen to have a solid, visceral understanding of special relativity. This enabled me to grasp immediately the essence of [another piece of work]. ” – “Special relativity teaches us that there is no invariant total ordering of events in N SIO IS space-time; different observers can disagree about which of two events RM PE happened first. There is only a partial order in which an event e 1 precedes an ’S R event e 2 iff e 1 can causally affect e 2. ” [Emphasis added] O TH U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 167
Partial Orders Example • Define a numerical ordering (let’s call it “<”) on pairs of numbers as follows N (A, B) < (C, D) M A < C and B PER <D R’S if and only if IO ISS O H UT EA TH T • Thus, • We say U HO IT W TE IBU (3, 9) < (4, 10) < (5, 11) , but, TR IS D (3, 11) <> (4, 10) , i. e. , they are “incomparable” OR PY CO E, US T NO that (3, 11) and (4, 10) are incomparable or unrelated O ED AS LE P • Note that (3, 9) is not < (3, 9) 2002 -10 -29 168
Partial and Total Orders • Formally, a partial order “<” is a relation that is: 1. Irreflexive: A <> A 2. Transitive: (i. e. , it is never true that A < A) A < B and B < C implies A < C N RM IO ISS PE • If we also add the requirement that any two items must be related, we ’S OR have a “Total Order” TH U EA TH T • Formally, a total order “<” 1. Irreflexive: A <> A 2. Transitive: 3. Total: E PL 2002 -10 -29 U HO IT is a relation that EW T IBU R IST D is: A < B and B <OR implies A < C C Y P C for any , A, OB, either A < B or B < A SE O ED AS U OT N 169
An Event-based Model of Concurrency • Space-time diagrams: see fig. 1 in Lamport’s paper • Happens-before relation: A B if N – A, B belong to the same process and A sequentially executes before. OB, SI • • – A is a send event and B is the corresponding receive event, or, RM PE ’S R – There exists an event E, such that A E, and E B THO AU HE T UT O A, B are concurrent iff (if and only if) WITH E UT RIB STA B Neither DI nor B A OR PY CO E, US T A can cause (affect) B only if A B NO O – It is possible D A B without A causing (affecting) B E for AS LE P IS • “ ” turns out to be a partial order 2002 -10 -29 170
Logical Clock Problem • Assign a numerical timestamp C(A) to each event A such that – C(A) < C(B) if A B Clock condition N – C(A) = C(B) implies A = B ER SP R’ HO T U • Benefits of clock – Clock ordering is total M Uniqueness IO ISS T OU ITH EA TH W E – Easier to reason with than the space-time diagrams, or their mathematical model, UT IB the happens-before partial order TR S relation I D OR the happens-before – Clock ordering is consistent with PY CO E, US T NO O ED AS LE P 2002 -10 -29 171
Logical Clock Algorithm (a. k. a. “Lamport Clocks”) • Each process Pi maintains a local counter, Ci 1. On every event A, process Pi updates Ci as shown in steps 3 and 4 below, then assigns a timestamp (a. k. a. Lamport Clock) to the event A as follows C(A) = (Ci, i) That is, the timestamp is a pair N M ER SP IO ISS R’ HO as follows T 2. On every non-receive event, Pi simply increments counter AU E Ci = Ci + 1 T TH U HO IT E W event’s timestamp to its message. 3. On every send event, Pi attaches the. Tsend IBU This is called the “message timestamp”. TR IS RD YO OPP updates its counter based on the maximum of its C 4. On every receive event, i E, S current value, and the timestamp attached to the message received as follows TU NO O Ci = max(Ci , msg timestamp) + 1 D SE EA PL 2002 -10 -29 172
Lamport Clocks Solve the Logical Clock Problem • Proof that clock condition holds – Clock condition says: C(A) < C(B) if A B – If A, B belong to the same process, the it is satisfied (why? ) N – If A, B is a send a corresponding receive, then it is satisfied (why? ) SIO • IS RM – By induction, we can prove that the condition is also satisfied. E(how? ) P R’S O • Assume that the condition is satisfied for an execution TH AU • Add an extra event (either a computation step or a communication step) HE T U • Prove that for every case the condition still holds T O ITH Proof that the uniqueness condition E W holds UT RIB –… ST I RD – Oops! Need to fix the algorithm a little bit (how? ) YO OP C E, S TU NO O ED AS E PL 2002 -10 -29 173
Connection between Events and States • See space-time diagram in fig. 2 in Lamport’s paper N M ER SP IO ISS R’ HO T U E UT RIB T OU ITH EA TH W T DIS R YO P SE E PL 2002 -10 -29 O ED AS U OT O , C N 174
6d832479969711ae6444c9201f5faf28.ppt