Professional Documents
Culture Documents
Chapter Four
4. Device management
Os manages device communication via their respective drivers. device management
implies the management of I/O devices. There are four main functions of the device
manager
Monitor the status of all devices. The program responsible for this task is I/O controller.
Decides which process gets the device when and for how much time/for how long.
Deal with the allocation of devices to processes
Deal with the de-allocation of devices to processes
Examples of devices
• Keyboard
• Mouse
• Monitor
• Scanner
• CD-ROM
• USB ports
• Disk
• Printer
• microphone
Dedicated devices
These are devices that are assigned to one process at a time and the process only releases
the device once it is completed. This makes sense for devices like plotters, and tape
drivers. The problem with this is that it means only one user is using it at a time, and it
maight be inefficient if the device isn’t being used 100% of the time that it is being
locked by the user.
Shared devices
These are devices that can be shared between several processes. Considering an example
like a hard disk, it is shared but interleaving between different processes requests.
All conflicts for device need to be resolved but pre-determined polices to decide which request is
handled first.
Virtual devices
These are devices are combination of dedicated and shared devices. So a printer is d
dedicated device but using spooling(queues) means it can be shared.
Spooling: Suppose we have a printer connected to a machine. Many users may seek to
use the printer. To avoid print clashes, it is important to be able to queue up all the print
requests. This is achieved by spooling.
A print job isn’t sent straight to the printer ,instead it goes to the disk (spool) until it is fully
prepared with all the necessary printer sequences and formatting then it goes to the printer
,ensuring that the printers (and all I/O devices) are used efficiently.
I/O is important for communication between the user and computer. The following are functions
of the operating system as I/O manager:
Example: disks
Character devices: process stream of characters without any block structure. Delivers or
accepts a stream of characters, without regard to any block structure. It transfer single
character at a time.
Example: printers, network interfaces, mice, keyboards.
I/O Unit: indicates the hardware components. There are two major components – Electronic
Component (Adapter/device controller) and the Mechanical Component (the moving parts)
A controller has an interface into which a cable that connects its device is plugged in. Each
controller has a few registers for communication with the operating system. Besides registers,
some devices have data buffer on which programs and the operating system can read/write data.
For the CPU to communicate with device controllers, each device must have a unique ID.
Device Naming – responsible for mapping symbolic devices names onto the proper
driver
Device protection – prevent users from accessing devices that they are not entitled to
access
Buffering: if a user process write half a block, the OS will normally keep the data in
buffer until the rest of the data are written. Keyboard inputs that arrive before it is needed
also require buffering.
Storage allocation on block devices: when a file is created and filled with data, new
disk blocks have to be allocated to the file. To perform this allocation, the OS needs a list
of free blocks and used some algorithms for allocation
Allocating and releasing dedicated devices: It is up to the OS to examine requests for
devices usage and accept or reject them.
Error reporting: Errors handling, by and large, is done by drivers. Most errors are
device dependent. After the driver tries to read the block a certain number of times, it
gives up and informs the device-independent software. It then reports to the caller.
4. User Space I/O Software
A small portion of the I/O software is outside the OS
System calls, including the I/O system calls, are normally made by library procedures
Formatting of input and output is done by library procedures
• A small portion of I/O software that is consists of libraries linked together with user
programs, and even whole programs running outside the kernel.
The following figure shows the I/O system layers and the main functions of each layer
Shortest Seek First (SSF): the next cylinder to be accessed is the nearest to the current
one. This algorithm minimizes average seek time but cylinders at the extreme locations
suffers long waits since most requests tend to cylinders near the middle. Thus, minimal
response time compromises fairness. Figure 4.8 illustrates shortest seek first disk
scheduling algorithm.
• Many devices have common characteristics; e.g., different brands of disk or printer
Buffers are temporary storage areas residing in convenient locations throughout system:
main memory, channels, and control units. Used extensively to better synchronize
movement of data between relatively slow I/O devices & very fast CPU.
A buffer is a memory area that stores data while they are transferred between two
devices or between a device and an application. It overlaps the input/output of one job with
the execution of the same job.
Buffering is done for three reasons:
• To cope with a speed mismatch between the producer and consumer and
consumer of a data stream.
Double buffering – two buffers taking turns: while one is being copied to user space, the
other is accumulating new input.
Double Buffer
Use two system buffers instead of one
A process can transfer data to or from one buffer while the operating system
empties or fills the other buffer
Circular buffering – has a region of memory and two pointers. One pointer points to the
next free word, where new data can be placed. The other pointer points to the first word
of data in the buffer that has not been removed yet.
Circular Buffer
• More than two buffers are used
• Each individual buffer is one unit in a circular buffer
• Used when I/O operation must keep up with Process
The direct memory access (DMA) I/O technique provides direct access to the memory while the
microprocessor is temporarily disabled.
I/O devices are connected to system bus via a special interference circuit known as DMA
controller.
In DMA, both CPU and DMA controller have access to main memory via a shared system bus
having data, address and control lines.
It is sometimes referred to as a channel. In an alternative configuration, the DMA controller may
be incorporated directly into the I/O device.
• CPU needs to address the device controllers to exchange data with them.
• DMA controller has access to the system bus independent of the CPU.
• It contains several registers that can be written and read by the CPU.
• The control registers specify the I/O port to use, the direction of the transfer (read or
write to I/O), transfer unit (byte or word), and the number of bytes to transfer in one
burst.
Why DMA
An important aspect of governing the computer system performance of data b/n memory
and I/O devices. The operation involves loading programs or data files from disk into
memory, saving file on disk, and accessing virtual memory pages on any secondary
storage medium.
The process would be much quicker if we could bypass the CPU and transfer data
directly from the I/O device to memory. Direct memory access does exactly that
During DMA transfer, the CPU is idle and no control of the memory buses.
DMA mode
• Cycle stealing – the device controller sneaks in and steals an occasional bus cycle from
the CPU once in a while, delaying it slightly (word-at-a-time).
• Burst mode – DMA controller tells the device to acquire the bus, issues a series of
transfers, then release the bus (block).
• Fly-by mode – DMA controller tells the device controller to transfer the data directly to
main memory.
Advantages of DMA
DMA allows a peripheral device to read from/write to memory without going through the
CPU.
DMA allows for faster processing since the processor can be working on something else
while the peripheral can be population memory.
Disadvantages of DMA
DMA transfer requires a DMA controller to carry out the operation, hence cost of the
system increases.
Leads to Cache coherence problems.