CS 153 Design of Operating Systems

Similar documents
CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems Fall 18

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

Lecture 13: Exceptions and Interrupts

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems Spring 18

Lecture 2: Architectural Support for OSes

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems

Operating Systems ECE344

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems

EXAMINATIONS 2010 END OF YEAR NWEN 242 COMPUTER ORGANIZATION

EXAMINATIONS 2003 END-YEAR COMP 203. Computer Organisation

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems

CS 153 Design of Operating Systems Spring 18

Chapter 3 & Appendix C Pipelining Part A: Basic and Intermediate Concepts

Exceptions and interrupts

TDT4255 Friday the 21st of October. Real world examples of pipelining? How does pipelining influence instruction

Review. A single-cycle MIPS processor

EMC ViPR. User Guide. Version

CS 153 Design of Operating Systems

CAPL Scripting Quickstart

Making Full Use of Multi-Core ECUs with AUTOSAR Basic Software Distribution

EEC 483 Computer Organization. Branch (Control) Hazards

1048: Computer Organization

Prof. Kozyrakis. 1. (10 points) Consider the following fragment of Java code:

Machines and Virtualization. Systems and Networks Jeff Chase Spring 2006

Isilon InsightIQ. Version 2.5. User Guide

CS153: Process. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

EMC M&R (Watch4net ) Installation and Configuration Guide. Version 6.4 P/N REV 02

Tdb: A Source-level Debugger for Dynamically Translated Programs

Traps and Faults. Review: Mode and Space

Memory Protection. Machines and Virtualization. Architectural Foundations of OS Kernels. Memory and the CPU. Introduction to Virtual Addressing

The single-cycle design from last time

Putting the dynamic into software security testing

Computer User s Guide 4.0

(2, 4) Tree Example (2, 4) Tree: Insertion

Local Run Manager. Software Reference Guide for MiSeqDx

Protection and System Calls. Otto J. Anshus

VirtuOS: an operating system with kernel virtualization

The extra single-cycle adders

Processes (Intro) Yannis Smaragdakis, U. Athens

Networks An introduction to microcomputer networking concepts

The final datapath. M u x. Add. 4 Add. Shift left 2. PCSrc. RegWrite. MemToR. MemWrite. Read data 1 I [25-21] Instruction. Read. register 1 Read.

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary

Lecture 7. Building A Simple Processor

dss-ip Manual digitalstrom Server-IP Operation & Settings

Anne Bracy CS 3410 Computer Science Cornell University

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Review: Computer Organization

PART I: Adding Instructions to the Datapath. (2 nd Edition):

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

Architectural Support for OS

EMC AppSync. User Guide. Version REV 01

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

4.13 Advanced Topic: An Introduction to Digital Design Using a Hardware Design Language 345.e1

Enhanced Memory Management

Introduction to the Process David E. Culler CS162 Operating Systems and Systems Programming Lecture 2 Sept 3, 2014

Review Multicycle: What is Happening. Controlling The Multicycle Design

Hardware OS & OS- Application interface

USER S GUIDE: SPRINT RELAY CUSTOMER PROFILE

CS 537 Lecture 2 - Processes

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Architectural Support for Operating Systems. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Winter 2013 MIDTERM TEST #2 Wednesday, March 20 7:00pm to 8:15pm. Please do not write your U of C ID number on this cover page.

COPYRIGHTED MATERIAL. Recording Macros and Getting Started with VBA. Part 1

Gigaset M34 USB Ya-LBA / englisch / A31008-M403-R / cover_front.fm / User Manual

POWER-OF-2 BOUNDARIES

DSCS6020: SQLite and RSQLite

BIS - Basic Package V4.4

Bits, Bytes, and Integer

CS5460: Operating Systems

L EGAL NOTICES. ScanSoft, Inc. 9 Centennial Drive Peabody, MA 01960, United States of America

Lab 8 (All Sections) Prelab: ALU and ALU Control

CS 550 Operating Systems Spring Interrupt

Introduction to Windows Server Copyright 2018 NY SYSTEMS INC.

Anne Bracy CS 3410 Computer Science Cornell University

EMC VNX Series. Problem Resolution Roadmap for VNX with ESRS for VNX and Connect Home. Version VNX1, VNX2 P/N REV. 03

BIS - Basic Package V4.6

Traps, Exceptions, System Calls, & Privileged Mode

3. Process Management in xv6

Mechanisms for entering the system

1048: Computer Organization

Analog Telephones. User Guide. BusinessPhone Communication Platform

CS 251, Spring 2018, Assignment 3.0 3% of course mark

BIS - Basic package V4.3

CS 251, Winter 2019, Assignment % of course mark

Local Run Manager Generate FASTQ Analysis Module

