Operating System Support

Similar documents
Operating System Support

Figure 6.1 System layers

Applications, services. Middleware. OS2 Processes, threads, Processes, threads, communication,... communication,... Platform

0. Course Overview. 8 Architecture models; network architectures: OSI, Internet and LANs; interprocess communication III. Time and Global States

POSIX Threads: a first step toward parallel programming. George Bosilca

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Processes and Threads

Process. Program Vs. process. During execution, the process may be in one of the following states

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 9: Midterm Review

CSE 153 Design of Operating Systems

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Lecture 2 Process Management

Concurrency: Deadlock and Starvation

CSE 120 Principles of Operating Systems

Overview. Thread Packages. Threads The Thread Model (1) The Thread Model (2) The Thread Model (3) Thread Usage (1)

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Concurrency: Deadlock and Starvation. Chapter 6

Threads, SMP, and Microkernels. Chapter 4

Process Description and Control

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

OPERATING SYSTEM : RBMCQ0402. Third RavishBegusarai.

CS533 Concepts of Operating Systems. Jonathan Walpole

Dealing with Issues for Interprocess Communication

Distributed Systems Operation System Support

CS 318 Principles of Operating Systems

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Resource management. Real-Time Systems. Resource management. Resource management

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

VEOS high level design. Revision 2.1 NEC

SMD149 - Operating Systems

CSE Traditional Operating Systems deal with typical system software designed to be:

IT 540 Operating Systems ECE519 Advanced Operating Systems

Processes & Threads. Process Management. Managing Concurrency in Computer Systems. The Process. What s in a Process?

CHAPTER 3 - PROCESS CONCEPT

Concurrency: a crash course

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 4: Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

CSE 120 Principles of Operating Systems

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

Chapter 4: Processes

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Verteilte Systeme (Distributed Systems)

QUESTION BANK UNIT I

Midterm Exam. October 20th, Thursday NSC

Process Management And Synchronization

CSE 120 Principles of Operating Systems

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Computer Systems II. First Two Major Computer System Evolution Steps

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

CS450/550 Operating Systems

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

Processes. Process Concept

Architectural Support. Processes. OS Structure. Threads. Scheduling. CSE 451: Operating Systems Spring Module 28 Course Review

EECS 482 Introduction to Operating Systems

Threads. CS3026 Operating Systems Lecture 06

What s in a process?

!! How is a thread different from a process? !! Why are threads useful? !! How can POSIX threads be useful?

Announcements/Reminders

CMSC421: Principles of Operating Systems

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Timers 1 / 46. Jiffies. Potent and Evil Magic

Multiprocessor and Real- Time Scheduling. Chapter 10

Concurrency, Thread. Dongkun Shin, SKKU

CS450/550 Operating Systems

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Chapter 3 Process Description and Control

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Synchronization for Concurrent Tasks

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

UNIT:2. Process Management

Process Description and Control. Chapter 3

Concept of a process

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

CS370 Operating Systems Midterm Review

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

Chapter 4: Multithreaded

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

What s in a traditional process? Concurrency/Parallelism. What s needed? CSE 451: Operating Systems Autumn 2012

(MCQZ-CS604 Operating Systems)

CSC 4320 Test 1 Spring 2017

Chapter 6 Process Synchronization

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Operating System Architecture. CS3026 Operating Systems Lecture 03

Transcription:

Teaching material based on Distributed Systems: Concepts and Design, Edition 3, Addison-Wesley 2001. Copyright George Coulouris, Jean Dollimore, Tim Kindberg 2001 email: authors@cdk2.net This material is made available for private study and for direct use by individual teachers. It may not be included in any product or employed in any service without the written permission of the authors. Viewing: These slides must be viewed in slide show mode. Distributed Systems Course Operating System Support Chapter 6: 6.1 Introduction 6.2 The operating system layer 6.4 es and threads 6.5 Communication and invocation 6.6 operating system architecture Learning objectives Know what a modern operating system does to support distributed applications and middleware Definition of network OS Definition of distributed OS Understand the relevant abstractions and techniques, focussing on: processes, threads, ports and support for invocation mechanisms. Understand the options for operating system architecture monolithic and micro-kernels 2 System layers Middleware and the Operating System Figure 6.1 OS: kernel, libraries & servers OS1 es, threads, communication,... Computer & network hardware Applications, services Middleware 3 Figure 2.1 Software and hardware service layers in distributed systems OS2 es, threads, communication, Applications, services... Middleware Computer & network hardware Operating system Node 1 Node 2 Computer and network hardware Platform Platform Middleware implements abstractions that support networkwide programming. Examples: RPC and RMI (Sun RPC, Corba, Java RMI) event distribution and filtering (Corba Event Notification, Elvin) resource discovery for mobile and ubiquitous computing support for multimedia streaming Traditional OS's (e.g. early Unix, Windows 3.0) simplify, protect and optimize the use of local resources Network OS's (e.g. Mach, modern UNIX, Windows NT) do the same but they also support a wide range of communication standards and enable remote processes to access (some) local resources (e.g. files). 4 Networked OS to Distributed OS The support required by middleware and distributed applications Distributed OS Presents users (and applications) with an integrated computing platform that hides the individual computers. Has control over all of the nodes (computers) in the network and allocates their resources to tasks without user involvement. In a distributed OS, the user doesn't know (or care) where his programs are running. One OS managing resources on multiple machines Examples: Cluster computer systems Amoeba, V system, Sprite, Globe OS 5 OS manages the basic resources of computer systems Tasks: programming interface for these resources: abstractions such as: processes, virtual memory, files, communication channels Protection of the resources used by applications Concurrent processing provide the resources needed for (distributed) services and applications: Communication - network access ing - processors scheduled at the relevant computers 6 1

