Sie sind auf Seite 1von 49

CHAPTER FIVE

INPUT/OUTPUT

I/O devices
I/O software
Organization of I/O
functions
Disk scheduling
Clocks
1

I/O Devices
Input

Process

Output

Main functions of an operating system with regard to I/O


control all the computers I/O (Input/Output) devices

issue commands to the devices


catch interrupts
handle errors
provide an interface between the devices and the rest of the
system that is simple and easy to use
2

I/O devices ..

External devices that engage in I/O with computer systems can be


roughly grouped into three categories:
Human readable: Suitable for communicating with the
computer user.
Examples include video display terminals, consisting of display,

keyboard, mouse, and printers.


Machine readable: Suitable for communicating with electronic

equipment.
Examples are disk and tape drives, sensors, controller, and actuators.

Communication: Suitable for communicating with remote

devices.

Examples are digital line drivers and modems

The following are the differences between I/O Devices


1.Data rate:- data rates vary b/n I/O devices .
Out of all devices keyboard is the least data transmission rate and graphics display is

the highest transmission rate.

2. Application:-Different devices have different use in the system.


3. Complexity of Control:-A disk is much more complex whereas a mouse
or a keyboard requires simple control interface.
4. Unit of transfer:-Data may be transferred as a stream of bytes or
characters or in larger blocks.
5. Data representation:-Different data encoding schemes are used for
different devices.
6. Error Conditions:-The nature of errors differs widely from one device
to another.

Cont
I/O devices cover a huge range in speeds

Input/output component
To view a document stored on a hard disk, you accessed hard disk

and issue the command to display the document


This tasks are performed by input-out put hard ware and I/O software in

coordination .

Input/out put component


1. I/O hardware

are I/O devices such as hard disk, floppy disk


Includes an electrical component called devices controller
Consists of mechanical and electrical component
Mechanical component is the devices itself
Electrical component is the devices controller

2.

I/O software
Include different layer of the operating system that mange the I/O devices

Device Controllers

Form of a printed circuit card that can be inserted into an


expansion slot
Has a connector on it, into which a cable leading to the device
itself can be plugged
The interface between the controller and the device is often a
very low-level interface
Receive serial bit stream, convert the serial bit stream into a
block of bytes and calculate checksum
After the block declared to be error free, it can then be copied to
main memory

I/O hardware
Electrical engineers view of I/O hardware
chips, wires, power supplies, motors, and all the other

physical components that make up the hardware


Programmers view of I/O hardware
the interface presented to the software
the commands the hardware accepts
the functions it carries out
the errors that can be reported back

I/O devices

I/O devices can be roughly divided into two categories:


block devices:
stores information in fixed-size blocks, each one with its own
address.
Common block sizes range from 512 bytes to 32,768 bytes.
it is possible to read or write each block independently of all the
other ones.
Disks are the most common block devices.
character devices:
A character device delivers or accepts a stream of characters, without
regard to any block structure.
It is not addressable and does not have any seek operation.
Printers, network interfaces, mice (for pointing), rats (for psychology
lab experiments), and most other devices that are not disk-like can be
seen as character devices.

I/O communication
Each controller has a few registers that are used for communicating
with the CPU

10

control registers

Used to communicate with the CPU

OS reads/writes onto this register to command the


device to receive or send and check status
data buffer

A buffer that the operating system can read and write

a common way for computers to display pixels on the


screen is to have a video RAM, which is a data buffer,
available for programs or the operating system to write
into

Memory-Mapped I/O

11

Cont.

Two alternatives exist for the CPU to communicate with the device controller
Assign I/O port number to each device controller

To access this device OS can use these address


IN REG,PORT - to read control register to CPU REG
OUT PORT,REG to write the CPU REG to a control register
Memory-mapped I/O

12

Each device will have a unique 8-bit or 16-bit integer address

Each control register is assigned a unique memory address to which


no memory is assigned

Memory-Mapped I/O are assigned addresses at the top of the address


space

Device-control registers are mapped into the address space of the


processor

CPU executes I/O requests using the standard data-transfer


instructions to read/write the device-control registers.

Cont.
Memory-Mapped I/O are assigned addresses at the top of the

address space
Device-control registers are mapped into the address space of the
processor
CPU executes I/O requests using the standard data-transfer
instructions to read/write the device-control registers.
E.g. Graphics controller has a large memory-mapped region to hold
screen contents sending output to screen by writing data into the
memory-mapped region. Controller generates the screen image based on
the contents of this memory.
Simpler and faster to write millions of bytes to the graphics memory
compared to issuing millions of I/O instructions.

13

Memory-Mapped I/O
Advantages:
device control registers are just variables in memory and can be addressed in C
the same way as any other variables

