Chapter Os DSTV 4-1
Chapter Os DSTV 4-1
Chapter Os DSTV 4-1
4.1 Introduction
The two main jobs of a computer are I/O and processing. The role of the operating system in
computer I/O is to manage and control I/O operations and I/O devices. Computers operate a
great many kinds of devices. Most fit into the general categories of storage devices (disks,
tapes), transmission devices (network cards, modems), and human-interface devices (screen,
keyboard, mouse).
Because of the different types of devices that send and receive information, two major types
of data transfers take place within a computer: parallel and serial (Figure 4.1).
Figure 4.1: Parallel data transfers move data 8 bits at a time, whereas serial data transfers
move 1 bit at a time.
Parallel cables that are too long can cause signal skew, allowing the parallel signals to
become "out of step" with each other.
Figure 4.2: Parallel cables that are too long can cause signal skew, allowing the parallel
signals to become “out of step” with each other.
The following ports and devices in the computer use serial transfers:
Serial (also called RS-232 or COM) ports and devices
USB (Universal Serial Bus) 1.1 and 2.0 ports and devices
Modems (which can be internal devices or can connect to serial or USB ports)
IEEE-1394 (FireWire, i.Link) ports and devices
Serial ATA (SATA) host adapters and drives
Although RS-232 serial ports are slow, newer types of serial devices are as fast as or faster
than parallel devices. The extra speed is possible because serial transfers don’t have to worry
about interference or other problems caused by running so many data lines together.
When device A has a cable that plugs into device B, and device B has a cable that plugs into
device C, and device C plugs into a port on the computer, this arrangement is called a daisy
chain. A daisy chain usually operates as a bus.
A controller is a collection of electronics that can operate a port, a bus, or a device. Some
devices have their own built-in controllers. If you look at a disk drive, you will see a circuit
board attached to one side. This board is the disk controller.
Each device controller is in charge of a specific type of device. Depending on the controller,
there may be more than one attached device. For instance, seven or more devices can be
attached to the small computer-systems interface (SCSI) controller. A device controller
maintains some local buffer storage and a set of special-purpose registers. The device
controller is responsible for moving the data between the peripheral devices that it controls
and its local buffer storage. Typically, operating systems have a device driver for each device
controller. This device driver understands the device controller and presents a uniform
interface to the device to the rest of the operating system.
To start an I/O operation, the device driver loads the appropriate registers within the device
controller. The device controller, in turn, examines the contents of these registers to
determine what action to take (such as “read a character from the keyboard”) - The controller
starts the transfer of data from the device to its local buffer. Once the transfer of data is
complete, the device controller informs the device driver via an interrupt that it has finished
its operation. The device driver then returns control to the operating system.
Each controller has a few registers that are used for communicating with the CPU. By writing
into these registers, the operating system can command the device to deliver data, accept
data, switch itself on or off, or otherwise perform some action. By reading from these
registers, the operating system can learn what the device’s state is, whether it is prepared to
accept a new command, and so on. In addition to the control registers, many devices have a
data buffer that the operating system can read and write.
4.4.1 Polling
The complete protocol for interaction between the host and a controller may be complicated,
but the basic handshaking notion is simple. We explain handshaking with an example. We
assume that 2 bits are used to coordinate the producer - consumer relationship between the
controller and the host. The controller indicates its state through the busy bit in the status
register. To set a bit means to write a 1 into the bit and to clear a bit means to write a 0 into it.
The controller sets the busy bit when it is busy working and clears the busy bit when it is
ready to accept the next command. The host signals its wishes via the command-ready bit in
the command register. The host sets the command-ready bit when a command is available for
the controller to execute. For this example, the host writes output through a port, coordinating
with the controller by handshaking as follows:
1. The host repeatedly reads the busy bit until that bit becomes clear.
2. The host sets the write, bit 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 that 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
to indicate that the device I/O succeeded, and clears the busy bit to indicate that it is
finished.
This loop is repeated for each byte. In step 1, the host is busy-waiting or polling: It is in a
loop. Polling is a process by which a host waits for controller response. It is a looping
process, reading the status register over and over until the busy bit of status register becomes
clear.
4.5 Buffering
A buffer is a memory area that stores data while they are transferred between two devices or
between a device and an application. The buffers are usually set up in the main memory.
Device drivers and the kernel both may access device buffers. Basically, the buffers absorb
mismatch in the data transfer rates of processor or memory on one side and device on the
other.
A key concern, and a major programming issue from the OS point of view, is the
management of buffers. One key issue in buffer management is buffer-size. How buffer-sizes
may be determined can be explained by using a simple analogy. Ideally, the buffer sizes
should be chosen in computer systems to allow for free flow of data, with neither the
producer (process) of data nor the consumer (process) of data is required to wait on the other
to make the data available. Next we shall look at various buffering strategies:
Single buffer: The device first fills out a buffer. Next the device driver hands in its
control to the kernel to be emptied the buffer. Once the buffer has been used up, the
device fills it up again for input.
Double buffer: In this case there are two buffers. The device fills up one of the two
buffers, say buffer-0. The device driver hands in buffer-0 to the kernel to be emptied
and the device starts filling up buffer-1 while kernel is using up buffer-0. The roles
are switched when the buffer-1 is filled up.
Circular buffer: One can say that the double buffer is a circular queue of size two.
We can extend this notion to have several buffers in the circular queue. These buffers
are filled up in sequence. The kernel accesses the filled up buffers in the same
sequence as these are filled up. The buffers are organized as a circular queue data
structure.
4.6 Spooling
Acronym for Simultaneous Peripheral Operations On-line, spooling refers to putting jobs in a
buffer, a special area in memory or on a disk where a device can access them when it is
ready. Spooling is useful because devices access data at different rates. The buffer provides a
waiting station where data can rest while the slower device catches up.
The most common spooling application is print spooling. In print spooling, documents are
loaded into a buffer (usually an area on a disk), and then the printer pulls them off the buffer
at its own rate. Because the documents are in a buffer where they can be accessed by the
printer, you can perform other operations on the computer while the printing takes place in
the background. Spooling also lets you place a number of print jobs on a queue instead of
waiting for each one to finish before specifying the next one.
How a device driver handles a request is as follows: Suppose a request comes to read a block
N. If the driver is idle at the time a request arrives, it starts carrying out the request
immediately. Otherwise, if the driver is already busy with some other request, it places the
new request in the queue of pending requests.