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

Similar documents
I/O Systems. Jo, Heeseung

[08] IO SUBSYSTEM 1. 1

Module 11: I/O Systems

OS Structure. Kevin Webb Swarthmore College January 25, Relevant xkcd:

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.

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

I/O. Disclaimer: some slides are adopted from book authors slides with permission 1

I/O Devices. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

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

CS162 Operating Systems and Systems Programming Lecture 16. I/O Systems. Page 1

Review: Hardware user/kernel boundary

Chapter 13: I/O Systems

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

Module 12: I/O Systems

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)

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

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

-Device. -Physical or virtual thing that does something -Software + hardware to operate a device (Controller runs port, Bus, device)

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

Operating Systems CMPSC 473. Input/Output April 22, Lecture 22 Instructor: Trent Jaeger

I/O. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter 6.5-6

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

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

Operating Systems 2010/2011

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

OPERATING SYSTEMS CS136

CS 104 Computer Organization and Design

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

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

File System Performance (and Abstractions) Kevin Webb Swarthmore College April 5, 2018

Hardware OS & OS- Application interface

Computer System Overview

Chapter 8: I/O functions & socket options

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

Roadmap. CPU management. Memory management. Disk management. Other topics. Process, thread, synchronization, scheduling. Virtual memory, demand paging

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

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

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Anne Bracy CS 3410 Computer Science Cornell University

Chapter 13: I/O Systems

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

Module 12: I/O Systems

Sistemi in Tempo Reale

C02: Interrupts and I/O

Silberschatz and Galvin Chapter 12

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

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

Devices and Device Controllers. secondary storage (disks, tape) and storage controllers

Bus Architecture Example

Chapter 5 Input/Output. I/O Devices

CSC 2405: Computer Systems II

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

Quiz: Address Translation

Operating Systems. V. Input / Output

Computer Science 61C Spring Friedland and Weaver. Input/Output

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

Reserves time on a paper sign-up sheet. Programmer runs his own program. Relays or vacuum tube hardware. Plug board or punch card input.

Operating Systems (CS1022) Input/Output. Yagiz Özbek Evren

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

CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems

Input/Output Systems

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

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

CSCI-GA Operating Systems I/O. Hubertus Franke

Module 6: INPUT - OUTPUT (I/O)

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

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

2 nd Half. Memory management Disk management Network and Security Virtual machine

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1

CS162 Operating Systems and Systems Programming Lecture 16. Page Allocation and Replacement (con t) I/O Systems

Chapter 13: 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)

CSE 380 Computer Operating Systems

CIS Operating Systems File Systems. Professor Qiang Zeng Fall 2017

Device-Functionality Progression

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

CIS Operating Systems File Systems. Professor Qiang Zeng Spring 2018

Memory Management. Kevin Webb Swarthmore College February 27, 2018

Hard Disk Drives (HDDs) Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

I/O SYSTEMS. Sunu Wibirama

I/O Management Intro. Chapter 5

COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr.

Problem Set: Processes

Hard Disk Drives (HDDs)

October 26 th, 2015 Prof. John Kubiatowicz

Operating Systems, Fall

I/O Management Intro. Chapter 5

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

Chapter 13: I/O Systems

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

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

Lecture 15: I/O Devices & Drivers

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

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

Utilizing Linux Kernel Components in K42 K42 Team modified October 2001

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

20-EECE-4029 Operating Systems Fall, 2015 John Franco

Transcription:

Input / Output Kevin Webb Swarthmore College April 12, 2018 xkcd #927 Fortunately, the charging one has been solved now that we've all standardized on mini-usb. Or is it micro-usb?

Today s Goals Characterize devices the landscape of I/O devices. Mechanisms for data transfer, interacting with devices, and initiating I/O Device drivers and their place in OS structure. I/O interfaces for userspace applications.

Device Diversity Thus far: lots of focus on one specific I/O type: files & disk. Devices we ve seen so far are the big / important ones: CPU: Differences in ISA, but overall behavior similar: execute instructions. Memory: Stores data when powered. Disks: have some interesting variations (spinning vs. SSD) General I/O takes this to another level!

Devices for Machines Some I/O helps machine to talk to other machine devices: Most devices are for PEOPLE!

Devices for People

