Operating Systems CSE 411 CPU Management Sept. 25 2006 - Lecture 9 Instructor: Bhuvan Urgaonkar.

Slides:



Advertisements
Similar presentations
Multithreading Overview Multithreading Models Threading Issues
Advertisements

Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
國立台灣大學 資訊工程學系 Chapter 4: Threads. 資工系網媒所 NEWS 實驗室 Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the.
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.
Course: Operating Systems Instructor: Umar Kalim NUST Institute of Information Technology, Pakistan Operating Systems.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads CS 170 TY, Sept 2011.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 4 Multithreaded Programming Objectives Objectives To introduce a notion of.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
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 CMPSC 473 Processes (6) September Lecture 12 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Typical Program Processor utilization?
Operating System Concepts
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads (7 th Edition)
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Multithreaded Programming.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Chapter 4: Multithreaded Programming
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar

Last time –Pre-emptive scheduling –Lottery, Reservation, … Today –Signals –Introduction to accounting CPU accounting –Threads

Interrupts/Traps and Signals Compared Recap interrupt/trap –Used to notify the OS that something has happened that it needs to attend to E.g. 1: Network packet arrived at the Ethernet card E.g. 2: Process made a system call E.g. 3: Process performed division by zero E.g. 4: CPU about to melt! –Interrupt/trap handlers implemented by the OS; their addresses stored at fixed locations indexed by their numbers –Usually handled right away Linux: Top-half right away, bottom-half at leisure Interrupts: Asynchronous generation, synchronous handling Traps: Synchronous generation and handling

Interrupts/Traps versus Signals Used to notify the OS that something has happened that it needs to attend to Interrupt/trap handlers are implemented by the OS Usually handled right away Interrupts asynch. generated, traps synch. generated Used to notify a process that something has happened that it needs to attend to Signal handlers may be implemented by the process Handled when the process is scheduled next Generated and handled synchronously –May be due to an asynch. interrupt, but the signal will be generated synch. WHY?

Signals Fixed number of signals defined by the OS and made known to the processes –UNIX: signal.h A process may implement its own handler for one or more signals –Allowed for most signals, not allowed for SIGKILL –Each PCB has indicators for which signals were received and are due –Upon getting scheduled, the handler for signals received are executed in some order Okay from the process point of view since it is unaware of when it is being scheduled or taken off the CPU

More on signals Each signal has a default action which is one of the following: –The signal is discarded after being received – The process is terminated after the signal is received – A core file is written, then the process is terminated – Stop the process after the signal is received Each signal defined by the system falls into one of five classes: –Hardware conditions – Software conditions – Input/output notification –Process control – Resource control

Examples of signals SIGHUP 1 /* hangup */ SIGINT 2 /* interrupt */ SIGQUIT 3 /* quit */ SIGILL 4 /* illegal instruction */ SIGABRT 6 /* used by abort */ SIGKILL 9 /* hard kill */ SIGALRM 14 /* alarm clock */ SIGCONT 19 /* continue a stopped process */ SIGCHLD 20 /* to parent on child stop or exit */

System calls related to signals kill(signal_num, pid) - to send a signal signal(signal_num, handler) - to handle it

Signal Handling (Visual) time Signal due indicators Signal is not due Signal is due Timer interruptSystem call (trap) Calls kill() to send a signal to P (trap) Accesses illegal memory location (trap) Runs SIGSEGV handler; dumps core and exits PCB of P ISR run; assume P scheduled again Sys call done; Par scheduled Timer interrupt OS Parent of P These are the events that P sees (its view of what is going on)

Some example programs to show signal handling in UNIX

CPU Accounting

OS keeps track of each process’s CPU usage –Scheduler needs this information –Billing in commercial settings E.g., Sun’s Grid: $1 per CPU-hour –Prevent resource exhaustion due to malicious or erroneous processes E.g., fork bomb! –Solution: Limit the number of processes a process can fork Lets look at the top utility –OS provides syscalls for getting certain usage information Look at getrusage() Issue: Who should be charged for CPU usage of the OS? –Consider the example of an I/O-intensive process –Suggested reading: “resource containers” paper (not part of the syllabus)

Threads

What is a Thread? A basic unit of CPU utilization like a process (not necessarily known to the OS though) “Smaller” than a process –Part of a process –Shares code + data + some other OS resources with other threads that belong to the same process Files and signal handlers

User Threads Thread management done by user-level threads library OS doesn’t know about the existence of these threads Three primary thread libraries: – POSIX Pthreads – Win32 threads – Java threads

Kernel Threads OS sees and manages these threads OS provides system calls to create, terminate, etc. (just like the system calls it provides for processes) Examples –Windows XP/2000 –Solaris –Linux –Tru64 UNIX –Mac OS X

Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures

Multithreading Models Many-to-One One-to-One Many-to-Many

Many-to-One Many user-level threads mapped to single kernel thread Examples: –Solaris Green Threads –GNU Portable Threads

Many-to-One Model

One-to-One Each user-level thread maps to kernel thread Examples –Windows NT/XP/2000 –Linux –Solaris 9 and later

One-to-one Model

Many-to-Many Model Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package

Many-to-Many Model

Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples –IRIX –HP-UX –Tru64 UNIX –Solaris 8 and earlier

Two-level Model