2014NachOS

advertisement
Operating System
NachOS Project
教授:周立德 老師
行動寬頻網路實驗室
太空遙測研究中心 R3-305 分機:57968
Email: 陳奕勳
1
andy1098137129@networklab.csie.ncu.edu.tw
Outline


What is NachOS
How does NachOS work
–
–


Install NachOS
Projects
–
–
2
Source Tree
System Starting
–
Installation
Multiprogramming
Scheduling
Project Goals



不聞不若聞之,聞之不若見之, 見之不若知之,
知之不若行之, 學至於行而止矣。
I hear I forget, I see I remember, I do and I
undertand.
Goals
–
–
–
–
–
3
–
Introduce abstractions for system components
Show different possible designs
Compare different design decisions
Research which architecture suits for different
environments
Research tradeoff effects
Review common implementation issues/bugs
NachOS
4
What is NachOS


Not Another Completely Heuristic Operating
System (NachOS)
Written by Tom Anderson and his students at UC
Berkeley in 1992
http://www.cs.washington.edu/homes/tom/nachos/
5
What is NachOS

An educational OS used to
–
–

Fact
–
–
6
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:
–
–
–
–
7
Use a virtual MIPS machine
Provide some basic OS elements
Threads
Interrupts
Virtual Memory
I/O driven by interrupts
What is NachOS

NachOS also contains some hardware simulation
–
MIPS processor


–
8
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
Console, Network interface, Timer
How does NachOS work


Run as a single UNIX process
Provide a skeletal OS that supports
–
–
–
–
9
Threads
User-level processes
Virtual memory
Interrupt-driven I/O devices
How does NachOS work

Two modes of execution
–
NachOS kernel

Executes when
–
NachOS starts up
– A user-program causes a software trap (page fault, syustem call,
etc.)
–
MIPS simulator

10
Initialized and started by NachOS kernel
How does NachOS work




11
NachOS v.4.0
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 NachOS work
12
How does NachOS work
13
How does NachOS work
14
Implementation
NachOS
MIPS
15
NachOS
Linux/Cygwin
MIPS
VM
Linux
Win OS
Physical Devices
Physical Devices
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
Source code
of NachOS
kernel and
MIPS
simulator
NachOS’s sample user programs
threads
16
User programs’ interfaces: system calls, address space, noff format
System Starting
> ./nachos start
code/threads/main.cc main
Start up interrupt handling
create kernel object
initialize the system
initialize the ready queue
and scheduler
initialize MIPS machine
Invoke user program
No user program
Load user program
System halt and
17 terminate
Run user program
Run some system testing
Install NachOS

Platform: Linux or Linux over VMware
–

RedHat Linux 9.0
Install steps
–
Get NachOS-4.0

–
Get Cross Compiler

–
18
mv ./mips-decstation.linux-xgcc.tgz /
Untar Cross Compiler


wget ../mips-decstation.linux-xgcc.tgz
Move Cross Compiler to /

–
wget ../nachos-4.0.tar.gz
tar zxvf /mips-decstation.linux-xgcc.tgz
http://networklab.csie.ncu.edu.tw/2014_os/osweb.html#download
Install NachOS

Untar NachOS-4.0
–

Make NachOS-4.0
–
–

–
–
19
cd ./nachos-4.0/code
make
Test if installation is succeeded
–

tar zxvf ./nachos-4.0.tar.gz
cd ./userprog
./nachos -e ../test/test1
./nachos -e ../test/test2
You should see the following…
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!
20
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!
21
Ticks: total 200, idle 32, system 40, user 128
Disk I/O: reads 0, writes 0
Operate NachOS

NachOS command help
–

Debugging mode
–

./nachos -s
Execute files on NachOS
–
22
./nachos -h
./nachos -e ../test/test1
Operate NachOS


各個部分的編譯運行
Nachos的各個部分都可以獨立編譯運行,也可
以同時編譯各個部分。全部編譯可以採用如下
命令:
–

當需要單獨編譯執行緒管理部分時,先進入
threads目錄,然後採用如下命令:
–
–
23
code]# make
threads]# make depend
threads]# make nachos
Recompile Modified NachOS Code



cd nachos-4.0/code
make clean (optional)
make
–
24
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



