Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 6:

Slides:



Advertisements
Similar presentations
Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Advertisements

Threads, SMP, and Microkernels
OPERATING SYSTEM SUPPORT
Operating Systems: Internals and Design Principles
Chapter 3 Process Description and Control
Chorus and other Microkernels Presented by: Jonathan Tanner and Brian Doyle Articles By: Jon Udell Peter D. Varhol Dick Pountain.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Lecture 6: Operating System Support Haibin Zhu, PhD. Assistant Professor Department of Computer Science Nipissing University © 2002.
Fast Communication Firefly RPC Lightweight RPC  CS 614  Tuesday March 13, 2001  Jeff Hoy.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Slides for Chapter 6: Operating System support From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
Edition 3, © Addison-Wesley 2001
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
3.5 Interprocess Communication
1 Chapter 4 Threads Threads: Resource ownership and execution.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Exercises for Chapter 6: Operating System Support
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Chapter 6 Operating System Support. This chapter describes how middleware is supported by the operating system facilities at the nodes of a distributed.
Threads, Thread management & Resource Management.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Exercises for Chapter 7 Operating.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Copyright © George Coulouris, Jean Dollimore, Tim Kindberg This material is made available for private study and for direct.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Threads G.Anuradha (Reference : William Stallings)
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
CS533 - Concepts of Operating Systems 1 The Mach System Presented by Catherine Vilhauer.
Middleware Services. Functions of Middleware Encapsulation Protection Concurrent processing Communication Scheduling.
IS473 Distributed Systems CHAPTER 6 Operating System Support.
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers Distribuerede.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
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.
The Mach System Silberschatz et al Presented By Anjana Venkat.
Operating Systems: Internals and Design Principles
Distributed Systems : Operating System Support
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 7: Operating.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
OPERATING SYSTEM SUPPORT
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Introduction to Operating Systems Concepts
Kernel Design & Implementation
CS533 Concepts of Operating Systems
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 6: Operating System Support
Threads, SMP, and Microkernels
Slides for Chapter 6: Operating System support
Lecture 4- Threads, SMP, and Microkernels
Threads Chapter 4.
Prof. Leonardo Mostarda University of Camerino
Chapter 4: Threads.
Presentation transcript:

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 6: Operating System Support

Network operating system –network capability access remote resources, e.g., NFS, rlogin, telnet –Multiple system images, one per node –Examples: Windows NT, Unix Distributed operating system –Single system image: transparency Network OS & Distributed OS

Middleware and network OS –No distributed OS in general use Users have much invested in their application software Users tend to prefer to have a degree of autonomy for their machines Network OS: meet the requirements of middleware –Efficient and robust access to physical resources –Flexibility to implement a variety of resource management policies Middleware and network OS

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Operating System –Tasks: processing, storage and communication –Components: kernel, library, user-level services Middleware –runs on a variety of OS-hardware combinations –remote invocations Architecture The relationship between OS and Middleware

Encapsulation –provide a set of operations that meet their clients’ needs Protection –protect resource from illegitimate access Concurrent processing –support clients access resource concurrently Supports for RMI –Communication in RMI Pass operation parameters and results –Scheduling in RMI Schedule the processing of the invoked operation Functions that OS should provide for middleware

Process manager –Handles the creation of and operations upon processes. Thread manager –Thread creation, synchronization and scheduling Communication manager –Communication between threads attached to different processes on the same computer Memory manager –Management of physical and virtual memory Supervisor –Dispatching of interrupts, system call traps and other exceptions –control of memory management unit and hardware caches –processor and floating point unit register manipulations Figure The core OS components

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Maliciously contrived code Benign code –contains a bug –have unanticipated behavior Example: read and write in File System –Illegal user vs. access right control –Access the file pointer variable directly (setFilePointerRandomly) vs. type-safe language Type–safe language, e.g. Java Non-type-safe language, e.g. C or C++ Illegitimate access

Kernel –always runs –complete access privileges for the physical resources Different execution mode –supervisor mode (kernel process) / user mode (user process) –Interface between kernel and user processes: system call trap Kernel design is a good choice for protection The price for protection –switching between different processes take many processor cycles –a system call trap is a more expensive operation than a simple method call Kernel and Protection

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Process –A unit of resource management, a single activity –Problem: sharing between related activities are awkward and expensive –Nowadays, a process consists of an execution environment together with one or more threads Thread –Abstraction of a single activity –Objective maximize the degree of concurrent execution between operations E.g. overlap of computation with input and output E.g. concurrent processing on multiple processors within a process Concepts

Execution environment –the unit of resource management –Consist of An address space Thread synchronization and communication resources such as semaphores and communication interfaces (e.g. sockets) Higher-level resources such as open files and windows –Shared by threads within a process, some times across process Heavyweight process / lightweight process Concepts … continued

