Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

CS 5460/6460 Operating Systems

Lecture 2: September 9

Architectural Support for Operating Systems

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

Even coarse architectural trends impact tremendously the design of systems

CSE 153 Design of Operating Systems Fall 18

CSE 120 Principles of Operating Systems

CS5460: Operating Systems

CSE 120 Principles of Operating Systems

Hardware OS & OS- Application interface

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Lecture 2: Architectural Support for OSes

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

Introduction to Operating Systems. Chapter Chapter

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

Even coarse architectural trends impact tremendously the design of systems. Even coarse architectural trends impact tremendously the design of systems

Introduction to Operating. Chapter Chapter

Anne Bracy CS 3410 Computer Science Cornell University

CSE 153 Design of Operating Systems

CSE 451: Operating Systems Winter Module 2 Architectural Support for Operating Systems

Even coarse architectural trends impact tremendously the design of systems

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

Unit 2 : Computer and Operating System Structure

CS370 Operating Systems

Introduction to Operating Systems. Chapter Chapter

Common Computer-System and OS Structures

Architecture and OS. To do. q Architecture impact on OS q OS impact on architecture q Next time: OS components and structure

CS333 Intro to Operating Systems. Jonathan Walpole

CS370 Operating Systems

Chapter 13: I/O Systems

Introduction. CS3026 Operating Systems Lecture 01

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

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Topic 18: Virtual Memory

CS 333 Introduction to Operating Systems. Class 1 - Introduction to OS-related Hardware and Software

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

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

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

Architectural Support for OS

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

CSC 2405: Computer Systems II

Computer Architecture and OS. EECS678 Lecture 2

Chapter 1 Computer System Overview

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

John Wawrzynek & Nick Weaver

Architectural Support for Operating Systems

CS 261 Fall Mike Lam, Professor. Virtual Memory

Threads Implementation. Jo, Heeseung

Computer System Overview

CS399 New Beginnings. Jonathan Walpole

Processes and Tasks What comprises the state of a running program (a process or task)?

Process Scheduling Queues

The Lesson Plan of OS. The syllabus of OS. Access the lesson plan and syllabus at

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

ECE 485/585 Microprocessor System Design

CS 153 Design of Operating Systems Winter 2016

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Intro to Virtual Memory

Last class: OS and Architecture. OS and Computer Architecture

Last class: OS and Architecture. Chapter 3: Operating-System Structures. OS and Computer Architecture. Common System Components

Introduction to System Programming

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

CS510 Operating System Foundations. Jonathan Walpole

ecture 33 Virtual Memory Friedland and Weaver Computer Science 61C Spring 2017 April 12th, 2017

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

Protection and System Calls. Otto J. Anshus

ELEC 377 Operating Systems. Week 1 Class 2

Computer architecture. A simplified model

Address spaces and memory management

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

CS 333 Introduction to Operating Systems. Class 1 - Introduction to OS-related Hardware and Software

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

Operating System Review

Introduction to Computer Systems and Operating Systems

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Page 1, 5/4/99 8:22 PM

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

EE458 - Embedded Systems Exceptions and Interrupts

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

CSE 560 Computer Systems Architecture

Distributed Systems Operation System Support

Q.1 Explain Computer s Basic Elements

GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATION SEMESTER: III

Dan Noé University of New Hampshire / VeloBit

Syscalls, exceptions, and interrupts, oh my!

OS: An Overview. ICS332 Operating Systems

CS330: Operating System and Lab. (Spring 2006) I/O Systems

CS 153 Design of Operating Systems Winter 2016

CSE 120 Principles of Operating Systems Spring 2017

Operating Systems 2010/2011

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Hardware, Modularity, and Virtualization CS 111

Chapter 5 B. Large and Fast: Exploiting Memory Hierarchy

What s the difference between threads/processes. Operating Systems

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Transcription:

Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst

Last Class: Intro to OS An operating system is the interface between the user and the architecture. User-level Applications virtual machine interface History lesson in change. Operating System OS reacts to changes in hardware, and can motivate changes. physical machine interface Hardware CS377: Operating Systems

