CS510 Operating System Foundations. Jonathan Walpole

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

CS399 New Beginnings. Jonathan Walpole

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

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

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

CS510 Operating System Foundations. Jonathan Walpole

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

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

CS370 Operating Systems

CS510 Operating System Foundations. Jonathan Walpole

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

OPERATING SYSTEMS CS136

Today: I/O Systems. Architecture of I/O Systems

virtual memory Page 1 CSE 361S Disk Disk

CS370 Operating Systems

Introduction to Operating Systems. Chapter Chapter

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

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

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

Chapter 5. Input / Output

Virtual Memory Oct. 29, 2002

I/O Systems. Jo, Heeseung

CS333 Intro to Operating Systems. Jonathan Walpole

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

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

ECE331: Hardware Organization and Design

CS399 New Beginnings. Jonathan Walpole

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

Review: Hardware user/kernel boundary

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

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

CSC 2405: Computer Systems II

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

UC Santa Barbara. Operating Systems. Christopher Kruegel Department of Computer Science UC Santa Barbara

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

Computer System Overview

The control of I/O devices is a major concern for OS designers

CISC 360. Virtual Memory Dec. 4, 2008

CS399 New Beginnings. Jonathan Walpole

Introduction to Operating Systems. Chapter Chapter

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

Architectural Support for Operating Systems

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

Introduction to Operating. Chapter Chapter

I/O. Fall Tore Larsen. Including slides from Pål Halvorsen, Tore Larsen, Kai Li, and Andrew S. Tanenbaum)

I/O. Fall Tore Larsen. Including slides from Pål Halvorsen, Tore Larsen, Kai Li, and Andrew S. Tanenbaum)

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Lecture 2 - Fundamental Concepts

CS 3733 Operating Systems:

Computer Organization ECE514. Chapter 5 Input/Output (9hrs)

Chapter 13: I/O Systems

Architectural Support for Operating Systems

ECE232: Hardware Organization and Design

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

Input/Output Systems

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

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

19: I/O. Mark Handley. Direct Memory Access (DMA)

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Lecture 1 Introduction (Chapter 1 of Textbook)

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

Hardware OS & OS- Application interface

Chapter 13: I/O Systems

Chapter 13: I/O Systems

CS 153 Design of Operating Systems Winter 2016

Virtual Memory: From Address Translation to Demand Paging

Module 12: I/O Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

CMSC 313 Lecture 26 DigSim Assignment 3 Cache Memory Virtual Memory + Cache Memory I/O Architecture

Computer Organization

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

SE-292 High Performance Computing. Memory Hierarchy. R. Govindarajan

Virtual Memory Review. Page faults. Paging system summary (so far)

CS307: Operating Systems

Address spaces and memory management

Chapter 5 Input/Output. I/O Devices

Input/Output. Today. Next. Principles of I/O hardware & software I/O software layers Disks. Protection & Security

Topic 18: Virtual Memory

Chapter 12: I/O Systems

Chapter 13: I/O Systems

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

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Module 6: INPUT - OUTPUT (I/O)

Summary of Computer Architecture

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

Lecture 15: I/O Devices & Drivers

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

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

5.b Principles of I/O Hardware CPU-I/O communication

HY225 Lecture 12: DRAM and Virtual Memory

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Transcription:

CS510 Operating System Foundations Jonathan Walpole

OS-Related Hardware & Software 2

Lecture 2 Overview OS-Related Hardware & Software - complications in real systems - brief introduction to memory protection, relocation, virtual memory and I/O 3

Key Points From Class 1 Why do we need an interrupt mechanism? Why do we need a timer device? Why do we need privileged instructions? Why are system calls different to procedure calls? How are system calls different to interrupts? Why is memory protection necessary? 4

Real World Complexity Our simple hardware model is valid, but real systems have more complexity - Pipelined CPUs - Superscalar CPUs - Multi-level memory hierarchies - Virtual memory addressing - Complexity of devices and buses 5

Pipelined CPUs Fetch unit Decode unit Execute unit Execution of current instruction is performed in parallel with decode of next instruction and fetch of the one after that 6

Superscalar CPUs Fetch unit Decode unit Execute unit Fetch unit Decode unit Holding buffer Execute unit Execute unit 7

