COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware



Similar documents
I/O Device and Drivers

Have both hardware and software. Want to hide the details from the programmer (user).

I/O. Input/Output. Types of devices. Interface. Computer hardware

Devices and Device Controllers

1. Computer System Structure and Components

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Introduction. What is an Operating System?

Chapter 1 Computer System Overview

Computer Systems Structure Input/Output

Linux Driver Devices. Why, When, Which, How?

Chapter Introduction. Storage and Other I/O Topics. p. 570( 頁 585) Fig I/O devices can be characterized by. I/O bus connections

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

CS161: Operating Systems

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

Chapter 11 I/O Management and Disk Scheduling

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Operating System Structures

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Quiz for Chapter 6 Storage and Other I/O Topics 3.10

Outline: Operating Systems

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Practice Test for the Domain 1 - PC Hardware (Brought to you by RMRoberts.com)

Computer Organization & Architecture Lecture #19

CSC 2405: Computer Systems II

CPS104 Computer Organization and Programming Lecture 18: Input-Output. Robert Wagner

Obj: Sec 1.0, to describe the relationship between hardware and software HW: Read p.2 9. Do Now: Name 3 parts of the computer.

Plug and Play for Windows 2000

Phoenix SecureCore TM Setup Utility

Operating Systems Design 16. Networking: Sockets

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

Ways to Use USB in Embedded Systems

Device Drivers: Their Function in an Operating System

Virtual vs Physical Addresses

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

What is involved in input/output? How does the operating system manage I/O?

Gigabit Ethernet Design

Datacenter Operating Systems

Chapter 02: Computer Organization. Lesson 04: Functional units and components in a computer organization Part 3 Bus Structures

Operating Systems: Basic Concepts and History

OPERATING SYSTEM SERVICES

UNIX Sockets. COS 461 Precept 1

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Computer-System Architecture

Operating System Overview. Otto J. Anshus

TELE 301 Lecture 7: Linux/Unix file

TEST CHAPTERS 1 & 2 OPERATING SYSTEMS

Chapter 2: OS Overview

Introduction to I/O and Disk Management

OS Concepts and structure

11: I/O Device Management

Storage and File Systems. Chester Rebeiro IIT Madras

Chapter 8 Objectives. Chapter 8 Operating Systems and Utility Programs. Operating Systems. Operating Systems. Operating Systems.

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

An Analysis of Wireless Device Implementations on Universal Serial Bus

PCI-to-SATA RAID Adapter AEC-6890M. User s Manual Version:1.0

Operating System Tutorial

Operating Systems 4 th Class

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

File System & Device Drive. Overview of Mass Storage Structure. Moving head Disk Mechanism. HDD Pictures 11/13/2014. CS341: Operating System

Chapter 6, The Operating System Machine Level

VMWare Workstation 11 Installation MICROSOFT WINDOWS SERVER 2008 R2 STANDARD ENTERPRISE ED.

Lecture 25 Symbian OS

Ultra Thin Client TC-401 TC-402. Users s Guide

Computer Setup (F10) Utility Guide Evo Desktop Family Evo Workstation Family

lesson 1 An Overview of the Computer System

What is a bus? A Bus is: Advantages of Buses. Disadvantage of Buses. Master versus Slave. The General Organization of a Bus

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

Computer Setup (F10) Utility Guide Business Desktops

Price/performance Modern Memory Hierarchy

Update: About Apple RAID Version 1.5 About this update

IDE ATA/133 Controller

The Bus (PCI and PCI-Express)

Chapter 12: Mass-Storage Systems

This tutorial will take you through step by step approach while learning Operating System concepts.

Violin: A Framework for Extensible Block-level Storage

Hardware Based Virtualization Technologies. Elsie Wahlig Platform Software Architect

Computer Setup (F10) Utility Guide HP Compaq dx2200 Microtower Business PC

- An Essential Building Block for Stable and Reliable Compute Clusters

How To Connect A Port Replicator With An Ethernet To A Usb Port From A Usb Device

v1 System Requirements 7/11/07

INPUT/OUTPUT ORGANIZATION

Chapter 3 Operating-System Structures

Operating System Components

