I/O CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University

Slides:



Advertisements
Similar presentations
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Advertisements

I/O and Networking Fred Kuhns
CS-334: Computer Architecture
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
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.
04/18/2007CSCI 315 Operating Systems Design1 Mass Storage Structure Notice: The slides for this lecture have been largely based on those accompanying the.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
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)
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
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
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
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.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-2: I/O Management (Review) Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O.
I/O Systems I/O Hardware Application I/O Interface
1 Module 12: I/O Systems n I/O hardware n Application I/O Interface n Kernel I/O Subsystem n Transforming I/O Requests to Hardware Operations n Performance.
© 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.
2007 Oct 18SYSC2001* - Dept. Systems and Computer Engineering, Carleton University Fall SYSC2001-Ch7.ppt 1 Chapter 7 Input/Output 7.1 External Devices.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures T.Yang, 2012 Partially based on the.
I/O management is a major component of operating system design and operation Important aspect of computer operation I/O devices vary greatly Various methods.
UNIX Files File organization and a few primitives.
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 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 13: I/O Systems I/O Hardware Application I/O Interface.
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.
XE33OSA Chapter 13: I/O Systems. 13.2XE33OSA Silberschatz, Galvin and Gagne ©2005 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 13: I/O Systems.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13: I/O Systems Overview I/O Hardware Application.
IT3002 Computer Architecture
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 I/O through system calls Protection.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
CMSC 421 Section 0202 I/O Systems Chapter 13: I/O Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Major OS Components CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
Chapter 13: I/O Systems.
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.
I/O SYSTEMS MANAGEMENT Krishna Kumar Ahirwar ( )
Operating Systems (CS 340 D)
CSCI 315 Operating Systems Design
I/O Systems I/O Hardware Application I/O Interface
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
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:

I/O CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University

2 Rutgers UniversityCS 416: Operating Systems I/O Devices So far we have talked about how to abstract and manage CPU and memory Computation “inside” computer is useful only if some results are communicated “outside” of the computer I/O devices are the computer’s interface to the outside world (I/O  Input/Output) Example devices: display, keyboard, mouse, speakers, network interface, and disk

3 Rutgers UniversityCS 416: Operating Systems Basic Computer Structure CPUMemory Bridge Disk NIC Memory Bus (System Bus) I/O Bus

4 Rutgers UniversityCS 416: Operating Systems OS: Abstractions and Access Methods OS must virtualizes a wide range of devices into a few simple abstractions: Storage Hard drives, Tapes, CDROM Networking Ethernet, radio, serial line Multimedia DVD, Camera, microphones Operating system should provide consistent methods to access the abstractions Otherwise, programming is too hard

5 Rutgers UniversityCS 416: Operating Systems User/OS method interface The same interface is used to access devices (like disks and network lines) and more abstract resources like files 4 main methods: open() close() read() write() Semantics depend on the type of the device (block, char, net) These methods are system calls because they are the methods the OS provides to all processes. A Java program can’t access these methods directly, they are used by the JVM. C and C++ programs can call these directly.

6 Rutgers UniversityCS 416: Operating Systems Unix I/O Methods fileHandle = open(pathName, flags, mode) a file handle is a small integer, valid only within a single process, to operate on the device or file pathname: a name in the file system. In unix, devices are put under /dev. E.g. /dev/ttya is the first serial port, /dev/sda the first SCSI drive flags: blocking or non-blocking … mode: read only, read/write, append … errorCode = close(fileHandle) Kernel will free the data structures associated with the device

7 Rutgers UniversityCS 416: Operating Systems Unix I/O Methods byteCount = read(fileHandle, byte [] buf, count) read at most count bytes from the device and put them in the byte buffer buf. Bytes placed from 0 th byte. Kernel can give the process less bytes, user process must check the byteCount to see how many were actually returned. A negative byteCount signals an error (value is the error type) byteCount = write(fileHandle, byte [] buf, count) write at most count bytes from the buffer buf actual number written returned in byteCount a Negative byteCount signals an error

8 Rutgers UniversityCS 416: Operating Systems Unix I/O Example What’s the correct way to write a 1000 bytes? calling: ignoreMe = write(fileH, buffer, 1000); works most of the time. What happens if: can’t accept 1000 bytes right now? disk is full? someone just deleted the file? Let’s work this out on the board

9 Rutgers UniversityCS 416: Operating Systems I/O semantics From this basic interface, three different dimension to how I/O is processed: blocking vs. non-blocking buffered vs. unbuffered synchronous vs. asynchronous The O/S tries to support as many of these dimensions as possible for each device The semantics are specified during the open() system call

10 Rutgers UniversityCS 416: Operating Systems Blocking vs. Non-Blocking I/O Blocking –process is suspended until all bytes in the count field are read or written E.g., for a network device, if the user wrote 1000 bytes, then the operating system would write the bytes to the device one at a time until the write() completed. + Easy to use and understand - if the device just can’t perform the operation (e.g. you unplug the cable), what to do? Give up an return the successful number of bytes. Nonblocking – the OS only reads or writes as many bytes as is possible without suspending the process + Returns quickly - more work for the programmer (but really for robust programs)?

11 Rutgers UniversityCS 416: Operating Systems Buffered vs. Unbuffered I/O Sometime we want the ease of programming of blocked I/O without the long waits if the buffers on the device are small. buffered I/O allows the kernel to make a copy of the data write() side: allows the process to write() many bytes and continue processing read() side: As device signals data is ready, kernel places data in the buffer. When the process calls read(), the kernel just copies the buffer. Why not use buffered I/O? - Extra copy overhead - Delays sending data