What does this mean for the OS? Pipelined CPUs - more complexity in capturing the state of a running application - more expensive to suspend and resume applications Superscalar CPUs - even more complexity in capturing state of a running application - even more expensive to suspend and resume applications - but we have support from hardware (precise interrupts) More details, but its fundamentally the same task The BLITZ CPU is not pipelined or superscalar and it has precise interrupts 8

The Memory Hierarchy 2GHz processor has 0.5 ns clock cycle Data/instruction cache access time is ~0.5ns This is where the CPU looks first! Cache is fast but small and cant hold everything Main memory access time is ~100 ns Its slow but it can hold everything (8 GB+) Secondary storage access time is ~10 ms Tbytes in size, but 20 million times slower access time! 9

Typical Latency Numbers L1 cache reference 0.5ns Branch mispredict 5 ns L2 cache reference 7 ns Mutex lock/unlock 25 ns Main memory reference 100 ns Compress 1K bytes with Zippy 3,000 ns 3 us Send 1K bytes over 1 Gbps network 10,000 ns 10 us Read 4K randomly from SSD* 150,000 ns 150 us Read 1 MB sequentially from memory 250,000 ns 250 us Round trip within same datacenter 500,000 ns 500 us Read 1 MB sequentially from SSD* 1,000,000 ns 1,000 us 1 ms Disk seek 10,000,000 ns 10,000 us 10 ms Read 1 MB sequentially from disk 20,000,000 ns 20,000 us 20 ms Send packet USA->Europe->USA 150,000,000 ns 150,000 us 150 ms

Managing the Memory Hierarchy Data is copied from lower levels to higher levels - it is temporarily resident in higher levels Space is allocated in multi-byte units at each level - cache lines (64 bytes on x86) - memory pages (often 4KB or 8KB) - disk blocks/sectors Data access attempts cause cache lines to be loaded automatically - Placement and replacement policy is fixed by hardware 11

Managing the Memory Hierarchy Operating Systems have some control - Lay out data carefully in memory - Be careful about the order in which they access data items - Use instructions to flush the cache when necessary Movement of data between lower levels is under direct control of the OS - Virtual memory page faults - File system calls 12

Other Memory-Related Issues How do you protect one application s area of memory from that of another application? How do you relocate an application in memory? - How does the programmer know where the program will ultimately reside in memory? 13

Memory Protection & Relocation Memory protection the basic idea Virtual vs physical addresses - Address range in each application starts at 0 - Applications use virtual addresses, but hardware and OS translate them automatically into physical addresses - A simple way to do this via a base register: - Get the CPU to interpret address indirectly via a base register - Base register holds starting, or base address - Add base value to address to get a real address before main memory is accessed - Relocation is simple: change the base register value 14

Paged virtual memory The base register idea doesn t work well in practice Paged virtual memory is a similar concept, but... - Supports non-contiguous allocation of memory - Allows allocated memory to grow and shrink dynamically - Requires hardware support for page-based address translation * Sometimes referred to as a memory management unit (MMU) or a translation lookaside buffer (TLB) Much more on this later... 15

Device Input/Output

Simple Model of I/O Devices Monitor Bus 17

More Realistic 18

Device Terminology Device (mechanical hardware) Device controller (electrical hardware) Device driver (software)

Device Controllers The Device vs. its Controller Some duties of a device controller: - Interface between CPU and the Device - Start/Stop device activity - Convert serial bit stream to a block of bytes - Deal with error detection/correction - Move data to/from main memory Some controllers may handle several (similar) devices

Software s View of Devices Hardware supports I/O ports or memory mapped I/O for accessing device controller registers and buffers

I/O Ports Each port has a separate number. CPU has special I/O instructions in r4,3 out 3,r4 Port numbers form an address space... separate from main memory Contrast with load r4,3 store 3,r4 The I/O Port Number

Memory-Mapped I/O 0x00000000 One address space for main memory I/O devices CPU has no special instructions load store r4,addr addr,r4 Physical Installed Memory I/O devices are mapped into very high addresses 0xFFFF0000 0xFFFFFFFF I/O Devices

Wide Range of Device Speeds

