2 Getting Started With PintosWhat does Pintos Include?Threads in PintosProject 1

3 What is Pintos? Pintos is a teaching operating system from StanfordWritten in CImplements enough functionality to boot…… perform basic device I/O…… and has a small standard libraryYour goal will be to expand it’s functionality

4 $ cp /course/cs5600f14/install/pintos.tar.gz ~Pintos DocumentationAll of the Pintos docs are available on the course webpageYou will need to copy the Pintos source to your home directory$ cp /course/cs5600f14/install/pintos.tar.gz ~Source can also be downloaded from the course webpage

5 Setting Up Your EnvironmentWe have installed all necessary code and scripts on the CCIS Linux machinesYou will need to modify your PATH to access themAdd the following line to ~/.bash_profileexport PATH=${PATH}:/course/cs5600f14/bin:/course/cs5600f14/pintos/binIf ~/.bash_profile does not exist, create itRestart your shell

7 Building and Running Pintos$ cd ~/pintos/src/threads $ make $ cd build/ $ pintos -v -- -q run alarm-singleScript to run Pintos in the QEMU simulatorParameters for the simulatorParameters for the Pintos kernel

8 Making Pintos When you run make, you compile two thingsbuild/loader.binThe Pintos bootloader (512 byte MBR image)Locates the kernel in the filesystem, loads it into memory, and executes itbuild/kernel.binThe Pintos kernelThe pintos script automatically creates a file system image that includes the MBR and kernel

9 QEMU Pintos could be run on an actual machineBut that would require installing it, dual booting with another OSDebugging would be hardInstead, we will run Pintos inside QEMUQEMU is a machine emulatorIn our case, a 32-bit x86 CPU with basic devicesExecutes a BIOS, just like a real machineLoads bootloader from MBR of emulated disk drive

10 Getting Started With PintosWhat does Pintos Include?Threads in PintosProject 1

11 Pintos Features Pintos is already a basic, bootable OSSwitches from real to protected modeHandles interruptsHas a timer-interrupt for process preemptionDoes basic memory managementSupports a trivial file system

15 $ pintos -v -- run alarm-singleChristo Wilson8/22/2012TestsEach Pintos project comes with a set of testsUseful for debuggingAlso what we will use to grade your codeOut-of-the-box, Pintos cannot run user programsThus, tests are compiled into the kernelYou tell the kernel which test to execute on the command line$ pintos -v -- run alarm-singleUse $ make check to run the testsDefense

18 Getting Started With PintosWhat does Pintos Include?Threads in PintosProject 1

19 Threads in Pintos Pintos already implements a simple threading systemThread creation and completionSimple scheduler based on timer preemptionSynchronization primitives (semaphore, lock, condition variable)But this system has problems:Wait is based on a spinlock (i.e. it just wastes CPU)The thread priority system is not implemented

21 Switching ThreadsRemember the switch() function we talked about earlier?Pintos has one in threads/switch.SSaves the state of the CUR threadSaves ESP of the CUR threadLoads the state of the NEXT threadLoads ESP of the NEXT threadReturns to NEXT thread

22 Idle Thread There is always one thread in the systemKnown as the idle threadExecutes when there are no other threads to runfor (;;) {intr_disable (); /* Disable interrupts */thread_block (); /* Let another thread run *//* Re-enable interrupts and wait for the next one.The `sti' instruction disables interrupts until thecompletion of the next instruction, so these twoinstructions are executed atomically. */asm volatile ("sti; hlt" : : : "memory");}

23 Getting Started With PintosWhat does Pintos Include?Threads in PintosProject 1

24 Pintos Projects All four Pintos projects will involve two thingsModifying the Pintos OSProducing a DESIGNDOC that explains your modificationsWe will use automated tests to gauge the correctness of your modified codeThe TA/graders will evaluate the quality of your DESIGNDOCTemplates for DESIGNDOCs are provided by us

34 Return to original priorityPriority DonationReturn to original priorityDonate priorityThread 1Priority 063Thread 2Priority 63Challenges:What if a thread holds multiple locks?What if thread A depends on B, and B depends on C?LOCKReadAddLOCKStoreUNLOCKReadAddStoreUNLOCK

35 Overall File ModificationsWhat files will you be modifying in project 1?devices/timer.cthreads/synch.c  Most edits will be here…threads/thread.c  … and herethreads/thread.hthreads/DESIGNDOC  Text file that you will write

36 Advanced Scheduler? MLFQ?Project 1 originally included more workAsked student to build an advanced scheduler that implements MLFQWe have removed this from the assignmentYou’re welcome :)If you see references in the docs to “advanced scheduler” or references in the code to “mlfq” ignore them

37 Grading 15 points total To receive full credit:Turn in working, well documented code that compiles successfully and completes all tests (50%)You do not need to pass the MLFQ testsTurn in a complete, well thought our design document (50%)If your code doesn’t compile or doesn’t run, you get zero creditMust run on the CCIS Linux machines!All code will be scanned by plagiarism detection software

38 Turning In Your ProjectRegister yourself for the grading system$ /course/cs5600f14/bin/register-student [NUID]Register your groupAll group members must run the script!$ /course/cs5600f14/bin/register project1 [team name]Run the turn-in scriptTwo parameters: project name and code directory$ /course/cs5600f14/bin/turnin project1 ~/pintos/src/