Lecture 15: I/O Devices & Drivers

Similar documents
Chapter 13: I/O Systems

Module 12: I/O Systems

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)

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

Device-Functionality Progression

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

Module 12: I/O Systems

Chapter 13: I/O Systems

Chapter 13: I/O Systems

Lecture 13 Input/Output (I/O) Systems (chapter 13)

Chapter 12: I/O Systems

Chapter 13: I/O Systems

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

Input/Output Systems

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

I/O Systems. 04/16/2007 CSCI 315 Operating Systems Design 1

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

Chapter 13: I/O Systems

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

Chapter 13: I/O Systems

Chapter 13: I/O Systems

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

Chapter 13: I/O Systems

Silberschatz and Galvin Chapter 12

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)

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

CSE 4/521 Introduction to Operating Systems. Lecture 24 I/O Systems (Overview, Application I/O Interface, Kernel I/O Subsystem) Summer 2018

I/O SYSTEMS. Sunu Wibirama

Module 11: I/O Systems

Ref: Chap 12. Secondary Storage and I/O Systems. Applied Operating System Concepts 12.1

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

COT 4600 Operating Systems Fall Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:00-4:00 PM

Input/Output Systems

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

Lecture 4: Memory Management & The Programming Interface

NWI-IBC019: Operating systems

CS370 Operating Systems

CSC Operating Systems Spring Lecture - XIX Storage and I/O - II. Tevfik Koşar. Louisiana State University.

RAID Structure. RAID Levels. RAID (cont) RAID (0 + 1) and (1 + 0) Tevfik Koşar. Hierarchical Storage Management (HSM)

CS370 Operating Systems

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

Operating Systems 2010/2011

CS420: Operating Systems. Kernel I/O Subsystem

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

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

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

[08] IO SUBSYSTEM 1. 1

Outline. Operating Systems: Devices and I/O p. 1/18

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

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.

Operating Systems. Steven Hand. Michaelmas / Lent Term 2008/ lectures for CST IA. Handout 4. Operating Systems

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

Lecture 14: Cache & Virtual Memory

I/O Systems. Jo, Heeseung

CHAPTER 12 AND 13 - MASS-STORAGE STRUCTURE & I/O- SYSTEMS

Lecture 5: Concurrency and Threads

CIS Operating Systems I/O Systems & Secondary Storage. Professor Qiang Zeng Spring 2018

UNIT-7. Overview of Mass Storage Structure

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

Principles of Operating Systems CS 446/646

Operating Systems 2010/2011

Main Points of the Computer Organization and System Software Module

CIS Operating Systems I/O Systems & Secondary Storage. Professor Qiang Zeng Fall 2017

Lecture 1 Introduction (Chapter 1 of Textbook)

Process Scheduling Queues

Chapter 7: Mass-storage structure & I/O systems. Operating System Concepts 8 th Edition,

Operating System Review

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

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

CS350: Final Exam Review

Lecture 13: Address Translation

Chapter 5 Input/Output. I/O Devices

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

Operating Systems. V. Input / Output

CSC 2405: Computer Systems II

Introduction. CS3026 Operating Systems Lecture 01

CSI3131 Final Exam Review

Today: Protection! Protection!

7/20/2008. What Operating Systems Do Computer-System Organization

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

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

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

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

Common Computer-System and OS Structures

CSE 153 Design of Operating Systems

I/O. CS 416: Operating Systems Design Department of Computer Science Rutgers University

or edit a file, our immediate interest is to read or enter some information, not to compute an answer.

Today: Protection. Sermons in Computer Science. Domain Structure. Protection

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

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

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

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

CIS 21 Final Study Guide. Final covers ch. 1-20, except for 17. Need to know:

3.1 Introduction. Computers perform operations concurrently

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

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

Computer Systems II. First Two Major Computer System Evolution Steps

Transcription:

CS 422/522 Design & Implementation of Operating Systems Lecture 15: I/O Devices & Drivers Zhong Shao Dept. of Computer Science Yale University Acknowledgement: some slides are taken from previous versions of the CS422/522 lectures taught by Prof. Bryan Ford and Dr. David Wolinsky, and also from the official set of slides accompanying the OSPP textbook by Anderson and Dahlin. The big picture Previous lectures Management of CPU & concurrency Management of main memory & virtual memory Future lectures --- Management of I/O devices 1

Concurrency: a summary Thread vs. process How to implement threads/processes? * thread/process state transition diagram * thread/process scheduler * context switch * thread/process creation / finish How to write concurrent programs? * how to eliminate race condition? how to synchronize? * locks, condition variables, monitors, semaphore, message passing Multithreading model (kernel vs. user threads) How to deal with deadlocks Effective CPU scheduling (local + global) Virtual memory: a summary Goal: multiprogramming with protection + illusion of infinite memory Approaches HW-based solution for protection * dual mode operation + address space address translation: virtual address -> physical address * segmentation + paging + multilevel paging making address translation faster? use TLB demand paged virtual memory techniques for dealing with thrashing Other topics kernel memory allocator (similar to malloc-free packages) virtual memory-based hack (exploiting page fault) 2

The big picture Previous lectures Management of CPU & concurrency Management of main memory & virtual memory Future lectures --- Management of I/O devices This week: I/O devices & device drivers This week: storage devices Next week: file systems * File system structure * Naming and directories * Efficiency and performance * Reliability and protection Raw hardware revisited CPU... CPU Memory Chipset I/O bus ROM Network 3

