I/O Management Software. Chapter 5

Similar documents
I/O Management Software. Chapter 5

Operating System Design Issues. I/O Management

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

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

I/O Design, I/O Subsystem, I/O-Handler Device Driver, Buffering, Disks, RAID January WT 2008/09

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

Chapter-6. SUBJECT:- Operating System TOPICS:- I/O Management. Created by : - Sanjay Patel

Principles of Operating Systems CS 446/646

Introduction to Operating Systems. Chapter Chapter

CSE 120. Overview. July 27, Day 8 Input/Output. Instructor: Neil Rhodes. Hardware. Hardware. Hardware

OPERATING SYSTEMS CS136

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

Introduction to Operating Systems. Chapter Chapter

Introduction to Operating. Chapter Chapter

Process Scheduling Queues

Spring 2017 :: CSE 506. Device Programming. Nima Honarmand

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

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

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

I/O Systems. Jo, Heeseung

Misc. Third Generation Batch Multiprogramming. Fourth Generation Time Sharing. Last Time Evolution of OSs

Chapter 13: I/O Systems

Operating Systems 2010/2011

Module 11: I/O Systems

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

Chapter 5 - Input / Output

The Kernel Abstraction

Operating Systems. V. Input / Output

Ausgewählte Betriebssysteme - Mark Russinovich & David Solomon (used with permission of authors)

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

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

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

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02).

Part 1: Introduction to device drivers Part 2: Overview of research on device driver reliability Part 3: Device drivers research at ERTOS

Device-Functionality Progression

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

Virtual Memory COMPSCI 386

I/O Management Intro. Chapter 5

Comp 204: Computer Systems and Their Implementation. Lecture 18: Devices

Organisasi Sistem Komputer

Chapter 5 Input/Output. I/O Devices

Chapter 11 I/O Management and Disk Scheduling

Scuola Superiore Sant Anna. I/O subsystem. Giuseppe Lipari

System Call. Preview. System Call. System Call. System Call 9/7/2018

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)

CS 104 Computer Organization and Design

Devices. Today. Comp 104: Operating Systems Concepts. Operating System An Abstract View 05/01/2017. Devices. Devices

Generic Model of I/O Module Interface to CPU and Memory Interface to one or more peripherals

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

Input/Output Management

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

I/O Management and Disk Scheduling. Chapter 11

Input Output (IO) Management

Hardware OS & OS- Application interface

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

I/O SYSTEMS. Sunu Wibirama

CS 450 Fall xxxx Final exam solutions. 2) a. Multiprogramming is allowing the computer to run several programs simultaneously.

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Tolerating Malicious Drivers in Linux. Silas Boyd-Wickizer and Nickolai Zeldovich

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 13: I/O Systems

Chapter 9: Virtual-Memory

Virtual Memory Outline

QUESTION BANK UNIT I

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

Lecture 2: September 9

I/O Device Controllers. I/O Systems. I/O Ports & Memory-Mapped I/O. Direct Memory Access (DMA) Operating Systems 10/20/2010. CSC 256/456 Fall

操作系统概念 13. I/O Systems

OPERATING SYSTEM. Chapter 9: Virtual Memory

I/O MANAGEMENT CATEGORIES OF I/O DEVICES 1. Slide 1. Slide 3. Controller: Three classes of devices (by usage):

Silberschatz and Galvin Chapter 12

Chapter 9: Virtual Memory

CSCI-GA Operating Systems I/O. Hubertus Franke

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

OPERATING SYSTEMS & Network OVERVIEW. 1: OS & Network Overview

Process Description and Control. Chapter 3

I/O Management Intro. Chapter 5

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

CS370 Operating Systems

Input-Output (I/O) Input - Output. I/O Devices. I/O Devices. I/O Devices. I/O Devices. operating system must control all I/O devices.

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Computer architecture. A simplified model

Virtual Memory Paging

CSE 451: Operating Systems Winter I/O System. Gary Kimura

Chapter 13: I/O Systems

Lecture 15: I/O Devices & Drivers

Mon Sep 17, 2007 Lecture 3: Process Management

Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

Review: Hardware user/kernel boundary

Operating Systems, Fall

CS 261 Fall Mike Lam, Professor. Virtual Memory

Module 12: I/O Systems

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

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

Main Points of the Computer Organization and System Software Module

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

OS: An Overview. ICS332 Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Input / Output. Kevin Webb Swarthmore College April 12, 2018

Transcription:

I/O Management Software Chapter 5 1