12 Rutgers UniversityCS 416: Operating Systems Synchronous vs. Asynchronous I/O Synchronous I/O: the user process does not run at the same time the I/O does --- it is suspended during I/O So far, all the methods presented have been synchronous. Asynchronous I/O: The read() or write() call returns a small object instead of a count. separate set of methods in unix: aio_read(), aio_write() The user can call methods on the returned object to check “how much” of the I/O has completed The user can also allow a signal handler to run when the the I/O has completed.

13 Rutgers UniversityCS 416: Operating Systems Handling Multiple I/O streams If we use blocking I/O, how do we handle > 1 device at a time? Example : a small program that reads from serial line and outputs to a tape and is also reading from the tape and outputting to a serial line Structure the code like this? while (TRUE) { read(tape); // block until tape is ready write(serial line);// send data to serial line read(serial line); write(tape); } Could use non-blocking I/O, but huge waste of cycles if data is not ready.

14 Rutgers UniversityCS 416: Operating Systems Solution: select system call totalFds = select(nfds, readfds, writefds, errorfds, timeout); nfds: the range (0.. nfds) of file descriptors to check readfds: bit map of fileHandles. user sets the bit X to ask the kernel to check if fileHandle X ready for reading. Kernel returns a 1 if data can be read on the fileHandle. writefds: bit map if fileHandle Y for writing. Operates same as read bitmap. errorfds: bit map to check for errors. timeout: how long to wait before un-suspending the process totalFds = number of set bits, negative number is an error

15 Rutgers UniversityCS 416: Operating Systems Three Device Types Most operating system have three device types: Character devices Used for serial-line types of devices (e.g. USB port) Network devices Used for network interfaces (E.g. Ethernet card) Block devices: Used for mass-storage (E.g. disks and CDROM) What you can expect from the read/write methods changes with each device type

16 Rutgers UniversityCS 416: Operating Systems Character Devices Device is represented by the OS as an ordered stream of bytes bytes sent out the device by the write() system call bytes read from the device by the read() system call Byte stream has no “start”, just open and start/reading writing The user has no control of the read/write ratio, the sender process might write() 1 time of 1000 bytes, and the receiver may have to call 1000 read calls each receiving 1 byte.

17 Rutgers UniversityCS 416: Operating Systems Network Devices Like I/O devices, but each write() call either sends the entire block (packet), up to some maximum fixed size, or none. On the receiver, the read() call returns all the bytes in the block, or none.

18 Rutgers UniversityCS 416: Operating Systems Block Devices OS presents device as a large array of blocks Each block has a fixed size (1KB - 8KB is typical) User can read/write only in fixed sized blocks Unlike other devices, block devices support random access We can read or write anywhere in the device without having to ‘read all the bytes first’ But how to specify the nth block with current interface?

19 Rutgers UniversityCS 416: Operating Systems The file pointer O/S adds a concept call the file pointer A file pointer is associated with each open file, if the device is a block device the next read or write operates at the position in the device pointed to by the file pointer The file pointer is measured in bytes, not blocks

20 Rutgers UniversityCS 416: Operating Systems Seeking in a device To set the file pointer: absoluteOffset = lseek(fileHandle, offset, whence); whence specifies if the offset is absolute, from byte 0, or relative to the current file pointer position the absolute offset is returned; negative numbers signal error codes For devices, the offset should be a integral number of bytes relative to the size of a block. How could you tell what the current position of the file pointer is without changing it?

21 Rutgers UniversityCS 416: Operating Systems Block Device Example You want to read the 10 th block of a disk each disk block is 2048 bytes long fh = open(/dev/sda,,, ); pos = lseek(fh, size*count, ); if (pos < 0 ) error; bytesRead = read(fh, buf, blockSize); if (bytesRead < 0) error; …

22 Rutgers UniversityCS 416: Operating Systems Getting and setting device specific information Unix has an IO ConTroL system call: ErrorCode = ioctl(fileHandle, int request, object); request is a numeric command to the device can also pass an optional, arbitrary object to a device the meaning of the command and the type of the object are device specific

23 Rutgers UniversityCS 416: Operating Systems Programmed I/O vs. DMA Programmed I/O is ok for sending commands, receiving status, and communication of a small amount of data Inefficient for large amount of data Keeps CPU busy during the transfer Programmed I/O  memory operations  slow Direct Memory Access Device read/write directly from/to memory Memory  device typically initiated from CPU Device  memory can be initiated by either the device or the CPU

24 Rutgers UniversityCS 416: Operating Systems Programmed I/O vs. DMA CPUMemory Disk Interconnect CPUMemory Disk Interconnect CPUMemory Disk Interconnect Programmed I/O DMA Device  Memory Problems?

25 Rutgers UniversityCS 416: Operating Systems Direct Memory Access Used to avoid programmed I/O for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory

26 Rutgers UniversityCS 416: Operating Systems Six step process to perform DMA transfer

27 Rutgers UniversityCS 416: Operating Systems Life Cycle of an I/O Request

28 Rutgers UniversityCS 416: Operating Systems Performance I/O a major factor in system performance Demands CPU to execute device driver, kernel I/O code Context switches due to interrupts Data copying Network traffic especially stressful

29 Rutgers UniversityCS 416: Operating Systems Intercomputer communications

30 Rutgers UniversityCS 416: Operating Systems Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Balance CPU, memory, bus, and I/O performance for highest throughput