Address space –a unit of management of a process’s virtual memory –2 32 bytes, 2 64 bytes –consists of one or more regions Region –an area of continuous virtual memory that is accessible by the threads of the owning process UNIX address space Address space

The number of regions is indefinite –Support a separate stack for each thread –access mapped file –Share memory between processes The uses of shared region –Libraries –Kernel –Data sharing and communication between two processes, or between process and kernel Address space … continued

Traditional process creation –Fork, exec in Unix Process creation in distributed system –The choice of a target host –The creation of an execution environment, an initial thread Creation of a new execution environment –initializing the address space Statically defined format With respect to an existing execution environment, e.g. fork –Copy-on-write schemeCopy-on-write Creation of new process in distributed system

Choice of process host –run new processes at their originator’s computer –load sharing between a set of computers Load sharing policy –Transfer policy: situate a new process locally or remotely? –Location policy: which node should host the new process? Static policy Adaptive policy –Migration policy: when&where should migrate the running process? Load sharing system –Centralized –Hierarchical –Decentralized Choice of process host

Example: client and server with threads Given: t p = 2 ms, t io = 8 ms, Quest.: T (maximum server throughput) ? Threads – an example Server N threads Input-output Client Thread 2 makes T1 Thread 1 requests to server generates results Requests Receipt & queuing

1.A single thread: T = 1000/(2+8) = 100 –requests are handled one by one 2.Two threads: T = 1000/8 = 125 –processing on one request can overlap the disk IO of another request Different server implementations (1, 2) 8 ms (2)

3.Two threads, disk cache (75% hit): T = 1000 / 2.5 = 400 – t io = 75%*0+25%*8 = 2ms; due to search in cache, processing delay increase, say 2.5ms, t p = 2.5 ms 4.Up to two threads, disk cache, two processors: T = 1000 / 2 = 500 –Processing on different requests can be overlapped Different server implementations (3, 4) 2ms (4) 2.5 ms (3)

Worker pool –Server creates a fixed pool of “worker” threads to process the requests when it starts up –Pro: simple –Cons Inflexibility: worker threads number unequal current request number High level of switching between the I/O and worker thread Thread-per-request –Server spawn a new worker thread for each new request, destroy it when the request processing finish –Pro: throughput is potentially maximized –Con: overhead of the thread creation and destruction Architectures for multi-threaded servers

Thread-per-connection –Server creates a new worker thread when client creates a connection, destroys the thread when the client closes the connection –Pro: lower thread management overheads compared with the thread-per-request –Con: client may be delayed while a worker thread has several outstanding requests but another thread has no work to perform Thread-per-object –Associate a thread with each remote object –Pro&Con are similar to thread-per-connection Architectures for multi-threaded servers … continued

The client example –First thread: generates results to be passed to a server by remote method invocation, but does not need a reply –Second thread: perform the remote method and block while the first thread is able to continue computing further results Web browser –Multiple threads handle multiple concurrent requests for web pages Threads within clients

Main state components of Execution Environment and ThreadMain state components of Execution Environment and Thread The comparison of processes and threads –Creating a new thread within an existing process is cheaper than creating a process 1ms vs.11ms –Switching to a different thread within the same process is cheaper than switching between threads belonging to different processes 0.4ms vs. 1.8ms –Threads within a process may share data and other resources conveniently and efficiently compared with separate process –But, threads within a process are not protected from one another Threads versus multiple processes

Concurrent programming –Race condition, critical section, monitor, condition variable, semaphore –C Threads package or pthreads for C, Java The Java thread classThe Java thread class Threads programming

Variable –each thread’s local variables in methods are private to it –no private copies of static variables or object instance variables Java synchronized methods Example: multiple threads manipulate a queue –Mutual exclusive Synchronized method of addto() and removefrom() methods in the queue class –Producer-consumer Wait(): block on waiting condition variables notify(): unblock the waiting threads Thread synchronization

Preemptive scheduling –A thread may be suspended at any point to make way for another thread Non-preemptive scheduling –a thread runs until it makes a call to the threading system, when the system may de-schedule it and schedule another thread to run Avoid race condition Can’t take advantage of a multiprocessor since it run exclusively The programmer need to insert yield() calls Thread scheduling

Kernel (e.g., Windows NT, Solaris, Mach) / User level (runtime library) User-level implementation –Cons: Threads within a process can’t take advantage of multiprocessors A thread that takes a page fault blocks the entire process Threads within different processes can’t be scheduled –Pros: less costly, e.g. no system call customization more user-level threads can be supported Hybrid approach –Two-tier scheduling the kernel provides access to multiple processors, while user-level code handles the details of scheduling policy –Solaris 2 operating system lightweight process (kernel level threads) and user level threads Threads implementation

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Communication primitives –TCP(UDP) Socket in Unix and Windows –DoOperation, getRequest, sendReply in Amoeba –Group communication primitives in V system Protocols and openness –provide standard protocols that enable internetworking between middleware –integrate low-level protocols without upgrading their application –Static stack new layer to be integrated statically as a “driver” –Dynamic stack protocol stack be composed on the fly E.g. web browser utilize wide-area wireless link on the road and faster Ethernet connection in the office Communication primitives & protocols

