Clarifications.
[pintos-anon] / doc / threads.texi
index 9138daf5e12082273d00fdc667cc6618c7a6448b..ac9ccd43cef23abedec89ab50b69e7fa1c79c258 100644 (file)
@@ -77,10 +77,8 @@ single-step from there.@footnote{@command{gdb} might tell you that
 @func{schedule} doesn't exist, which is arguably a @command{gdb} bug.
 You can work around this by setting the breakpoint by filename and
 line number, e.g.@: @code{break thread.c:@var{ln}} where @var{ln} is
-the line number of the first declaration in @func{schedule}.
-Alternatively you can recompile with optimization turned off, by
-removing @samp{-O3} from the @code{CFLAGS} line in
-@file{Make.config}.}  Be sure to keep track of each thread's address
+the line number of the first declaration in @func{schedule}.}  Be sure
+to keep track of each thread's address
 and state, and what procedures are on the call stack for each thread.
 You will notice that when one thread calls @func{switch_threads},
 another thread starts running, and the first thing the new thread does
@@ -295,7 +293,8 @@ program twice and have it do exactly the same thing.  On second and
 later runs, you can make new observations without having to discard or
 verify your old observations.  This property is called
 ``reproducibility.''  The simulator we use, Bochs, can be set up for
-reproducibility, and that's the way that @command{pintos} invokes it.
+reproducibility, and that's the way that @command{pintos} invokes it
+by default.
 
 Of course, a simulation can only be reproducible from one run to the
 next if its input is the same each time.  For simulating an entire
@@ -313,50 +312,73 @@ thread switches.  That means that running the same test several times
 doesn't give you any greater confidence in your code's correctness
 than does running it only once.
 
-So, to make your code easier to test, we've added a feature to Bochs
-that makes timer interrupts come at random intervals, but in a
-perfectly predictable way.  In particular, if you invoke
-@command{pintos} with the option @option{-j @var{seed}}, timer
+So, to make your code easier to test, we've added a feature, called
+``jitter,'' to Bochs, that makes timer interrupts come at random
+intervals, but in a perfectly predictable way.  In particular, if you
+invoke @command{pintos} with the option @option{-j @var{seed}}, timer
 interrupts will come at irregularly spaced intervals.  Within a single
 @var{seed} value, execution will still be reproducible, but timer
 behavior will change as @var{seed} is varied.  Thus, for the highest
 degree of confidence you should test your code with many seed values.
 
+On the other hand, when Bochs runs in reproducible mode, timings are not
+realistic, meaning that a ``one-second'' delay may be much shorter or
+even much longer than one second.  You can invoke @command{pintos} with
+a different option, @option{-r}, to make it set up Bochs for realistic
+timings, in which a one-second delay should take approximately one
+second of real time.  Simulation in real-time mode is not reproducible,
+and options @option{-j} and @option{-r} are mutually exclusive.
+
 @node Tips
 @section Tips
 
+@itemize @bullet
+@item
 There should be no busy-waiting in any of your solutions to this
-assignment.  Furthermore, resist the temptation to directly disable
-interrupts in your solution by calling @func{intr_disable} or
+assignment.
+
+@item
+Do your best to resist the temptation to directly disable interrupts
+in your solution by calling @func{intr_disable} or
 @func{intr_set_level}, although you may find doing so to be useful
 while debugging.  Instead, use semaphores, locks and condition
-variables to solve synchronization problems.  Hint: read the comments
-in @file{threads/synch.h} if you're unsure what synchronization
+variables to solve synchronization problems.  Read the tour section on
+synchronization (@pxref{Synchronization}) or the comments in
+@file{threads/synch.h} if you're unsure what synchronization
 primitives may be used in what situations.
 
 Given some designs of some problems, there may be one or two instances
 in which it is appropriate to directly change the interrupt levels
-instead of relying on the given synchroniztion primitives.  This must
+instead of relying on the given synchronization primitives.  This must
 be justified in your @file{DESIGNDOC} file.  If you're not sure you're
 justified, ask!
 