I/O Device Data Rates Device Keyboard Mouse Spinning Hard Disk Fast Network Card (10 GBE) Graphics Card / GPU Transfer Rate ~ 10 Bytes / sec ~ 100 Bytes / sec ~ 100 Megabytes / sec ~ 1.2 Gigabytes / sec Up to 16 Gigabytes / sec

System Hardware and Connections CPU CPUs Memory Bus Memory Slots

System Hardware and Connections CPU CPUs Memory Bus Memory Slots I/O Controller (Southbridge) High-speed device slots(e.g., PCI-e x16)

System Hardware and Connections CPU CPUs Memory Bus Memory Slots Goal for I/O: Move data between devices and memory. I/O Bus (e.g., PCI) I/O Controller (Southbridge) High-speed device slots(e.g., PCI-e x16) SATA Controller USB Controller IDE Controller Device slots (e.g., PCI, PCI-e x1)

Which component should be responsible for moving data between the memory and device(s)? Why? A. The CPU. B. The memory. C. The device that has data to move. D. Some other component.

Programmed I/O vs. Direct Memory Access Programmed I/O (PIO) CPU transfers data between device and memory. Direct Memory Access (DMA) Device communicates directly with memory. We commonly use both of these methods!

PIO vs. DMA Want to move data from device to memory. CPU Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Request Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Data Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Data Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU Request Memory I/O Device

PIO vs. DMA Want to move data from device to memory. CPU I/O Device Data Memory

PIO vs. DMA Want to move data from device to memory. CPU I did it! Memory I/O Device

What types of devices would you expect to use PIO? DMA? Why?

Initiating I/O PIO and DMA help us move data. CPU How do we tell the device what to do? Request I/O Device

How do we tell a device what to do? Example: suppose you have an IBM model M keyboard and you want to light up the caps lock light

How do we tell a device what to do? The device has a controller, with some registers. One of the registers controls the status lights.

How can the OS issue a command to a device? Suppose you re writing the kernel code. What does it look like?

Interacting with Devices Port-mapped I/O Assign each device to a numbered I/O port. Access device s registers through port-based CPU instructions. Memory-mapped I/O Logically place device s registers into kernel s address space. Access registers by issuing standard memory load / store instructions. Memory-mapped I/O is (almost?) exclusively used today.

Memory-Mapped I/O OS kernel s virtual address space is typically much larger than physical memory. (e.g., 48-bit VAS -> address 256 TB) 0 PCB Data Page tables Disk caches Lots of unused addresses 256 TB

Memory-Mapped I/O OS kernel s virtual address space is typically much larger than physical memory. (e.g., 48-bit VAS -> address 256 TB) 0 PCB Data Page tables Disk caches Device control registers 256 TB Writing to this region of VAS does NOT touch system memory. It changes the device state!

Detecting Available Input PIO and DMA help us move data. CPU MMIO gives us a mechanism for talking to device. How can we determine that a device has data for us? I have something for you! I/O Device

How should the OS learn that a device has input available? Why? Under what conditions? A. Ask the device if it has data. B. Let the device signal the OS if it has data. C. Learn about data via some other mechanism.

Polling vs. Interrupts Polling: periodically ask device hey, do you have anything for me? Interrupts: device signals CPU to stop what it s doing, context switch to OS so that it can initiate data transfer. Most devices use interrupts to avoid wasted polling time. In some cases, it might make sense to switch to polling: Eliminating Receive Livelock in an Interrupt-driven Kernel (1997)

Interrupt Handlers If a device uses interrupts, the OS needs a handler for it. Disk: wake up the process that blocked requesting disk access Network: copy newly-received data from device to kernel buffer When interrupt signal sent to CPU, determine which device sent it, and which handler to invoke. Analogous to system calls, OS keeps a table with unique numbers for each device. Maps device to handler code.

The story so far Lots of decisions to be made in accessing a device: PIO vs. DMA, ports vs. MMIO, polling vs. interrupts Available options depend on hardware support, of course. In OS, control for each device implemented in device driver. Drivers often loaded as OS kernel modules. OS Kernel (core services): Signal handling, I/O system, swapping, scheduling, page replacement, virtual memory file system: ext4 device driver: USB disk file system: fat32

Device Drivers Executes in OS kernel address space. (except for microkernels) Defines how to interact with device Where the device s registers are mapped in memory What type of device it is (how users interact with it) Device types: character, block, network Block: disk-like device, typically can do random access, transfers large chunks Character: transfers a stream of characters, data typically consumed when read Network: transfers small data chunks (packets)

