Operating System NachOS Project

Preview:

DESCRIPTION

Operating System NachOS Project. 教授:周立德 老師. 行動寬頻網路實 驗室 太空遙測研究中心 R3-305 分機: 57968 Email: kkw@networklab.csie.ncu.edu.tw. Outline. What is NachOS How does NachOS work Source Tree System Starting Install NachOS Projects Installation Multiprogramming Scheduling. What is NachOS. - PowerPoint PPT Presentation

Citation preview

1

Operating System NachOS Project

教授:周立德 老師

行動寬頻網路實驗室 太空遙測研究中心 R3-305 分機: 57968

Email: kkw@networklab.csie.ncu.edu.tw

2

Outline

What is NachOS How does NachOS work

– Source Tree– System Starting

Install NachOS Projects

– Installation– Multiprogramming– Scheduling

3

What is 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/

4

What is NachOS

An educational OS used to– Teach monolithic kernel design and implementation– Do experiments, you can (and will) modify and extend

it

Fact– Real hardware is difficult to handle– May break if handled wrong

5

What is NachOS

Approach– Use a virtual MIPS machine– Provide some basic OS elements

Includes many facets of a real OS:– Threads– Interrupts– Virtual Memory– I/O driven by interrupts

6

What is NachOS

NachOS also contains some hardware simulation– MIPS processor

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

7

How does NachOS work

Run as a single UNIX process Provide a skeletal OS that supports

– Threads– User-level processes– Virtual memory– Interrupt-driven I/O devices

8

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 Initialized and started by NachOS kernel

9

How does NachOS work

10

How does NachOS 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

11

How does NachOS work

12

How does NachOS work

13

How does NachOS work

14

Root directory

C++ introduction to teach how to write C++

Root directory of Nachos’s source code

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

The tool to convert user programs from MIPS’s COFF into NachOS’s NOFF (NachOS Object File Format ) format

User programs’ interfaces: system calls, address space, noff format

Source Tree

15

System Starting

code/threads/main.cc main

> ./nachos start

create kernel object

initialize the system

Start up interrupt handling

initialize the ready queue and scheduler

initialize MIPS machine

Run some system testingInvoke user program

Load user program

Run user program

System halt and terminate

No user program

16

Install NachOS

Platform: Linux or Linux over VMware– RedHat Linux 9.0

Install steps– Get NachOS-4.0

# wget http://140.115.155.199/2012_os/file/nachos-4.0.tar.gz– Get Cross Compiler

# wget http://140.115.155.199/2012_os/file/mips-decstation.linux-xgcc.gz– Move Cross Compiler to / ( 根目錄 )

# mv ./mips-decstation.linux-xgcc.gz /– Untar Cross Compiler

# cd /# tar zxvf /mips-decstation.linux-xgcc.gz

17

Install NachOS

Untar NachOS-4.0– tar zxvf ./nachos-4.0.tar.gz

Make NachOS-4.0– cd ./nachos-4.0/code– make

Test if installation is succeeded– cd ./userprog– ./nachos -e ../test/test1– ./nachos -e ../test/test2

You should see the following…

18

The test1 result

Total 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

19

The test2 result

Total 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

20

Operate NachOS

NachOS command help– ./nachos -h

Debugging mode– ./nachos -s

Execute files on NachOS– ./nachos -e ../test/test1

21

Operate NachOS

各個部分的編譯運行 Nachos 的各個部分都可以獨立編譯運行,也可以同時編譯各個部分。全部編譯可以採用如下命令:– code]# make

當需要單獨編譯執行緒管理部分時,先進入threads 目錄,然後採用如下命令:– threads]# make depend– threads]# make nachos

22

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)

23

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/nachos/main/

main.html

24

Project 1 - Installation

NachOS 介紹 安裝 NachOS ,環境,過程 把安裝過程抓圖作成說明文件 (word 檔 )

– 利用 Print Screen Button( 請勿使用 Alt+ Print Screen)

把所有在 linux 下用到的指令解釋清楚其用法,並舉例說明

25

Project 2 - Multiprogramming

到 nachos-4.0/code/userprog 目錄下執行– ./nachos –e ../test/test1 –e ../test/test2

Total 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

Race Condition

26

27

Project 2 - Multiprogramming

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

28

Project 2 - Multiprogramming

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

29

Project 3 - Scheduling

Implement system call “Sleep” Implement Multilevel Queue Scheduling (three

Queue)– Non-preemptive Shortest-Job-First Scheduling (1 Queue)– First-Come, First-Served Scheduling (2 Queue)– Round-Robin Scheduling (3 Queue)

30

System call “Sleep”

請實作 Sleep(int x) 這個 system call, 把呼叫這個 system call 的 thread block 住 , 並且在 x 次的 timer interrupts 以後才又回到 READY 的狀態。

31

System call “Sleep” (cont.)

修改 exception.cc, syscall.h, start.s 呼叫 alarm.cc 的 WaitUntil(int x) 來處理

Sleep(int x) 這個 system call

32

SJF Scheduling

NachOS 內定的 scheduling algorithm 是 Round-Robin ,請設計 non-preemptive SJF Scheduling

請自行設計一組或多組 test case 來證明你的 project 是對的,針對 FCFS 、 RR 或是 SJF 都要能運作,放到 NachOS 下面去執行的 thread ,每個 Queue 個數至少 3 個

33

SJF Scheduling (cont.)

由於是 non-preemptive ,所以當 timer interrupts 時不用將 thread yield– 什麼時候有可能換 thread 執行?

需要記錄每個 thread 實際 CPU burst 長度 (timer interrupts 數目 ), 與預測將來 CPU burst 長度– 在哪裡可以得到這個資訊?– 何時該進行預測?

34

SJF Scheduling (cont.)

Begin Running

Invoke Sleep(x)

Per timer interrupt:1.Record actual CPU burst2. 叫醒應該起床的 threads

1.Set next predicted CPU burst2.Insert this thread to Sleeping thread lists3.Invoke thread->Sleep

35

Demo

報告內容– Project1 安裝過程介紹– Project2 執行結果證明– Project3 主程式介紹、執行結果證明– 未完成項目和遭遇困難說明

把寫好的 source code 與報告 (word 檔 ) 壓縮成 ”學號 .tar.gz” , email to: kkw@networklab.csie.ncu.edu.tw

36

Demo (cont.)

郵件主旨請定為– NachOS project #NO. ,學號:姓名– Ex: NachOS project #1 , 965402001: 周立德

助教收到 email 後會回信表示收到– 如果一週內沒收到回信,請再寄一次

37

Something you need to know

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.

38

References

http://www.cs.washington.edu/homes/tom/nachos/ http://inst.eecs.berkeley.edu/~cs162/sp08/Nachos/ (JAVA NachOS) http://www.student.cs.uwaterloo.ca/~cs350/common/install.html

Installation: http://flyingwinnie.blogspot.com/2008/05/nachos.html redhat 9.0 http://www.youtube.com/watch?v=epT7eFJLxls ubuntu 11.04 http://www.student.cs.uwaterloo.ca/~cs350/common/install.html

ubuntu 10.10 http://www.youtube.com/watch?v=plGyUq4PcVA ubuntu 10.10

Recommended