Download Kernel I/O Subsystem

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Plan 9 from Bell Labs wikipedia , lookup

Process management (computing) wikipedia , lookup

Copland (operating system) wikipedia , lookup

Mobile operating system wikipedia , lookup

Security-focused operating system wikipedia , lookup

Distributed operating system wikipedia , lookup

VS/9 wikipedia , lookup

Spring (operating system) wikipedia , lookup

DNIX wikipedia , lookup

Unix security wikipedia , lookup

CP/M wikipedia , lookup

Transcript
Chapter 13: I/O Systems
 I/O Hardware
 Application I/O Interface
 Kernel I/O Subsystem
 Transforming I/O Requests to Hardware Operations
 Streams (skip 13.6)
 Performance
Operating System Concepts – 8th Edition
13.1
Silberschatz, Galvin and Gagne ©2009
Objectives
 Explore the structure of an operating system’s I/O
subsystem
 Discuss the principles of I/O hardware and its complexity
 Provide details of the performance aspects of I/O
hardware and software
Operating System Concepts – 8th Edition
13.2
Silberschatz, Galvin and Gagne ©2009
13.1 Overview
& 13.2 I/O Hardware
 Incredible variety of I/O devices

Increasing standardization of software and hardware interfaces

Increasing broad variety of I/O devices
 The device drivers module present a uniform device-
access interface to the I/O sub-system
 Common concepts

Port – connection point of computer and a device

Bus (daisy chain or shared direct access)

Controller – a collection of electronics that can operate a port, a
bus, or a device

SCSI bus controller (or host adapter) typically contains a
processor, microcode, and some private memory
Operating System Concepts – 8th Edition
13.3
Silberschatz, Galvin and Gagne ©2009
A Typical PC Bus Structure
slow
devices
Operating System Concepts – 8th Edition
13.4
Silberschatz, Galvin and Gagne ©2009
13.2
I/O Hardware
 Question: How do the processor give commands and
data to a controller to accomplish an I/O transfer?
 Answer: The controller has one or more registers for
data and control signals

Special I/O instructions control devices by specifying the transfer
of a byte or a word into or out of a device register


The I/O instruction triggers bus lines to select the proper device and
to move bits into or out of a device register
Alternatively, the controller can support Memory-mapped I/O

The device-control registers are mapped into the address space of
the processor

Disadvantage: a memory-mapped device register is vulnerable to
accidental modification. The risk could be reduced by protected
memory
Operating System Concepts – 8th Edition
13.5
Silberschatz, Galvin and Gagne ©2009
Device I/O Port Locations on PCs (partial)
Operating System Concepts – 8th Edition
13.6
Silberschatz, Galvin and Gagne ©2009
13.2
I/O Hardware
 An I/O port typically consist of four registers




The data-in register: 1 to 4 bytes
The data-out register: 1 to 4 bytes
The status register
The control register
 Possible state of device



command-ready
busy
error
 Polling

Busy-waiting cycle: Reading the status register until
the busy bit becomes clear (0)
Operating System Concepts – 8th Edition
13.7
Silberschatz, Galvin and Gagne ©2009
Polling
 Example: The host writes output through a port,
coordinating with the controller by handshaking as
follows:
1.
The host repeatedly read the busy bit until the bit is cleared (0).
2.
The host sets the write bit (1) in the command register and writes
a byte into the data-out register
3.
The host sets the command-ready bit.
4.
When the controller notices the command-ready bit is set, it sets
the busy bit
5.
The controller reads the command register and sees the write
command. It reads the data-out register to get the byte and does
the I/O to the device
6.
The controller clears the command-ready bit, clears the error bit
in the status register, and clears the busy bit to indicate that it is
finished
Operating System Concepts – 8th Edition
13.8
Silberschatz, Galvin and Gagne ©2009
Interrupts
 Polling becomes inefficient when it is attempted
repeatedly yet rarely finds a device to be ready for
service

Instead, use CPU Interrupt-request line triggered by I/O device
 Interrupt-handler routine receives interrupts
 Maskable to ignore or delay some interrupts
 Interrupt vector to dispatch interrupt to correct handler

Based on priority

Some nonmaskable
 Interrupt mechanism also used for exceptions
Operating System Concepts – 8th Edition
13.9
Silberschatz, Galvin and Gagne ©2009
Interrupt-Driven I/O Cycle
Operating System Concepts – 8th Edition
13.10
Silberschatz, Galvin and Gagne ©2009
Interrupts
 In a modern OS, more sophisticated interrupt handling
