What s the difference between threads/processes. Operating Systems

Similar documents
Introduction. CS3026 Operating Systems Lecture 01

Computer Systems II. First Two Major Computer System Evolution Steps

CS 4284 Systems Capstone. Processes and Threads Godmar Back

Operating System. Operating System Overview. Structure of a Computer System. Structure of a Computer System. Structure of a Computer System

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Process Characteristics

Sistemi in Tempo Reale

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Four Components of a Computer System. Operating System Concepts 7 th Edition, Jan 12, 2005

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

CS 550 Operating Systems Spring Interrupt

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Operating Systemss and Multicore Programming (1DT089)

Introduction to Operating. Chapter Chapter

CS370 Operating Systems

Introduction to Operating Systems. Chapter Chapter

Introduction to Operating Systems. Chapter Chapter

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

Introduction to Operating Systems

Hardware OS & OS- Application interface

Concurrent programming: Introduction II. Anna Lina Ruscelli Scuola Superiore Sant Anna

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Chapter 13: I/O Systems

Chapter 13: I/O Systems

Process Scheduling Queues

Chapter 13: I/O Systems. Operating System Concepts 9 th Edition

Inter-Process Communication and Synchronization of Processes, Threads and Tasks: Lesson-1: PROCESS

Chapter 13: I/O Systems

I/O Systems. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

CS370 Operating Systems

Processes and Threads

Chapter 12: I/O Systems

Chapter 13: I/O Systems

Chapter 12: I/O Systems. Operating System Concepts Essentials 8 th Edition

Part I Overview Chapter 1: Introduction

Lecture 2 Fundamental OS Concepts. Bo 2018, Spring

Role 1: The Operating System is an Abstract Machine. Learning Outcomes. Introduction to Operating Systems. What is an Operating System?

Operating System Services

Basic Computer Hardware

Computer Architecture and OS. EECS678 Lecture 2

Processes and Exceptions

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Chapter 13: I/O Systems

Chapter 13: I/O Systems. Chapter 13: I/O Systems. Objectives. I/O Hardware. A Typical PC Bus Structure. Device I/O Port Locations on PCs (partial)

Lecture 4: Memory Management & The Programming Interface

Process Description and Control

Threads, SMP, and Microkernels. Chapter 4

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Chapter 13: I/O Systems

Lecture 15: I/O Devices & Drivers

Exceptions and Processes

CS 201. Exceptions and Processes. Gerson Robboy Portland State University

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

CS 5460/6460 Operating Systems

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

CPSC 341 OS & Networks. Introduction. Dr. Yingwu Zhu

Device-Functionality Progression

Chapter 12: I/O Systems. I/O Hardware

EECS 678: Introduction to Operating Systems. Heechul Yun

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

EE458 - Embedded Systems Exceptions and Interrupts

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications

Operating Systems Overview. Chapter 2

2008 Chapter-8 L1: "Embedded Systems - Architecture, Programming and Design", Raj Kamal, Publs.: McGraw-Hill, Inc.

Operating Systems Fundamentals. What is an Operating System? Focus. Computer System Components. Chapter 1: Introduction

Module 12: I/O Systems

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

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

Operating Systems Course 2 nd semester 2016/2017 Chapter 1: Introduction

Operating Systems Overview. Chapter 2

CSC 2405: Computer Systems II

Operating Systems Overview

3.1 Introduction. Computers perform operations concurrently

Chapter 13: I/O Systems

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

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

Operating System Overview

Advanced Operating Systems (CS 202) Scheduling (1)

I/O Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Process Description and Control. Chapter 3

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Mon Sep 17, 2007 Lecture 3: Process Management

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Process Description and Control. Chapter 3

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

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

CS 326: Operating Systems. CPU Scheduling. Lecture 6

Module 12: I/O Systems

Lecture 2: Architectural Support for OSes

2/14/2012. Using a layered approach, the operating system is divided into N levels or layers. Also view as a stack of services

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

CS140 Operating Systems

CS420: Operating Systems

Princeton University Computer Science 217: Introduction to Programming Systems Exceptions and Processes

EECS 3221 Operating System Fundamentals

Transcription:

Overview Definitions 1 How does OS execute processes? How do kernel & processes interact How does kernel switch between processes How do interrupts fit in What s the difference between threads/processes Process States Priority Scheduling Process These are all possible definitions: A program in execution An instance of a program running on a computer Schedulable entity (*) Unit of resource ownership Unit of protection Execution sequence (*) + current state (*) + set of resources 2 (*) can be said of threads as well