Learning Outcomes An understanding of the structure of I/O related software, including interrupt handers. An appreciation of the issues surrounding long running interrupt handlers, blocking, and deferred interrupt handling. An understanding of I/O buffering and buffering's relationship to a producer-consumer problem. 2

Operating System Design Efficiency Issues Most I/O devices slow compared to main memory (and the CPU) Use of multiprogramming allows for some processes to be waiting on I/O while another process executes Often I/O still cannot keep up with processor speed Swapping may used to bring in additional Ready processes More I/O operations Optimise I/O efficiency especially Disk & Network I/O 3

Operating System Design Issues The quest for generality/uniformity: Ideally, handle all I/O devices in the same way Both in the OS and in user applications Problem: Diversity of I/O devices Especially, different access methods (random access versus stream based) as well as vastly different data rates. Generality often compromises efficiency! Hide most of the details of device I/O in lower-level routines so that processes and upper levels see devices in general terms such as read, write, open, close. 4

I/O Software Layers Layers of the I/O Software System 5

Interrupt handlers Interrupt Handlers Can execute at (almost) any time Raise (complex) concurrency issues in the kernel Can propagate to userspace (signals, upcalls), causing similar issues Generally structured so I/O operations block until interrupts notify them of completion kern/dev/lamebus/lhd.c 6