I/O hardware A computer = CPU(s) + Memory + I/O devices Common concepts Port (a connection point between a machine and a device) Bus (one or more devices share a common set of wires) Controller (has private processor, microcode, memory) The processor gives commands and data to a controller to accomplish an I/O transfer The controller has a few registers for data & control signals * typical registers: status, control, data-in, data-out Special I/O instructions (w. port addr) or memory mapped I/O A typical PC bus structure 4

Device I/O port locations on PCs (partial) CPU I/O interaction: polling the status register indicates the state of the device a command-ready bit and a busy bit Procedure for writing out a byte: the host reads the busy bit until it becomes clear the host issues write command, puts the byte in data-out The host sets the command-ready bit The controller sees command-ready, sets the busy bit The controller executes the write, does I/O The controller clears the command-ready and busy bits Inefficient: busy-wait cycle to wait for device I/O 5

CPU I/O interaction: interrupts CPU interrupt request line triggered by I/O device Interrupt handler receives interrupts Maskable to ignore or delay some interrupts Interrupt vector to dispatch interrupt to correct handler Based on priority Some unmaskable Interrupt mechanism also used for exceptions Interrupt-driven I/O cycle 6

Intel processor event-vector table Interrupt handling revisited/refined Save more context Mask interrupts if needed Set up a context for interrupt service Set up a stack for interrupt service Acknowledge the interrupt controller, enable it if needed Save entire context to PCB Run the interrupt service Unmask interrupts if needed Possibly change the priority of the process Run the scheduler 7

I/O software stack User-Level I/O Software Device-Independent OS software Device Drivers Interrupt handlers Hardware Direct Memory Access (DMA) Used to avoid programmed I/O for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory 8

Performing DMA transfer Application I/O interface I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel Devices vary in many dimensions Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only 9

A kernel I/O structure Characteristics of I/O devices 10

Block and character devices Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing Network devices Different enough from the block & character devices to have own interface Unix and Windows/NT include socket interface Separates network protocol from network operation Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) 11

Clocks and timers Provide current time, elapsed time, timer if programmable interval time used for timings, periodic interrupts ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers Blocking and nonblocking I/O Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed 12

Two I/O methods Synchronous" Asynchronous" Next: device drivers 13

Device driver design issues Operating system and driver communication Commands and data between OS and device drivers Driver and hardware communication Commands and data between driver and hardware Driver operations Initialize devices Interpreting commands from OS Schedule multiple outstanding requests Manage data transfers Accept and process interrupts Maintain the integrity of driver and kernel data structures Device driver interface Open( devicenumber ) Initialization and allocate resources (buffers) Close( devicenumber ) Cleanup, deallocate, and possibly turnoff Device driver types Block: fixed sized block data transfer Character: variable sized data transfer Terminal: character driver with terminal control Network: streams for networking 14

Block device interface read( devicenumber, deviceaddr, bufferaddr ) transfer a block of data from deviceaddr to bufferaddr write( devicenumber, deviceaddr, bufferaddr ) transfer a block of data from bufferaddr to deviceaddr seek( devicenumber, deviceaddress ) move the head to the correct position usually not necessary Character device interface read( devicenumber, bufferaddr, size ) reads size bytes from a byte stream device to bufferaddr write( devicenumber, bufferaddr, size ) write size bytes from buffersize to a byte stream device 15

Unix device driver interface entry points init(): initialize hardware start(): boot time initialization (require system services) open(dev, flag, id): initialization for read or write close(dev, flag, id): release resources after read and write halt(): call before the system is shutdown intr(vector): called by the kernel on a hardware interrupt read/write calls: data transfer poll(pri): called by the kernel 25 to 100 times a second ioctl(dev, cmd, arg, mode): special request processing Device driver: other design issues Build device drivers Statically Dynamically How to down load device driver dynamically? Load drivers into kernel memory Install entry points and maintain related data structures Initialize the device drivers 16

Next: kernel I/O subsystem Kernel I/O subsystem: Scheduling Some I/O request ordering via per-device queue Some OSes try fairness Device status table 17

Kernel I/O subsystem (cont d) Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch (e.g., packets in networking) To maintain copy semantics * Copy data from user buffer to kernel buffer How to deal with address translation? I/O devices see physical memory, but programs use virtual memory Caching - fast memory holding copy of data Always just a copy Key to performance Spooling - hold output for a device If a device can serve only one request at a time, i.e., printing Error handling OS can recover from disk read, device unavailable, transient write failures Most return an error number or code when I/O request fails System error logs hold problem reports 18

I/O protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions All I/O instructions defined to be privileged I/O must be performed via system calls * Memory-mapped and I/O port memory locations must be protected too Life cycle of an I/O request 19

Kernel data structures Kernel keeps state info for I/O components, including open file tables, network connections, character device state Many, many complex data structures to track buffers, memory allocation, dirty blocks Some use object-oriented methods and message passing to implement I/O UNIX I/O kernel structure 20

I/O requests to hardware operations Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process Another example: blocked read w. DMA A process issues a read call which executes a system call System call code checks for correctness and cache If it needs to perform I/O, it will issues a device driver call Device driver allocates a buffer for read and schedules I/O Controller performs DMA data transfer, blocks the process Device generates an interrupt on completion Interrupt handler stores any data and notifies completion Move data from kernel buffer to user buffer and wakeup blocked process User process continues 21