I/O Device and Drivers

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

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

Devices and Device Controllers

1. Computer System Structure and Components

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

CS161: Operating Systems

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

Introduction. What is an Operating System?

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

CSC 2405: Computer Systems II

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

Chapter 11 I/O Management and Disk Scheduling

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

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

Chapter 2: OS Overview

Operating System Structures

OPERATING SYSTEMS STRUCTURES

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

Operating Systems 4 th Class

Operating System Components and Services

Operating System Overview. Otto J. Anshus

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

Chapter 3 Operating-System Structures

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

Operating Systems Design 16. Networking: Sockets

UNIX Sockets. COS 461 Precept 1

Computer-System Architecture

An Analysis of Wireless Device Implementations on Universal Serial Bus

Computer Systems Structure Input/Output

Chapter 6, The Operating System Machine Level

Chapter 1 Computer System Overview

Device Drivers: Their Function in an Operating System

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Chapter 2 System Structures

Resource Utilization of Middleware Components in Embedded Systems

Virtual vs Physical Addresses

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

Lecture 1 Operating System Overview

Device Management Functions

Outline: Operating Systems

Operating Systems: Basic Concepts and History

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

Web Server Architectures

Network Attached Storage. Jinfeng Yang Oct/19/2015

Operating System Components

OPERATING SYSTEM SERVICES

Computer Organization & Architecture Lecture #19

Plug and Play for Windows 2000

Example of Standard API

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

SYSTEM ecos Embedded Configurable Operating System

COS 318: Operating Systems. Virtual Machine Monitors

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

COMPUTER SCIENCE AND ENGINEERING - Basic Functions and Operational Units - Kevin Skadron, BASIC FUNCTIONS AND OPERATIONAL UNITS

COS 318: Operating Systems. Virtual Memory and Address Translation

Scaling Networking Applications to Multiple Cores

Operating system Dr. Shroouq J.

- An Essential Building Block for Stable and Reliable Compute Clusters

ENABLING WIRELESS DATA COMMUNICATION IN CONSTRUCTION MANAGEMENT SYSTEM

INPUT/OUTPUT ORGANIZATION

TCP Servers: Offloading TCP Processing in Internet Servers. Design, Implementation, and Performance

Operating System Tutorial

COS 318: Operating Systems. Virtual Machine Monitors

1B11 Operating Systems. Input/Output and Devices

sndio OpenBSD audio & MIDI framework for music and desktop applications

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

x64 Servers: Do you want 64 or 32 bit apps with that server?

Hardware Based Virtualization Technologies. Elsie Wahlig Platform Software Architect

White Paper. Real-time Capabilities for Linux SGI REACT Real-Time for Linux

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

How To Understand And Understand An Operating System In C Programming

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Hello, and welcome to this presentation of the STM32 SDMMC controller module. It covers the main features of the controller which is used to connect

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

Operating System Structures

Using process address space on the GPU

How to design and implement firmware for embedded systems

IOMMU: A Detailed view

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

CS3600 SYSTEMS AND NETWORKS

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Operating System Structure

ELEC 377. Operating Systems. Week 1 Class 3

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

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

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

A Comparison of NVMe and AHCI

Violin: A Framework for Extensible Block-level Storage

Virtualization in Linux KVM + QEMU

Linux Kernel Architecture

Overview of Operating Systems Instructor: Dr. Tongping Liu

CPS221 Lecture: Operating System Structure; Virtual Machines

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

Operating System Organization. Purpose of an OS

C-GEP 100 Monitoring application user manual

Transcription:

COS 318: Operating Systems I/O Device and Drivers Prof. Margaret Martonosi Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall11/cos318/

Announcements Project 2 due Tomorrow Oct 19 at noon Precept today is open questions Thur Oct 20: I m out of town: Program Committee meeting for ASPLOS. Translation: All-day meeting in which researchers who have peer-reviewed about 150 paper submissions discuss in person which ~30 should be accepted for publication at the 17 th International Conference on Architectural Support for Programming Languages and Operating Systems Prof. Vivek Pai will teach Midterm Thursday, Oct. 27 during normal class time 2