A Comparison of NVMe and AHCI

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

EaseUS Partition Master

C-GEP 100 Monitoring application user manual

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

IDE/ATA Interface. Objectives. IDE Interface. IDE Interface

Lecture 1 Operating System Overview

1B11 Operating Systems. Input/Output and Devices

PERFORMANCE TUNING ORACLE RAC ON LINUX

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Transcription:

COS 318: Operating Systems I/O and Drivers Input and Output A computer s job is to process data Computation (, cache, and memory) Move data into and out of a system (between I/O devices and memory) Challenges with I/O devices Different categories: storage, networking, displays, etc. Large number of device drivers to support drivers run in kernel mode and can crash systems Goals of the OS Provide a generic, consistent, convenient and reliable way to access I/O devices As device-independent as possible Don t hurt the performance capability of the I/O system too much 2 Revisit Hardware Definitions and General Method Compute hardware and caches Chipset Memory I/O Hardware I/O bus or interconnect I/O controller or adaptor I/O device Two types of I/O Programmed I/O (PIO) does the work of moving data Direct Memory Access (DMA) offloads the work of moving data to DMA controller Memory I/O bus Network Overhead Time that the is tied up initiating/ ending an operation Initiate Latency Time to transfer one bit (typ. byte) Overhead + 1 bit reaches destination Bandwidth Rate of I/O transfer, once initiated Mbytes/sec General method Higher level abstractions of byte transfers Batch transfers into block I/O for efficiency to amortize overhead and latency over a large unit Data transfer 3 4 1

Programmed Input controller Status register ready: tells if the host is done busy: tells if the controller is done int: interrupt Data registers A simple mouse design Put (X, Y) in data registers on a move Interrupt Input on an interrupt Read values in X, Y registers Set ready bit Wake up a process/thread or execute a piece of code Programmed Output Status registers (ready, busy, ) Data registers Example A serial output device Perform an output Wait until ready bit is clear Poll the busy bit Writes the data to register(s) Set ready bit Controller sets busy bit and transfers data Controller clears the ready bit and busy bit 5 6 Direct Memory Access (DMA) I/O Software Stack DMA controller or adaptor Status register (ready, busy, interrupt, ) DMA command register DMA register (address, size) DMA buffer Host initiates DMA driver call (kernel mode) Wait until DMA device is free Initiate a DMA transaction (command, memory address, size) Block Controller performs DMA DMA data to device (size--; address++) Interrupt on completion (size == 0) Interrupt handler (on completion) Wakeup the blocked process User-Level I/O Software -Independent OS software Drivers Interrupt handlers Hardware 7 8 2

Recall Interrupt Handling Save context (registers that hw hasn t saved, PSW etc) Mask interrupts if needed Set up a context for interrupt service Set up a stack for interrupt service Acknowledge interrupt controller, perhaps enable it Save entire context to PCB Run the interrupt service Unmask interrupts if needed Possibly change the priority of the process Run the scheduler Then OS will set up context for next process, load registers and PSW, start running process 9 Drivers controller controller. controller Interrupt Handling driver driver. driver I/O System Rest of the operating system Manage the complexity and differences among specific types of devices (disk vs. mouse, different types of disks ) Each handles one type of device or small class of them (eg SCSI) 10 Typical Driver Design 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 responsibilities 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 Simplified Driver Behavior Check input parameters for validity, and translate them to devicespecific language Check if device is free (wait or block if not) Issue commands to control device Write them into device controller s registers Check after each if device is ready for next (wait or block if not) Block or wait for controller to finish work Check for errors, and pass data to device-indept software Return status information Process next queued request, or block waitng for next Challenges: Must be reentrant (can be called by an interrupt while running) Handle hot-pluggable devices and device removal while running Complex and many of them; bugs in them can crash system 11 12 3