features are needed:
1.
The ability to defer interrupt handling during critical processing
2.
An efficient way to dispatch to the proper interrupt handler for a
device without first polling all the devices to see which one
raised the interrupt
3.
Multi-level interrupts, so that the OS can distinguish between
high- and low-priority interrupts and can respond with the
appropriate degree of urgency
 In modern computer hardware, these three features are
provided by the CPU and by the interrupt-controller
hardware
skip p. 561 line 9 to end of 13.2.2 in p.563
Operating System Concepts – 8th Edition
13.11
Silberschatz, Galvin and Gagne ©2009
13.2.3 Direct Memory Access
 Used to avoid burdening the main CPU with
programmed I/O for large data movement
 Requires DMA controller
 Bypasses CPU to transfer data directly between I/O
device and memory
skip p. 564 最後一段
Operating System Concepts – 8th Edition
13.12
Silberschatz, Galvin and Gagne ©2009
Six Step Process to Perform DMA Transfer
cycle
stealing
Operating System Concepts – 8th Edition
13.13
Silberschatz, Galvin and Gagne ©2009
13.3 Application I/O Interface
 I/O system calls encapsulate device behaviors in
generic classes – abstraction, encapsulation,
software layering

Devices are abstracted to a few general kinds. Each
general kind is accessed through a standardized set of
functions -- an interface
 Device-driver layer hides differences among I/O
controllers from kernel
Operating System Concepts – 8th Edition
13.14
Silberschatz, Galvin and Gagne ©2009
A Kernel I/O Structure
Operating System Concepts – 8th Edition
13.15
Silberschatz, Galvin and Gagne ©2009
Characteristics of I/O Devices
Operating System Concepts – 8th Edition
13.16
Silberschatz, Galvin and Gagne ©2009
Application I/O Interface
 Devices vary in many dimensions

Character-stream or block

Sequential or random-access

Synchronous or asynchronous

Sharable or dedicated

Speed of operation

Read-write, read only, or write only
 The major access conventions include

Block I/O

Character-stream I/O

Memory-mapped file access

Network sockets
Operating System Concepts – 8th Edition
13.17
Silberschatz, Galvin and Gagne ©2009
13.3.1 Block and Character Devices
 Block devices include disk drives

Commands include read(), write(), seek()

Raw I/O or file-system access


Also for special applications such as DBMS

The special applications would provide their own locking and
buffering. OS provides other services. – called direct I/O in UNIX.
Memory-mapped file access can be layered on top of blockdevice drivers

Provides access to the disk storage via an array of byes in main
memory
 Character-stream interface for character devices, such
as keyboards, mice, serial ports

Commands include get(), put()

Libraries layered on top to offer line-at-a-time access
Operating System Concepts – 8th Edition
13.18
Silberschatz, Galvin and Gagne ©2009
13.3.2
Network Devices
 Varying enough from block and character to have their
own interface

Popular one is the socket interface
 Unix and Windows NT/9x/2000 include socket interface

Separates network protocol from network operation

Includes the select() functionality

A call to select() returns information about which sockets have a
packet waiting to be retrieved and which sockets have room to
accept a packet to be sent
 Approaches vary widely (pipes, FIFOs, streams, queues,
mailboxes)
skip 13.3.3
Operating System Concepts – 8th Edition
13.19
Silberschatz, Galvin and Gagne ©2009
13.3.4 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 early as available

For user interface (keyboard, mouse), video application (reading,
decompressing, and displaying the output)

Implemented via multi-threading


Returns quickly with count of bytes read or written
Implemented via asynchronous system calls - I/O call returns
immediately

Process continues without waiting while I/O executes

When I/O completed, I/O subsystem notifies process through setting
of some variables, triggering a software interrupt, or call-back
function

Difficult to use
Operating System Concepts – 8th Edition
13.20
Silberschatz, Galvin and Gagne ©2009
Two I/O Methods
Asynchronous
Synchronous
Operating System Concepts – 8th Edition
13.21
Silberschatz, Galvin and Gagne ©2009
13.4
Kernel I/O Subsystem
 I/O services provides by kernel

Scheduling, buffering, caching, spooling, device reservation,
error handling, I/O protection
 I/O Scheduling

Some I/O request ordering via per-device queue

Some OSs try fairness – no one application receives poor
service