Alternative definition Thread: Execution sequence + CPU state (registers + stack) 3 Process: n Threads + Resources shared by them (specifically: accessible heap memory, global variables, file descriptors, etc.) In most contemporary OS, n >= 1. In Pintos, n=1: a process is a thread as in traditional Unix. Following discussion applies to both threads & processes. Context Switching 4 Multiprogramming: switch to another process if current process is (momentarily) blocked Time-sharing: switch to another process periodically to make sure all process make equal progress this switch is called a context switch. Must understand how it works how it interacts with user/kernel mode switching how it maintains the illusion of each process having the CPU to itself (process must not notice being switched in and out!)

Single Program vs Multiprogramming 5 Context Switching 6 Timer Timer interrupt: P1 P1 is is preempted, context context switch switch to to P2 P2 Process 1 Process 2 I/O I/O device device interrupt: P2 s P2 s I/O I/O complete switch switch back back to to P2 P2 user mode kernel mode Kernel System System call: call: (trap): (trap): P2 P2 starts starts I/O I/O operation, blocks blocks context context switch switch to to process 1 Timer Timer interrupt: P2 P2 still still has has time time left, left, no no context context switch switch

Aside: Kernel Threads 7 Process 1 Most Most OS OS (including Pintos) Pintos) support kernel kernel threads threads that that never never run run in in user user mode mode in in fact, fact, in in Project Project 1, 1, all all Pintos Pintos threads threads run run like like that. that. Process 2 user mode kernel mode Kernel Kernel Thread Careful: kernel thread not the same as kernel-level thread (KLT) more on KLT later Mode Switching User Kernel mode For reasons external or internal to CPU 8 External (aka hardware) interrupt: timer/clock chip, I/O device, network card, keyboard, mouse asynchronous (with respect to the executing program) Internal interrupt (aka software interrupt, trap, or exception) are synchronous can be intended: for system call (process wants to enter kernel to obtain services) or unintended (usually): fault/exception (division by zero, attempt to execute privileged instruction in user mode) Kernel User mode switch on iret instruction

Context vs Mode Switching Mode switch guarantees kernel gains control when needed To react to external events To handle error situations Entry into kernel is controlled 9 Not all mode switches lead to context switches Kernel code s logic decides when subject of scheduling Mode switch always hardware supported Context switch (typically) not this means many options for implementing it! Protection Multiprogramming requires isolation 10 OS must protect/isolate applications from each other, and OS from applications This requirement is absolute In Pintos also: if one application crashes, kernel should not! Bulletproof. Three techniques Preemption Interposition Privilege

Protection #1: Preemption 11 Resource can be given to process and access can be revoked Example: CPU, Memory, Printer, abstract resources: files, sockets CPU Preemption using interrupts Hardware timer interrupt invokes OS, OS checks if current process should be preempted, done every 1ms in Linux Solves infinite loop problem! Q.: Does it work with all resources equally? Protection #2: Interposition OS hides the hardware 12 Application have to go through OS to access resources OS can interpose checks: Validity (Address Translation) Permission (Security Policy) Resource Constraints (Quotas)

Protection #3: Privilege Two fundamental modes: kernel mode privileged aka system, supervisor or monitor mode Intel calls its PL0, Privilege Level 0 on x86 user mode non-privileged PL3 on x86 Bit in CPU controls operation of CPU Protection operations can only be performed in kernel mode. Example: hlt Carefully control transitions between user & kernel mode 13 int intmain() {{ asm( hlt ); }} OS as a Resource Manager 14 OS provides illusions, examples: every process is run on its own CPU every process has all the memory of the machine (and more) every process has its own I/O terminal Stretches resources Possible because resource usage is bursty, typically Increases utilization

Resource Management Multiplexing increases complexity 15 Car Analogy (by Rosenblum): Dedicated road per car would be incredibly inefficient, so cars share freeway. Must manage this. (abstraction) different lanes per direction (synchronization) traffic lights (increase capacity) build more roads More utilization creates contention (decrease demand) slow down (backoff/retry) use highway during off-peak hours (refuse service, quotas) force people into public transportation (system collapse) traffic jams Resource Management OS must decide who gets to use what resource 16 Approach 1: have admin (boss) tell it Approach 2: have user tell it What if user lies? What if user doesn t know? Approach 3: figure it out through feedback Problem: how to tell power users from resource hogs?

Goals for Resource Management Fairness Assign resources equitably 17 Differential Responsiveness Cater to individual applications needs Efficiency Maximize throughput, minimize response time, support as many apps as you can These goals are often conflicting. All about trade-offs