Interrupt Handler Example static int lhd_io(struct device *d, struct uio *uio) {... /* Loop over all the sectors * we were asked to do. */ for (i=0; i<len; i++) { INT /* Wait until nobody else * is using the device. */ P(lh->lh_clear);... /* Tell it what sector we want... */ lhd_wreg(lh, LHD_REG_SECT, sector+i); /* and start the operation. */ lhd_wreg(lh, LHD_REG_STAT, statval); /* Now wait until the interrupt * handler tells us we're done. */ P(lh->lh_done); SLEEP } /* Get the result value * saved by the interrupt handler. */ result = lh->lh_result; lhd_iodone(struct lhd_softc *lh, int err) { lh->lh_result = err; V(lh->lh_done); } void lhd_irq(void *vlh) {... val = lhd_rdreg(lh, LHD_REG_STAT); switch (val & LHD_STATEMASK) { case LHD_IDLE: case LHD_WORKING: break; case LHD_OK: case LHD_INVSECT: case LHD_MEDIA: lhd_wreg(lh, LHD_REG_STAT, 0); lhd_iodone(lh, lhd_code_to_errno(lh, val)); break; } } 7

Interrupt Handler Steps Save Registers not already saved by hardware interrupt mechanism (Optionally) set up context for interrupt service procedure Typically, handler runs in the context of the currently running process No expensive context switch Set up stack for interrupt service procedure Handler usually runs on the kernel stack of current process Ack/Mask interrupt controller, re-enable other interrupts What does this imply? 8

Interrupt Handler Steps Run interrupt service procedure Acknowledges interrupt at device level Figures out what caused the interrupt Received a network packet, disk read finished, UART transmit queue empty If needed, it signals blocked device driver In some cases, will have woken up a higher priority blocked thread Choose newly woken thread to schedule next. Set up MMU context for process to run next What if we are nested? Load new/original process' registers Re-enable interrupt; Start running the new process 9

Sleeping in Interrupts Interrupt generally has no context (runs on current kernel stack) Unfair to sleep interrupted process (deadlock possible) Where to get context for long running operation? What goes into the ready queue? What to do? Top and Bottom Half Linux implements with tasklets and workqueues Generically, in-kernel thread(s) handle long running kernel operations. 10

Top/Half Bottom Half Higher Software Layers Bottom Half Top Half (Interrupt Handler) Top Half Interrupt handler remains short Bottom half Is preemtable by top half (interrupts) performs deferred work (e.g. IP stack processing) Is checked prior to every kernel exit signals blocked processes/threads to continue Enables low interrupt latency Bottom half can t block 11

Stack Usage Kernel Stack Upper software Interrupt (interrupts disabled) T H H Deferred processing (interrupt reenabled) B H Interrupt while in bottom half T B H 12

Deferring Work on In-kernel Threads Interrupt handler defers work onto in-kernel thread In-kernel thread handles deferred work (DW) Scheduled normally Can block Both low interrupt latency and blocking operations Normal process/thread stack I H D W In-kernel thread stack 13

Logical position of device drivers is shown here Drivers (originally) compiled into the kernel Including OS/161 Device installers were technicians Number and types of devices rarely changed Nowadays they are dynamically loaded when needed Linux modules Typical users (device installers) can t build kernels Number and types vary greatly Even while OS is running (e.g hot-plug USB devices) Device Drivers 14

Device Drivers Drivers classified into similar categories Block devices and character (stream of data) device OS defines a standard (internal) interface to the different classes of devices Device specs often help, e.g. USB Device drivers job translate request through the device-independent standard interface (open, close, read, write) into appropriate sequence of commands (register manipulations) for the particular hardware Initialise the hardware at boot time, and shut it down cleanly at shutdown 15

Device Driver After issuing the command to the device, the device either Completes immediately and the driver simply returns to the caller Or, device must process the request and the driver usually blocks waiting for an I/O complete interrupt. Drivers are re-entrant (or thread-safe) as they can be called by another process while a process is already blocked in the driver. Re-entrant: Mainly no static (global) non-constant data. 16

Device-Independent I/O Software There is commonality between drivers of similar classes Divide I/O software into device-dependent and device-independent I/O software Device independent software includes Buffer or Buffer-cache management Managing access to dedicated devices Error reporting 17

Device-Independent I/O Software (a) Without a standard driver interface (b) With a standard driver interface 18

Driver Kernel Interface Major Issue is uniform interfaces to devices and kernel Uniform device interface for kernel code Allows different devices to be used the same way No need to rewrite file-system to switch between SCSI, IDE or RAM disk Allows internal changes to device driver with fear of breaking kernel code Uniform kernel interface for device code Drivers use a defined interface to kernel services (e.g. kmalloc, install IRQ handler, etc.) Allows kernel to evolve without breaking existing drivers Together both uniform interfaces avoid a lot of programming implementing new interfaces 19

Buffering 20

Device-Independent I/O Software (a) Unbuffered input (b) Buffering in user space (c) Single buffering in the kernel followed by copying to user space (d) Double buffering in the kernel 21

No Buffering Process must read/write a device a byte/word at a time Each individual system call adds significant overhead Process must what until each I/O is complete Blocking/interrupt/waking adds to overhead. Many short runs of a process is inefficient (poor CPU cache temporal locality) 22

User-level Buffering Process specifies a memory buffer that incoming data is placed in until it fills Filling can be done by interrupt service routine Only a single system call, and block/wakeup per data buffer Much more efficient 23

Issues User-level Buffering What happens if buffer is paged out to disk Could lose data while buffer is paged in Could lock buffer in memory (needed for DMA), however many processes doing I/O reduce RAM available for paging. Can cause deadlock as RAM is limited resource Consider write case When is buffer available for re-use? Either process must block until potential slow device drains buffer or deal with asynchronous signals indicating buffer drained 24

Single Buffer Operating system assigns a buffer in kernel s memory for an I/O request Stream-oriented Used a line at time User input from a terminal is one line at a time with carriage return signaling the end of the line Output to the terminal is one line at a time 25

Single Buffer Block-oriented Input transfers made to buffer Block moved to user space when needed Another block is moved into the buffer Read ahead 26

Single Buffer User process can process one block of data while next block is read in Swapping can occur since input is taking place in system memory, not user memory Operating system keeps track of assignment of system buffers to user processes 27

Single Buffer Speed Up Assume T is transfer time for a block from device C is computation time to process incoming block M is time to copy kernel buffer to user buffer Computation and transfer can be done in parallel Speed up with buffering T + C max( T, C) + M 28

Single Buffer What happens if kernel buffer is full, the user buffer is swapped out, and more data is received??? We start to lose characters or drop network packets 29

Double Buffer Use two system buffers instead of one A process can transfer data to or from one buffer while the operating system empties or fills the other buffer 30

Double Buffer Speed Up Computation and Memory copy can be done in parallel with transfer Speed up with double buffering T + C max( T, C + M ) Usually M is much less than T giving a favourable result 31

Double Buffer May be insufficient for really bursty traffic Lots of application writes between long periods of computation Long periods of application computation while receiving data Might want to read-ahead more than a single block for disk 32

Circular Buffer More than two buffers are used Each individual buffer is one unit in a circular buffer Used when I/O operation must keep up with process 33

Important Note Notice that buffering, double buffering, and circular buffering are all Bounded-Buffer Producer-Consumer Problems 34

Is Buffering Always Good? T + C T + C max( T, C) + M max( T, C + M ) Single Double Can M be similar or greater than C or T? 35

Buffering in Fast Networks Networking may involve many copies Copying reduces performance Especially if copy costs are similar to or greater than computation or transfer costs Super-fast networks put significant effort into achieving zero-copy Buffering also increases latency 36

I/O Software Summary Layers of the I/O system and the main functions of each layer 37