Modern Operating Systems by Herbert Bos ...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Showing 386-387 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 386
SEC. 5.2
PRINCIPLES OF I/O SOFTWARE
355
copy
from
user(buffer, p, count);
if (count == 0) {
enable
interrupts( );
unblock
user( );
while (
*
printer
status
reg != READY) ;
} else {
*
printer
data
register = p[0];
*
printer
data
register = p[i];
scheduler( );
count = count
1;
i = i + 1;
}
acknowledge
interrupt( );
return
from
interrupt( );
(a)
(b)
Figure 5-9.
Writing a string to the printer using interrupt-driven I/O. (a) Code
executed at the time the print system call is made.
(b) Interrupt service procedure
for the printer.
5.2.4 I/O Using DMA
An obvious disadvantage of interrupt-driven I/O is that an interrupt occurs on
every character. Interrupts take time, so this scheme wastes a certain amount of
CPU time.
A solution is to use DMA.
Here the idea is to let the DMA controller
feed the characters to the printer one at time, without the CPU being bothered.
In
essence, DMA is programmed I/O, only with the DMA controller doing all the
work, instead of the main CPU.
This strategy requires special hardware (the DMA
controller) but frees up the CPU during the I/O to do other work. An outline of the
code is given in Fig. 5-10.
copy
from
user(buffer, p, count);
acknowledge
interrupt( );
set
up
DMA
controller( );
unblock
user( );
scheduler( );
return
from
interrupt( );
(a)
(b)
Figure 5-10.
Printing a string using DMA.
(a) Code executed when the print
system call is made.
(b) Interrupt-service procedure.
The big win with DMA is reducing the number of interrupts from one per
character to one per buffer printed.
If there are many characters and interrupts are
slow, this can be a major improvement. On the other hand, the DMA controller is
usually much slower than the main CPU.
If the DMA controller is not capable of
driving the device at full speed, or the CPU usually has nothing to do anyway
while waiting for the DMA interrupt, then interrupt-driven I/O or even pro-
grammed I/O may be better.
Most of the time, though, DMA is worth it.


Page 387
356
INPUT/OUTPUT
CHAP. 5
5.3 I/O SOFTWARE LAYERS
I/O software is typically organized in four layers, as shown in Fig. 5-11. Each
layer has a well-defined function to perform and a well-defined interface to the ad-
jacent layers. The functionality and interfaces differ from system to system, so the
discussion that follows, which examines all the layers starting at the bottom, is not
specific to one machine.
User-level I/O software
Device-independent operating system software
Device drivers
Interrupt handlers
Hardware
Figure 5-11.
Layers of the I/O software system.
5.3.1 Interrupt Handlers
While programmed I/O is occasionally useful, for most I/O, interrupts are an
unpleasant fact of life and cannot be avoided. They should be hidden away, deep in
the bowels of the operating system, so that as little of the operating system as pos-
sible knows about them. The best way to hide them is to have the driver starting an
I/O operation block until the I/O has completed and the interrupt occurs. The driver
can block itself, for example, by doing a
down
on a semaphore, a
wait
on a condi-
tion variable, a
receive
on a message, or something similar.
When the interrupt happens, the interrupt procedure does whatever it has to in
order to handle the interrupt. Then it can unblock the driver that was waiting for it.
In some cases it will just complete
up
on a semaphore.
In others it will do a
signal
on a condition variable in a monitor.
In still others, it will send a message to the
blocked driver. In all cases the net effect of the interrupt will be that a driver that
was previously blocked will now be able to run. This model works best if drivers
are structured as kernel processes, with their own states, stacks, and program
counters.
Of course, reality is not quite so simple. Processing an interrupt is not just a
matter of taking the interrupt, doing an
up
on some semaphore, and then executing
an
IRET
instruction to return from the interrupt to the previous process. There is a
great deal more work involved for the operating system.
We will now give an out-
line of this work as a series of steps that must be performed in software after the
hardware interrupt has completed.
It should be noted that the details are highly


Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Great resource for chem class. Had all the past labs and assignments
Leland P.
Santa Clara University
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades

Students also viewed documents