CS 3204 Operating Systems Lecture 25 Godmar Back.

Slides:



Advertisements
Similar presentations
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Advertisements

Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Chapter 5 Processes and Threads Copyright © 2008.
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
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CS533 Concepts of Operating Systems Class 3 Integrated Task and Stack Management.
Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
A. Frank - P. Weisberg Operating Systems Threads Implementation.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
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.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Threads & Scheduling What are threads?
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
CS 153 Design of Operating Systems Spring 2015
Operating Systems Lecture 09: Threads (Chapter 4)
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Operating System 4 THREADS, SMP AND MICROKERNELS
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
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.
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 Systems CMPSC 473 Lecture 8: Threads September Instructor: Bhuvan Urgaonkar.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Operating System 4 THREADS, SMP AND MICROKERNELS.
Operating Systems CMPSC 473 Processes (6) September Lecture 12 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Processes & Threads Introduction to Operating Systems: Module 5.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
Operating System Concepts
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.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
CS 3214 Computer Systems Lecture 9 Godmar Back.
Chapter 4: Threads.
CS 6560: Operating Systems Design
Day 12 Threads.
Chapter 4 Threads.
Threads & multithreading
Threads Chapter 4.
Threads Chapter 4.
CS 3204 Operating Systems Lecture 30 Godmar Back.
CS703 – Advanced Operating Systems
CS 5204 Operating Systems Lecture 5
Presentation transcript:

CS 3204 Operating Systems Lecture 25 Godmar Back

Announcements Project 4 due Dec 10 11:59pm Don’t postpone to after Thanksgiving Should get done before break: buffer cache (so all regression tests pass), and have designed and partially implemented on-disk data structures (inode + index trees) Project 4 Help Session Slides online Check exam time and let me know of possible conflicts as per University policy Reading Chapter 10-12 CS 3204 Fall 2008 4/25/2017

Address Spaces vs Protection Domains

Address Spaces & Protection Domains Normal case: each user process has its own address space & own protection domain Sharing an address space means to put the same meaning to a particular virtual address Sharing a protection domain means to have the same access rights to a particular piece of memory The two are not always identical: Single address space OS all processes share one address space – ideally 64bit advantage: can use pointers as names for objects disadvantage: loading/linking slightly more complex CS 3204 Fall 2008 4/25/2017

Address Space & Threads Real-world combinations # of address spaces 1 many 1 thread/space MS-DOS MacOS-9 Traditional Unix (BSD 4.3, 4.4, SVR3); Pintos many threads/space multi-threading Embedded Systems; Pilot (1978) VMS, Mach, Win/NT, Solaris, Linux NB: threads listed here are “kernel-level” threads (KLT) – threads of which the kernel is aware CS 3204 Fall 2008 4/25/2017

Kernel-level vs User-level Threads

Kernel-level vs User-level Threads Kernel-level threads: (KLT) Aka 1:1 model Kernel knows about them: Have kernel-assigned thread id + TCB Have their own kernel stack Alternative: it is also possible to build “user-level” threads (ULT) Kernel is unaware of them Aka 1:N model Combinations of these models are possible as well CS 3204 Fall 2008 4/25/2017

User-level Threads Usually implemented using library (recall: core of context switching code in Pintos did not require any privileged instructions – so can do it in a user program also) Possible to implement via setjmp/longjmp Similar to “co-routine” concept Advantages can be lightweight context switches can be fast (don’t have to enter kernel, and since shared address space no TLB flush required) can be done (almost) portably for any OS CS 3204 Fall 2008 4/25/2017

User-level Threads - Issues How can traditional RUNNING/READY/BLOCKED state model be implemented? Problem: RUNNING->BLOCKED transitions should cause another READY thread to be scheduled Q.: what happens if user-level thread calls the “read()” system call and blocks in kernel? Must use elaborate mechanisms that avoid blocking in the kernel Option: Redirect all system calls that might block entire process and replace them with non-blocking versions Then poll kernel later when I/O has completed (or have kernel notify you) Overhead: may require additional system call for starting and completing I/O Since kernel sees only one thread, can use at most 1 CPU – not truly SMP-capable But: where application-specific scheduling is desirable, it can be more easily implemented in a ULT system CS 3204 Fall 2008 4/25/2017

Preemption vs Nonpreemption Implementing preemption in user-level threads requires timer- or I/O-interrupt like notification facility (SIGALRM + SIGIO in Unix) But then overhead of saving all state returns Truly lightweight user-level threads are non-preemptive Highly scalable in number of threads Makes implementing locks really easy – no need for atomic instructions! But then: cannot preempt uncooperative threads, lose ability to round-robin schedule CPU bound threads CS 3204 Fall 2008 4/25/2017

Aside: UNIX/POSIX Signals General notification interface that is used for many things in POSIX-like systems Examples (read kill(2), signal(2), signal(7)): Job control (Ctrl-C, Ctrl-Z) send SIGINT/SIGSTOP to process Processes can send each other (or themselves) signals Signals are used for error conditions: SIGSEGV, SIGILL Also used for timers, I/O conditions, profiling Default handling depends on signal: ignore, terminate, stop, core-dump processes can override handling kernel may invoke signal handlers if so instructed: like interrupt handlers – same issues apply wrt safety POSIX signals are per-process, complex rules describe which thread within process may handle a signal CS 3204 Fall 2008 4/25/2017

Managing Stack Space stack1 stack2 guard Stacks require continuous part of virtual address space On 32-bit systems: virtual address space fragmentation can result only have 3GB total in user space for code, data, shared libs – limits the number of threads What size should stack have? This is an issue for both ULT & KLT How to detect stack overflow (or grow stack)? Detect in software or in hardware (or ignore) Stack growth usually only available in KLT implementations Compiler support can create discontiguous stacks Related Issues: how to implement Get local thread id “pthread_self()” Thread-local storage (TLS) CS 3204 Fall 2008 4/25/2017

M:N Model Solaris Lightweight Processes CS 3204 Fall 2008 4/25/2017

M:N Model (cont’d) Invented for use in Solaris OS early 90s Championed for a while Idea was to get the best of both worlds Fast context switches if between user-level threads Yet enough concurrency to exploit multiple CPUs Since abandoned in favor of kernel-level threads only approach Too complex – what’s the “right” number of LWP? 2-level scheduling/resource management was hard: both user/kernel operated half-blind Interesting history can be found here CS 3204 Fall 2008 4/25/2017

Multi-Threading in Linux Went through different revisions Started as 1:1 with minimal kernel support (only clone(2)), and high overhead (“linux-threads”) Today (Linux 2.6): NPTL – Next-Generation POSIX Thread Library 1:1 model optimizes synchronization via “futexes” avoids mode switch for common case of uncontended locks by performing atomic operation constant-time scheduling operation allow for scaling in number of threads CS 3204 Fall 2008 4/25/2017

Summary Address Spaces vs Protection Domains Kernel vs User-Level Threads Don’t confuse “kernel-level threads” with “kernel threads” kernel threads: never execute user code, execute kernel code, in kernel mode, only; are not associated with user address space kernel-level threads: are threads that execute user code, can call into the kernel via syscalls/page faults; are associated with a user address space both are viewed as schedulable entities by the kernel CS 3204 Fall 2008 4/25/2017