Operating System Principles OS as juggler/virtualizer: providing the illusion of a dedicated machine with infinite memory and CPU. OS as government: protecting users from each other, allocating resources efficiently and fairly, and providing secure and safe communication. OS as complex system: keeping OS design and implementation as simple as possible is the key to getting the OS to work. OS as history teacher: learning from past to predict the future, i.e., OS design tradeoffs change with technology. CS377: Operating Systems

Today: OS and Architecture Basic OS Functionality Basic Architecture reminder What the OS can do is dictated in part by the architecture. Architectural support can greatly simplify or complicate the OS. CS377: Operating Systems

Architecture Basics

Mobile What is important here?

Generic Architecture System Networ CPU: performs the actual computation Multiple cores common in today s processors I/O devices: terminal, disks, video board, printer, etc. Network card is a key component, but also an I/O device Memory: RAM containing data and programs used by CPU System bus: communication CPU, memory, peripherals

Modern OS Functionality Process and Thread Management Concurrency: Doing many things simultaneously (I/0, processing, multiple programs, etc.) Several users work at the same time as if each has a private machine Threads (unit of OS control) - one thread on the CPU at a time, but many threads active concurrently I/O devices: let the CPU work while a slow I/O device is working Memory management: OS coordinates allocation of memory and moving data between disk and main memory. Files: OS coordinates how disk space is used for files, in order to find files and to store multiple files Distributed systems & networks: allow a group of machines to work together on distributed hardware CS377: Operating Systems

Architectural Features Motivated by OS OS Service Protection Interrupts System calls I/O Scheduling, error recovery, accounting Synchronization Virtual memory Hardware Support Kernel/user mode, protected instructions, base/limit Interrupt vectors Trap instructions and trap Interrupts vectors and memory Timer Atomic instructions Translation look-aside buffers CS377: Operating Systems

Protection CPU supports a set of assembly instructions MOV [address], ax ADD ax, bx MOV CRn (move control register) IN, INS (input string) HLT (halt) LTR (load task register) INT n (software interrupt) Some instructions are sensitive or privileged

Protection Kernel mode vs. User mode: To protect the system from aberrant users and processors, some instructions are restricted to use only by the OS. Users may not (but Kernel can..) address I/O directly use instructions that manipulate the state of memory (page table pointers, TLB load, etc.) set the mode bits that determine user or kernel mode disable and enable interrupts halt the machine The hardware must support at least kernel and user mode. A status bit in a protected processor register indicates the mode. Protected instructions can only be executed in kernel mode.

Crossing Protection Boundaries System call: OS procedure that executes privileged instructions (e.g., I/O) ; This is the API exported by the kernel Causes a trap, which vectors (jumps) to the trap handler in the OS kernel. The trap handler uses the parameter to the system call to jump to the appropriate handler (I/O, Terminal, etc.). The handler saves caller's state (PC, mode bit) so it can restore control to the user process. The architecture must permit the OS to verify the caller's parameters. The architecture must also provide a way to return to user mode when finished.

Example System calls

Windows System Calls

Memory Protection Architecture must provide support so OS can protect user programs from each other, and protect the OS from user programs. The simplest technique is to use base and limit registers. Base and limit registers are loaded by the OS before starting a program. The CPU checks each user reference (instruction and data addresses), ensuring it falls between the base and limit register values Base register Limit register

Process Layout in Memory Processes have three segments: text, data, stack 12

Clicker Question #1 If a machine s addresses go from 0 to FFFF, what kind of machine is this? (A) 8 bit machine (B) 16 bit machine (C) 32 bit machine (D) 64 bit machine

Answer on Next Slide

Registers Register = dedicated name for one word of memory managed by CPU General-purpose: AX, BX, CX on x86 Special-purpose: SP = stack pointer FP = frame pointer PC = program counter Change processes: save current registers & load saved registers = context switch CS377: Operating Systems 14

Memory Hierarchy registers 1-cycle latency L1 2-cycle latency load L2 evict 7-cycle latency RAM 100 cycle latency Disk 40,000,000 cycle latency Network 200,000,000+ cycle latency

Clicker Question #2 Listed from fastest to slowest, which is correct? (A) Registers, L2 Cache, L1 Cache, RAM, Disk, Network (B) Registers, L1 Cache, L2 Cache, RAM, Disk, Network (C) Registers, RAM, L2 Cache, L1 Cache, Network, Disk, (D) Registers, RAM, L2 Cache, L1 Cache, Disk, Network

