Input and output devices information
Of
course you’re aware that no matter how powerful the CPU is, a computer system’s
usefulness ultimately depends on its input and output facilities. Without I/O
there is no possibility of keyboard input, of screen output, of printout, or
even of disk storage and retrieval. Although you might be inclined to think of
I/O in terms of user input and output, there would be no computer network or
Internet access either. To the CPU and its programs, all these devices require
specialized input and output processing facilities and routines. In fact, for
most business programs and for nearly every multimedia application, I/O is the
predominant factor. E-business applications offer an even bigger challenge: Web
services generally require massive amounts of fast I/O to handle and process
I/O requests as they occur. The speed at which most of these programs operate
is determined by the ability of their I/O operations to stay ahead of their processing.
With personal computers rapidly increasing in CPU-processing capability, but
still somewhat limited in I/O processing, it has been greater I/O capability
that has maintained, until recently, the advantage of mainframe computers over
PCs for business transaction processing.
We
handled input and output in the Little Man Computer by providing input and
output baskets for that purpose. Each input instruction transferred one
three-digit data number from the input basket to the calculator; similarly, each
output instruction transferred one data number from the calculator to the
output basket. If we wanted to input three numbers, for example, an input
instruction had to be executed three times. This could be done with three
separate input instructions or in a loop, but either way, each individual piece
of data required the execution of a separate input instruction. If the input
was a large file of data, it would take a massive number of input instructions
to process the data. It is possible, though possibly not always practical, to
transfer data between input and output devices and the CPU of a real computer
in a similar manner. In the real computer, the in basket and out basket are
commonly replaced by a bus interface that allows a direct transfer between a
register within the CPU and a register within an I/O controller that controls
the particular device. Both input and output are handled similarly. The
technique is known as programmed I/O. There are a number of complicating
factors in handling input/output processes (which we will normally simply call
I/O) in a real computer. Although the method of transferring data one word at a
time does really exist, and maybe adequate and appropriate for some slow operating
I/O devices, the volume of data commonly transferred in I/O devices, such as
disks and tapes, makes this method too slow and cumbersome to be practical as
the only I/O transfer method in a modern high-speed machine. We need to
consider some method of transferring data in blocks rather than executing an
instruction for each individual piece of data. The problem is further
complicated by the fact that in a real computer, there may be many input and
output devices all trying to do I/O, sometimes at the same time. There needs to
be a way of distinguishing and separating the I/O from these different devices.
Additionally, devices operate at different speeds from each other and from the
CPU. An inkjet printer may output characters at a rate of 150 per second, whereas
a disk may transfer data at a rate of tens or hundreds of thousands, or even
millions, of bytes per second. Synchronization of these different operations
must be achieved to prevent data loss.
PROGRAMMED I/O
In
the simplest method for performing I/O, an I/O controller is connected to a
pair of I/O registers in the CPU via a bus. The I/O data register serves the
same role in the real CPU as the input and output baskets served in the Little
Man Computer. Alternatively, one might view the I/O baskets as buffers, holding
multiple inputs or outputs, with the I/O data register as the interface between
the CPU and the buffer. The I/O operation is similar to that of the Little Man Computer.
Input from the peripheral device is transferred from the I/O controller or
buffer for that peripheral device one word at a time to the I/O data register
and from there to an accumulator or general-purpose register under program
control, just as occurred in the Little Man Computer. Similarly, individual
words of output data pass from a register to the I/O data register where they
can be read by the appropriate I/O controller, again under program control. Each
instruction produces a single input or output. This method is known as programmed
I/O. In practice, it is most likely that there will be multiple devices
connected to the CPU. Since each device must be recognized individually,
address information must be sent with the I/O instruction. The address field of
the I/O instruction can be used for this purpose. An I/O address register in
the CPU holds the address for transfer to the bus. Each I/O controller will have
an identification address that will allow it to identify I/O instructions
addressed to it and to ignore other I/O not intended for it. As has been noted,
it is common for an I/O controller to have several addresses, each of which
represents a different control command or status request, or which addresses a
different device when a particular module supports multiple devices. For
example, the address field in the Little Man input and output instructions
could be used to address up to a combination of one hundred devices, status
requests, or control commands. The I/O data and address registers work
similarly to the memory address register (MAR) and memory data register (MDR).
In fact, in some systems, they may even be connected to the same bus. The CPU
places a control signal on the bus to indicate whether the transfer is I/O or memory.
Programmed I/O is obviously slow, since a full instruction fetch–execute cycle
must be performed for each and every I/O data word to be transferred.
Programmed I/O is used today primarily to read data from keyboards and similar
devices, with occasional application to other simple character-based data
transfers, such as the transmission of commands through a network controller.
These operations are slow compared with the computer, with small quantities of data
that can be handled one character at a time. One limitation, which we shall
address later in the chapter, is that with programmed I/O, input from the
keyboard is accepted only under program control. An alternative means must be
found to accept unexpected input from the keyboard. There is one important
application for programmed I/O: alternative methods of I/O use the I/O
controller to control certain types of I/O operations independently from the
CPU, using memory as the intermediate site for the data transfer. Programmed
I/O is used by programs in the CPU to send the necessary commands to the I/O
controllers to set up parameters for the transfer and to initiate I/O
operations.
INTERRUPTS
As
you know from our previous discussion, there are many circumstances under which
it is important to interrupt the normal flow of a program in the computer to
react to special events. Indeed, it would be unusual for a modern program to
execute without some sort of interaction with the outside world. An
unexpected user command from the keyboard, a click of a mouse or touch of a finger
on a screen, external input from a device requiring attention, an abnormal situation,
such as a power failure, that requires immediate attention from the computer,
an attempt to execute an illegal instruction, a request for service from a
network controller, or the completion of an I/O task initiated by the program:
all of these suggest that it is necessary to include some means to allow the
computer to take special actions when required. As you will see shortly,
interrupt capabilities are also used to make it possible to time-share the CPU between
several different programs or program segments at once. Computers provide
interrupt capability by providing one or more special control lines to the
central processor known as interrupt lines. For example, the standard
I/O for a modern PC may contain as many as thirty-two interrupt lines, labeled
IRQ0 through IRQ31. (IRQ stands for Interrupt ReQuest.) The messages sent to
the computer on these lines are known as interrupts. The presence of a message
on an interrupt line will cause the computer to suspend the program being
executed and jump to a special interrupt processing program. Interrupt messages
are triggered primarily by the various I/O controllers in the system.
The Uses of Interrupts
The
way in which an interrupt is used depends on the nature of the device. You’ve
already seen that externally controlled inputs, such as a mouse click, are best
handled by generating interrupts whenever action is required. In other cases,
interrupts occur when some action is completed. This section introduces
several different ways in which interrupts are used.
THE
INTERRUPT AS AN EXTERNAL EVENT NOTIFIER As previously discussed, interrupts are
useful as notifiers to the CPU of external events that require action.
This frees the CPU from the necessity of continuously checking the various
input devices, a method called polling, to determine that input data is
waiting.
THE
INTERRUPT AS A COMPLETION SIGNAL The keyboard and transducer examples demonstrate
the usefulness of the interrupt as a means for the user to control the computer
from an input device, in this case the keyboard or transducer. Let us next
consider the interrupt technique as a means of controlling the flow of data to
an output device. Here, the interrupt serves to notify the computer of the
completion of a particular course of action.
THE
INTERRUPT AS A MEANS OF ALLOCATING CPU TIME A third major application for
interrupts is to use the interrupt as amethod of allocating CPU time to different
programs or threads that are sharing the CPU. (Threads are small pieces of a
program that can be executed independently, such as the spell checker in a
word-processing program.)
THE
INTERRUPT AS AN ABNORMAL EVENT INDICATOR The fourth major use for interrupts
is to handle abnormal events that affect operation of the computer
system itself. Under certain conditions, we would like the computer to respond
with a specific course of action quickly and effectively. This usage is similar
to that of other external input events, but in this case, the events are
directed at problems or special conditions within the computer system itself. One
obvious example of an external event requiring special computer action is power
failure. Most computers provide enough internal power storage to save the work
that is being performed and to shut down gracefully, provided that the computer
has quick notification of the power failure. A power line monitor that connects
to the interrupt facility provides this capability. The interrupt routine will
save the status of programs that are in memory, close open files, and perform
other housekeeping operations that will allow the computer to restart without
any loss of data. It will then halt the computer. Another important application
of the abnormal event interrupt is when a program attempts to execute an
illegal instruction such as a divide by 0 or a nonexistent op code, or when
a hardware error is detected, such as a memory parity error. When the error
occurs, it is not possible to complete the executing program. Yet it is
important that the system attempt to recover from the error and that the
appropriate personnel be notified. It is not acceptable simply to halt the
computer. Particularly in modern multitasking computer systems this would be
undesirable since it would also stop other executing programs that might not be
affected by the error and would affect other users if the system is a multiuser
system. Instead, an interrupt routine can notify the user of the error and
return control of the CPU to the operating system program. You should notice
that these interrupts are actually generated from inside the CPU, whereas the
other interrupts that we have discussed so far are generated externally.
Internal interrupts are sometimes called traps or exceptions.
SOFTWARE
INTERRUPTS In
addition to the actual hardware interrupts already discussed, modern CPU
instruction sets include an instruction that simulates an interrupt. In the
Intel x86 architecture, for example, this instruction has the mnemonic INT, for
Interrupt. The IBM System z uses the mnemonic SVC for SUPERVISOR CALL.
The interrupt instruction works in the same way as hardware interrupt, saving
appropriate registers and transferring control to an interrupt handling
procedure. The address space of the INT instruction can be used to provide a parameter
that specifies which interrupt is to be executed. The software interrupt is
very similar to a subroutine jump to a known, fixed location.
I/O
CONTROLLERS
A major role is played by the disk controller. The disk controller is, of course, an example of an I/O controller. The I/O controller serves as an interface between the CPU and the specific device, in this case a disk drive, accepting commands from the CPU on one side and controlling the device on the other. In this example, the disk controller provides the following functions:
1. The disk controller recognizes messages addressed to it and accepts commands from the CPU, establishing what the disk drive is to do. In this case, the disk controller recognizes that a block of data is to be written from memory to disk using DMA.
2. The disk controller provides a buffer where the data from memory can be held until it can be transferred to the disk.
3. The disk controller provides the necessary registers and controls to perform a direct memory transfer. This requires that the disk controller have access to a memory address register and a memory data register separate from those of the CPU, either within the disk controller or as a separate DMA controller.
4. The disk controller controls the disk drive, moving the head to the physical location on the disk where data is to be written. The disk controller copies data from its buffer to the disk.
5. The disk controller has interrupt capability, which it uses to notify the CPU when the transfer is complete. It can also interrupt the CPU to notify it of errors or problems that arise during the transfer.
The use of separate I/O controllers offers several benefits:
1. The controller can be designed to provide the specialized control required by a particular device.
2. The controller frees the CPU to perform other tasks while the much slower I/O operations are taking place.
3. The presence of I/O controllers allows control of several different I/O devices to occur simultaneously.
4.
4. A
processor-based controller can provide specialized services that would
otherwise overload the system CPU with time-consuming CPU-intensive work. For
example, a high-end graphics display controller can decode compressed and
encrypted MPEG video or adjust images for lighting and shading effects.
0 Comments