Hide menu

Lab 0 - Pintos: Introduction and Installation:

Pintos is an instructional operating system that runs on x86 machines. You will run it in QEMU -- a computer system emulator, which runs as a user process under Unix. Pintos is written in C. The lab assignments require modification of the provided version of Pintos by adding functionality to parts of it, for instance, synchronization of threads and memory management.

Installation

First, set up necessary modules and paths by running the following commands:

        module initadd ~TDDB68/labs/modules/pintos prog/subversion
and
        module add ~TDDB68/labs/modules/pintos prog/subversion

Alternative 1 - Version controlled with Subversion (recommended)

Subversion is a version control system commonly used for maintaining software projects. It will help you to track your modifications to the source code. Also you can easily revert any changes that you realize were bad.

Step 1: The first thing you must do is to create a repository:

       svnadmin create $HOME/svnrepository

Step 2: Import the original Pintos files into it (have patience, this may take a few minutes):

       svn import /home/TDDB68/labs/original/ file://$HOME/svnrepository -m "original pintos"

Step 3: Now check out a working copy into a directory called pintos:

       svn checkout file://$HOME/svnrepository/pintos pintos
       cd pintos

Step 4: Run the following script to instruct svn to ignore some files

       ~TDDB68/labs/propset.bash

Step 5: Do not allow anyone else to read your code:

       chmod -R og-rwx $HOME/svnrepository/ $HOME/pintos

Using Subversion: Every time you wish to make a change in your working copy permanent in the repository you do:

       svn -m "commit message" commit
You should commit at least every time you are finished with an assignment.

To see the commit history try:

       svn up 
       svn log 
And to see all changes since revision rev, in a nice format, you can do:
       svn diff -x -wup -r rev 

For information on what you can do with svn, see:

       svn help [subtopic]

Compilation

 

To compile Pintos for the first time, change your current directory to the threads directory (cd pintos/src/threads) and issue the command:

        gmake

This will create build sub-directory under the threads directory with a version of Pintos ready to run in a simulator. A more detailed description of what is created in build directory during this step can be found here

Go down to the build directory and start Pintos to see that it runs:

        cd build
        pintos --qemu -- run alarm-multiple
You should get a new window with an output that ends with something similar to the following:
astmatix <313> pintos --qemu -- run alarm-multiple
Writing command line to /tmp/rCAZSDplHd.dsk...
qemu -hda /tmp/rCAZSDplHd.dsk -m 4 -net none -nographic -monitor null
Kernel command line: run alarm-multiple
Pintos booting with 4,096 kB RAM...
374 pages available in kernel pool.
374 pages available in user pool.
Calibrating timer...  2,454,400 loops/s.
Boot complete.
Executing 'alarm-multiple':
(alarm-multiple) begin
(alarm-multiple) Creating 5 threads to sleep 7 times each.
(alarm-multiple) Thread 0 sleeps 10 ticks each time,
(alarm-multiple) thread 1 sleeps 20 ticks each time, and so on.
(alarm-multiple) If successful, product of iteration count and
(alarm-multiple) sleep duration will appear in nondescending order.
(alarm-multiple) thread 0: duration=10, iteration=1, product=10
(alarm-multiple) thread 1: duration=20, iteration=1, product=20
(alarm-multiple) thread 0: duration=10, iteration=2, product=20
(alarm-multiple) thread 0: duration=10, iteration=3, product=30
(alarm-multiple) thread 2: duration=30, iteration=1, product=30
(alarm-multiple) thread 0: duration=10, iteration=4, product=40
(alarm-multiple) thread 1: duration=20, iteration=2, product=40
(alarm-multiple) thread 3: duration=40, iteration=1, product=40
(alarm-multiple) thread 0: duration=10, iteration=5, product=50
(alarm-multiple) thread 4: duration=50, iteration=1, product=50
(alarm-multiple) thread 0: duration=10, iteration=6, product=60
(alarm-multiple) thread 1: duration=20, iteration=3, product=60
(alarm-multiple) thread 2: duration=30, iteration=2, product=60
(alarm-multiple) thread 0: duration=10, iteration=7, product=70
(alarm-multiple) thread 1: duration=20, iteration=4, product=80
(alarm-multiple) thread 3: duration=40, iteration=2, product=80
(alarm-multiple) thread 2: duration=30, iteration=3, product=90
(alarm-multiple) thread 4: duration=50, iteration=2, product=100
(alarm-multiple) thread 1: duration=20, iteration=5, product=100
(alarm-multiple) thread 3: duration=40, iteration=3, product=120
(alarm-multiple) thread 1: duration=20, iteration=6, product=120
(alarm-multiple) thread 2: duration=30, iteration=4, product=120
(alarm-multiple) thread 1: duration=20, iteration=7, product=140
(alarm-multiple) thread 2: duration=30, iteration=5, product=150
(alarm-multiple) thread 4: duration=50, iteration=3, product=150
(alarm-multiple) thread 3: duration=40, iteration=4, product=160
(alarm-multiple) thread 2: duration=30, iteration=6, product=180
(alarm-multiple) thread 3: duration=40, iteration=5, product=200
(alarm-multiple) thread 4: duration=50, iteration=4, product=200
(alarm-multiple) thread 2: duration=30, iteration=7, product=210
(alarm-multiple) thread 3: duration=40, iteration=6, product=240
(alarm-multiple) thread 4: duration=50, iteration=5, product=250
(alarm-multiple) thread 3: duration=40, iteration=7, product=280
(alarm-multiple) thread 4: duration=50, iteration=6, product=300
(alarm-multiple) thread 4: duration=50, iteration=7, product=350
(alarm-multiple) end
Execution of 'alarm-multiple' complete.

After that, you can stop the emulator by Ctrl+C or by closing the simulator window. After you change some files you will re-compile the local version of nachos that exists in the current working directory (which will be threads or userprog depending on the lab), using the command gmake. To explore available options when starting Pintos run pintos without any arguments.

Debugging

The lab assignments are hard to debug without a debugger, in fact, in order to get help from the lab assistants you will have to use one. There is a debugger called ddd available which works fine with Pintos. It is a graphical interface on top of the gdb (the GNU debugger).

To debug with DDD:

  1. Change to the pintos/threads/build directory.
  2. Run ddd --gdb --debugger pintos-gdb kernel.o& (if you get an X error, ignore it).
  3. Run pintos --qemu --gdb --dport=port_number -- run alarm-single, choose a port (port_number > 1023) that no one else uses.
  4. Execute command target remote localhost:port_number in the GDB console inside DDD (the bottom frame inside the DDD window).
  5. Set any breakpoints (for example break thread.c:164)
  6. Start execution by clicking on cont in the ddd window.
  7. When the breakpoint is reached you can for example click step to execute step by step.
Note, that all commands are supposed to run from the threads/build directory.

The reason why you must choose a port number is that you are using thin clients which means that multiple groups can be working on the same server. If everyone used the default port (1234), you would all try to debug to each others processes, and we would all become even more confused.

Try to open and use debugger and make sure that it works.

Documentation

The most extensive information information available to you about Pintos can be found here.

Hint: There is a lot of useful information to find in the comments of various .c and .h files. Read them!

Next Laboratory work

Laboratory Assignment 1


Page responsible: Christoph W Kessler
Last updated: 2014-01-13