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

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

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

Device-Functionality Progression

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

Chapter 12: I/O Systems

Chapter 13: I/O Systems

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

Module 12: I/O Systems

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

Chapter 13: I/O Systems

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

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

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

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

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)

Chapter 13: I/O Systems

Module 12: I/O Systems

Operating Systems 2010/2011

Chapter 13: I/O Systems

Operating Systems. V. Input / Output

Chapter 13: I/O Systems

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

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

Input/Output Systems

Chapter 13: I/O Systems

Chapter 13: I/O Systems

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

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

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

Comp 204: Computer Systems and Their Implementation. Lecture 18: 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.

Silberschatz and Galvin Chapter 12

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

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

Chapter 13: I/O Systems

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

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

Module 11: I/O Systems

Chapter 12: Mass-Storage Systems. Operating System Concepts 8 th Edition,

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

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

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

Chapter 5 Input/Output. I/O Devices

[08] IO SUBSYSTEM 1. 1

Operating Systems. V. Input / Output. Eurecom

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

CS420: Operating Systems. Kernel I/O Subsystem

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

I/O Systems. Jo, Heeseung

Input Output (IO) Management

Lecture 15: I/O Devices & Drivers

Chapter 10: Mass-Storage Systems

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

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

Answer to exercises chap 13.2

I/O AND DEVICE HANDLING Operating Systems Design Euiseong Seo

I/O Management and Disk Scheduling. Chapter 11

Input/Output Systems

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

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

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

Operating Systems 2010/2011

Chapter 12: Secondary-Storage Structure. Operating System Concepts 8 th Edition,

Operating System 1 (ECS-501)

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

OPERATING SYSTEMS CS136

Input/Output Management

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

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Overview of Mass Storage Structure

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)

Free Space Management

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

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

Chapter 5 - Input / Output

CSCI-GA Operating Systems I/O. Hubertus Franke

Lecture 9. I/O Management and Disk Scheduling Algorithms

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

Hard Disk Drives (HDDs)

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

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

EIDE, ATA, SATA, USB,

CS370 Operating Systems

I/O & Storage. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

Secondary storage. CS 537 Lecture 11 Secondary Storage. Disk trends. Another trip down memory lane

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. (done)

UNIT 4 Device Management

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

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Chapter 11 I/O Management and Disk Scheduling

Input/Output. Chapter 5: I/O Systems. How fast is I/O hardware? Device controllers. Memory-mapped I/O. How is memory-mapped I/O done?

NWI-IBC019: Operating systems

QUESTION BANK UNIT I

Input/Output. Today. Next. ! Principles of I/O hardware & software! I/O software layers! Secondary storage. ! File systems

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

CPS104 Computer Organization and Programming Lecture 18: Input-Output. Outline of Today s Lecture. The Big Picture: Where are We Now?

CSE 153 Design of Operating Systems Fall 2018

Transcription:

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

Input/Output (I/O) Typical application flow consists of alternating phases Compute I/O operation Often I/O is the primary component with very short compute bursts Recall that OS manages resources Also includes I/O resources Initiates and controls I/O operations Controls I/O devices and device drivers I/O systems allow process to interact w/ physical devices Both within the computer: Disks, printer, keyboard, mouse And outside the computer: Network operations 2

Processor Interface to IO Devices Processor Chip P0 P1 P2 P3 PCIe On-Chip Cache Memory Controller Other IO Processor Chip has IO Pins E.g. for connection to buses Memory bus PCIe bus Other dedicated IO to chip E.g. for power To main memory (e.g. DRAM) 3

IO System Connections monitor graphics controller processor memory disk controller USB controller disk mouse keyboard USB PCIe Card 4

IO System Devices connect via a port or a bus A bus is a set of wires with a well defined protocol Controller operates a port, bus or device Wide ranging complexities Disk controllers can be very complex Sometimes even a dedicated embedded processor is used Runs the controller software Two sides of the communication Processor: On-chip hardware (e.g. PCIe controller) interfaces to the bus protocol Or bridge / IO controller on separate chip in older systems IO devices: Via the controller mentioned above 5

Device Controller Processor interacts with controller for a target device Processor can send commands / data (or receive) Controller contains registers for commands / data Two ways for processor to communicate with these registers Dedicated I/O instructions that transfer bits to I/O port address Memory mapped I/O: controller regs are mapped to mem address Standard load/store instructions can write to registers E.g. graphics controller has large mem mapped space for pixel data Control register bit patterns indicate different commands to device Usually at least 4 register Data-in (to the processor) and Data-out (from the processor) Status: state of the device (device busy, data ready, error, etc.) Control Register: written by device to initiate command or change device settings 6

Processor Device Interaction Handshake protocol 1. Host reads a busy bit in the status register until device free 2. Host sets write bit in command register & writes data into data-out 3. Host sets the command ready bit in the command register 4. Controller detects command ready bit set & sets busy bit 5. Controller reads command register; sees command; does I/O w/ device 6. Controller clears command ready bit; clear error & busy bits in status reg How to handle step 1 Polling (busy-waiting) executing a small code loop Load branch if bit not set Performance-inefficient if device is frequently busy Interrupt mechanism to notify the CPU Recall our previous lecture 7

More on Interrupts & I/O Steps for reading from disk Initiate I/O read operations for disk drive Bring data into kernel buffer in memory Copy data from kernel space buffer into user space buffer Initiating I/O read ops from disk is high priority Want to efficiently utilize disk Use pair of interrupt handlers High priority handler handshakes w/ disk controller Keeps I/O requests moving to disk Raises low-priority interrupt when disk operations are complete Low priority handler services interrupt Moves data from kernel buffer to user space Calls scheduler to move process to ready queue Threaded kernel architecture is a good fit 8

