Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 4600 Operating Systems Spring 2011

Similar presentations


Presentation on theme: "COP 4600 Operating Systems Spring 2011"— Presentation transcript:

1 COP 4600 Operating Systems Spring 2011
Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM

2 Lecture 16 – Tuesday, March 22, 2011
Last time: Virtualization for the three abstractions Threads Virtual Memory Bounded buffer The kernel of an operating syste Today: State Processor switching Semaphores Deadlocks Next time Communication with a bounded buffer Lecture 16

3 Thread and VM management – virtual computer
The kernel supports thread and virtual memory management Thread management: Creation and destruction of threads Allocation of the processor to a ready to run thread Handling of interrupts Scheduling – deciding which one of the ready to run threads should be allocated the processor Virtual memory management  maps virtual address space of a thread to physical memory. Each module runs in own address space; if one module runs multiple threads all share one address space. Thread + virtual memory  virtual computer for each module. Lecture 16

4 Threads and the Thread Manager
Thread  virtual processor - multiplexes a physical processor a module in execution; a module may have several threads. sequence of operations: Load the module’s text Create a thread and lunch the execution of the module in that thread. Scheduler  system component which chooses the thread to run next Thread manager implements the thread abstraction. 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 16

5 The state of a thread; kernel versus application threads
Thread state: Thread Id  unique identifier of a thread Program Counter (PC) -the reference to the next computational step Stack Pointer (SP) PMAR – Page Table Memory Address Register Other registers Threads User level threads/application threads – threads running on behalf of users Kernel level threads – threads running on behalf of the kernel Scheduler thread – the thread running the scheduler Processor level thread – the thread running when there is no thread ready to run Lecture 16

6 Lecture 16

7 Virtual versus real; the state of a processor
Virtual objects need a physical support. In addition to threads we should be concerned with the processor or cores running a thread. A system may have multiple processors and each processor may have multiple cores The state of the processor or core: Processor Id/Core Id  unique identifier of a processor /core Program Counter (PC) -the reference to the next computational step Stack Pointer (SP) PMAR – Page Table Memory Address Register Other registers Lecture 16

8 Lecture 16

9 Processor and thread tables – control structures that must be locked for serialization
Lecture 16

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

11 Thread states and state transitions
Lecture 16

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

13 Switching the processor from one thread to another
Thread creation: thread_id ALLOCATE_THREAD(starting_address_of_procedure, address_space_id); YIELD  function implemented by the kernel to allow a thread to wait for an event. Save the state of the current thread Schedule another thread Start running the new thread – dispatch the processor to the new thread YIELD cannot be implemented in a high level language, must be implemented in the machine language. can be called from the environment of the thread, e.g., C, C++, Java allows several threads running on the same processor to wait for a lock. It replaces the busy wait we have used before. Lecture 16

14 Implementation of YIELD
Apply the principle of least astonishment; deal first with a simpler case: A fixed number of threads (7). All threads run on the same core and in the same address space. When switching states we do not need to update the PMAR (Page Memory address Register) When we enter the processor layer change the state of the current thread from RUNNING to RUNNABLE Save the stack pointer in the thread table Invoke the scheduler The SCHEDULER Searches the thread table for a thread in RUNNABLE state and changes its state to RUNNING Update the processor table to mark this thread as running on that processor EXITS the Processor layer Lecture 16

15 Lecture 16

16 Lecture 16


Download ppt "COP 4600 Operating Systems Spring 2011"

Similar presentations


Ads by Google