WEBVTT

00:00:00.650 --> 00:00:04.059
Here’s an old quiz
problem we can use to test

00:00:04.059 --> 00:00:06.260
our understanding of all
the factors that went

00:00:06.260 --> 00:00:10.900
into the final design of
our ReadKey() SVC code.

00:00:10.900 --> 00:00:13.400
We’re considering three
different versions (R1, R2,

00:00:13.400 --> 00:00:16.920
and R3) of the
ReadKey() SVC code,

00:00:16.920 --> 00:00:20.040
all variants of the various
attempts from the previous

00:00:20.040 --> 00:00:21.610
section.

00:00:21.610 --> 00:00:26.160
And there are three types of
systems (Models A, B, and C).

00:00:26.160 --> 00:00:28.420
We’ve been asked to
match the three handlers

00:00:28.420 --> 00:00:30.760
to the appropriate system.

00:00:30.760 --> 00:00:33.830
Looking at R1, we see it’s
similar to Attempt #2 from

00:00:33.830 --> 00:00:37.510
the previous section, except
it always reads from the same

00:00:37.510 --> 00:00:42.140
keyboard regardless of the
process making the SVC request.

00:00:42.140 --> 00:00:45.830
That wouldn’t make much sense
in a timesharing system since

00:00:45.830 --> 00:00:48.780
a single stream of input
characters would be shared

00:00:48.780 --> 00:00:50.870
across all the processes.

00:00:50.870 --> 00:00:55.140
So this handler must be intended
for the Model C system, which

00:00:55.140 --> 00:00:58.660
has only a single process.

00:00:58.660 --> 00:01:01.710
Looking at R2, we see it’s
similar to Attempt #1 from

00:01:01.710 --> 00:01:05.500
the previous section, which had
the fatal flaw of a potentially

00:01:05.500 --> 00:01:09.730
infinite loop if attempting
to read from an empty buffer.

00:01:09.730 --> 00:01:13.290
So this code would only run
successfully on the Model B

00:01:13.290 --> 00:01:17.170
system, which *does* allow
device interrupts even when

00:01:17.170 --> 00:01:20.760
the CPU is running
inside an SVC call.

00:01:20.760 --> 00:01:23.550
So the keyboard interrupt would
interrupt the while loop in R2

00:01:23.550 --> 00:01:26.000
and the next
iteration of the loop

00:01:26.000 --> 00:01:29.840
would discover that buffer
was no longer empty.

00:01:29.840 --> 00:01:32.240
By the process of
elimination that

00:01:32.240 --> 00:01:37.950
leaves the R3 handler to be
paired with the Model A system.

00:01:37.950 --> 00:01:40.620
R3 is Attempt #3 from
the previous section

00:01:40.620 --> 00:01:44.120
and is designed for our standard
system in which the kernel is

00:01:44.120 --> 00:01:46.720
uninterruptible.

00:01:46.720 --> 00:01:49.100
The problem goes on to say
that a fumble-fingered summer

00:01:49.100 --> 00:01:51.960
intern has jumbled up the
disks containing the handlers

00:01:51.960 --> 00:01:53.790
and sent an unknown
handler version

00:01:53.790 --> 00:01:57.990
to each user running one
of the three model systems.

00:01:57.990 --> 00:02:00.810
To atone for the mistake,
he’s been assigned the task

00:02:00.810 --> 00:02:04.360
of reading various user messages
sent after the user has tried

00:02:04.360 --> 00:02:08.289
the new handler disk on
their particular system.

00:02:08.289 --> 00:02:11.830
Based on the message, he’s been
asked to identify which handler

00:02:11.830 --> 00:02:15.430
disk and system
the user is using.

00:02:15.430 --> 00:02:18.420
The first message says “I
get compile-time errors;

00:02:18.420 --> 00:02:22.870
Scheduler and ProcTbl
are undefined!”

00:02:22.870 --> 00:02:25.780
On the right of the slide we’ve
included a table enumerating

00:02:25.780 --> 00:02:28.500
all the combinations of
handlers and systems,

00:02:28.500 --> 00:02:32.460
where we’ve X-ed the matches
from the previous slide

00:02:32.460 --> 00:02:35.800
since they correspond to
when the new handler would be

00:02:35.800 --> 00:02:38.740
the same as the old handler and
the user wouldn’t be sending

00:02:38.740 --> 00:02:40.970
a message!