Today s Topics Device controllers Device driver design Synchronous and asynchronous I/O Speaking of I/O: We ve got no time to watch it all here, but check out the Mother of All Demos : http://www.youtube.com/watch?v=jfigzsotmos (and others) Douglas Engelbart First demo of a mouse. December 9, 1968 3

Input and Output A computer s job is to process data Computation (CPU, 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 Device 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 Achieve potential I/O performance in a system 4

Revisit Hardware Compute hardware CPU and caches Chipset Memory CPU CPU CPU CPU I/O Hardware I/O bus or interconnect I/O controller or adaptor I/O device Memory I/O bus Two types of I/O devices Programmed I/O (PIO) Direct Memory Access (DMA) Network 5

I/O Devices

Memory-Mapped I/O (1) Figure 5-2. (a) Separate I/O and memory space. (b) Memory-mapped I/O. (c) Hybrid.

Definitions and General Method Overhead CPU time to initiate an operation Latency Time to transfer one byte Overhead + 1 byte reaches destination Bandwidth Rate of I/O transfer, once initiated Mbytes/sec General method Abstraction of byte transfers Batch transfers into block I/O for efficiency to prorate overhead and latency over a large unit Initiate Data transfer 8

Programmed Input Device Device controller Status register ready: if the host is done busy: 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 9

Programmed Output Device Device Status registers (ready, busy, ) Example Data registers 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 10

Direct Memory Access (DMA) Figure 5-4. Operation of a DMA transfer.

Direct Memory Access (DMA) DMA controller or adaptor Status register (ready, busy, interrupt, ) DMA command register DMA register (address, size) DMA buffer Host CPU initiates DMA Device 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 12

Today s Topics Device controllers Device driver design Synchronous and asynchronous I/O 13

I/O Software Stack User-Level I/O Software Device-Independent OS software Device Drivers Interrupt handlers Hardware 14

Uniform Interfacing for Device Drivers Distinct devices may have classes of similar behavior (a) Without vs. (b) with a standard driver interface.

Recall Interrupt Handling Save 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 16

Device Drivers Device Device controller Device driver Device Device Device Device controller. Device controller Interrupt Handling Device driver. Device driver I/O System Rest of the operating system 17

A Typical Device 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 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 18

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 19

Character and Block Device 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 20

Unix Device Driver Interface Entry Points init() Initialize hardware start() Boot time initialization (require system services) open(dev, flag, id) and close(dev, flag, id) halt() Initialization resources for read or write, and release afterwards 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 21

Today s Topics Device controllers Device driver design Synchronous and asynchronous I/O 22

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 the user process can do other things before I/O completion I/O completion will notify the user process 23

Detailed Steps of Blocked Read A process issues a read call which executes a system call System call code checks for correctness and buffer 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 Block the current process and schedule a ready process Device 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 24

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 is there Otherwise, return with a special status 25

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 Spooling Avoid deadlock problems Caching Avoid I/O operations 26

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? 10 users or 10 modems 900 interrupts/sec per user What should the overhead of an interrupt be Technique to minimize interrupt overhead Interrupt coalescing 27

Other Design Issues 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 28

Dynamic Binding: Indirection Open( 1, ); Indirect table Interrupt handlers Other Kernel services Driver-kernel interface Driver for device 1 open( ) { } read( ) { } Driver for device 0 open( ) { } read( ) { } 29

Issues with Device Drivers Flexible for users, ISVs and IHVs Users can download and install device drivers Vendors can work with open hardware platforms Dangerous methods Device 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 30

Summary Device controllers Programmed I/O is simple but inefficient DMA is efficient (asynchronous) and complex Device drivers Dominate the code size of OS Dynamic binding is desirable for desktops or laptops Device drivers can introduce security holes Progress on secure code for device drivers but completely removing device driver security is still an open problem 31