CSCI 3323 (Principles of Operating Systems), Fall 2011:
Homework 7
- Credit:
- 20 points.
Be sure you have read Chapter 5.
Answer the following questions. You may write out your answers by
hand or using a word processor or other program, but please submit
hard copy, either in class or in my mailbox in the department office.
- (5 points)
Consider the following two I/O devices. For each device,
say whether you think programmed I/O or interrupt-driven I/O
makes the most sense, and justify your answer.
(Hint: Consider the time required for interrupt
processing versus the time needed for the actual
input/output operation.)
- A printer that prints at a maximum rate of
400 characters per second,
connected to a computer system in which writing to
the printer's output register takes essentially no time,
and using interrupt-driven I/O means that
each character printed requires an interrupt that
takes a total of 50 microseconds (i.e.,
seconds) to process.
- A simple memory-mapped video terminal (output only),
connected to a system where interrupts take a minimum of 100 nsec
to process and copying a byte
into the terminal's video RAM takes 10 nsec.
- (5 points)
Consider a system that uses its local area network as
follows. An application program makes a system call
to write data packets (each 1024 bytes, ignoring headers)
to the network.
The operating system first copies the data to be sent
to a kernel buffer. Working on one packet at a time,
it then copies the data to the network controller.
When all 1024 bytes have been copied to the network
controller, it sends them over the network at a rate
of 10 megabits (
bits)
per second. The receiving controller
receives each bit a microsecond after it is sent.
When the last bit in the packet is received, the destination
CPU is interrupted, and its operating system copies
the packet into a kernel buffer, inspects it, and
copies it into a buffer owned by the application program
that should receive it. It then sends back an acknowledgment
(assume one bit)
to the sending computer, which interrupts the sending CPU,
and work can begin on the next packet.
How long does it take to send each packet, if it takes
one millisecond to process an interrupt (on either CPU) and
one microsecond to copy a byte? Assume that the time taken
for the receiving CPU to inspect the packet is negligible.
What is the effective
transfer rate (in bits per second) over this connection?
(Hints: Notice that some times are per bit and some
are per byte. If you think you need to make additional
assumptions, do so and explain them. If you show your
calculations and briefly explain what you are doing, your
odds of getting partial credit are better.)
- (5 points)
The textbook divides the many routines that make up
an operating system's I/O software into four layers.
In which of these layers
should each of the following be done? Why?
(Assume that in general
functionality should be provided at the highest level
at which it makes sense -- e.g., in user-level
software rather than device-independent software.)
- Converting floating-point numbers to ASCII for
printing.
- Computing the track, sector, and head for
a disk read operation.
- Writing commands to a printer controller's device
registers.
- Detecting that an application program is attempting
to write data from an invalid buffer address.
(Assume that detecting an invalid buffer address
can only be done in supervisor mode.)
- (5 points)
Suppose at a given point in time a disk driver has in its
queue requests to read cylinders 10, 22, 20, 2, 40, 6, and
38, received in that order. If a seek takes 5 milliseconds
(i.e.,
seconds)
per cylinder moved, and the arm is initially at cylinder 20,
how much seek time is needed to process
these requests using each of the three scheduling
algorithms discussed (FCFS, SSF, and elevator)?
Assume that no other requests arrive while these are being
processed and that for the elevator algorithm the
initial direction of movement is outward (toward
larger cylinder numbers).
For extra credit,
do one or more of the following programming problems.
You will end up with at least one code file per problem.
Submit your program source (and any other needed files)
by sending mail to
bmassing@cs.trinity.edu,
with each file as an attachment.
Please use a subject line that mentions the course number and
the assignment (e.g., ``csci 3323 homework 7'').
You can develop your programs on any system that provides the
needed functionality, but I will test them on one of the department's
Linux machines, so you should probably make sure they work
in that environment before turning them in.
- (Up to 5 extra-credit points).
The Linux lab machines have special files
/dev/random and
/dev/urandom that generate sequences of ``random'' bytes.
(Read the man page for urandom for an explanation of
the difference between them.)
Write a program that compares the results of generating
integers using one or both of these special files to the results
of generating
integers using function rand().
(It's up to you to decide how to compare them.
A simple test might be to count how many are even and how
many are odd. You may have a better idea!)
Submit your source code and a text file containing output
of one or more executions.
(Hint:
You will probably need to use open
and read rather than fopen and fscanf
to read from the special file. man pages for these
two functions can be found via
man 2 open and man 2 read.)
Berna Massingill
2011-11-28