Concurrency, threads, and events

Slides:



Advertisements
Similar presentations
Concurrency, Thread and Event CS6410 Sept 6, 2011 Ji-Yong Shin.
Advertisements

Concurrency, Threads, and Events Presented by Hakim Weatherspoon.
Hugh Lauer Xerox Corporation Roger Needham Cambridge University Presented by Vidhya Priyadharshnee Palaniswamy Gnanam Spring 2011.
1 On the Duality of Operating System Structures by Hugh C. Lauer, Xerox Corporation and Roger M. Needham, Cambridge University Presented by Scott Fletcher.
Processes CSCI 444/544 Operating Systems Fall 2008.
Scheduler Activations Effective Kernel Support for the User-Level Management of Parallelism.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
“Why Events are a Bad Idea (For high-concurrency servers)” Paper by Rob von Behren, Jeremy Condit and Eric Brewer, May 2003 Presentation by Loren Davis,
1 On the Duality of Operating System Structures Hugh Lauer, Xerox Roger Needham, Cambridge University Oct 1978, reprinted April 1979 Presented by David.
Concurrency, Threads, and Events Robbert van Renesse.
On the Duality of Operating System Structures Hugh Lauer Xerox Corporation Roger Needham Cambridge University Presented by Yahia Mahmoud.
Processes April 5, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
On the Duality of Operating System Structures Hugh C. Lauer Xerox Corporation Roger M. Needham Cambridge University Presented By: Ashwini Kulkarni.
Concurrency, Threads, and Events Ken Birman (Based on a slide set prepared by Robbert van Renesse)
Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Introduction to Embedded Systems
COP 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Implementing Processes and Process Management Brian Bershad.
Dave Archer - CS533 - Spring On the Duality of Operating System Structures Hugh C. Lauer, Roger M. Needham.
On the Duality of Operating System Structures 1. Hugh C. Lauer Xerox Corporation Palo Alto, Californi a Roger M. Needham Cambridge University Cambridge,
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services Presented by Changdae Kim and Jaeung Han OFFENCE.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CS533 - Concepts of Operating Systems 1 On The Duality of Operating System Structures Hugh Lauer, Xerox Roger Needham, Cambridge University 1979 Presented.
ON THE DUALITY OF OPERATING SYSTEM STRUCTURES Hugh C. Lauer and Roger M. Needham Presented by: Ali R. Butt (adapted from many slides available online and.
M. Accetta, R. Baron, W. Bolosky, D. Golub, R. Rashid, A. Tevanian, and M. Young MACH: A New Kernel Foundation for UNIX Development Presenter: Wei-Lwun.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
REVIEW OF “ON THE DUALITY OF OPERATING SYSTEM STRUCTURES” Paper by Hugh C. Lauer and Roger M. Needham Presentation by Erin Chapman.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
MICROKERNELS: MACH AND L4 Hakim Weatherspoon CS
Processes and threads.
Advanced Operating Systems CIS 720
SEDA: An Architecture for Scalable, Well-Conditioned Internet Services
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
PROCESS MANAGEMENT IN MACH
Microkernels: mach and L4
CS 6560: Operating Systems Design
On the Duality of Operating System Structures
Scheduler activations
Processes Overview: Process Concept Process Scheduling
CS533 Concepts of Operating Systems
Intro to Processes CSSE 332 Operating Systems
ICS 143 Principles of Operating Systems
COP 4600 Operating Systems Spring 2011
Processes in Unix, Linux, and Windows
On the Duality of Operating System Structures
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
Processes Hank Levy 1.
Hugh Lauer Xerox Corporation Roger Needham Cambridge University
Processes and Process Management
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Why Threads Are A Bad Idea (for most purposes)
Operating Systems: A Modern Perspective, Chapter 6
CS510 Operating System Foundations
On the Duality of Operating System Structures
Processes Hank Levy 1.
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CS703 – Advanced Operating Systems
Microkernels: mach and L4
Threads CSE 2431: Introduction to Operating Systems
CS533 Concepts of Operating Systems Class 4
Presentation transcript:

Concurrency, threads, and events CS6410 Hakim Weatherspoon

On the Duality of Operating System Structure Hugh C. Lauer Adjunct Prof., Worcester Polytechnic Institute Xerox, Apollo Computer, Mitsubishi Electronic Research Lab, etc. Founded a number of businesses: Real-Time Visualization unit of Mitsubishi Electric Research Labs (MERL) Roger M. Needham Prof., Cambridge University Microsoft Research, Cambridge Lab Kerberose, Needham-Schroeder security protocol, and key exchange systems

Message vs Procedure oriented system (i.e. Events vs Threads) Are they really the same thing? Lauer and Needham show 1) two models are duals Mapping exists from one model to other 2) dual programs are logically identical Textually similar 3) dual programs have identical performance Measured in exec time, compute overhead, and queue/wait times “UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” – Dennis Ritchie

Message-oriented system (Event) Small, static # of process Explicit messaging Limited data sharing in memory Identification of address space or context with processes

Message-oriented system Characteristics Queuing for congested resource Data structure passed by reference (no concurrent access) Peripheral devices treated as processes Priority of process statically determined No global naming scheme is useful

Message-oriented system Calls: SendMessage, AwaitReply SendReply WaitForMessage Characteristics Synchronization via message queues No sharing of data structures/address space Number of processes static “UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” – Dennis Ritchie

Message-oriented system Canonical model begin Do forever WaitForMessages case port port 1: …; port 2: …; SendReply; …; end case end loop end

Procedure-Oriented System (Thread) Large # of small processes Rapidly changing # of processes Communication using direct sharing and interlocking of data Identification of context of execution with function being executed

