InputOutput Systems - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

InputOutput Systems

Description:

Daisy chain devices bus-connected in series ... e.g. message disassembly and reassembly of messages in networking. To maintain 'copy semantics' ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 47
Provided by: sinc150
Category:

less

Transcript and Presenter's Notes

Title: InputOutput Systems


1
Input-OutputSystems
  • Chapter 13

2
Chapter 13 I/O Systems
  • I/O Hardware
  • Application I/O Interface
  • Kernel I/O Subsystem
  • I/O Requests to Hardware Operations
  • UNIX STREAMS
  • Performance

3
OS Components
Processes
Memory Manager
Storage Manager
File Manager
I/O Manager
Networking
System Protection
Command Interpreter
4
I/O Hardware
  • Incredible variety of I/O devices
  • Common concepts
  • Port (e.g. serial 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

5
I/O Term Definitions
  • Port a connection point
  • Bus
  • A set of wires and a rigidly defined protocol
    that specifies a set of messages that can be
    carried on the wires.
  • Daisy chain devices bus-connected in series
  • Controller a collection of electronics that
    operates a port, a bus, or a device.
  • host adapter controller on plug-in card

6
A Typical PC Bus Structure
7
Latest PC
System Bus 533 MHz
P4
8
I/O Styles
  • Direct I/O
  • Write/read directly to device registers
  • Memory-mapped I/O
  • Device registers are mapped to memory
  • Fast
  • e.g. graphics controller has a memory-mapped
    region to hold screen contents
  • but pointer errors can be severe

9
I/O Device
  • PCI6208 D/A Converter

10
Registers for PCI 6208 A/D card
  • PCI Configuration Registers
  • Initialized and controlled by PCI PnP BIOS
  • Local Configuration Registers
  • PCI bus controller from PLX Technology Inc.
  • PCI-6208 Registers
  • I/O Address Map
  • Analog Output Status Register
  • Digital Output Register
  • Digital Input Register

Offset
6208V
11
Typical I/O Port Registers
  • Status Register
  • Read by the host
  • States, such as command completion, data ready
  • Control Register
  • Written by the host, sets mode, parity check,
    etc.
  • Data-in Register
  • Read by the host to get input
  • Data-out Register
  • Written by the host to send input

12
Typical I/O Port Addresses on PC
13
Polling
  • Determines state of device
  • command-ready
  • busy
  • error
  • Busy-wait cycle to wait for I/O from device
  • 1. Host repeatedly reads busy bit until bit is
    clear
  • 2. Host sets write bit in the command register
  • 3. Write a byte into the data-out register
  • 4. Host sets the command-ready bit
  • 5. Controller replies by setting the busy bit
  • 6. Controller recognizes write command
  • 7. Controller reads data-out register
  • 8. Controller send data to the device

14
Interrupts
  • Device controller raises an interrupt by
    asserting a signal on the interrupt request line.
  • CPU catches the interrupt
  • CPU dispatches to the interrupt handler
  • Handler clears the interrupt, services the
    device
  • Interrupt vector to dispatch interrupt to correct
    handler
  • Multilevel interrupts, based on priority
  • Maskable to ignore or delay some interrupts
  • Some unmaskable, e.g. unrecoverable memory errors
  • Interrupt mechanism also used for exceptions (eg.
    0)

15
Interrupt-Driven I/O Cycle
16
Pentium Event-Vector Table
17
Interrupts for OS Use
  • Time slice interruption for context switching
  • Page fault interrupt for virtual paging
  • Suspend current process
  • Invoke page-fault handler
  • Move current process to wait queue
  • Retrieve status of page cache
  • Request a new page from the disk system
  • Schedule another process
  • System call invokes a software interrupt or trap
  • Argument identifies needed kernel routine
  • Save state of user code
  • Switch to supervisor mode, execute requested
    operation

18
Direct Memory Access
  • Used to avoid programmed I/O for large data
    movement
  • i.e. having CPU move data a byte at a time
  • Requires DMA controller
  • Bus mastering boards have own DMA
  • Bypasses CPU to transfer data directly between
    I/O device and memory
  • Operates memory bus directly
  • DMA request alternates with DMA acknowledge

19
Process to Perform DMA Transfer
20
Application I/O Interface
  • Abstraction, encapsulation, layering
  • 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
  • Synchronous or asynchronous (unpredictable)
  • Sharable or dedicated (to a process or thread)
  • Speed of operation (bytes/sec to GB/sec)
  • Read-write, read only, or write only

21
A Kernel I/O Structure
22
Characteristics of I/O Devices
23
Block and Character Devices
  • Block devices include disk drives
  • Commands include read, write, seek
  • Raw I/O accesses a linear array of blocks
  • File-system, normal means of access
  • Memory-mapped file access possible, using a
    virtual memory array copy of the file
  • Character devices
  • e.g. keyboards, mice, serial ports
  • Commands get, put one character
  • Libraries layered on top allow line editing

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

25
Select( )
  • Select() allows the process to instruct the
    kernel to wait for any one of multiple events to
    occur, and to wake up the process when it occurs
    or when time is up

include ltsys/select.hgt include
ltsys/time.hgt int select(int maxfdp1, fd_set
readset, fd_set writeset, fd_set
exceptset, const struct timeval timeout)
Descriptors to test
Null to wait forever, 0 to poll, nonzero for
timed wait
26
Clocks and Timers
  • Provide current time
  • Programmable interrupt timer for
  • Elapsed time,
  • Periodic interrupts to trigger operations
  • e.g. for periodic cache write to disk
  • e.g. to time out slow network operations
  • e.g. to time user I/O operations
  • Hardware clock at 16 60 ticks per second
    somewhat inaccurate.
  • ioctl (on UNIX) covers odd aspects of I/O such as
    clocks and timers

27
Blocking and Nonblocking I/O
  • Blocking system call
  • Process suspended until I/O completed (on wait
    queue)
  • Normal application interface, easier to use
  • Nonblocking - I/O call returns as much as
    available
  • e.g. mouse and keyboard user interface with
    screen display
  • Implemented with multi-threading
  • Returns quickly with count of any bytes read or
    written
  • Asynchronous - process runs while I/O executes
  • Returns to process when job is done
  • Invokes software interrupt, callback routine, or
    just variable change

28
Kernel I/O Subsystem
  • I/O Scheduling
  • I/O request ordering via per-device queue
  • e.g. schedule disk head motion for efficiency
  • Basis for reordering I/O requests
  • Fairness, so no one application suffers
  • Priority, e.g. virtual memory over user app

29
Kernel I/O Subsystem
  • Buffering store data in memory while
    transferring between devices
  • To cope with device speed mismatch
  • e.g. double buffering between modem and disk
  • To cope with device transfer size mismatch
  • e.g. message disassembly and reassembly of
    messages in networking
  • To maintain copy semantics
  • e.g. if data is selected to be written to disk,
    copy it to a kernel buffer before returning
    control to the application, to ensure that
    unchanged data will actually be written

30
Sun Enterprise 6000 Device-Transfer Rates
31
Kernel I/O Subsystem
  • Caching fast memory holding copy of data
  • Always just a copy (buffer may have original
    only)
  • Key to performance (e.g. of a disk)
  • Spooling hold output for a device
  • If device can serve only one request at a time
  • i.e., Printing
  • Device reservation exclusive access to a device
  • System calls for allocation and deallocation
  • Watch out for deadlock (e.g. tape drives)

32
Error Handling
  • OS can recover from disk read, device
    unavailable, transient write failures
  • e.g. disk read failure results in a read() retry
  • e.g. network send error answered by resend
  • Most return an error number or code when I/O
    request fails e.g. UNIX returns errno with one
    of 100 values
  • System error logs hold problem reports
  • e.g. stored in SCSI devices for debugging

33
Kernel Data Structures
  • Kernel keeps state info for I/O components
  • includes open file tables, network connections,
    character device state
  • Many complex data structures to track buffers,
    memory allocation, dirty blocks
  • e.g. to read user file, check buffer cache
  • e.g. to read raw disk, ensure alignment with
    sectors
  • Some use object-oriented methods and message
    passing to implement I/O
  • Capture differences within a uniform structure

34
UNIX I/O Kernel Structure
35
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

36
Name to Device Representation
  • Windows
  • C represents the primary hard drive
  • Mapped to a specific port address through a
    device table
  • Device name space separate from file-system name
    space within each device
  • UNIX
  • Device name space is incorporated in regular
    file-system name space
  • Mount table associates prefixes of path names
    with specific device names

37
Life Cycle of An I/O Request
11
1
2
10
3
4
5
9
8
6
7
38
Life Cycle of an I/O Request
  • Process issues blocking read to an open file
  • Check parameters for correctness.
  • Check for presence in cache, return value
  • If not in cache, place process on wait queue
  • Allocate buffer space, schedule I/O
  • Device controller operates hardware

39
Life Cycle of an I/O Request
  • When ready, DMA controller generates interrupt
  • Interrupt handler stores data, signals device
    driver, and returns
  • Device driver receives signal, checks status,
    signals kernel I/O system
  • Kernel I/O transfers data to requesting process,
    places process on ready queue
  • Scheduler assigns process to CPU

40
STREAMS
  • STREAM a full-duplex communication channel
    between a user-level process and a device
  • Provides a modular and incremental approach to
    writing device drivers and network protocols.
  • A STREAM consists of
  • - STREAM head interfaced with the user process
  • - driver end interfaced 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

41
The STREAMS Structure
This can block
These are nonblocking
42
Performance
  • I/O a major factor in system performance
  • Heavy demands on CPU to execute device driver,
    kernel I/O code with fair, efficient scheduling.
  • Associated context switching stresses CPU and its
    hardware caches
  • Data copying loads down memory bus
  • Network traffic especially stressful
  • e.g. remote login transmits data a character at a
    time, across network layers and generating
    keyboard interrupts.

43
Intercomputer Communications
44
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
  • Use specialized I/O CPU, a front-end processor
    for terminal I/O

45
Improving Performance
  • Where should I/O functionality be implemented
    in device hardware, device driver, or application
    software?
  • Initially, implement I/O algorithms at
    application level, for flexibility and security
  • When stable, reimplement I/O in the kernel, with
    thorough debugging
  • For highest performance, move to hardware in
    device or controller (difficult to debug, lengthy
    process, decreased flexibility)

46
Device-Functionality Progression
Write a Comment
User Comments (0)
About PowerShow.com