-While all parts of this assignment are required if you intend to earn
-full credit on this project, keep in mind that Problem 1-2 (Join) will
-be needed for future assignments, so you'll want to get this one
-right.  We don't give out solutions, so you're stuck with your Join
-code for the whole quarter.  Problem 1-1 (Alarm Clock) could be very
-handy, but not strictly required in the future.  The upshot of all
-this is that you should focus heavily on making sure that your
-implementation of @func{thread_join} works correctly, since if it's
-broken, you will need to fix it for future assignments.  The other
-parts can be turned off in the future if you find you can't make them
-work quite right.
-
-Also keep in mind that Problem 1-4 (the MLFQS) builds on the features you
-implement in Problem 1-3, so to avoid unnecessary code duplication, it
+@item
+All parts of this assignment are required if you intend to earn full
+credit on this project.  However, some will be more important in
+future projects:
+
+@itemize @minus
+@item
+Problem 1-1 (Alarm Clock) could be handy for later projects, but it is
+not strictly required.
+
+@item
+Problem 1-2 (Join) will be needed for future projects.  We don't give
+out solutions, so to avoid extra work later you should make sure that
+your implementation of @func{thread_join} works correctly.
+
+@item
+Problems 1-3 and 1-4 won't be needed for later projects.
+@end itemize
+
+@item
+Problem 1-4 (MLFQS) builds on the features you
+implement in Problem 1-3.  To avoid unnecessary code duplication, it
 would be a good idea to divide up the work among your team members
 such that you have Problem 1-3 fully working before you begin to tackle
 Problem 1-4.
+@end itemize
 
 @node Problem 1-1 Alarm Clock
 @section Problem 1-1: Alarm Clock
@@ -378,11 +400,21 @@ advanced far enough.  This is undesirable because it wastes time that
 could potentially be used more profitably by another thread.  Your
 solution should not busy wait.
 
-The argument to @func{timer_sleep} is expressed in timer ticks, not
-in milliseconds or another unit.  There are @code{TIMER_FREQ} timer
+The argument to @func{timer_sleep} is expressed in timer ticks, not in
+milliseconds or any another unit.  There are @code{TIMER_FREQ} timer
 ticks per second, where @code{TIMER_FREQ} is a macro defined in
 @code{devices/timer.h}.
 
+Separate functions @func{timer_msleep}, @func{timer_usleep}, and
+@func{timer_nsleep} do exist for sleeping a specific number of
+milliseconds, microseconds, or nanoseconds, respectively, but these will
+call @func{timer_sleep} automatically when necessary.  You do not need
+to modify them.
+
+If your delays seem too short or too long, reread the explanation of the
+@option{-r} option to @command{pintos} (@pxref{Debugging versus
+Testing}).
+
 @node Problem 1-2 Join
 @section Problem 1-2: Join
 
@@ -476,7 +508,7 @@ A partial fix for this problem is to have the waiting thread
 the lock, then recall the donation once it has acquired the lock.
 Implement this fix.
 
-You will need to account for all different orders that priority
+You will need to account for all different orders in which priority
 donation and inversion can occur.  Be sure to handle multiple
 donations, in which multiple priorities are donated to a thread.  You
 must also handle nested donation: given high, medium, and low priority
@@ -487,8 +519,9 @@ that @var{L} holds, then both @var{M} and @var{L} should be boosted to
 
 You only need to implement priority donation when a thread is waiting
 for a lock held by a lower-priority thread.  You do not need to
-implement this fix for semaphores, condition variables or joins.
-However, you do need to implement priority scheduling in all cases.
+implement this fix for semaphores, condition variables, or joins,
+although you are welcome to do so.  However, you do need to implement
+priority scheduling in all cases.
 
 You may assume a static priority for priority donation, that is, it is
 not necessary to ``re-donate'' a thread's priority if it changes
@@ -636,7 +669,8 @@ off interrupts.
 @item
 Examples of synchronization mechanisms have been presented in lecture.
 Going over these examples should help you understand when each type is
-useful or needed.
+useful or needed.  @xref{Synchronization}, for specific information
+about synchronization in Pintos.
 @end enumerate
 
 @item
@@ -653,8 +687,8 @@ wake ups.  I think it's a problem in the test program.  What gives?}
 @anchor{Out of Order 1-1}
 
 This test is inherently full of race conditions.  On a real system it
-wouldn't work perfectly all the time either.  However, you can help it
-work more reliably:
+wouldn't work perfectly all the time either.  There are a few ways you
+can help it work more reliably:
 
 @itemize @bullet
 @item
@@ -664,17 +698,11 @@ Make time slices longer by increasing @code{TIME_SLICE} in
 @item
 Make the timer tick more slowly by decreasing @code{TIMER_FREQ} in
 @file{timer.h} to its minimum value of 19.
-
-@item
-Increase the serial output speed to the maximum of 115,200 bps by
-modifying the call to @func{set_serial} in @func{serial_init_poll} in
-@file{devices/serial.c}.
 @end itemize
 
 The former two changes are only desirable for testing problem 1-1 and
 possibly 1-3.  You should revert them before working on other parts
-of the project or turn in the project.  The latter is harmless, so you
-can retain it or revert it at your option.
+of the project or turn in the project.
 
 @item
 @b{Should @file{p1-1.c} be expected to work with the MLFQS turned on?}