Chapter 5 Input/Output. 2 Introduction I/O: main function of OS –Drive devices, catch interrupts, handle errors –Provide a device independent interface.

Slides:



Advertisements
Similar presentations
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Advertisements

Principles of I/O Hardware I/O Devices Block devices, Character devices, Others Speed Device Controllers Separation of electronic from mechanical components.
CS 6560: Operating Systems Design
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
Part 5 (Stallings) Input/Output 5.1 Principles of I/O hardware
1 Input/Output Chapter Principles of I/O hardware 5.2 Principles of I/O software 5.3 I/O software layers 5.4 Disks 5.5 Clocks 5.6 Character-oriented.
EEE 435 Principles of Operating Systems Principles and Structure of I/O Software (Modern Operating Systems 5.2 & 5.3) 5/22/20151Dr Alain Beaulieu.
04/14/2008CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Operating Systems Input/Output Devices (Ch , 12.7; , 13.7)
Operating System - Overview Lecture 2. OPERATING SYSTEM STRUCTURES Main componants of an O/S Process Management Main Memory Management File Management.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
1 I/O Devices Controller: physically controls the devices Devices are diverse and complicated Present simpler interface to OS E.g, convert a linear sector.
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Device Management.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 3 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
1 Input/Output Chapter 3 TOPICS Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks Reference: Operating Systems Design.
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
Operating Systems Input/Output Devices (Ch 5: )
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
CSE 451: Operating Systems Winter 2010 Module 15 I/O Mark Zbikowski Gary Kimura.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
1 Input/Output. 2 Principles of I/O Hardware Some typical device, network, and data base rates.
1 Outline Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design issues for paging systems.
1 I/O and Filesystems. 2 How to provide interfaces Rough reading guide (no exam guarantee): Tanenbaum Ch. 5.1 – 5.5 & Silberschatz Ch. 13 & ,
Disk Access. DISK STRUCTURE Sector: Smallest unit of data transfer from/to disk; 512B 2/4/8 adjacent sectors transferred together: Blocks Read/write heads.
1 I/O Management and Disk Scheduling Chapter Categories of I/O Devices Human readable Used to communicate with the user Printers Video display terminals.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-1: I/O Management Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
NETW 3005 I/O Systems. Reading For this lecture, you should have read Chapter 13 (Sections 1-4, 7). NETW3005 (Operating Systems) Lecture 10 - I/O Systems2.
Sistem Operasi IKH311 Masukan Luaran (Input/Output)
CSC 322 Operating Systems Concepts Lecture - 25: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
1 Lecture 20: I/O n I/O hardware n I/O structure n communication with controllers n device interrupts n device drivers n streams.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS6: Device Management 6.1. Principles of I/O.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1 Comp 104: Operating Systems Concepts Devices. 2 Today Devices –Introduction –Handling I/O Device handling Buffering and caching.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
12/8/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Silberschatz, Galvin and Gagne  Operating System Concepts Six Step Process to Perform DMA Transfer.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Processor Memory Processor-memory bus I/O Device Bus Adapter I/O Device I/O Device Bus Adapter I/O Device I/O Device Expansion bus I/O Bus.
Input/Output Chapter 5 Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
I/O Software CS 537 – Introduction to Operating Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
1 Chapter 11 I/O Management and Disk Scheduling Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and.
I/O Management.
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Multiple Platters.
Operating System I/O System Monday, August 11, 2008.
Computer Architecture
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
Selecting a Disk-Scheduling Algorithm
CS703 - Advanced Operating Systems
Chapter 5: I/O Systems.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems.
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

Chapter 5 Input/Output

2 Introduction I/O: main function of OS –Drive devices, catch interrupts, handle errors –Provide a device independent interface between devices and rest of the computer systems To understand I/O –Principles of I/O hardware –Principles of I/O software –Layer structure of I/O software –Some specific I/O devices as examples

3 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks

4 Block and Character Devices Block devices: store info in fixed-size blocks –Examples: disks –Each block has its own address –Each block can be read/written independently Character devices: no block structure, deliver/accept a stream of characters –Examples: printers, network, mice –Not addressable, no seek operation Devices not in the classification: clock

5 Huge Range in Speeds Many orders of magnitude in data rates –Keyboard: 10 bytes/sec –Mouse: 100 bytes/sec –Laser printer: 100kb/sec –IDE disk: 5mb/sec –PCI bus: 528mb/sec Challenge: how to design a general structure to control various I/O devices?