Doesnt require the use of assembly code like IN or OUT

I/O device driver can be written entirely in C


no special protection mechanism is needed to keep user processes from
performing I/O
every instruction that can reference memory can also reference control registers
Disadvantages:
Caching a device control register would be disastrous unless the hardware

supports selective caching


If there is only one address space, then all memory modules and all I/O devices

must examine all memory references to see which ones to respond to

Single bus -> everyone look at every address

Multiple buses ->Mark non memory ranges and forward to non memory
buses.
14

Direct memory access (DMA):

15

A special control unit is used to transfer block of data directly between an


external device and the main memory, without intervention by the processor.
This approach is called Direct Memory Access (DMA).
A DMA module controls the exchange of data between main memory and an
I/O module.
The processor sends a request for the transfer of a block of data to the DMA
module and is interrupted only after the entire block has been transferred
DMA is the dominant form of transfer that must be supported by the
operating system.
The operating system can only use DMA if the hardware has a DMA
controller, which most systems do
Sometimes this controller is integrated into disk controllers and other
controllers
requires a separate DMA controller for each device.
More commonly, a single DMA controller is available (e.g., on the parent
board) for regulating transfers to multiple devices, often concurrently

Direct Memory Access

Disk read without DMA:


The device controller

reads the block from the drive serially, bit by


bit, until the entire block is in the controllers
internal buffer
computes the checksum to verify that no
read errors have occurred
causes an interrupt

The operating system starts running

read the disk block from the controllers


buffer a byte or a word at a time by
executing a loop and store in memory
16

Direct Memory Access


With DMA:
First the CPU programs the DMA controller by setting

17

its registers so it knows what to transfer where


CPU also issues a command to the disk controller
telling it to read data and verify the checksum
The DMA controller initiates the transfer by issuing a
read request over the bus to the disk controller
When the write is complete, the disk controller sends
an acknowledgement signal to the disk controller
Then DMA controller interrupts the CPU to let it know
that the transfer is now complete
When the operating system starts up, it does not
have to copy the disk block to memory; it is already
there

Direct Memory Access

18

CHAPTER FIVE
INPUT/OUTPUT
I/O devices

I/O software
Organization of I/O functions
Disk scheduling
Clocks
19

I/O Software
Goals of I/O software design:
device independence

it should be possible to write programs that can access any


I/O device without having to specify the device

uniform naming.
The name of a file or a device should not depend on the
device in any way
error handling.
errors should be handled as close to the hardware as
possible
synchronous (blocking) versus asynchronous

(interrupt-driven)

User programs are much easier to write if the I/O operations


are blocking
operating system to make operations that are actually
interrupt-driven look blocking to the user programs.

Some other issues


20
Buffering

I/O Software
Programmed I/O
The simplest form of I/O is to have the CPU do all

21

the work
The operating system then (usually) copies the
buffer with the string to an array, say, p, in kernel
space, where it is more easily accessed (because
the kernel may have to change the memory map to
get at user space).
It then checks to see if the I/O is currently available.
If not, it waits until it is available.
As soon as the I/O is available, the operating system
copies the first character to the printers data
register, in this example using memory-mapped I/O.

I/O Software
Programmed I/O
Consider a user process that wants to print the

eight-character string ABCDEFGH on the


printer

22

I/O Software

Programmed I/O

First the data are copied to the kernel.


Then the operating system enters a tight loop

23

outputting the characters one at a time.


The essential aspect of programmed I/O, clearly
illustrated in this figure, is that after outputting a
character, the CPU continuously polls the device
to see if it is ready to accept another one.
This behavior is often called polling or busy
waiting
The processor issues an I/O command, on behalf
of a process, to an I/O module;
that process then busy waits for the operation to
be completed before proceeding

I/O Software

Disadvantages:
Tying up the CPU in busy waiting
24

I/O Software
Interrupt-Driven I/O
The processor issues an I/O command on behalf of

a process and continues with other activities

Nonblocking instruction processor continues


to execute instructions from the process that issued
the I/O command
Blocking instruction put the current process in
a blocked state and schedule another process to run

When the data is ready, the processor is

interrupted and handles the transfer


Now let us consider the case of printing on a
printer that does not buffer characters but prints
each one as it arrives
25

I/O Software

After interrupt

Send a character to the buffer


and continue

Disadvantage:
Handling interrupt after
every char
26

Processor is involved in

I/O Software
I/O Using DMA
A DMA module controls the exchange of
data between main memory and an I/O
module.
The processor sends a request for the
transfer of a block of data to the DMA
module and is interrupted only after the
entire block has been transferred
Lets consider the printing again:
let the DMA controller feed the characters to the
27

printer one at time, without the CPU being


bothered
Interrupt the CPU after the entire data has been