00:02:40.970 --> 00:02:44.680
The phrase “Scheduler and
ProcTbl are undefined” wouldn’t

00:02:44.680 --> 00:02:49.130
apply to a timesharing system,
which includes both symbols.

00:02:49.130 --> 00:02:53.260
So we can eliminate the first
two columns from consideration.

00:02:53.260 --> 00:02:55.690
And we can also
eliminate the second row,

00:02:55.690 --> 00:03:00.540
since handler R2 doesn’t
include a call to Scheduler.

00:03:00.540 --> 00:03:03.000
So this message came
from a user trying

00:03:03.000 --> 00:03:07.210
to run handler R3
on a Model C system.

00:03:07.210 --> 00:03:09.480
Since Model C doesn’t
support timesharing,

00:03:09.480 --> 00:03:13.580
it would have neither Scheduler
nor ProcTbl as part the OS

00:03:13.580 --> 00:03:16.150
code.

00:03:16.150 --> 00:03:18.680
Okay, here’s the
next message: “Hey,

00:03:18.680 --> 00:03:22.430
now the system always reads
everybody’s input from keyboard

00:03:22.430 --> 00:03:23.680
0.

00:03:23.680 --> 00:03:27.070
Besides that, it seems to waste
a lot more CPU cycles than it

00:03:27.070 --> 00:03:28.980
used to.”

00:03:28.980 --> 00:03:32.430
R1 is the only handler that
always reads from keyboard 0,

00:03:32.430 --> 00:03:35.760
so we can eliminate
rows 2 and 3.

00:03:35.760 --> 00:03:39.520
So how can we tell if R1
is being run on a Model

00:03:39.520 --> 00:03:42.610
A or a Model B system?

00:03:42.610 --> 00:03:44.960
The R1 handler wastes
a lot of cycles

00:03:44.960 --> 00:03:47.790
looping while waiting
for a character to arrive

00:03:47.790 --> 00:03:51.580
and the implication is that
was a big change for the user

00:03:51.580 --> 00:03:54.560
since they’re complaining that
running R1 is wasting time

00:03:54.560 --> 00:03:57.550
compared to their
previous handler.

00:03:57.550 --> 00:04:01.100
If the user had been running
R2 on a model B system,

00:04:01.100 --> 00:04:04.300
they’re already used to the
performance hit of looping

00:04:04.300 --> 00:04:07.050
and so wouldn’t have noticed
a performance difference

00:04:07.050 --> 00:04:11.060
switching to R1, so we
can eliminate Model B from

00:04:11.060 --> 00:04:13.170
consideration.

00:04:13.170 --> 00:04:16.500
So this message came from
a user running handler R1

00:04:16.500 --> 00:04:20.260
on a model A system.

00:04:20.260 --> 00:04:23.590
The final message reads “Neat,
the new system seems to work

00:04:23.590 --> 00:04:24.590
fine.

00:04:24.590 --> 00:04:28.760
It even wastes less CPU
time than it used to!”

00:04:28.760 --> 00:04:32.030
Since the system works as
expected with the new handler,

00:04:32.030 --> 00:04:36.020
we can eliminate a
lot of possibilities.

00:04:36.020 --> 00:04:39.770
Handler R1 wouldn’t work fine
on a timesharing system since

00:04:39.770 --> 00:04:43.570
the user could tell that the
processes were now all reading

00:04:43.570 --> 00:04:46.530
from the same keyboard
buffer, so we can eliminate R1

00:04:46.530 --> 00:04:49.500
on Models A and B.

00:04:49.500 --> 00:04:54.180
And handlers R2 and R3 wouldn’t
work on a Model C system since

00:04:54.180 --> 00:04:57.250
that doesn’t include process
tables or scheduling,

00:04:57.250 --> 00:05:00.650
eliminating the
right-most column.

00:05:00.650 --> 00:05:04.940
Finally handler R2 wouldn’t work
on a Model A system with its

00:05:04.940 --> 00:05:08.910
uninterruptible kernel since any
attempt to read from an empty

00:05:08.910 --> 00:05:12.150
buffer would cause
an infinite loop.

00:05:12.150 --> 00:05:14.940
So, the message must have
been sent by a Model B

00:05:14.940 --> 00:05:16.430
user now running R3.

00:05:16.430 --> 00:05:19.560
Well, that was fun!

00:05:19.560 --> 00:05:22.260
Just like solving the logic
puzzles you find in games

00:05:22.260 --> 00:05:24.060
magazines :)