6 Structure of I/O Units A mechanical component: the device itself An electronic component: device controller, adaptor –Printed circuit card inserted into expansion slot –Connector: a cable to device –Interface between controller and device ANSI, IEEE, ISO, e.g. IDE and SCSI interface Very low level –Convert a serial bit stream into a block of bytes and perform necessary error correction

7 Mechanical / Electronic Components Bus CPUMemory Video controller Keyboard controller Floppy disk controller Hard disk controller Monitor Keyboard Floppy disk driver Hard disk driver Mechanical components Electronic components

8 Memory in I/O Controllers Some registers for communication with CPU –CPU writes commands into registers –CPU reads states of devices from registers Data buffer for transferring data How CPU communicates with control registers/device data buffers?

9 I/O Port Each control register is assigned an I/O port number (8-/16-bit integer) Instruction IN and OUT –IN REG, PORT –OUT PORT, REG Used in early computers, mainframes Separated address spaces 0xFFFF… 0 Memory I/O ports

10 Memory-Mapped I/O Map all control registers into memory space –Usually at the top of the address space Hybrid scheme 0xFFFF… 0 Memory 0xFFFF… 0 Memory I/O ports

11 Pros & Cons of Memory-Mapped I/O Advantages –Hide details of I/O for programming –No special protection mechanism is needed –Access control registers directly, save time Disadvantages –Caching a control register is disastrous –Memory modules and I/O devices must examine all memory references

12 Direct Memory Access (DMA) Disk reads without DMA –Controller reads the block from drive –Interrupt, OS read controller’s buffer  memory DMA approach CPU DMA controller Disk controller Main memory Bus Address Count Control Drive 1. CPU programs the DMA and controller Buffer 2. DMA requires transfer to memory 3. Data transferred 4. Ack Interrupt when done

13 DMA Controller  Memory Transfer Use bus to transfer Cycle stealing –Send a word at at time –Don’t block CPU for bus control Burst mode –Acquire bus, transfer in blocks –More efficient –Block CPU from using bus

14 Interrupts Revisited CPU Bus Interrupt controller Disk 1. Device is finished Keyboard Clock Printer 2. Controller issues interrupt 3. CPU acks interrupt

15 Interrupt Processing I/O devices raise interrupt by asserting a signal on a bus line assigned Multiple interrupts  the one with high priority goes first Interrupt controller interrupts CPU –Put device # on address lines Device #  check interrupt vector table for interrupt handler (a program) –Enable interrupts shortly after the handler starts

16 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks

17 Goals of The I/O Software Device independence Uniform naming Error handling Synchronous (blocking) vs. asynchronous (interrupt-driven) transfers –Synchronous transfers: easy to program –Asynchronous transfers: good for CPU Buffering Sharable vs. dedicated devices

18 How to Perform I/O? Programmed I/O –Have the CPU do all the work Interrupt-driven I/O I/O using DMA User space String to be printed: ABC Kernel space User space Kernel space ABC A

19 Polling/Busy Waiting Simple Waste a lot of CPU time copy_from_user(buffer, p, count); for (i=0; i<count; i++){ while (*printer_status_reg!=READY); *printer_data_register=p[I]; } return_to_user(); // p is the kernel buffer // loop on every character // loop until ready // output one character

20 Interrupt-Driven I/O Print system call copy_from_user(buffer, p, count); enable_interrupts(); while (*printer_status_reg!=READY); *printer_data_register=p[0]; scheduler(); Interrupt service procedure if (count==0){ unblock_user(); } else { *printer_data_register=p[I]; count--; i++; } acknowledge_interrupt(); return_from_interrupt(); Interrupt occurs on every character!

21 I/O Using DMA Too many interrupts in interrupt-driven I/O DMA reduces # of interrupts from 1/char to 1/buffer printed Print system call copy_from_user(buffer, p, count); set_up_DMA_controller(); scheduler(); Interrupt service procedure acknowledge_interrupt(); unblock_user(); return_from_interrupt();

22 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks

23 An Overview User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

24 Interrupt Handlers Hide IO interrupts deep in OS –Driver starts I/O and blocks –Interrupt wakes up driver –See details in text book Process switching and interrupt Interrupt processing takes considerable number of CPU instructions User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

