NachOS - Operating System ­ NachOS Project Introduction ­...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Operating System ­ NachOS Project Introduction ­ • “* ­ • “* ( F A312 � � 35231 ­ • “* � � ­ Email: [email protected] NachOS Not 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 NachOS An educational OS used to Fact – Teach monolithic kernel design and implementation – Do experiments, you can (and will) modify and extend it – Real hardware is difficult to handle – May break if handled wrong What is NachOS Approach Includes many facets of a real OS: – Threads – Interrupts – Virtual Memory – I/O driven by interrupts – Use a virtual MIPS machine – Provide some basic OS elements What is NachOS NachOS also contains some hardware simulation – MIPS processor – Console, Network interface, Timer Can handle MIPS code in standard COFF, except for floating point instructions You can (and will) write code in C/C++, compile it to MIPS and run it on NachOS How does it work Run as a single UNIX process Provide a skeletal OS that supports – Threads – User­level processes – Virtual memory – Interrupt­driven I/O devices How does it work Two modes of execution – NachOS kernel Executes when – MIPS simulator – NachOS starts up – A user­program causes a hardware trap (page fault, syustem call, etc.) Initialized and started by NachOS kernel How does it work How does it work Simulates 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 Tree Root directory C++ introduction to teach how to write C++ Root directory of Nachos’s source code The tool to convert user programs from MIPS’s COFF into NachOS’s NOFF (NachOS Object File Format ) format File system Nachos’s library MIPS machine In/Out message queues NachOS’s sample user programs threads Source code of NachOS kernel and MIPS simulator User programs’ interfaces: system calls, address space, noff format System Start UP > ./nachos start code/threads/main.cc main create kernel object initialize the system Invoke user program No user program Start up interrupt handling initialize the ready queue and scheduler initialize MIPS machine Run some system testing Load user program System halt and terminate Run user program Install NachOS Platform: Linux or Linux over VMware Install steps – RedHat Linux 9.0 (ftp.tku.edu.tw) – Get NachOS­4.0 – Get Cross Compiler wget http://dslab.csie.ncu.edu.tw/OS2006/nachos­4.0.tar.gz wget http://dslab.csie.ncu.edu.tw/OS2006/mips­decstation.linux­xgcc.tgz – Move Cross Compiler to / – Untar Cross Compiler mv ./mips­decstation.linux­xgcc.tgz / tar zxvf /mips­decstation.linux­xgcc.tgz Install NachOS – Untar NachOS­4.0 – Make NachOS­4.0 tar zxvf ./nachos­4.0.tar.gz cd ./nachos­4.0/code make – Test if installation is succeeded – You should see the following… cd ./userprog ./nachos ­e ../test/test1 ./nachos ­e ../test/test2 The test1 result Total threads number is 1 Thread ../test/test1 is executing. Print integer:9 Print integer:8 Print integer:7 Print integer:6 return value:0 No threads ready or runnable, and no pending interrupts. Assuming the program completed. Machine halting! Ticks: total 200, idle 66, system 40, user 94 Disk I/O: reads 0, writes 0 Console I/O: reads 0, writes 0 Paging: faults 0 Network I/O: packets received 0, sent 0 The test2 result Total threads number is 1 Thread ../test/test2 is executing. Print integer:20 Print integer:21 Print integer:22 Print integer:23 Print integer:24 Print integer:25 return value:0 No threads ready or runnable, and no pending interrupts. Assuming the program completed. Machine halting! Ticks: total 200, idle 32, system 40, user 128 Disk I/O: reads 0, writes 0 Operate NachOS NachOS command help Debugging mode Execute files on NachOS – ./nachos ­e ../test/test1 – ./nachos ­s – ./nachos ­h Recompile Modified NachOS Code cd nachos­4.0/code make clean (optional) make – If 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 NachOS Read *.h and *.cc to have an overview about the whole system and see how it is implemented Documentation (A Road Map Through NachOS) – http://www.cs.duke.edu/~narten/110/nach os/main/main.html Assignment 1 NachOS � ­ � �� NachOS 4 •• “* NachOS ­ “* � –� h �� �ö * � � � �( �F� � (word ) �� � (word • linux � ­ – h ** � � � � �( �F� � � 4�� � •“ linux 4 •• ““ ­ Assignment 2 � nachos­4.0/code/userprog � �•� nachos­4.0/code/userprog ­ – ./nachos –e ../test/test1 –e ../test/test2 Total threads number is 2 Thread ../test/test1 is executing. Thread ../test/test2 is executing. Print integer:9 Print integer:8 Print integer:7 Print integer:20 Print integer:21 Print integer:22 Assignment 2 (cont.) � –� h � �ö ��* �� � F � � � �� � (� Please trace the following files to see why the output results are wrong – nachos­4.0/code/userprog/addrspace.h – nachos­4.0/code/userprog/addrspace.cc – nachos­4.0/code/userprog/userkernel.cc – nachos­4.0/code/machine/translate.h – Nachos­4.0/code/machine/translate.cc Assignment 2 (cont.) Please modified the Nachos code to run the correct results You may need to modify the following functions – nachos­4.0/code/userprog/addrspace.cc constructor destructor initRegister Load Assignment 3 Implement system call “Sleep” Implement Shortest­Job­First scheduling System call “Sleep” � �� � Sleep(int x) � system call, Sleep(int x) ­ system call, Ł •• system call ­ system call thread block thread block , � � x � timer interrupts � • , ­ x ­ timer interrupts ­ �� � READY � �•� ­ READY ­ System call “Sleep” (cont.) � � exception.cc, syscall.h, start.s exception.cc, syscall.h, start.s �� � alarm.cc alarm.cc WaitUntil(int x) � � WaitUntil(int x) ­ Sleep(int x) � system call Sleep(int x) ­ system call SJF Scheduling NachOS � � scheduling algorithm ­ scheduling algorithm Round­Robin ¨ • non­ Round­Robin ­ non­ preemptive SJF Scheduling � � � � �� � ��� � test case ¨ ­ • “ test case project ¨­ • “ * RR � SJF � project RR ­ SJF ­ ¨­ • “ * NachOS ¨ • “* NachOS ­ thread ¨ ­ • “ 3 thread 3 SJF Scheduling (cont.) � �� � non­preemptive ‚ ­ � •• timer non­preemptive timer interrupts ‚ ­ � •• thread yield thread yield ‚ � �• � �ª � * thread � CPU burst � thread ­ CPU burst ­ (timer interrupts � ), ‚ ­ � •“ •“ CPU (timer interrupts ­ CPU burst � ­ F – � � � � � �� �� �� H ( u • * – ‚� � �• �“ � �� �� � –� �� ���� � thread � � thread ­ SJF Scheduling (cont.) Begin Running Per timer interrupt: 1.Record actual CPU burst 2. ł c “ * � threads Invoke Sleep(x) 1.Set next predicted CPU burst 2.Insert this thread to Sleeping thread lists 3.Invoke thread­>Sleep Demo Accompany 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 ) ­ e ”“ * .tar.gz” email to: ­ email to: [email protected] Demo (cont.) xª�� � � ª � * � �� • x ª � •� �� ­ “* – NachOS project report NUM xª• • “* �� �� � – � – h �* �� �� � � ( F �� �� �� �� email x ª • “ “ * *� �� � email ­ • ...
View Full Document

This note was uploaded on 02/16/2010 for the course COMPUTER S n/a taught by Professor P.j.deitel during the Spring '09 term at 東京大学.

Ask a homework question - tutors are online