Chapter Five
Chapter Five
Device management
Device Abstraction
• An abstraction is software that hides lower level details and provides a set of
higher-level functions.
• An operating system transforms the physical world of devices, instructions,
memory, and time into virtual world that is the result of abstractions built by
the operating system.
• A hardware abstraction layer (HAL)
• It is a logical division of code that serves as an abstraction layer between a
computer's physical hardware and its software.
• It provides a device driver interface allowing a program to communicate
with the hardware.
• The main purpose of a HAL is to conceal different hardware architectures
from the OS by providing a uniform interface to the system peripherals.
I/O devices
• In addition to providing abstractions such as processes, address spaces, and
files, an operating system also controls all the computer’s I/O
(Input/Output) devices
• I/O is important for communication between the user and computer.
• The following are functions of the operating system as I/O manager:
Control all the computer I/O devices
Issue commands to I/O devices, catch interrupts and handle errors
Provide an interface between the device and the rest of the system
I/O Hardware
• Wide variety of ‘devices’ which interact with the computer via I/O:
• Human readable: graphical displays, keyboard, mouse, printers
• Machine readable: disks, tapes, CD, sensors
• Communications: modems, network interfaces
• They differ significantly from one another with regard to:
• Data rate
• Complexity of control
• Unit of transfer
• Direction of transfer
• Data representation
• Error handling
⇒ hard to present a uniform I/O system which masks all complexity I/O
subsystem is generally the ‘messiest’ part of OS.
Principles of I/O hardware
• I/O devices have three sections:
A. I/O devices: - concerns with the way data are handled by the I/O device. There are
two types of I/O devices blocked and character
• Blocked devices (such as disks) –
• A block device is one that stores information in fixed-size blocks, each one with its own address.
• Common block size range from 512 bytes to 32,768 bytes.
• The essential property of a block device is that it is possible to read or write each block
independently of all the other ones.
• Disks are the most common block devices.
• A disk is a block addressable device because no matter where the arm currently is, it is always
possible to seek to another cylinder and then wait for the required block to rotate under the head.
• Character devices (such as printers, mouse and NIC) –
• The other type of I/O device is the character device.
• A character device delivers or accepts stream of character, without regard to any block structure.
• It is not addressable and does not have any seek operation.
B. I/O Unit: indicates the hardware components.
• There are two major components – Electronic Component (Device
controller/Adapter) and the Mechanical Component (the moving parts)
C. Direct Memory Access (DMA): is a technique for moving a data directly
between main memory and I/O devices without the CPU’s intervention.
• In the absence of DMA reading from a disk is done with the following steps:
• The controller reads the block (one or more sectors) from the drive serially,
bit by bit, until the entire block is in the controller’s internal buffer
• The controller computes the checksum to verify that no read errors have
occurred
• The controller causes an interrupt
• The OS reads the disk block from the controller’s buffer a byte or a word at
a time and stores it on memory
Principles of I/O software
• Layered technique is used
• Goals and issues of I/O software:
1. Device Independence: It should be possible to write programs that can read
files on a floppy disk, on hard disk, or on a CD-ROM, without having to
modify the program for each different device types. It is up to the operating
system to take care of the problems caused by the fact that these devices are
really different.
2. Uniform Naming: the name of a file or a device should simply be a string or
an integer and not dependent on the device in any way.
3. Error handling: In general, errors should be handled as close to the hardware
as possible (at the device controller level). Many errors are transient, such as
read errors caused by specks of dust on the read head, and will go away if the
operations are repeated.
4. Transfer: There are two types of transfer modes – Synchronous (Blocking)
and Asynchronous (interrupt –driven).
• In the case of synchronous transfer the program requesting I/O transfer will
be suspended until the transfer is completed.
• In the case of Asynchronous transfer the CPU starts the transfer and goes
off to do something until the interrupt that shows the completion of the
transfer arrives.
5. Device types: There are two device types –
• Sharable (such as disk) - used by many users at the same time. No
problems are caused by multiple users having open files on the same disk
at the same time.
• Dedicated (tape drives) have to be dedicated to a single user until that user
is finished. Having two or more users writing blocks intermixed at random
to the same tape will definitely not work
Buffering
• Buffering of I/O is performed for ( at least ) 3 major reasons:
A. Speed differences between two devices.
• slow device may write data into a buffer, and when the buffer is full,
the entire buffer is sent to the fast device all at once.
• So that the slow device still has somewhere to write while this is
going on, a second buffer is used, and the two buffers alternate as
each becomes full.
• This is known as double buffering. ( Double buffering is often used
in ( animated ) graphics, so that one screen image can be generated in
a buffer while the other ( completed ) buffer is displayed on the
screen.
• This prevents the user from ever seeing any half-finished screen
images. )
B. Data transfer size differences. Buffers are used in particular in
networking systems to break messages up into smaller packets for transfer,
and then for re-assembly at the receiving side.
C. To support copy semantics.
• For example, when an application makes a request for a disk write, the
data is copied from the user's memory area into a kernel buffer.
• Now the application can change their copy of the data, but the data
which eventually gets written out to disk is the version of the data at
the time the write request was made.