Direct Memory Access (DMA) We ve talked about a tight control loop (handshake) so far Processor monitors status bits (or interrupts) Move data in bytes or words at a time via data-in / data-out regs Also called Programmed I/O (PIO) Some devices want to perform large data transfers E.g. disk, network DMA: Typically done w/ dedicated HW engine or logic Processor writes DMA commands to a memory buffer Pointer to src and dest addresses, # of bytes to transfer Processor writes address of DMA command block to DMA engine DMA engine operates on memory & handshakes with device 9

DMA Operation DMA-request & DMA-acknowledge to device controller Device asserts DMA-request when data is available to transfer DMA controller obtains bus control Puts appropriate request address on the bus Asserts DMA-acknowledge wire Device controller puts data on the bus DMA controller generates CPU interrupt when transfer is complete 10

Application Interface to I/O System Many different devices All with different functionality, register control definitions, etc. How can OS talk to new devices without modification? How can OS provide consistent API to applications for I/O? Solution to all computer science problems Either add a level of indirection (abstraction) or cache it! Abstract away IO device details Identify sets of similar devices; provide standard interface to each Add a new layer of software to implement each interface Device Drivers Type of kernel module (OS extensions that can be loaded / unloaded) 11

Device Drivers Purpose: hide device-specific controller details from I/O subsystem as much as possible OS is easier to develop & maintain Device manufacturers can conform to common interfaces Can attach new I/O devices to existing machines Device driver software is typically OS-specific Different interface standards across Oses Several different device categories (each w/ interface) Based on different device characteristics Block I/O, Character-stream I/O, Memory-mapped file, Network sockets OS also has low-level system calls (ioctl on Linux) Look at man page 12

Block-Device Interface API for accessing block-oriented devices read, write, seek (if random access device) Applications normally access via file system interface Low-level device operation & policies are hidden by API 13

Character-Stream Interface Keyboard, mice, for example API: get(), put() a character at a time Often libraries are implemented on top of this interface E.g. buffer and read a line at a time Useful for devices that produce input data unpredictably 14

Memory-mapped File Interface Layer on top of block-device interface Provides access to storage as bytes in memory System call sets up this memory mapping We ve seen an example of this for memory-mapped disk files Processor can read & write bytes in memory Data transfers only performed as needed between memory & device 15

Network Device Interface UNIX network sockets for example Applications can Create socket Connect a local socket to a remote address Address = host IP address and port number This will plug the socket into an application on the remote machine Use select() to monitor activity on any of a number of sockets 16

Blocking vs. Nonblocking (vs. Async) Blocking Process is suspended on issuing a blocking IO system call Moved from ready queue to wait queue Moved back to ready queue after IO completes Nonblocking Process does not wait for IO call completion Any data that is ready is returned E.g. user Interface receives keyboard & mouse input Asynchronous IO call returns immediately & IO operation is initiated Process is notified of IO completion via later interrupt E.g. select() w/ wait time of 0 Followed by read() if any source has data ready 17

OS Kernel I/O Subsystem Provides many services for I/O Scheduling Buffering Caching Spooling Device Reservation Error Handling Protection of I/O 18

I/O Scheduling Scheduling = Ordering application requests to IO devices OS does not necessarily have to send them in order received Can impact many aspects of the system Performance Average wait time by applications for I/O requests IO device utilization (how often are they busy performing useful work) Fairness Do applications get uniform access to I/O devices? Should some users / applications be prioritized? Implementation OS implements a wait queue for requests to each device Reorders queue to schedule requests to optimize metrics 19

Example: Disk Scheduling Traditional hard disk has two access time components Seek time: disk arm moves heads to cylinder containing sector Rotational latency: disk rotates to desired sector Bandwidth is also important (# bytes per unit time) Somewhat analogous to CPU scheduling we discussed FCFS: first-come, first-served Fair, but generally not fast or high bandwidth SSTF: shortest seek time first Equivalent to SJF (see pros & cons from CPU scheduling) SCAN: move disk arm from one end to the other, back & forth Service requests as disk arm reaches their cylinder Elevator algorithm C-SCAN: move disk arm in a cyclical round trip Improves wait time relative to SCAN 20

I/O Buffering Memory region to store in-flight data E.g. between two devices or a device and application Reasons for buffering Speed mismatch between source and destination device E.g. data received over slow network going to fast disk Want to write big blocks of data to disk at a time, not small pieces Double buffering Alternate which buffer is being filled from src and which is written to dst Removes need for timing requirements between producer / consumer Efficiently handle device data with different transfer sizes Support copy semantics Example 21

I/O Caching Similar concept to other types of caching you ve learned CPU caching (L1, L2, L3 caches for main memory) Disk caching using main memory Use memory to cache data regions for IO transfers Similar to buffering, but for a different purpose E.g. for disk IO, cache buffers in main memory Improves efficiency for shared files that are read/written often Improve latency for reads; Reduce disk bandwidth for writes Reads serviced by memory instead of slow disk Writes can be gathered and a single bulk disk write done later 22

I/O Spooling Spool: type of buffer to hold data for device that cannot accept interleaved data streams Printers! Kernel stores each applications print I/O data Spooled to a separate disk file Later, the kernel queues a spool file to the printer Often managed by a running daemon process Allows applications to view pending jobs, cancel jobs, etc. Device Reservation: For similar purposes as spooling Kernel facility for allocating an idle device & deallocating later 23

I/O Error Handling & Protection I/O system calls return information about status errno variable in UNIX Indicate general nature of failure Failures can happen due to transient problems OS can compensate by re-trying failed operations Protection mechanisms for I/O by kernel All I/O instructions are privileged cannot be executed directly by user process User process must execute system call System call can check for valid request & data 24