COP 4600 Operating Systems Fall 2010 Dan C

  • Slides: 24
Download presentation
COP 4600 Operating Systems Fall 2010 Dan C. Marinescu Office: HEC 439 B Office

COP 4600 Operating Systems Fall 2010 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3: 30 -4: 30 PM

Lecture 15 – Tuesday October 12, 2010 n Last time: n n n NFS

Lecture 15 – Tuesday October 12, 2010 n Last time: n n n NFS (Network File System) Virtualization Today: n n Presentation of the paper “DNS Complexity” by Vixie Threads, Virtual memory, Bounded buffers. Virtual Links. Primitives for processor virtualization Threads. The state of a thread. ¨ ¨ ¨ n ¨ Thread manager. Interrupts. Interrupt handler. Race conditions and locks. Thread and processor layers Processor sharing; Scheduling; Switching the processor from one thread to another – YIELD. Implementation of YIELD and SCHEDULER Deadlocks Next time n Thread coordination with a bounded buffer. Race conditions Lecture 15 2

Virtualization – relating physical with virtual objects n Virtualization simulating the interface to a

Virtualization – relating physical with virtual objects n Virtualization simulating the interface to a physical object by: 1. 2. 3. Multiplexing create multiple physical objects from one instance of a physical object. Aggregation create one virtual object from multiple physical objects Emulation construct a virtual object from a different type of a physical object. Emulation in software is slow. Method Physical Resource Virtual Resource Multiplexing processor thread real memory virtual memory communication channel virtual circuit processor server (e. g. , Web server) disk RAID core multi-core processor disk RAM disk system (e. g. Macintosh) virtual machine (e. g. , Virtual PC) real memory + disk virtual memory with paging communication channel + processor TCP protocol Aggregation Emulation Multiplexing + Emulation Lecture 15 3

Virtualization of the three abstractions. (1) Threads n 1. Implemented by the operating system

Virtualization of the three abstractions. (1) Threads n 1. Implemented by the operating system for the three abstractions: Threads a thread is a virtual processor; a module in execution Multiplexes a physical processor 2. The state of a thread: (1) the reference to the next computational step (the Pc register) + (2) the environment (registers, stack, heap, current objects). 3. Sequence of operations: 1. 2. Load the module’s text Create a thread and lunch the execution of the module in that thread. A module may have several threads. 5. The thread manager implements the thread abstraction. 4. 1. 2. 3. Interrupts processed by the interrupt handler which interacts with the thread manager Exception interrupts caused by the running thread and processed by exception handlers Interrupt handlers run in the context of the OS while exception handlers run in the context of interrupted thread. Lecture 15 4

Virtualization of the three abstractions. (2) Virtual memory 2. Virtual Memory a scheme to

Virtualization of the three abstractions. (2) Virtual memory 2. Virtual Memory a scheme to allow each thread to access only its own virtual address space (collection of virtual addresses). 1. Why needed: 1. 2. To implement a memory enforcement mechanism; to prevent a thread running the code of one module from overwriting the data of another module The physical memory may be too small to fit an application; otherwise each application would need to manage its own memory. Virtual memory manager maps virtual address space of a thread to physical memory. Thread + virtual memory allow us to create a virtual computer for each module. Each module runs in own address space; if one module runs mutiple threads all share one address space. Lecture 15 5

Virtualization of the three abstractions: (3) Bounded buffers 3 Bounded buffers implement the communication

Virtualization of the three abstractions: (3) Bounded buffers 3 Bounded buffers implement the communication channel abstraction 1 2 Bounded the buffer has a finite size. We assume that all messages are of the same size and each can fit into a buffer cell. A bounded buffer will only accommodate N messages. Threads use the SEND and RECEIVE primitives. Lecture 15 6

Lecture 15 7

Lecture 15 7

Lecture 15 8

Lecture 15 8

Lecture 15 9

Lecture 15 9

One more pitfall of the previous implementation of bounded buffer n If in and

One more pitfall of the previous implementation of bounded buffer n If in and out are long integers (64 or 128 bit) then a load requires two registers, e. , g, R 1 and R 2. int “ 0000 FFFF” L R 1, int /* R 1 0000 L R 2, int+1 /* R 2 FFFF n Race conditions could affect a load or a store of the long integer. Lecture 15 10

Lecture 15 11

Lecture 15 11

System model n n n Resource types R 1, R 2, . . .

System model n n n Resource types R 1, R 2, . . . , Rm (CPU cycles, memory space, I/O devices) Each resource type Ri has Wi instances. Resource access model: ¨ request ¨ use ¨ release Lecture 15 12

Simultaneous conditions for deadlock n n Mutual exclusion: only one process at a time

Simultaneous conditions for deadlock n n Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it (presumably after that process has finished). Circular wait: there exists a set {P 0, P 1, …, P 0} of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, Pn– 1 is waiting for a resource that is held by Pn, and P 0 is waiting for a resource that is held by P 0. Lecture 15 13

Basic primitives for processor virtualization Memory CREATE/DELETE_ADDRESS SPACE ALLOCATE/FREE_BLOCK MAP/UNMAP Interpreter ALLOCATE_THREAD EXIT_THREAD AWAIT

Basic primitives for processor virtualization Memory CREATE/DELETE_ADDRESS SPACE ALLOCATE/FREE_BLOCK MAP/UNMAP Interpreter ALLOCATE_THREAD EXIT_THREAD AWAIT TICKET ACQUIRE DESTROY_THREAD YIELD ADVANCE RELEASE Communication ALLOCATE/DEALLOCATE_BOUNDED_BUFFER SEND/RECEIVE channel Lecture 15 14

Lecture 15 15

Lecture 15 15

The state of a thread and its associated virtual address space Lecture 15 16

The state of a thread and its associated virtual address space Lecture 15 16

Thread states and state transitions Lecture 15 17

Thread states and state transitions Lecture 15 17

Lecture 15 6 18

Lecture 15 6 18

Lecture 15 19

Lecture 15 19

Implementation of YIELD Lecture 15 20

Implementation of YIELD Lecture 15 20

Lecture 15 21

Lecture 15 21

Lecture 15 22

Lecture 15 22

Lecture 15 23

Lecture 15 23

Lecture 15 24

Lecture 15 24