Core OS functionality Protection: Figure 6.2 Why does the kernel need to be protected? manager Communication manager Kernels and protection kernel has all privileges for the physical resources, processor, memory.. execution mode kernel and user address space kernel and user user transferred to kernel Thread manager Memory manager - system call trap try to invoke kernel resources switch to kernel mode Supervisor cost switching overhead to provide protection 7 8 es and Threads (1) es and Threads (2) process has one environment thread: activity, "thread" of execution in one environment execution environment: an address space synchronization and communication resources i/o resources why execution environment? threads share one execution environment, why? older names: heavyweight and lightweight processes Address space Address space unit of management of a process' virtual memory Regions Text, heap, stack Each region beginning virtual address and size read/write/exe permissions for the process' threads growth direction Why regions: different functionalities, for example: different stack regions for threads memory-mapped file Shared memory regions among processes? libraries kernel data sharing and communication 9 10 es and Threads (3): address space es and Threads (4): process creation Figure 6.3 2 N 0 Auxiliary regions Stack Heap Text 11 Distributed OS choice of target host actual creation of execution env choice of target host transfer policy: local or remote? location policy: if not local, which host/processor V and Sprite system: user has a command and OS chooses Amoeba: a run server decides, more transparent static and adaptive location policies static: predetermined function adaptive: depends on current state of the processing nodes load-sharing systems centralized: one load manager hierarchical: tree of managers decentralized: nodes exchange information, local decision sender-initiated receiver-initiated process migration moved while it's running what need to be sent? 12 2

es and Threads (5) es and Threads (6): Copy-on-write creating an execution env address space with initial contents initialization statically defined format from a list of regions derived from an existing exe env fork in unix derived from the parent shares the text region a copy of the heap and stack copy-on-write Figure 6.4 A s address space A's page table RA Shared frame RB copied from RA Kernel B's page table B s address space RB a) Before write b) After write 13 14 es and Threads (7): Thread memory regions es and Threads (8): Client and server Thread activations Figure 6.5 Thread 2 makes requests to server Receipt & queuing Input-output Activation stacks (parameters, local variables) Thread 1 generates results Requests N threads Heap (dynamic storage,, global variables) 15 'text' (program code) system-provided resources (sockets, windows, open files) Client 16 The 'worker pool' architecture Server See Figure 4.6 for an example of this architecture programmed in Java. es and Threads (9) es and Threads (10): server threading architectures average interval of successive job completions one request: 2 milliseconds of processing and 8 for i/o delay one thread: 2+8 = 10 milliseconds, 100 requests/second Figure 6.6 server process I/O workers remote server process per-connection threads remote server process I/O per-object threads remote two threads: 125 requests/second, serial i/o, why? two threads: 200 requests/second, concurrent i/o, why? two threads with cache (75% hit): 2 milliseconds (.750 +.258), 500 requests/sec cpu overhead of caching: 2.5 milliseconds, 400 requests/sec 17 a. Thread-per-request b. Thread-per-connection c. Thread-per-object Implemented by the server-side ORB in CORBA (a) would be useful for UDP-based service, e.g. NTP (network time protocol) (b) is the most commonly used - matches the TCP connection model (c) is used where the service is encapsulated as an object. E.g. could have multiple shared whiteboards with one thread each. Each object has only one thread, avoiding the need for thread synchronization within. 18 3

es and Threads (11): Threads vs processes es and Threads (12): Concurrency Creating a thread is (much) cheaper than a process (~10-20 times) Switching to a different thread in same process is (much) cheaper (5-50 times) Threads within same process can share data and other resources more conveniently and efficiently (without copying or messages) Threads within a process are not protected from each other Figure 6.7 State associated with execution environments and threads Execution environment Address space tables Communication interfaces, open files Semaphores, other synchronization List of thread identifiers Thread Saved processor registers Priority and execution state (such as BLOCKED) Software interrupt handling information Execution environment identifier Pages of address space resident in memory; hardware cache entries Issues in concurrency: Race condition Deadlock Starvation Programming support library (POSIX pthreads) language support (Ada95, Modula-3, Java) 19 20 es and Threads (13) thread (process) execution create/fork exit join/wait yield es and Threads (14) Synchronization coordinate current tasks and prevent race conditions on shared Critical region: only one thread/process at a time is allowed Why critical regions should be as small as possible? Programming support Mutual exclusion Condition Variables Semaphores 21 22 es and Threads (15): Mutual Exclusion Mutual exclusion (mutex) critical region/section before entering critical region, try to lock mutex_lock(l): if try to lock is successful lock and continue else blocked mutex_unlock(l): release the lock es and Threads (16) One producer, one consumer, producer can produce many items (1P1CinfD) How about npncinfd? produce one item while (no data) // count <= 0 sleep (how long? spin poll) consume one item 23 24 4