Hardware Performance Challenges How to prevent slow devices from slowing down CPU s access to memory due to bus contention - Only one thing can use the bus at a time - Moving a single character from the keyboard can prevent millions of memory accesses by the CPU The challenge: how to perform I/O without interfering with memory performance

A hardware solution: Dual Bus Architecture q

Pentium Bus Architecture

Software Performance Challenges For slow devices: how to prevent CPU throughput from being limited by I/O device speed - Why would slow devices affect the CPU? - CPU must wait for devices to be ready for next command For fast devices: how to prevent I/O throughput from being limited by CPU speed - When devices can move data faster than the CPU We must also achieve good utilization of CPU and I/O devices and meet the real-time requirements of devices

Programmed I/O Steps in printing a string

Programmed I/O Example: Writing a string to a serial output or printing a string CopyFromUser(virtAddr, kernelbuffer, bytecount) for i = 0 to bytecount-1 while *serialstatusreg!= READY endwhile *serialdatareg = kernelbuffer[i] endfor return Called Busy Waiting or Polling Problem: CPU is continually busy working on I/O! If I/O device is slow, CPU is idle most of the time

Interrupt-Driven I/O Getting the I/O started: CopyFromUser(virtAddr, kernelbuffer, bytecount) EnableInterrupts() while *serialstatusreg!= READY endwhile *serialdatareg = kernelbuffer[0] Sleep () The Interrupt Handler: if i == bytecount Wake up the requesting process else *serialdatareg = kernelbuffer[i] i = i + 1 endif Return from interrupt

Hardware Support For Interrupts Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires

Interrupt Driven I/O Problem Problem: - CPU is still involved in every data transfer - Interrupt handling overhead is high - Overhead cost is not amortized over much data - Overhead is too high for fast devices - Gbps networks - Disk drives

Direct Memory Access (DMA) Data transferred from device straight to/from memory CPU not involved The DMA controller: Does the work of moving the data CPU sets up the DMA controller ( programs it ) CPU continues The DMA controller moves the bytes

Sending Data Using DMA Getting the I/O started: CopyFromUser(virtAddr, kernelbuffer, bytecount) Set up DMA controller Sleep () The Interrupt Handler: Acknowledge interrupt from DMA controller Wake up the requesting process Return from interrupt

Direct Memory Access (DMA)

Direct Memory Access (DMA) Cycle Stealing DMA Controller acquires control of bus Transfers a single byte (or word) Releases the bus The CPU is slowed down due to bus contention Burst Mode DMA Controller acquires control of bus Transfers all the data Releases the bus The CPU operation is temporarily suspended

Program-Device Interaction Devices vs device controllers vs device drivers - Device drivers are part of the OS (ie. software) - Programs call the OS which calls the device driver - Device drivers interact with device controllers using special IO instructions or by reading/writing controller registers that appear as memory locations - Device controllers are hardware that communicate with device drivers via interrupts 38

Device to Program Interaction 39

Types of Interrupt Timer interrupts - Allows OS to regain control of the CPU - One way to keep track of time I/O interrupts - Keyboard, mouse, disks, network, etc Program generated (traps & faults) - Address translation faults (page fault, TLB miss) - Programming errors: seg. faults, divide by zero, etc. - System calls like read(), write(), gettimeofday() 40

Interrupts, Traps, Faults and Exceptions Synchronous? Intentional? Error? Interrupt No No No Trap Yes Yes No Fault Yes No No Exception Yes Maybe Sometimes

System calls System calls are the mechanism by which programs invoke the OS Implemented via a TRAP instruction Example UNIX system calls: open(), read(), write(), close() kill(), signal() fork(), wait(), exec(), getpid() link(), unlink(), mount(), chdir() setuid(), getuid(), chown() 42

System calls If all system calls cause a trap, how can the OS tell which one the application wants it to execute? How can we pass parameters to the call and receive results? 43

System Call Implementation User-level code Library code Process usercode {... read (file, buffer, n); }... Procedure read(file, buff, n) {... read_syscall(file, buff, n) }... _read_syscall: LOAD r1, @SP+2 LOAD r2, @SP+4 LOAD r3, @SP+6 TRAP 44

Communication Protocol Could use Stack or Dedicated Registers 45

Before Next Class Do the reading for next week s class Finish project 1 Introduction to BLITZ 46