I/O Software
Initiate printing

Handling Interrupt

28

CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software

Organization of I/O functions


Disk scheduling
Clocks
29

Organization of I/O functions


I/O Software Layers
I/O software is typically organized in four
layers,

30

Device drivers
Each I/O device attached to a computer

31

needs some device-specific code for


controlling it, called device driver
Device drivers are generally written by the
devices manufacturer and delivered along
with the devices.
Each device driver normally handles one
device type, or at most, one class of closely
related devices
In order to access the devices hardware,
meaning the controllers registers, the
device driver normally has to be part of the
operating system kernel
Operating systems need to have an

Device drivers
Functions:
accept abstract read and write requests from

32

the device-independent software above it and


see that they are carried out
checking the input parameters to see if they are
valid and convert them from abstract to
concrete terms, e.g. in disks from block number
to actual head, sector, track and cylinder
numbers
Check device status if the operation can be
applied, otherwise queue the request
Controlling the device: issuing sequence of
commands

Device driver

33

Device-Independent I/O
Software
The boundary between device-independent I/O

software and device driver is system


dependent

some functions that could be done in a device-

independent way may actually be done in the


drivers, for efficiency or other reasons.

The basic function of the device-independent

software is to perform the I/O functions that


are common to all devices and to provide a
uniform interface to the user-level software

34

Device-Independent I/O
Software
Typical functions:
Uniform interfacing for device drivers
make all I/O devices and drivers look more-or-

less the same:


Interface for device-driver, Name, protection

Buffering
create a buffer inside the kernel and have the
interrupt handler put the characters there
Error reporting
Many errors are device-specific and must be
handled by the appropriate driver, but the
framework for error handling is device
independent
Allocating and releasing dedicated devices
35
Providing a device-independent block size

User-Space I/O Software


Most of the I/O software is within the

operating system
Consists of libraries linked together with
user programs
System calls are normally made by library
procedures
write(filePointer, varBuffer, nobytes);
Library procedure write will be linked with

the program and contained in the binary


program present in memory at run time
36

I/O Software Layers

37

Layers of the I/O system and the main functions of


each layer

CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O functions

Disk scheduling
Clocks
38

Disk scheduling
Disk Structure

39

Disk drives are addressed as large 1-dimensional


arrays of logical blocks, where the logical block is
the smallest unit of transfer.

The 1-dimensional array of logical blocks is


mapped into the sectors of the disk sequentially.
Sector 0 is the first sector of the first track on
the outermost cylinder.
Mapping proceeds in order through that track,
then the rest of the tracks in that cylinder, and
then through the rest of the cylinders from
outermost to innermost.

Disk Structure

40

Disk Structure

Arm
Assembly

41

Disk Structure

42

Disk Arm Scheduling


The operating system is responsible for using hardware
efficiently for the disk drives, this means having a
fast access time and disk bandwidth.
Access time has two major components
Seek time is the time for the disk to move the heads
to the cylinder containing the desired sector.
Rotational latency is the additional time waiting for
the disk to rotate the desired sector to the disk head.
Minimize seek time
Seek time seek distance

43

Disk bandwidth is the total number of bytes transferred,


divided by the total time between the first request for
service and the completion of the last transfer.

Disk Arm Scheduling


Time required to read or write a
disk block determined by 3
factors

44

Seek time
Rotational delay
Actual transfer time

Seek time dominates


Error checking is done by
controllers

READING ASSIGNMENT
Disk Arm Scheduling
C-SCAN
C-LOOK

RAID and its Level

45

CHAPTER FIVE
INPUT/OUTPUT
I/O devices
I/O software
Organization of I/O functions
Disk scheduling

Clocks
46

Clocks
Clock
Clocks (or timers) are essential to the

operation of any multiprogrammed system:


maintain the time of day
prevent one process from monopolizing the

CPU
Set a timer to trigger operation X at time T
Clocks take the same form as the other

devices:

Hardware
Software
47

Clock Hardware
Programmable clocks typically have several

modes of operation

one-shot mode
Copy value of holding register, decrement counter for every
pulse and interrupt
Wait until explicitly restarted
square-wave mode
after getting to zero and causing the interrupt, the holding
register is automatically copied into the counter, and the
whole process is repeated again indefinitely.

These periodic interrupts are called clock

ticks

48

Clock Hardware
All the clock hardware does is generate

interrupts at known intervals.


Everything else involving time must be done
by the software, the clock driver:
Maintaining the time of day (also called the real

49

time)
Preventing processes from running longer than
they are allowed to.
Accounting for CPU usage.
Handling the alarm system call made by user
processes.
Providing watchdog timers for parts of the system
itself.

Das könnte Ihnen auch gefallen