Invocation costs –Different invocationsDifferent invocations –The factors that matter synchronous/asynchronous, domain transition, communication across a network, thread scheduling and switching Invocation over the network –Delay: the total RPC call time experienced by a client –Latency: the fixed overhead of an RPC, measured by null RPC –Throughput: the rate of data transfer between computers in a single RPC –An exampleAn example Threshold: one extra packet to be sent, an extra acknowledge packet is needed Invocation performance

Marshalling & unmarshalling –Copy and convert data –a significant overhead as the amount of data grows Data copying –Across the user-kernel boundary –Across each protocol layer ( e.g., RPC/UDP/IP/Ethernet ) –Between the network interface and kernel buffers Packet initialization –Initializing protocol headers and trailers –Checksums: in proportional to the amount of data sent Thread scheduling and context switching –System calls as stub invoke the kernel’s communication operations –one or more server threads –network manager process and threads Waiting for acknowledgements Network transmission Main components accounting for remote invocation delay

Memory sharing –rapid communication between processes in the same computer Choice of protocol –TCP/UDP –Persistent connections: several invocations during one –OS’s buffer collect several small messages and send them together Invocation within a computer –Most cross-address-space invocation take place within a computer –LRPC (lightweight RPC)LRPC (lightweight RPC) Improve the performance of RPC

Performance characteristics of the Internet –High latencies, low bandwidths and high server loads –Network disconnection and reconnection. –outweigh any benefits that the OS can provide Asynchronous operation –Concurrent invocations E.g., the browser fetches multiple images in a home page by concurrent GET requests –Asynchronous invocation: non-blocking call E.g., CORBA oneway invocation: maybe semantics, collect result by a separate call Asynchronous operation

Persistent asynchronous invocations –Designed for disconnected operation –Try indefinitely to perform the invocation, until it is known to have succeeded or failed, or until the application cancels the invocation –QRPC (Queued RPC) Client queue outgoing invocation requests in a stable log Server queue invocation results The issues to programmers –How user can continue while the results of invocations are still not known? Asynchronous operation … continued

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Monolithic kernel –Kernel is massive: perform all basic operating system functions, megabytes of code and data –Kernel is undifferentiated: coded in a non-modular way –E.g. Unix –Pros: efficiency –Cons: lack of structure Microkernel –Kernel provides only the most basic abstractions: address spaces, threads and local interprocess communication –All other system services are provided by servers that are dynamically loaded –E.g., VM of IBM 370 –Pros: extensibility, modularity, free of bugs –Cons: relatively inefficiency Hybrid approaches Monolithic kernels and microkernels

Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary Chapter 5: Operating System Support

Process & thread –A Process consists of multiple threads and an execution environment –Multiple-threads: cheaper concurrency, take advantage of multiprocessors for parallelism Remote invocation cost –Marshalling & unmarshalling –data copying –packet initialization –thread scheduling and context switching –Network transmission OS architecture –Monolithic kernel & microkernel Summary

System layers

Core OS functionality

Address space

Copy-on-write scheme a) Before writeb) After write Shared frame A's page table B's page table Process A’s address spaceProcess B’s address space Kernel RARB RB copied from RA

Alternative server threading architecture

State associated with execution environments and threads Execution environmentThread Address space tablesSaved processor registers Communication interfaces, open filesPriority and execution state (such as BLOCKED) Semaphores, other synchronization objects Software interrupt handling information List of thread identifiersExecution environment identifier Pages of address space resident in memory; hardware cache entries

Java Thread constructor and management methods Thread(ThreadGroup group, Runnable target, String name) Creates a new thread in the SUSPENDED state, which will belong to group and be identified as name; the thread will execute the run() method of target. setPriority(int newPriority), getPriority() Set and return the thread’s priority. run() A thread executes the run() method of its target object, if it has one, and otherwise its own run() method (Thread implements Runnable). start() Change the state of the thread from SUSPENDED to RUNNABLE. sleep(int millisecs) Cause the thread to enter the SUSPENDED state for the specified time. yield() Enter the READY state and invoke the scheduler. destroy() Destroy the thread.

Invocations between address spaces

Delay of an RPC operation when returned data size varies

A lightweight remote procedure call

Times for serialized and concurrent invocations

Monolithic kernel and Microkernel