Types of I/O s Typical Speeds Block devices Organize data in fixed-size blocks Transfers are in units of blocks Blocks have addresses and data are therefore addressable E.g. hard disks, USB disks, CD-ROMs Character devices Delivers or accepts a stream of characters, no block structure Not addressable, no seeks Can read from stream or write to stream Printers, network interfaces, terminals Like everything, not a perfect classification E.g. tape drives have blocks but not randomly accessed Clocks are I/O devices that just generate interrupts Keyboard Mouse Compact Flash card USB 2.0 52x CD-ROM Scanner 56K modem 802.11g wireless net Gigabit Ethernet FireWire-1 FireWire 800 SCSI Ultra-2 disk SATA disk PCI bus Ultrium tape 10 B/s 100 B/s 40 MB/s 60 MB/s 7.8 MB/s 400 KB/s 7 KB/s 6.75 MB/s 320 MB/s 50 MB/s 100 MB/s 80 MB/s 300 MB/s 528 MB/s 320 MB/s 13 14 Driver Interface Open( devicenumber ) Initialization and allocate resources (buffers) Close( devicenumber ) Cleanup, deallocate, and possibly turnoff driver types Block: fixed sized block data transfer Character: variable sized data transfer Terminal: character driver with terminal control Network: streams for networking Interfaces for block and character/stream oriented devices (at least) are different Like to preserve same interface within each category Character and Block Interfaces 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 bufferaddr to a byte stream device 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 15 16 4

Unix Driver Interface Entry Points init() Initialize hardware start() Boot time initialization (require system services) open(dev, flag, id) and close(dev, flag, id) Initialization resources for read or write, and release afterwards halt() Call before the system is shutdown intr(vector) Called by the kernel on a hardware interrupt read( ) and write() calls Data transfer poll(pri) Called by the kernel 25 to 100 times a second ioctl(dev, cmd, arg, mode) special request processing Synchronous vs. Asynchronous I/O Synchronous I/O read() or write() will block a user process until its completion OS overlaps synchronous I/O with another process Asynchronous I/O read() or write() will not block a user process user process can do other things before I/O completion I/O completion will notify the user process 17 18 Detailed Steps of Blocked Read A process issues a read call which executes a system call System call code checks for correctness If it needs to perform I/O, it will issues a device driver call driver allocates a buffer for read and schedules I/O Controller performs DMA data transfer Block the current process and schedule a ready process generates an interrupt on completion Interrupt handler stores any data and notifies completion Move data from kernel buffer to user buffer Wakeup blocked process (make it ready) User process continues when it is scheduled to run Asynchronous I/O API Non-blocking read() and write() Status checking call Notification call Different form the synchronous I/O API Implementation On a write Copy to a system buffer, initiate the write and return Interrupt on completion or check status On a read Copy data from a system buffer if the data are there Otherwise, return with a special status 19 20 5

Why Buffering? Speed mismatch between the producer and consumer Character device and block device, for example Adapt different data transfer sizes (packets vs. streams) Deal with address translation I/O devices see physical memory User programs use virtual memory Caching Avoid I/O operations User-level and kernel-level buffering Spooling Avoid user processes holding up resources in multi-user environment Think About Performance A terminal connects to computer via a serial line Type character and get characters back to display RS-232 is bit serial: start bit, character code, stop bit (9600 baud) Do we have any cycles left? What should the overhead of an interrupt be Technique to minimize interrupt overhead Interrupt coalescing 21 22 Other Design Issues Dynamic Binding: Indirection Build device drivers Statically A new device driver requires reboot OS Dynamically Download a device driver without rebooting OS Almost every modern OS has this capability How to down load device driver dynamically? Load drivers into kernel memory Install entry points and maintain related data structures Initialize the device drivers Open( 1, ); Indirect table Interrupt handlers Other Kernel services Driver-kernel interface Driver for device 1 open( ) { read( ) { Driver for device 0 open( ) { read( ) { 23 24 6

Issues with Drivers Flexible for users, ISVs and IHVs Users can download and install device drivers Vendors can work with open hardware platforms Dangerous methods drivers run in kernel mode Bad device drivers can cause kernel crashes and introduce security holes Progress on making device driver more secure Checking device driver codes Build state machines for device drivers Summary controllers Programmed I/O is simple but inefficient DMA is efficient (asynchronous) and complex drivers Dominate the code size of OS Dynamic binding is desirable for desktops or laptops drivers can introduce security holes Progress on secure code for device drivers but completely removing device driver security is still an open problem 25 26 7