Process-oriented system Characteristics Synchronization and congestion control associates with waiting for locks Data is shared directly and lock lasts for short period of time Control of peripheral devices are in form of manipulating locks Priority is dynamically determined by the execution context Global naming and context is important

Process-oriented system Calls: Fork, Join (process) Wait, Signal (condition variables) Characteristics Synchronization via locks/monitors Share global address space/data structures Process creation very dynamic and low-overhead “UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” – Dennis Ritchie

Process-oriented system Canonical model Monitor -- global data and state info for the process proc1: ENTRY procedure proc2: ENTRY procedure returns begin If resourceExhausted then WAIT; …; RETURN result; …; end proc L: ENTRY procedure …; SIGNAL; … end; endloop; initialize;

Dual Mapping Event Thread Processes: CreateProcess Monitors: NEW/START Message channel External procedure id Message port Entry procedure id Send msg (immediate); AwaitReply Simple procedure call Send msg (delayed); AwaitReply FORK; … JOIN Send reply Return from procedure Main loop of std resource manager, wait for message stmt, case stmt Monitor lock, ENTRY attribute Arms of case statement ENTRY proc declaration Selective waiting Condition vars, WAIT, SIGNAL Can map one model to the other

Preservation of Performance Performance characteristics Same execution time Same computational overhead Same queuing and waiting times Do you believe they are the same? What is the controversy? “UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” – Dennis Ritchie

SEDA: An Architecture for Well-Conditioned, Scalable Internet Services (Welsh, 2001) 20 to 30 years later, still controversy! Analyzes threads vs event-based systems, finds problems with both Suggests trade-off: stage-driven architecture Evaluated for two applications Easy to program and performs well

SEDA: An Architecture for Well-Conditioned, Scalable Internet Services (Welsh, 2001) Matt Welsh Cornell undergraduate Alum (Worked on U-Net) PhD from Berkeley (Worked on Ninja clustering) Prof. at Harvard (Worked on sensor networks) Currently at Google David Culler Faculty at UC Berkeley Eric Brewer Faculty at UC Berkeley (currently on leave at Google)

What is a thread? A traditional “process” is an address space and a thread of control. Now add multiple thread of controls Share address space Individual program counters and stacks Same as multiple processes sharing an address space.

Thread Switching To switch from thread T1 to T2: Thread T1 saves its registers (including pc) on its stack Scheduler remembers T1’s stack pointer Scheduler restores T2’ stack pointer T2 restores its registers T2 resumes

Thread Scheduler Maintains the stack pointer of each thread Decides what thread to run next E.g., based on priority or resource usage Decides when to pre-empt a running thread E.g., based on a timer Needs to deal with multiple cores Didn’t use to be the case “fork” creates a new thread

Synchronization Primitives Semaphores P(S): block if semaphore is “taken” V(S): release semaphore Monitors: Only one thread active in a module at a time Threads can block waiting for some condition using the WAIT primitive Threads need to signal using NOTIFY or BROADCAST

Uses of threads To exploit CPU parallelism To exploit I/O parallelism Run two threads at once in the same program To exploit I/O parallelism Run I/O while computing, or do multiple I/O I/O may be “remote procedure call” For program structuring E.g., timers

Common Problems Priority Inversion Deadlock Incorrect Synchronization High priority thread waits for low priority thread Solution: temporarily push priority up (rejected??) Deadlock X waits for Y, Y waits for X Incorrect Synchronization Forgetting to release a lock Failed “fork” Tuning E.g. timer values in different environment

What is an Event? An object queued for some module Operations: create_event_queue(handler)  EQ enqueue_event(EQ, event-object) Invokes, eventually, handler(event-object) Handler is not allowed to block Blocking could cause entire system to block But page faults, garbage collection, …

Example Event System (Also common in telecommunications industry, where it’s called “workflow programming”)

Event Scheduler Decides which event queue to handle next. Based on priority, CPU usage, etc. Never pre-empts event handlers! No need for stack / event handler May need to deal with multiple CPUs

Synchronization? Handlers cannot block  no synchronization Handlers should not share memory At least not in parallel All communication through events

Uses of Events CPU parallelism I/O concurrency Program structuring Different handlers on different CPUs I/O concurrency Completion of I/O signaled by event Other activities can happen in parallel Program structuring Not so great… But can use multiple programming languages!

Common Problems Priority inversion, deadlock, etc. much the same with events Stack ripping

Threaded Server Throughput

Event-driven Server Throughput

Threads vs. Events Events-based systems use fewer resources Better performance (particularly scalability) Event-based systems harder to program Have to avoid blocking at all cost Block-structured programming doesn’t work How to do exception handling? In both cases, tuning is difficult

SEDA Mixture of models of threads and events Events, queues, and “pools of event handling threads”. Pools can be dynamically adjusted as need arises.

SEDA Stage

Best of both worlds Ease of programming of threads Or even better Performance of events Did we achieve Lauer and Needham’s vision with SEDA?

Next Time Read and write review: MP1 – due next Friday Let us know how you are doing; if need help Project Proposal due next week Also, talk to faculty and email and talk to me Check website for updated schedule Lab 0 – graded

Next Time Read and write review: Mach: A new kernel foundation for UNIX development, Mike Accetta, Robert Baron, William Bolosky, David Golub, Richard Rashid, Avadis Tevanian, and Michael Young. Proceedings of the USENIX Summer Conference, Atlanta, GA, 1986, pages 93—112. The Performance of µ-Kernel-based Systems, Hermann Härtig, Michael Hohmuth, Jochen Liedtke, Jean Wolter, and Sebastian Schönberg. 16th ACM Symposium on Operating Systems Principles (SOSP), Oct 1997, pages 66— 77.