You will need to trace in this project
Read *.h and *.cc to have an overview about the
whole system and see how it is implemented
Documentation (A Road Map Through NachOS)
–
–
25
http://www.cs.duke.edu/~narten/110/nachos/main/mai
n.html
http://rtlab.csie.ntu.edu.tw/course/OS2004/project/Nac
hOS-4.0/HTML/
Q&A
Q: Does NachOS support 64-bit OS?
A: No, NachOS v.4 only supports on 32-bit OS
Q: Can NachOS install on Ubuntu?
A: Most Yes. NachOS depends on GCC
version.
26
Project 1 - Installation



NachOS 介紹
安裝 NachOS,環境,過程
把安裝過程抓圖作成說明文件 (word 檔)
–

27
利用Print Screen Button(請勿使用Alt+ Print Screen)
把所有在 linux 下用到的指令解釋清楚其用法,
並舉例說明
Project 2 - Multiprogramming

到 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
28


29
job1 1 2 3 4
8 9
Job2
9 8 7
8 7
Project 2 - Multiprogramming

Please trace the following files to see why the
output results are wrong
–
–
–
–
–
30
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
Project 2 - Multiprogramming


Please modified the Nachos code to run the
correct results
You may need to modify the following functions
–
31
nachos-4.0/code/userprog/addrspace.cc
Project 3 - Scheduling


Implement system call “Sleep”
Implement Multilevel Queue Scheduling (three
Queue)
–
–
–
32
Non-preemptive Shortest-Job-First Scheduling (1 Queue)
First-Come, First-Served Scheduling
(2 Queue)
Round-Robin Scheduling
(3 Queue)
System call “Sleep”

33
請實作 Sleep(int x) 這個 system call, 把呼叫這
個 system call 的 thread block住, 並且在 x 次的
timer interrupts 以後才又回到 READY 的狀態。
System call “Sleep” (cont.)


34
修改 exception.cc, syscall.h, start.s
呼叫 alarm.cc 的 WaitUntil(int x) 來處理
Sleep(int x) 這個 system call
SJF Scheduling


35
NachOS 內定的 scheduling algorithm 是 RoundRobin,請設計 non-preemptive SJF Scheduling
請自行設計一組或多組 test case 來證明你的
project 是對的,針對 FCFS、RR 或是 SJF 都
要能運作,放到 NachOS 下面去執行的 thread,
每個Queue個數至少 3 個
SJF Scheduling (cont.)

由於是 non-preemptive,所以當 timer interrupts
時不用將 thread yield
–

需要記錄每個 thread 實際 CPU burst 長度
(timer interrupts 數目), 與預測將來 CPU burst
長度
–
–
36
什麼時候有可能換 thread 執行?
在哪裡可以得到這個資訊?
何時該進行預測?
SJF Scheduling (cont.)
Begin Running
Per timer interrupt:
1.Record actual CPU burst
2.叫醒應該起床的 threads
Invoke Sleep(x)
1.Set next predicted CPU burst
2.Insert this thread to Sleeping thread lists
3.Invoke thread->Sleep
37
Demo

報告內容
–
–
–
–

Project1 安裝過程介紹
Project2 執行結果證明
Project3 主程式介紹、執行結果證明
未完成項目和遭遇困難說明
把寫好的source code與報告(word檔)壓縮成 ”
學號.tar.gz”,email to:
andy1098137129@networklab.csie.ncu.edu.tw
38
Demo (cont.)

上傳FTP
–
–
–
–

助教確認後會回信表示收到
–
39
ftp://140.115.155.192
請留下組長的Email和電話
NachOS project,姓名/學號
Ex: NachOS project #1,965402001:周立德
如果兩天內沒收到回信,請主動詢問助教
Something you need to know


40
Don’t modify the files under “machine” directory.
Please keep a copy of your code in your own PC.
Course machine is for coding and testing. We
don’t guarantee the safety of your codes.
References




http://rtlab.csie.ntu.edu.tw/course/OS2004/index.htm
http://www.cs.washington.edu/homes/tom/nachos/
http://inst.eecs.berkeley.edu/~cs162/sp08/Nachos/ (JAVA NachOS)
http://vc.cs.nthu.edu.tw/home/courses/CS342301/96/
Installation:
 http://kakashi.twbbs.org/wiki/doku.php?id=course:nachos
 http://tech-zishen.blogspot.com/2005/06/nachos.html
41
Download