CSE 141 Computer Architecture Summer Session I, Lectures 10 Advanced Topics, Memory Hierarchy and Cache. Pramod V. Argade

CSSE232 Computer Architecture I. Mul5cycle Datapath

Transcription:

CS 153 Design of Operating Systems Spring 18 Lectre 3: OS model and Architectral Spport Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian

Last time/today Historic evoltion of Operating Systems (and compting!) Today: We start or jorney in exploring Operating Systems Try to answer qestions sch as:» How/When does the OS rn?» How do programs interact with it?» How is this spported by hardware? 2

Some qestions to get yo thinking What is the OS? Software? Is the OS always execting? If not, how do we make sre it gets to rn? How do we prevent ser programs from directly maniplating hardware? 3

Sleeping Beaty Model Answer: Sleeping beaty model Technically known as controlled direct exection OS rns in response to events ; we spport the switch in hardware Only the OS can maniplate hardware or critical system state Most of the time the OS is sleeping Good! Less overhead Good! Applications are rnning directly on the hardware 4

What do we need from the architectre/cpu? Maniplating privileged machine state Protected instrctions Maniplate device registers, TLB entries, etc. Controlling access Generating and handling events Interrpts, exceptions, system calls, etc. Respond to external events CPU reqires software intervention to handle falt or trap Other stff Mechanisms to handle concrrency, isolation, virtalization 5

Types of Arch Spport Maniplating privileged machine state Protected instrctions Maniplate device registers, TLB entries, etc. Controlling access Generating and handling events Interrpts, exceptions, system calls, etc. Respond to external events CPU reqires software intervention to handle falt or trap Other stff Interrpts, atomic instrctions, isolation 6

Protected Instrctions OS mst have exclsive access to hardware and critical data strctres Only the operating system can Directly access I/O devices (disks, printers, etc.)» Secrity, fairness (why?) Maniplate memory management state» Page table pointers, page protection, TLB management, etc. Maniplate protected control registers» Kernel mode, interrpt level Halt instrction (why?) 7

Privilege mode Hardware restricts privileged instrctions to OS Q: How does the HW know if the exected program is OS? HW mst spport (at least) two exection modes: OS (kernel) mode and ser mode Mode kept in a stats bit in a protected control register User programs execte in ser mode OS exectes in kernel mode (OS == kernel ) CPU checks mode bit when protected instrction exectes Attempts to execte in ser mode trap to OS 8

Switching back and forth Going from higher privilege to lower privilege Easy: can directly modify the mode register to drop privilege Bt how do we escalate privilege? Special instrctions to change mode» System calls (int 0x80, syscall, svc)» Saves context and invokes designated handler Yo jmp to the privileged code; yo cannot execte yor own» OS checks yor syscall reqest and honors it only if safe Or, some kind of event happens in the system 9

Types of Arch Spport Maniplating privileged machine state Protected instrctions Maniplate device registers, TLB entries, etc. Controlling access Generating and handling events Interrpts, exceptions, system calls, etc. Respond to external events CPU reqires software intervention to handle falt or trap Other stff 10

Review: Compter Organization Branch Address +4 Select PC New PC Program Conter CPU Instrctions Fetch Exec opcode 11

Events An event is an nnatral change in control flow Events immediately stop crrent exection Changes mode, context (machine state), or both The kernel defines a handler for each event type Event handlers always execte in kernel mode The specific types of events are defined by the machine Once the system is booted, OS is one big event handler all entry to the kernel occrs as the reslt of an event 12

Handling events Interrpt vector table Processor Register Interrpt Vector...... handletimerinterrpt() {... } handledividebyzero() {... } handlesystemcall() {... } 13

Categorizing Events Two kinds of events: synchronos and asynchronos Sync events are cased by execting instrctions Example? Async events are cased by an external event Example? Asynchronos events CPU ticks Synchronos events 14

Categorizing Events Two kinds of events: synchronos and asynchronos Sync events are cased by execting instrctions Async events are cased by an external event Two reasons for events: nexpected and deliberate Unexpected events are, well, nexpected Example? Deliberate events are schedled by OS or application Why wold this be sefl? 15

Categorizing Events This gives s a convenient table: Unexpected Deliberate Synchronos falt syscall trap Asynchronos interrpt signal Terms may be slightly different by OS and architectre E.g., POSIX signals, asynch system traps, async or deferred procedre calls 16

Falts Hardware detects and reports exceptional conditions Page falt, memory access violation (naligned, permission, not mapped, bonds ), illegal instrction, divide by zero Upon exception, hardware falts (verb) Mst save state (PC, regs, mode, etc.) so that the falting process can be restarted Invokes registered handler 17

Handling Falts Some falts are handled by fixing the exceptional condition and retrning to the falting context Page falts case the OS to place the missing page into memory Falt handler resets PC of falting context to re-execte instrction that cased the page falt 18