25 Device Drivers Device-specific code for controlling I/O devices –Written by manufacture, delivered along with device –One driver for one (class) device(s) Position: below the rest of OS Interfaces for rest of OS –Block device and character device have different interfaces User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

26 Logical Position of Device Drivers User program Rest of the OS Printer driver Printer controller printer User space Kernel space Hardware Devices

27 How to Install a Driver? UNIX systems –Often run by computer centers, devices rarely change –Drivers and OS are in a single binary program Windows –Devices often change, users don’t know how to compile OS –Dynamically load drivers into OS during execution

28 Functions of Device Drivers Accept abstract read/write requests Initialize device, if necessary Manage power requirements and log events Etc.

29 Structure of Device Drivers Check input parameters –If invalid, return error Translate form abstract to concrete terms –For disk driver, convert a linear block number into head, track, sector, and cylinder numbers Check if the device is currently in use –If so, queue the request –If not, prepare device for the request Issue a sequence of command to execute the request –May block and wait for interrupt Return data and status information

30 Device-Independent I/O Software Why dev-independent I/O software? –Perform I/O functions common to all devices –Provide a uniform interface to user-level software Functions in device- independent software –Uniform interfacing for dev. drivers –Buffering –Error reporting –Allocating and releasing dedicated devices –Providing a device- independent block size User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

31 Uniform Interfacing for Device Drivers Diverse device drivers  modify OS for new device, tedious work! Mapping symbolic device names onto proper driver Protection of devices from illegal access

32 Buffering for Input Unbuffered input –User process is started up for every character –Many short runs in a process  inefficient! Buffering in user space –More efficient than unbuffered input –Can the buffer be paged out? Yes  how to handle the next character? No  the pool of available pages shrink User space Kernel space unbuffered User space Kernel space Buffering in user space

33 Buffering in Kernel Buffering in kernel –Buffer is full  copy the buffer to user space –More efficient –What happens for characters during page swapping? Double buffering in kernel –Buffers are used in turn User space Kernel space Buffering in kernel User space Kernel space Double buffering

34 Buffering for Output Buffering in user space is not good –Block user process, or –Unblocked call, don’t know when the buffer can be reused Buffering in kernel –User can reuse the buffer in user space immediately User space Kernel space Buffering in user space User space Kernel space Buffering in kernel

35 If Data Buffered Too Many Times Many sequential buffering slow down transmission User process 1 2 Network controller Network User space Kernel space

36 Classes of I/O Errors Programming errors: ask for mission impossible –E.g. writing a keyboard, reading a printer –Invalid parameters, like buffer address –Report an error code to caller Actual I/O error –E.g. write a damaged disk block –Up to the driver and software, e.g., A dialog box Serious error: display message, system terminates –E.g. root directory is destroyed

37 Allocating/Releasing Dedicated Devices Blocking calls –Block the process if the device is unavailable Non-blocking calls –Operation “open” –If the device is unavailable, return “fail”

38 User-Space I/O Software Libraries of I/O software linked with user programs –Make system calls, e.g. write(fd, buffer, nbytes); –Format input/output, e.g. printf/scanf Spooling –User-level, controlled by a daemon –Eliminated unnecessarily waiting/deadlock User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

39 Summary User-level I/O software Make I/O call; format I/O; spooling Device-independent OS software Naming, protection, blocking, buffering, allocation Device drivers Setup device registers; check status Interrupt handlers Wake up driver when I/O completed Hardware Perform I/O operation I/O requestI/O reply

40 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks

41 Kinds of Disks Magnetic disks –Hard disks and floppy disks –Reads/writes are equally fast –Ideal secondary memory –Highly reliable storage Optical disks –CD-ROM, CD-Recordable, DVD

42 Structure of Magnetic Disks Cylinders  tracks  sectors IDE disks –The drive contains a microcontroller –Real controller issues higher-level commands Overlapped seeks –Seeks on two or more drives simultaneously Virtual geometry –x cylinders, y heads, z sectors/track Logical block addressing –Continuous numbering sectors Track Sector

43 RAID Redundant array of independent disks Use six specific disk organization to improve disk performance and reliability A disk box connected to computer RAID controller Appear like a single large disk Data distributed over drives –Allow parallel operations –Several different schemes: level 0 - 5