Answer on Next Slide

Caches Access to main memory: expensive : ~ 100 cycles Caches: small, fast, expensive memory (recently-accessed data/ instructions) Different sizes & locations Level 1 (L1) on-chip, smallish Level 2 (L2) on or next to chip, larger Level 3 (L3) pretty large, on bus Caches are managed by hardware (no explicit OS management) CS377: Operating Systems 15

Traps Traps: special conditions detected by the HW HW is invoking the OS as the exception handler Happens in response to a process instruction Examples: page fault, write to a read-only page, overflow, system call On completion, the OS resumes process, perhaps returning an error or sending a signal CS377: Operating Systems

Traps On detecting a trap, the hardware Saves the state of the process (PC, stack, etc.) Transfers control to correct trap handler (OS routine) The CPU indexes the memory-mapped trap vector with the trap number, then jumps to the address given in the vector, and starts to execute at that address.

Traps Trap Vector: 0: 0x00080000 Illegal Address 1: 0x00100000 Memory Violation 2: 0x00100480 Illegal Instruction 3: 0x00123010 System Call Modern OS use Virtual Memory traps for many functions: debugging, distributed VM, garbage collection, copy-on-write, etc. Traps are a performance optimization. A less efficient solution is to insert extra instructions into the code everywhere a special condition could arise. Recap of System Calls from page 8 CS377: Operating Systems

I/O Control Each I/O device has a little processor inside it that enables it to run autonomously. CPU issues commands to I/O devices, and continues When the I/0 device completes the command, it issues an interrupt CPU stops whatever it was doing and the OS processes the I/O device's interrupt CS377: Operating Systems

Three I/O Methods Synchronous Asynchronous Synchronous, asynchronous, memory-mapped CS377: Operating Systems

Memory-Mapped I/O Enables direct access to I/O controller (vs. being required to move the I/O code and data into memory) PCs (no virtual memory), reserve a part of the memory and put the device manager in that memory (e.g., all the bits for a video frame for a video controller). Access to the device then becomes almost as fast and convenient as writing the data directly into memory. CS377: Operating Systems

Interrupt based asynch. I/O Device controller has its own small processor which executes asynchronously with the main CPU. Device puts an interrupt signal on the bus when it is finished. CPU takes an interrupt. 1. Save critical CPU state (hardware state), 2. Disable interrupts, 3. Save state that interrupt handler will modify (software state) 4. Invoke interrupt handler using the in-memory Interrupt Vector 5. Restore software state 6. Enable interrupts 7. Restore hardware state, and continue execution of interrupted process CS377: Operating Systems

Timer & Atomic Instructions Timer Time of Day Accounting and billing CPU protected from being hogged using timer interrupts that occur at say every 100 microsecond. At each timer interrupt, the CPU chooses a new process to execute. Interrupt Vector: 0: 0x2ff080000 1: 0x2ff100000 2: 0x2ff100480 3: 0x2ff123010 keyboard mouse timer Disk 1

Clicker Question #3 What is the difference between a trap and an interrupt? (A) Traps are an exception caused by a user process or a way to invoke a system call. Interrupts are generated by hardware devices. (B) Interrupts are an exception in a user process or a way to invoke a system call. Traps are generated by hardware devices. (C) They are the same thing. (D) None of the above

Answer on Next Slide

Synchronization Interrupts interfere with executing processes. OS must be able to synchronize cooperating, concurrent processes. Architecture must provide a guarantee that short sequences of instructions (e.g., read-modify write) execute atomically. Two solutions: 1. Architecture mechanism to disable interrupts before sequence, execute sequence, enable interrupts again. 2. A special instruction that executes atomically (test&set) CS377: Operating Systems

Virtual Memory Virtual memory allows users to run programs without loading the entire program in memory at once. Instead, pieces of the program are loaded as they are needed. The OS must keep track of which pieces are in which parts of physical memory and which pieces are on disk. In order for pieces of the program to be located and loaded without causing a major disruption to the program, the hardware provides a translation lookaside buffer to speed the lookup. CS377: Operating Systems

Summary OS provides an interface to the architecture, but also requires some additional functionality from the architecture. The OS and hardware combine to provide many useful and important features. CS377: Operating Systems