Operating System - NachOS Project Introduction

  • View

  • Download

Embed Size (px)


Operating System - NachOS Project Introduction. A312 35231 Email: cyht@dslab.csie.ncu.edu.tw. NachOS. Not Another Completely Heuristic Operating System - PowerPoint PPT Presentation


  • Operating System - NachOS Project Introduction A312 35231Email: cyht@dslab.csie.ncu.edu.tw

  • NachOSNot Another Completely Heuristic Operating System

    Written by Tom Anderson and his students at UC Berkeley in 1992 http://www.cs.washington.edu/homes/tom/nachos/

  • What is NachOSAn educational OS used toTeach monolithic kernel design and implementationDo experiments, you can (and will) modify and extend itFactReal hardware is difficult to handleMay break if handled wrong

  • What is NachOSApproachUse a virtual MIPS machineProvide some basic OS elementsIncludes many facets of a real OS:ThreadsInterruptsVirtual MemoryI/O driven by interrupts

  • What is NachOSNachOS also contains some hardware simulationMIPS processorCan handle MIPS code in standard COFF, except for floating point instructionsYou can (and will) write code in C/C++, compile it to MIPS and run it on NachOSConsole, Network interface, Timer

  • How does it workRun as a single UNIX processProvide a skeletal OS that supportsThreadsUser-level processesVirtual memoryInterrupt-driven I/O devices

  • How does it workTwo modes of executionNachOS kernelExecutes whenNachOS starts upA user-program causes a hardware trap (page fault, syustem call, etc.)MIPS simulatorInitialized and started by NachOS kernel

  • How does it work

  • How does it workSimulates MIPS architecture on host system (UNIX / Linux / Windows / MacOS X)User programs need a cross-compiler (target MIPS)NachOS appears as a single threaded process to the host operating system

  • How does it work

  • How does it work

  • How does it work

  • Source TreeRoot directoryC++ introduction to teach how to write C++Root directory of Nachoss source codeFile systemNachoss libraryMIPS machineIn/Out message queuesNachOSs sample user programsthreadsSource code of NachOS kernel and MIPS simulatorThe tool to convert user programs from MIPSs COFF into NachOSs NOFF (NachOS Object File Format ) formatUser programs interfaces: system calls, address space, noff format

  • System Start UPcode/threads/main.cc main> ./nachos startcreate kernel objectinitialize the systemInvoke user programLoad user programRun user programSystem halt and terminate No user program

  • Install NachOSPlatform: Linux or Linux over VMwareRedHat Linux 9.0 (ftp.tku.edu.tw)Install stepsGet NachOS-4.0wget http://dslab.csie.ncu.edu.tw/OS2006/nachos-4.0.tar.gzGet Cross Compilerwget http://dslab.csie.ncu.edu.tw/OS2006/mips-decstation.linux-xgcc.tgzMove Cross Compiler to /mv ./mips-decstation.linux-xgcc.tgz /Untar Cross Compilertar zxvf /mips-decstation.linux-xgcc.tgz

  • Install NachOSUntar NachOS-4.0tar zxvf ./nachos-4.0.tar.gzMake NachOS-4.0cd ./nachos-4.0/codemakeTest if installation is succeededcd ./userprog./nachos -e ../test/test1./nachos -e ../test/test2You should see the following

  • The test1 resultTotal threads number is 1Thread ../test/test1 is executing.Print integer:9Print integer:8Print integer:7Print integer:6return value:0No threads ready or runnable, and no pending interrupts.Assuming the program completed.Machine halting! Ticks: total 200, idle 66, system 40, user 94Disk I/O: reads 0, writes 0Console I/O: reads 0, writes 0Paging: faults 0Network I/O: packets received 0, sent 0

  • The test2 resultTotal threads number is 1Thread ../test/test2 is executing.Print integer:20Print integer:21Print integer:22Print integer:23Print integer:24Print integer:25return value:0No threads ready or runnable, and no pending interrupts.Assuming the program completed.Machine halting!

    Ticks: total 200, idle 32, system 40, user 128Disk I/O: reads 0, writes 0

  • Operate NachOSNachOS command help./nachos -hDebugging mode./nachos -sExecute files on NachOS./nachos -e ../test/test1

  • Recompile Modified NachOS Codecd nachos-4.0/codemake clean (optional)makeIf you want to fully re-compile the source code, make clean is required. Or make will only re-compile the modified and related files. (save time)

  • Trace NachOSRead *.h and *.cc to have an overview about the whole system and see how it is implementedDocumentation (A Road Map Through NachOS)http://www.cs.duke.edu/~narten/110/nachos/main/main.html

  • Assignment 1NachOS NachOS (word ) linux

  • Assignment 2 nachos-4.0/code/userprog ./nachos e ../test/test1 e ../test/test2Total threads number is 2Thread ../test/test1 is executing.Thread ../test/test2 is executing.Print integer:9Print integer:8Print integer:7Print integer:20Print integer:21Print integer:22

  • Assignment 2 (cont.)Please trace the following files to see why the output results are wrongnachos-4.0/code/userprog/addrspace.hnachos-4.0/code/userprog/addrspace.ccnachos-4.0/code/userprog/userkernel.ccnachos-4.0/code/machine/translate.hNachos-4.0/code/machine/translate.cc

  • Assignment 2 (cont.)Please modified the Nachos code to run the correct resultsYou may need to modify the following functionsnachos-4.0/code/userprog/addrspace.ccconstructordestructorinitRegisterLoad

  • Assignment 3Implement system call SleepImplement Shortest-Job-First scheduling

  • System call Sleep Sleep(int x) system call, system call thread block, x timer interrupts READY

  • System call Sleep (cont.) exception.cc, syscall.h, start.s alarm.cc WaitUntil(int x) Sleep(int x) system call

  • SJF SchedulingNachOS scheduling algorithm Round-Robin non-preemptive SJF Scheduling test case project RR SJF NachOS thread 3

  • SJF Scheduling (cont.) non-preemptive timer interrupts thread yield thread thread CPU burst (timer interrupts ), CPU burst

  • SJF Scheduling (cont.)

  • DemoAccompany with your report about what did you done to the NachOS source code (why and how), and what did you get when tracing the NachOS source code.source code(word) .tar.gzemail to: cyht@dslab.csie.ncu.edu.tw

  • Demo (cont.)NachOS project report NUM email