44 RAID Level 0 Virtual single disk is divided into n strips –Each strip has k sectors –Total disk space: n * k sectors Striping: allocate consecutive strips over drives in round-robin fashion –Read 4 consecutive strips  parallel I/O Strip 4 Strip 0 Strip 5 Strip 1 Strip 6 Strip 2 Strip 7 Strip 3 Sector 0-(k-1) Sector k-(2k-1) Sector 2k-(3k-1) Sector 3k-(4k-1)

45 Pros and Cons of RAID Level 0 Good for large requests –Parallel I/O –The bigger the better Straightforward implementation Not good for one sector at a time –No parallelism  no performance gain Poorer reliability than SLED –1/n mean time to failure for n disks No redundancy – not a true RAID

46 RAID Level 1 Duplicate all disks –Primary disks and backup disks –Write  every strip is written twice –Read  either copy can be used Strip 4 Strip 0 Strip 5 Strip 1 Strip 6 Strip 2 Strip 7 Strip 3 Strip 4 Strip 0 Strip 5 Strip 1 Strip 6 Strip 2 Strip 7 Strip 3 Primary disksbackup disks

47 Pros and Cons of RAID Level 1 Write performance is poorer than SLED Read performance is up to twice as good as SLED Excellent fault tolerance –A drive fails  use its copy –Recovery: install a new drive, copy the whole backup drive

48 Bit 1Bit 2Bit 3 Bit 4 Bit 5Bit 6Bit 7 RAID Level 3 Work on a word/byte basis Split each byte into a pair of 4-bit nibbles Add a Hamming code to each one to form a 7-bit word 7 drives are synchronized in terms of arm position and rotational position –Write the 7-bit Hamming coded word over 7 drives, 1 bit/drive Bit 1Bit 2Bit 3 Bit 4 Bit 5Bit 6Bit 7 Word 1 Word 2

49 Pros and Cons of RAID Level 2 Advantages –Immense throughput Quadruple I/O capability if 7 drives are used 32 times speedup if 39 drives are used –One I/O request at a time –Highly fault tolerant Using Hamming code to correct faults on the fly Disadvantages –Require all drives rotationally synchronized –Use substantial number of drives –Do Hamming checksum every bit time

50 RAID Level 3 Simplified version of RAID level 2 A single parity bit for each data word Drives must be exactly synchronized Fault correction –Parity bit + crashed drive id High data rate One I/O request at a time Bit 1Bit 2Bit 3 Bit 4 Parity Bit 1Bit 2Bit 3 Bit 4 Parity

51 RAID Level 4 Use strips Strip-for-strip parity onto an extra drive –Each strip is k bytes long –Exclusive OR all strips  a parity strip k bytes long Strip 4 Strip 0 Strip 5 Strip 1 Strip 6 Strip 2 Strip 7 Strip 3 P4-7 P0-3

52 Pros and Cons of RAID Level 4 No synchronized drives Protect against the loss of one drive Poor performance for small updates –One sector is changed  read all the drives to recalculate and rewrite the parity –Read the old user data and old parity data to recompute the new parity –Small update  two reads and two writes

53 P8-11 RAID Level 5 Workload bottleneck: parity drive Distributing the parity bits uniformly over all drives in round robin fashion Reconstructing a crashed drive is complex Strip 4 Strip 0 Strip 5 Strip 1 Strip 6 Strip 2 P4-7 Strip 3 Strip 7 P0-3 P12-15 P16-19

54 Warm-up Structure of I/O units –Mechanical/electronic components, memory, I/O ports How to perform I/O? –Programmed I/O, interrupt-driven I/O, DMA Layers of I/O software Disks –RAID disk User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

55 Cost of Read / Write A Disk Block Seek time –The time to move the arm to the proper cylinder –Dominate the other two times for most disks Rotational delay –The time for the proper sector to rotate under the head Actual data transfer time 1 2

56 Optimize Seek Time Fist-come, first-served: little can be done Shortest seek first –Handle the closest request next –Requests far from the middle get poor service Total: 63 moves Total: 47 moves

57 Elevator Algorithm Upper bound: twice of the number of cylinders

58 Summary I/O module is an important component in OS Important features of I/O hardware –Device controllers, memory mapped I/O, DMA, and interrupts I/O software –Programmed I/O, interrupts, DMA Four layers of I/O software Disk –RAID and disk arm scheduling