To support asynchronous I/O, it must keep track of many I/O
requests at the same time

Use device-status table
Operating System Concepts – 8th Edition
13.22
Silberschatz, Galvin and Gagne ©2009
Device-status Table
Operating System Concepts – 8th Edition
13.23
Silberschatz, Galvin and Gagne ©2009
Kernel I/O Subsystem
 Buffering - store data in memory while transferring
between devices

To cope with device speed mismatch


To cope with device transfer size mismatch


Example: file received via modem for storage on the hard disk via
double buffering (next slide shows the differences in device
speeds)
Common in computer networking
To maintain “copy semantics”

The version of data written to disk is guaranteed to be the version on
the time of the application system call, independent of any
subsequent changes in the application’s buffer
Operating System Concepts – 8th Edition
13.24
Silberschatz, Galvin and Gagne ©2009
Sun Enterprise 6000 Device-Transfer Rates
Operating System Concepts – 8th Edition
13.25
Silberschatz, Galvin and Gagne ©2009
Kernel I/O Subsystem
 Caching - fast memory holding copy of data

Always just a copy

Key to performance
 Spooling – a buffer hat holds output for a device

If device can serve only one request at a time

Useful for printers and tape drives
 Device reservation – coordination to provide exclusive
access to a device

System calls for allocation and deallocation

Watch out for deadlock
Operating System Concepts – 8th Edition
13.26
Silberschatz, Galvin and Gagne ©2009
Kernel I/O Subsystem
 Error Handling

OS can recover from disk read, device unavailable, transient
write failures

Most OS’s return an error number or code when I/O request fails

System error logs hold problem reports
skip 13.4.5 第 2 段
Operating System Concepts – 8th Edition
13.27
Silberschatz, Galvin and Gagne ©2009
Kernel I/O Subsystem
 I/O Protection -- User process may accidentally or
purposefully attempt to disrupt normal operation via
illegal I/O instructions

All I/O instructions defined to be privileged

I/O must be performed via system calls

Memory-mapped and I/O port memory locations must be
protected too
Operating System Concepts – 8th Edition
13.28
Silberschatz, Galvin and Gagne ©2009
Use of a System Call to Perform I/O
Operating System Concepts – 8th Edition
13.29
Silberschatz, Galvin and Gagne ©2009
13.4.7 Kernel Data Structures
 Kernel keeps state info for I/O components, including
open file tables, network connections, character-device
communications, etc.
 Many, many complex data structures to track buffers,
memory allocation, “dirty” blocks (see next slide)
 Some use object-oriented methods

Windows NT uses a message passing mechanism to implement
I/O
Operating System Concepts – 8th Edition
13.30
Silberschatz, Galvin and Gagne ©2009
UNIX I/O Kernel Structure
Operating System Concepts – 8th Edition
13.31
Silberschatz, Galvin and Gagne ©2009
13.5 Transforming 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
skip 13.6
Operating System Concepts – 8th Edition
13.32
Silberschatz, Galvin and Gagne ©2009
Life Cycle of
An I/O
Request
Operating System Concepts – 8th Edition
13.33
Silberschatz, Galvin and Gagne ©2009
13.7 Performance
 I/O is a major factor in system performance.

It places heavy demands on the CPU to execute device-driver
code and to schedule processes fairly and efficiently as they
block and unblock

Interrupts handling is expensive -- context switches

Data copying between controllers and physical memory, and
between kernel buffers and application data space

Network traffic can also cause a high context-switch rate

Consider a remote login (see next slide)

To eliminate the context switches involved in moving each character
between daemons and the kernel, Solaris rei-mplemented the telnet
daemon using in-kernel threads
skip p.584 第 2 段
Operating System Concepts – 8th Edition
13.34
Silberschatz, Galvin and Gagne ©2009
Operating System Concepts – 8th Edition
Intercomputer Communications
13.35
Silberschatz, Galvin and Gagne ©2009
Improving I/O Performance
 Principles

Reduce number of context switches

Reduce data copying

Reduce the frequency of interrupts by using large transfers,
smart controllers, and polling

Increase concurrency by using DMA

Move processing primitives into hardware

Balance CPU, memory, bus, and I/O performance for highest
throughput
Operating System Concepts – 8th Edition
13.36
Silberschatz, Galvin and Gagne ©2009
Device-Functionality Progression
Operating System Concepts – 8th Edition
13.37
Silberschatz, Galvin and Gagne ©2009