Problem 3.
Real Virtuality, Inc markets three different computers, each with its
own operating system. The systems are:
Model A: A timeshared,multi-user Beta system whose OS kernel is
uninterruptable.
Model B: A timeshared Beta system which enables device
interrupts during handling of SVC traps.
Model C: A single-process (not timeshared) system which
runs dedicated application code.
Each system runs an operating system that supports concurrent I/O
on several devices, including an operator's console including a
keyboard. Les N. Dowd, RVI's newly-hired OS expert, is in a jam: he
has dropped the shoebox containing the master copies of OS source for
all three systems. Unfortunately, three disks containing handlers for
the ReadKey SVC trap, which reads and returns the ASCII code for the
next key struck on the keyboard, have gotten confused. Of course, they
are unlabeled, and Les isn't sure which handler goes into the OS for
which machine. The handler sources are
ReadCh_h() { /* VERSION R1 */
if (BufferEmpty(0)) /* Has a key been typed? */
User->Regs[XP] = User->Regs[XP]-4; /* Nope, wait. */
else
User->Regs[0] = ReadInputBuffer(0); /* Yup, return it. */
}
ReadCh_h() { /* VERSION R2 */
int kbdnum=ProcTbl[Cur].DpyNum;
while (BufferEmpty(kbdnum)) ; /* Wait for a key to be hit*/
User->Regs[0] = ReadInputBuffer(kbdnum); /*...then return it. */
}
ReadCh_h() { /* VERSION R3 */
int kbdnum=ProcTbl[Cur].DpyNum;
if (BufferEmpty(kbdnum)) { /* Has a key been typed? */
User->Regs[XP] = User->Regs[XP]-4; /* Nope, wait. */
Scheduler();
} else
User->Regs[0] = ReadInputBuffer(kbdnum); /* Yup, return it. /
}
-
Show that you're cleverer than Les by figuring out which handler goes
with each OS, i.e., for each operating system (A, B and C) indicate
the proper handler (R1, R2 or R3). Briefly explain your choices.
R1 goes with C. This handler hardwires the keyboard to port 0, so it must be Model C.
R2 goes with B. This handler is for a timeshared system, but does
not yield when waiting so the SVC must be interruptible.
R3 goes with A. This handler is also for a timeshared system, but
calls the scheduler before waiting so the kernel may not interrupt the
handler on its own.
-
But Les isn't that clever. In order to figure out which handler code
goes with each OS version, Les makes copies of each disk and
distributes them as "updates" to beta-test teams for each OS. Les
figures that if each handler version is tried by some beta tester in
each OS, the comments of the testers will allow him to determine the
proper OS for each handler.
Les sends out the alleged source code updates, routing each handler
source to testers for each OS. In response, he gets a barrage of
complaints from many of the testers. Of course, he's forgotten which
disk he sent to each tester. He asks your help to figure out which
combination of system and hander causes each of the complaints. For
each complaint below, explain which handler and which OS the
complainer is trying to use.
Complaint: "I get linkage errors; Scheduler and ProcTbl are undefined!"
Handler R3 and OS C. R3 is the only handler using Scheduler and C is
the only kernel without it
-
Complaint: "I can link up the system using the new handler, but the
system hangs when my application tries to read a key."
Handler R2 and OS A. R2 is the only handler that won't yield if no
key is available and A is the only kernel that timeshares but has
interrupts disabled when running in kernel mode (so the loop in the
R2 handler that waits for a key to be hit can never be interrupted).
-
Complaint: "Hey, now the system always reads everybody's input from
keyboard 0. Besides that, it seems to waste a lot more CPU cycles than
it used to."
Handler R1 and OS A. R1 is the only handler that assumes keyboard 0.
The model A user was using a handler (R3) which called scheduler when
the buffer was empty which in theory wastes fewer CPU cycles than busy
looping. So when the user substitutes R1, the program busy loops when
the buffer is empty. The model B user wouldn't have the same
complaint since the handler she was using (R2) already loops.
-
Complaint: "Neat, the new system seems to work fine. It even seems to
waste less CPU time than it used to!"
Handler R3 and OS B. The model B user is happy because we've replaced
her kernel busy loop in her old handler (R2) with a call to
Scheduler().