es and Threads (17): Condition Variables es and Threads (18) Condition variable wait for an event (condition) before proceeding Assoicated mutex with the condition Waiting for an event 1. lock associated mutex m 2. while (predicate is not true) // "if" could work, but less safe 3. cv_wait( c, m ) 4. do work 5. unlock associated mutex m Signaling an event 1. lock associated mutex m 2. set predicate to true 3. cv_signal( c ) // signal condition variable (wake-up one or all) 4. unlock associated mutex m 25 cv_wait(c, m): 1. unlock associated mutex m 2. block thread 3. put it on the queue to wait for a signal 4. lock associated mutex m // why? cv_signal(c): wake up a thread waiting on the condition 26 es and Threads (19) es and Threads (20): Semaphores produce one item cv_signal(yesd) while (no data) cv_wait(yesd, D) consume one item binary semaphores = mutex counting/integer semaphores P(s) [prolagen -- decrease (Dutch)] if s > 0 decrement s else blocked V(s) [verhogen -- increase] increment s 27 28 es and Threads (21): first try es and Threads (22): 1P1CinfD (npncinfd) D=1 //initialization P(D) P(D) while (no data) sleep P(D) Does this work? What are basically P and V used for? 29 D=1 // critical region Count=0 // # of items P(Count) P(D) P(D) // mutex; binary semaphore V(Count) P(Count) P(D) P(D) // mutex; binary semaphore V(Count) P(D) P(D) // mutex; binary semaphore P(Count) V(Count) 30 5

es and Threads (23) Versions 1 and 2 work Version 1 has more concurrency Versions 3 doesn t work Exercises One producer, one consumer, one data item (1P1C1D) [lock steps, PCPC...] One producer, one consumer, up to n data items (1P1CnD) same for npncnd es and Threads (24) What could happen here? mutex_lock(b) mutex_lock(a) mutex_lock(a) mutex_lock(b) do work do work mutex_unlock(b) mutex_unlock(a) mutex_unlock(a) mutex_unlock(b) How to prevent the problem? 31 32 es and Threads (25): Scheduling Preemptive a thread can be suspended at any point for another thread to run Non-preemptive a thread can only be suspended when it de-schedules itself (e.g. blocked by I/O, sync...) [critical region between calls that de-schedule] es and Threads (26): Thread Implementation Kernel-level Win NT, Solaris, Mach, Chorus Kernel schedules threads User-level library based (pthreads, or in the language like java) run-time system in user space manages threads Kernel schedules processes Disadvantages of user-level threads can't take advantage of multiprocessors one thread is blocked because of a page fault, the process is blocked, all the others threads in the same process are blocked threads in different processes aren't scheduled in the same environment Advantages of user-level threads less costly to manage scheduling can be customized more user-level threads can be supported 33 34 es and Threads (27) Mixed Mach: user-level code to provide scheduling hints to the kernel Solaris: assign each user-level thread to a kernel-level thread (multiple user threads can be in one kernel thread) creation/switching at the user level scheduling at the kernel level es and Threads (28) FastThread package hierarchical, event-based scheduling each process has a user-level thread scheduler virtual processors are allocated to processes the # of virtual processors depends on a process's needs physical processors are assigned to virtual processors virtual processors can be dynamically allocated and deallocated to a process according to its needs. Scheduler Activation (SA) event/call from kernel to user-level scheduler represents a time slice on a virtual processor (# of SA's < # of virtual processors) user-level scheduler can assign threads to SA's (time slices). 35 36 6

es and Threads (29) es and Threads (30): Scheduler activations Events from user-level scheduler to kernel P idle: virtual processor is idle P needed: new virtual processor needed Events from kernel to user-level scheduler virtual processor allocated (P added): User-level: scheduler can choose a ready thread to run SA blocked (in kernel): Kernel: sends a new SA User-level: a ready thread is assigned to the new SA to run SA unblocked (in kernel): user-level: thread is back on the ready queue kernel: allocate new virtual processor to process or preempt another SA SA preempted (in kernel): user-level: puts the thread back to the ready queue 37 A Kernel B Virtual processors A. Assignment of virtual processors to processes Skip Sections 6.5 and 6.6 Kernel 38 P idle P needed P added SA preempted SA unblocked SA blocked B. Events between user-level scheduler & kernel Key: P = processor; SA = scheduler activation 7