Handling Falts The kernel may handle nrecoverable falts by killing the ser process Program falt with no registered handler Halt process, write process state to file, destroy process In Unix, the defalt action for many signals (e.g., SIGSEGV) What abot falts in the kernel? Dereference NULL, divide by zero, ndefined instrction These falts considered fatal, operating system crashes Unix panic, Windows Ble screen of death» Kernel is halted, state dmped to a core file, machine locked p 19

Categorizing Events Unexpected Deliberate Synchronos falt syscall trap Asynchronos interrpt signal 20

System Calls For a ser program to do something privileged (e.g., I/O) it mst call an OS procedre Known as crossing the protection bondary, or a protected procedre call Hardware provides a system call instrction that: Cases an exception, which invokes a kernel handler» Passes a parameter determining the system rotine to call Saves caller state (PC, regs, mode) so it can be restored» Why save mode? Retrning from system call restores this state 21

System Call emacs: read() User mode Kernel mode Trap to kernel mode, save state Trap handler Find read handler Restore state, retrn to ser level, resme exection read() kernel rotine 22

Another view 0xFFFFFFFF 1G 0xC0000000 Kernel Stack Kernel Code SP2 PC2 Address Space 3G User Stack SP1 0x00000000 User Code PC1 25

System Call Qestions There are hndreds of syscalls. How do we let the kernel know which one we intend to invoke? Before issing int $0x80 or sysenter, set %eax/%rax with the syscall nmber System calls are like fnction calls, bt how to pass parameters? Jst like calling convention in syscalls, typically passed throgh %ebx, %ecx, %edx, %esi, %edi, %ebp 26

More qestions How to reference kernel objects (e.g., files, sockets)? Naming problem an integer mapped to a niqe object» int fd = open( file ); read(fd, bffer); Why can t we reference the kernel objects by memory address? 27

System calls in xv6 Look at trap.h and trap.c Interrpt handlers are initialized in two arrays (idt and vectors)» Tvinit() fnction does the initialization Syscalls have a single trap handler (T_SYSCALL, 64) Trap() handles all exceptions, inclding system calls» If the exception is a system call, it calls syscall() Keep digging from there to nderstand how system calls are spported Yo will be adding a new system call in Lab 1 28

Categorizing Events Unexpected Deliberate Synchronos falt syscall trap Asynchronos interrpt software interrpt Interrpts signal asynchronos events I/O hardware interrpts Software and hardware timers 29

Timer The key to a timesharing OS The fallback mechanism by which the OS reclaims control Timer is set to generate an interrpt after a period of time» Setting timer is a privileged instrction» When timer expires, generates an interrpt Handled by the OS, forcing a switch from the ser program» Basis for OS schedler (more later ) Also sed for time-based fnctions (e.g., sleep()) 31

I/O sing Interrpts Interrpts are the basis for asynchronos I/O OS initiates I/O Device operates independently of rest of machine Device sends an interrpt signal to CPU when done OS maintains a vector table containing a list of addresses of kernel rotines to handle varios events CPU looks p kernel address indexed by interrpt nmber, context switches to rotine 33

I/O Example 1. Ethernet receives packet, writes packet into memory 2. Ethernet signals an interrpt 3. CPU stops crrent operation, switches to kernel mode, saves machine state (PC, mode, etc.) on kernel stack 4. CPU reads address from vector table indexed by interrpt nmber, branches to address (Ethernet device driver) 5. Ethernet device driver processes packet (reads device registers to find packet in memory) 6. Upon completion, restores saved state from stack 34

Interrpt Qestions Interrpts halt the exection of a process and transfer control (exection) to the operating system Can the OS be interrpted? (Consider why there might be different interrpt levels) Interrpts are sed by devices to have the OS do stff What is an alternative approach to sing interrpts? What are the drawbacks of that approach? 35

Memory Isolation OS mst be able to protect programs from each other OS mst protect itself from ser programs OS may or may not protect ser programs from itself Memory management nit (MMU) Hardware nit provides memory protection mechanisms Virtal memory Segmentation Maniplating memory management hardware ses protected (privileged) operations 37

Example memory protection Physical Memory INSTR DATA HEAP STACK Base Bonds CPU Memory Reference OK? Yes Contine No Exception 38

Smmary Protection User/kernel modes Protected instrctions System calls Used by ser-level processes to access OS fnctions Access what is in the OS Exceptions Unexpected event dring exection (e.g., divide by zero) Interrpts Timer, I/O 39

Next Time Processes Project: Contine to get familiar with the environment» In particlar, Chapter 0 Read the system call/interrpt chapter in the xv6 book (Chapter 3) If yo have time, work throgh at least some of the booting seqence ttorial» Read appendix A and B in xv6 book Ask qestions on Piazza 40