Presentation is loading. Please wait.

Presentation is loading. Please wait.

I/O Management.

Similar presentations


Presentation on theme: "I/O Management."— Presentation transcript:

1 I/O Management

2 I/O Systems I/O Hardware Application I/O Interface
Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Streams Performance I/O Buffer

3 I/O Hardware Incredible variety of I/O devices Common concepts
Port Bus (daisy chain or shared direct access) Controller (host adapter) I/O instructions control devices Devices have addresses, used by Direct I/O instructions Memory-mapped I/O

4 A Typical PC Bus Structure

5 Device I/O Port Locations on PCs (partial)

6 I/O Devices and Controllers
In general, the closer an I/O unit is to the CPU, the faster it can be accessed. Three categories: Human Readable (display, keyboard) 80 b/s Machine Readable (disk) 6 Mb/s Communication (modem, network) 1 Gb/s Other Differences: Data rate, latency, signal propagation, bus arbitration, buffering time Application - disk requires file system support Complexity of Control - keyboard driver simpler than disk driver Unit of Transfer (byte, block) Data Representation (character set, parity) Error Conditions

7 Evolution of the I/O Function
CPU directly controls device Seen in simple microprocessor devices I/O module (i.e., serial port chip) CPU uses programmed I/O Add Interrupts More efficient – No polling needed I/O module supports DMA Device can move a block of data without involving the CPU I/O Processor I/O device enhanced with a set of I/O-specific instructions CPU creates I/O program I/O Module with memory Module becomes a computer of its own Minimal CPU involvement

8 Polling Determines state of device
command-ready busy Error Busy-wait cycle to wait for I/O from device

9 Interrupts CPU Interrupt request line triggered by I/O device
Interrupt handler receives interrupts Maskable to ignore or delay some interrupts Interrupt vector to dispatch interrupt to correct handler Based on priority Some unmaskable Interrupt mechanism also used for exceptions

10 Interrupt-Driven I/O Cycle

11 Intel Pentium Processor Event-Vector Table

12 DMA In general, polling is a waste of CPU time
Interrupt processing overhead is greater than polling but without “wasted” cycles DMA reduces CPU involvement when transferring larger chunks of data Cycle stealing causes the CPU to execute more slowly mitigated by cache smarter DMA controllers Improvement when path between DMA module and I/O module that does not include the system bus

13 DMA (continued…) Block structure Structure of operations:
Data count (# of bytes/words) Data register (data to/from device) Address register (memory location) Control logic Structure of operations: CPU initializes DMA unit Inform unit if this is a read or write Set the address of I/O device Address of memory to read/write Amount of data to transfer DMA device performs transfer Steals memory cycles from CPU These may occur in the middle of an instruction DMA device interrupts CPU at end Data Count Data Register Address Register Control Logic Data Lines Address Lines DMA request DMA acknowledge Interrupt Read Write

14 DMA Configuration

15 Six Step Process to Perform DMA Transfer

16 I/O Design Objectives Efficiency Generality I/O can be a bottleneck
Swapping is used to increase number of ready processes Requires I/O activity to do this Major emphasis is on disk efficiency due to its importance Generality Easier to handle devices uniformly How processes view I/O devices How O.S. manages I/O devices Because of differences in devices, it is hard to achieve true generality Can use a hierarchical, modular approach to hide I/O details Processes see open/read/write/close for all devices

17 Application I/O Interface
I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel Devices vary in many dimensions Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only

18 A Kernel I/O Structure

19 Characteristics of I/O Devices

20 Block and Character Devices
Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing

21 Network Devices Varying enough from block and character to have own interface Unix and Windows NT/9i/2000 include socket interface Separates network protocol from network operation Includes select functionality Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes)

22 Clocks and Timers Provide current time, elapsed time, timer
If programmable interval time used for timings, periodic interrupts ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers

23 Blocking and Nonblocking I/O
Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed

24 Kernel I/O Subsystem Scheduling
Some I/O request ordering via per-device queue Some OSs try fairness Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain “copy semantics”

25 Sun Enterprise 6000 Device-Transfer Rates

26 Kernel I/O Subsystem Caching - fast memory holding copy of data
Always just a copy Key to performance Spooling - hold output for a device If device can serve only one request at a time i.e., Printing Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock

27 Error Handling OS can recover from disk read, device unavailable, transient write failures Most return an error number or code when I/O request fails System error logs hold problem reports

28 Kernel Data Structures
Kernel keeps state info for I/O components, including open file tables, network connections, character device state Many, many complex data structures to track buffers, memory allocation, “dirty” blocks Some use object-oriented methods and message passing to implement I/O

29 UNIX I/O Kernel Structure

30 I/O Requests to Hardware Operations
Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process

31 Life Cycle of An I/O Request

32 STREAMS - STREAM head interfaces with the user process
STREAM – a full-duplex communication channel between a user-level process and a device A STREAM consists of: - STREAM head interfaces with the user process - driver end interfaces with the device - zero or more STREAM modules between them. Each module contains a read queue and a write queue Message passing is used to communicate between queues

33 The STREAMS Structure

34 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

35 Intercomputer Communications

36 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

37 Device-Functionality Progression

38 Logical Structure Hierarchical structure Simple structure
Divide levels by complexity time scale level of abstraction Low levels may work at nanosecond time frames Simple structure

39 I/O Organization Logical I/O – Think of the device as a logical resource Directory Management Convert file names to identifiers that reference a file File System Deal with logical structure and open, read, write, also permissions Physical Organization Convert logical references to storage addresses Device I/O – Convert operations and data into I/O instruction sequences May use buffering to improve speed Scheduling and Control – Actual queuing and scheduling of operations This level handles interrupts, status

40 I/O Buffering No buffering Single buffering Double buffering
Operating System User Process I/O Device In Single buffering Operating System User Process I/O Device In Move Double buffering I/O Device In Move Operating System User Process Circular buffering Operating System User Process I/O Device In Move

41 I/O Buffering I/O operations from user memory space creates problems
The pages holding the data must remain in main memory Limits choices O.S. can make Cannot completely swap out process, or deadlock may result Process waiting for I/O to complete I/O waiting for process to be swapped in May want to read in advance May want to delay writes Combine writes when updating disk Buffering Methods:

42 I/O Buffering Block-oriented Stream-oriented
information is stored in fixed sized blocks transfers are made a block at a time used for disks and tapes Stream-oriented transfer information as a stream of bytes used for terminals, printers, communication ports, mouse, and most other devices that are not secondary storage

43 Single Buffering I/O device transfers data to a system buffer, then O.S. copies data to user As soon as transfer is completed, try to read the next block in advance Hopefully that block will be used next User process can be working on one block while the next is being read Block transfer time: max[C,T]+M C = time to compute, T = time to do I/O, M = time to transfer to buffer Note: with no buffering, time is C+T O.S. must track which buffers are assigned to user processes Don’t want to swap to a device if we are waiting on that device for I/O Able to swap processes without interfering with I/O operations For character-I/O, can use buffer for byte buffering or line buffering - Producer/Consumer type problem

44 Buffering Double Buffering Circular Buffering Summary
Uses two system buffers, read into one buffer, copy data to user from the other Block transfer time: max[C,T] max[C+M,T]? – Account for move time Can do transfer while next I/O starts Circular Buffering Similar to double buffering, but have multiple system buffers Helps handle I/O bursts Summary Buffering helps smooth out peaks in I/O use Doesn’t improve sustained I/O rate Generally helps in multiprogramming systems


Download ppt "I/O Management."

Similar presentations


Ads by Google