Updating Repository and General Setup
You no longer need your code from Homework 4, as you'll be working with your cloned Homework 5 repository.
Cloning the Repository
After accepting the assignment on GitHub Classroom, you'll need to clone the repository to your CS 134 server account. Here's how you do it:
- Go to your repository on GitHub.
- Click the green button that says .
- You'll see a URL; copy that URL (the easiest way is to click the button that looks like two overlapping rectangles (i.e., select_window_2)).
- Open VS Code.
- Click on the button in the lower-left corner. In the pop-up menu, select and enter
for the host (whereusername @cs134.cs.hmc.eduusername is replaced by your CS 134 server username from Homework 1). When prompted, enter your server password. - On the sidebar of your VS Code window, click the “Explorer” icon (looks like two overlapping pieces of paper) or the “Source Control” icon (looks like three circles connected by two lines).
- Click .
- In the text box at the top of the window, paste the URL you copied from GitHub.
- Now edit the path to choose a place to save the cloned repo. We recommend using the
cs134directory that is already in your home directory. - VS Code will download the repository and ask if you want to open the repository. Say yes!
Selecting OS/161 Mode in VS Code
In the bottom right corner of your VS Code window (directly to the left of the bell icon notifications ) there is a “C/C++ Configuration” button, which will probably say “Linux”. Click that button, and a drop-down menu from the Command Palette will allow you to select a configuration. Choose “OS/161”, and the C/C++ Configuration button should change to read “OS/161”. VS Code's “IntelliSense” should now work properly with the OS/161 code.
Building the OS/161 User-Space Tools
As you did with HW 4, you'll need to build OS/161's user-space tools and kernel.
Run
./setup
to build the user-space tools.
Running ./setup can take a few moments depending on how busy the server is. Remember that you can skip ahead to do some of the reading parts of the assignment while you are waiting for some code to compile.
The build process should finish with a message like
Base system installed in /home/username /cs134/repo-name /root
Now you need to configure and build the kernel.
where
Building the OS/161 Kernel
For this assignment, you will configure the build using the SCHED configuration file. Make sure that your current directory is ~/cs134/, and then run
cd src/kern/conf
./config SCHED
cd ../compile/SCHED
bmake depend
and then build the kernel with
cd ../../../../root
cd - ; bmake && bmake install ; cd -
Testing the Kernel
Once it's built, you can test it by changing your directory to your virtual root directory and run the kernel with
sys161 kernel
(You can also do cd ~/cs134/ (where
Checking in with the Kernel
The kernel has improved a great deal since we started Homework 4. Specifically,
- All of Homework 4's functionality is implemented, including the above-and-beyond feature of adding
-1as an argument towaitpid.- It's now possible to run useful programs from the shell, which supports I/O redirection with
<fileor>fileand backgrounding with&.
- It's now possible to run useful programs from the shell, which supports I/O redirection with
- The
wait4system call is implemented. - Shell now reports user and system time for each command you run (i.e, the time the CPU spent in user code and the time it spent in the kernel on behalf of the command, including any children).
- The
nanosleepsystem call is implemented (badly, but it's there). - A new program,
sleepyecho, is available to testnanosleep- The usage is
sleepyecho <microsecs> arg1 arg2 ...where<microsecs>is the number of microseconds to sleep before echoing each argument (microseconds because using nanoseconds would be more typing for little benefit).
- The usage is
Start the kernel with sys161 kernel, then use the menu's s command to start the shell, and run some commands like
hw4testto test the functionality from the previous assignment.add 14 28to add two numbers.hogto run a command that hogs the CPU for about eight seconds doing calculations.sleepyecho 250000 Oh, uh, isn't that new? ... Yes it is, do you like it?to test thenanosleepsystem call.1
sys161: System/161 release 2.0.3, compiled Jul 25 2024 16:47:30
OS/161 base system version 2.0.3
Copyright (c) 2000, 2001-2005, 2008-2011, 2013, 2014
President and Fellows of Harvard College. All rights reserved.
Our work-in-progress OS/161 system version 0 (SYSCALLS #112)
1808k physical memory available
Device probe...
lamebus0 (system main bus)
emu0 at lamebus0
ltrace0 at lamebus0
ltimer0 at lamebus0
beep0 at ltimer0
rtclock0 at ltimer0
lrandom0 at lamebus0
random0 at lrandom0
lhd0 at lamebus0
lhd1 at lamebus0
lser0 at lamebus0
con0 at lser0
cpu0: MIPS/161 (System/161 2.x) features 0x0
OS/161 kernel [? for menu]: s
/bin/sh: Timing enabled.
OS/161$ sleepyecho 250000 Oh, uh, isn't that new? ... Yes it is, do you like it?
Oh, uh, isn't that new? ... Yes it is, do you like it?
/bin/sh: subprocess user time: 0.001271 seconds, system time: 0.024736 seconds, real time: 3.447245 seconds
OS/161$ hw4test >hw4test.out
**********
* write() works for stderr
/bin/sh: subprocess user time: 0.073780 seconds, system time: 0.315039 seconds, real time: 2.452130 seconds
OS/161$ add 35 7
Answer: 42
/bin/sh: subprocess user time: 0.000889 seconds, system time: 0.014130 seconds, real time: 0.116180 seconds
OS/161$ hog &
[6] hog ... &
OS/161$ add 19 23
Answer: 42
/bin/sh: subprocess user time: 0.000890 seconds, system time: 0.014132 seconds, real time: 0.116497 seconds
pid 6: Exit 0 (user time 8.408489, system time 0.016842)
OS/161$ exit
Program exited with status 0.
Operation took 183.189776120 seconds
OS/161 kernel [? for menu]: q
Shutting down.
The system is halted.
sys161: 4941213733 cycles (313825446 run, 4627388287 global-idle)
sys161: cpu0: 23648915 kern, 210249760 user, 0 idle; 36721 ll, 36721/0 sc, 149246 sync
sys161: 2855 irqs 9384 exns 0r/0w disk 71r/1326w console 48r/373w/17m emufs 0r/0w net
sys161: Elapsed real time: 187.412347 seconds (26.3655 mhz)
sys161: Elapsed virtual time: 197.652851863 seconds (25 mhz)
You can also run sys161 -c sys161-m.conf kernel with an alternate configuration file that provides an 8-core machine rather than a single-core machine.
sys161: System/161 release 2.0.3, compiled Jul 25 2024 16:47:30
OS/161 base system version 2.0.3
Copyright (c) 2000, 2001-2005, 2008-2011, 2013, 2014
President and Fellows of Harvard College. All rights reserved.
Our work-in-progress OS/161 system version 0 (SYSCALLS #112)
1808k physical memory available
Device probe...
lamebus0 (system main bus)
emu0 at lamebus0
ltrace0 at lamebus0
ltimer0 at lamebus0
beep0 at ltimer0
rtclock0 at ltimer0
lrandom0 at lamebus0
random0 at lrandom0
lhd0 at lamebus0
lhd1 at lamebus0
lser0 at lamebus0
con0 at lser0
cpu0: MIPS/161 (System/161 2.x) features 0x0
cpu1: MIPS/161 (System/161 2.x) features 0x0
cpu2: MIPS/161 (System/161 2.x) features 0x0
cpu3: MIPS/161 (System/161 2.x) features 0x0
cpu4: MIPS/161 (System/161 2.x) features 0x0
cpu5: MIPS/161 (System/161 2.x) features 0x0
cpu6: MIPS/161 (System/161 2.x) features 0x0
cpu7: MIPS/161 (System/161 2.x) features 0x0
OS/161 kernel [? for menu]: s
/bin/sh: Timing enabled.
OS/161$ farm >farm.out
/bin/sh: subprocess user time: 25.225949 seconds, system time: 0.147329 seconds, real time: 8.726030 seconds
OS/161$ exit
Program exited with status 0.
Operation took 26.344074996 seconds
OS/161 kernel [? for menu]: q
Shutting down.
cpu0: offline.
cpu2: offline.
cpu6: offline.
cpu7: offline.
cpu5: offline.
cpu4: offline.
cpu3: offline.
The system is halted.
sys161: 753724784 cycles (277625427 run, 476099357 global-idle)
sys161: cpu0: 11653353 kern, 210015408 user, 4576092 idle; 17868 ll, 17868/0 sc, 78492 sync
sys161: cpu1: 7039170 kern, 210003963 user, 9201720 idle; 4779 ll, 4778/1 sc, 10649 sync
sys161: cpu2: 4998364 kern, 210000055 user, 11246434 idle; 1929 ll, 1928/1 sc, 34994 sync
sys161: cpu3: 4060222 kern, 0 user, 222184631 idle; 447 ll, 444/3 sc, 1303 sync
sys161: cpu4: 4060349 kern, 0 user, 222184504 idle; 447 ll, 443/4 sc, 1303 sync
sys161: cpu5: 4060476 kern, 0 user, 222184377 idle; 447 ll, 442/5 sc, 29908 sync
sys161: cpu6: 4060603 kern, 0 user, 222184250 idle; 446 ll, 441/5 sc, 31954 sync
sys161: cpu7: 4060278 kern, 0 user, 222184575 idle; 446 ll, 440/6 sc, 31948 sync
sys161: 4381 irqs 805 exns 0r/0w disk 24r/1298w console 61r/9w/17m emufs 0r/0w net
sys161: Elapsed real time: 27.388047 seconds (27.5202 mhz)
sys161: Elapsed virtual time: 30.153282203 seconds (25 mhz)
The farm program runs three hog processes and a cat process in the background, and then waits for them to finish. As you can see, even though 25.2 seconds of CPU time was used, the real time was only 8.7 seconds.
-
The sample text printed in the
sleepyechocommand is taken from the Alfred Hitchcock movie Rope, as sampled in the track “Intro” for Young American Primitive's eponymous album. ↩
(When logged in, completion status appears here.)