Device Drivers Executes in OS kernel address space. Hold on we re extending the trusted kernel code? Who writes these where do they come from? Linux: almost all drivers provided by kernel devs, open source code. Windows: some drivers provided by Microsoft, many by device maker. OS X: somewhere in between. Most from Apple, occasionally device maker. Do we trust these drivers? What happens if something goes wrong?

Windows BSOD When drivers go bad Driver support was a major contributing factor to the Windows Vista disaster, particularly at launch.

Hardware Kernel Userspace I/O Software Structure: Layered User Process User I/O (stdio library) Device-Independent I/O Device driver Device driver Device driver Device controller Device controller Device controller Device controller Device Dev Dev Device Dev Dev

Kernel Where would you expect to find an interrupt handler? A caching implementation? Why? Device-Independent I/O Device driver Device driver Device driver Answer Choice Interrupt Handler Caching A Device driver Device driver B Device-independent Device driver C Device driver Device-independent D Device-independent Device-independent

Hardware Kernel Userspace I/O Software Structure: Layered User Process Make I/O request, get I/O response User I/O (stdio library) Buffering, formatting Device-Independent I/O Naming, protection, blocking, buffering, caching Device driver Device driver Device driver Control via device registers, handle interrupts Device controller Device controller Device controller Device controller Wakeup driver when I/O completed Device Dev Dev Device Dev Dev Perform I/O operation

Recall: OS Buffering (From IPC Slides) Kernel s buffers have finite storage space! send(to, data) recv(from, data) P 1 P 2 TCP/IP Socket Buffer kernel Network series of tubes TCP/IP Socket Buffer kernel If sender fills buffer, OS will mark the process as blocked can t be scheduled until space is free. If the buffer is empty, OS will mark the receiver process as blocked can t read data before it arrives!

General Device Buffering write(to, data) read(from, data) P 1 P 2 kernel Device A: Output buffer Input buffer Device B: Output buffer Input buffer

Why should the OS buffer data to/from devices?

Why OS Buffering? Speed mismatch between device and user process. analogous to producer/consumer problem store produced items (data) in buffer, smooth out bursty requests Data transfer size mismatch between device and user process. e.g., receive large chunk of data from network, user only wants a few bytes DMA requires large, aligned, contiguous chunks of reserved memory. better not to rely on the user to set that up

Unix: I/O System Calls For most devices, uniform access via file system interface: fd = open( /dev/devname, ); bytes_read = read(fd, buf, count); bytes_written = write(fd, buf, count); ioctl(fd, request, ); close(fd); Notable exceptions: Devices that userspace can t access directly (e.g., timers used for scheduling). Network adapters FS interface awkward due to addressing.

What is ioctl()? ioctl is a catch-all for all I/O commands that are not open/close/read/write. It takes a request parameter that the I/O device then translates into the actual command it executes. e.g., asking a USB device its transfer rate (USB 1 vs. USB 2) e.g., instructing CD-ROM device to eject the disc. #include <sys/ioctl.h> int ioctl(int fd, unsigned long request,...);

Common I/O Interface Processes can mix and match descriptors (e.g., shell redirection). OS can cache / buffer / protect data in device-independent way. Easier for humans to remember!

Synchronous I/O For most devices, uniform access via file system interface: fd = open( /dev/devname, ); bytes_read = read(fd, buf, count); bytes_written = write(fd, buf, count); ioctl(fd, request, ); close(fd); The functions above are synchronous: when the user calls them, they need them to happen now. Can t make progress until they re done. This is the most common form of I/O, and it s what we ve been assuming all along: You perform I/O, which is slow, so you have to block while you wait!

Alternative: Asynchronous I/O

Alternative: Asynchronous I/O Issue a read or write request in the background, but don t block waiting for it. In the mean time, process can continue working on other things. Notification options when request completes: 1. Do nothing, my process will check later. 2. Send my process a signal. 3. Start a new thread in my process with the specified function.

Alternative: Asynchronous I/O

Summary Huge diversity in I/O devices, with many different characteristics. Many choices in interacting with devices: Programmed I/O (PIO) vs. Direct Memory Access (DMA) Port-mapped I/O vs. Memory-mapped I/O Polling vs. Interrupts Devices controlled by OS driver code. I/O interface usually synchronous, alternatives for asynch exist.