22
Introduction to the Nachos OS Simulator UMN CSci 5103 - Operating Systems Spring 2015

Introduction to Nachos

Embed Size (px)

Citation preview

Page 1: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 1/22

Introduction to the Nachos OS

Simulator 

UMN CSci 5103 - Operating Systems

Spring 2015

Page 2: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 2/22

hat is Nachos!

" #n instructional operating system simulator " ritten in $a%a at UC &er'eley" &ased on earlier C(( %ersions

" Implements many aspects o) real OS

" *hreads+ processes" *imers+ interrupts" Scheduling" Memory management

" Simulates hard,are" MIS-.ased CU

" Can load and e/ecute MIS .inaries as user

processes" *imer " Console

Page 3: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 3/22

hy Nachos!

" earn OS internals through )irst-hand e/posure" esigning" Implementing" *esting

" %aluating" asier to )ocus on main concepts ,ith a simulator 

" Still pro%ides .asic OS )unctionality+ .ut easier to e/tend

than real 'ernel e4g4+ inu/"

$a%a leads to simpler programming than other instructionalalternati%es easier to )ocus on high-le%el concepts

Page 4: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 4/22

Nachos #rchitecture

Page 5: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 5/22

o,nloading and Installing Nachos

" o,nload the Nachos code )rom the course Moodle site4

" /tract the tar )ile+ ,hich ,ill create Nachos-Java directory

> tar -xvf nachos-os-simulator.tar.gz

" /plore the Nachos-Java directory

" Source code" Con)iguration )iles" ocumentation

Page 6: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 6/22

Compiling and 6unning

" #dd nachos/bin to your PATH(Moif! bashrcfil"#4 *his directory contains the nachos script+ ,hich

launches Nachos )or you4

" *o compile Nachos+ go to the Nachos-Java directory,hich contains a ma'e)ile to .uild the entire pro7ect

> c Nachos-Java

> ma$"

" *o run Nachos8

> nachos

" Use the %h )lag to see the command-line parameters

" &e,are some are poorly documented4 9ou:ll ha%e to

Page 7: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 7/22

Con)iguration

" 6unning Nachos re;uires a con)iguration )ile4" &y de)ault nachos reads )rom a con)iguration )ile

named nachos.conf in the same directory" Use the %&' option to speci)y a di))erent

con)iguration" Important arameters

< "rn"l.$"rn"l)= #l,ays re;uired4 Speci)ies the 'ernel class to .e used4

< Machin".*roc"ssor)

= Speci)ies i) processor should .e simulated4 Set it to true only,hen running MIS .inaries as user processes

< "rn"l.sch"ul"r)= Speci)ies the scheduler class to .e used

Page 8: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 8/22

o,nloading and setting up MIS

Cross Compiler" o,nload the appropriate MIS cross compiler )romhttps://inst.eecs.berkeley.edu/~cs162/sp07/Nachos/xgcc.shtml 

" /tract the do,nloaded tar )ile

"Set the #6C>I6 en%ironment %aria.le to point to thee/tracted directory Modi)y .ashrc )ile

" #dd the e/tracted directory to #*> en%ironment

%aria.le Modi)y .ashrc )ile

Page 9: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 9/22

/ample rograms

" *hreading< Use the con)ig )ile nachos+thr"a.conf to run a

sample multi-threaded con)iguration

> nachos -&' nachos+thr"a.conf

< /ecutes a simple thread program ,hich loops 5times

< Change the num.er o) threads using the

"rn"l.numThr"as parameter 

" User rocess< Use the con)ig )ile nachos+*roc"ss.conf< 6uns ,s"r"rn"l.s"lfT"st echo

characters< *hen runs tri%ial MIS program halts< Change the program to .e e/ecuted ,ith the

Page 10: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 10/22

Nachos Components

" Important ac'ages

< nachos4machine8= Simulates machine hard,are and de%ices such

as rocessor+ Console+ *imer and interrupts< nachos4threads8

= Simulates 'ernel le%el threads+scheduling+ synchroni?ation primiti%es+

etc4< nachos4userprog8

= Supports e/ecution o) MIS .inaries as user-

le%el processes< nachos4%m8

= Basic  implementation o) %irtual memory

Page 11: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 11/22

&ooting Nachos

" nachos.machin".Machin" is responsi.le )or starting

and setting up nachos )or e/ecution4" 6eads the con)ig )ile and sets up hard,are de%ices8

processor+ interrupt controller+ timer+ console+ )ile system

etc4+ .ased on con)ig parameters4" *hen starts Autogra"r+ ,hich creates 'ernel o.7ect

.ased on the 'ernel class speci)ied on con)ig )ile4 *his

starts the OS4

" @ernel creates the scheduler class speci)ied in con)ig )ileand starts e/ecuting threads i) any4

Page 12: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 12/22

Interrupt Controller 

" @ic's o)) hard,are interrupts4" Implemented .y nachos.machin".nt"rru*t class4" Cloc' tic's a)ter e/ecution o) instruction or re-ena.ling

o) interrupts4

" #)ter e%ery tic'+ nt"rru*t class chec's )or pendinginterrupts and runs them4

" Important methods accessi.le .y other de%ices

< sch"ul"8 schedule interrupt+ speci)y time and

interrupt handler < "nabl"< isabl"< tic$

Page 13: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 13/22

*imer 

" Implemented .y nachos.machin".Tim"r" Causes timer interrupt at a.out e%ery 500 tic's can

.e changed through code" Important methods

< s"tnt"rru*tHanl"r8 speci)y handler to tell thetimer ,hat to do ,hen it goes o)) 

< g"tTim"8 tells ho, many tic's so )ar " ro%ides support )or preemption

Page 14: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 14/22

Serial Console

" $a%a inter)ace nachos.machin"."rialonsol"< r"a0!t" returns one .yte or -1 and ,aits to

interrupt ,hen it has more< 1rit"0!t" ta'es one .yte and ,aits to interrupt ,hen

its ready )or more< s"tnt"rru*tHanl"rs tells the console ,ho to call

,hen it recei%es data or )inishes sending data" Normally implemented .y

nachos.machin".tanaronsol"+ hoo'ed up tostandard input and standard output

Page 15: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 15/22

@ernel

" #.stract class nachos.machin"."rn"l" Important methods

< initializ"8 initiali?es the 'ernel< s"lfT"st8 per)orms test

< run8 runs any user code< t"rminat"8 terminate the OS

" /tend the a.stract "rn"l class to implement 'ernel-

le%el )unctionality

< *he code changes ,ill .e speci)ic to programmingassignments

< See nachos.thr"as.Thr"a""rn"l class )or

re)erence implementation

Page 16: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 16/22

*hreading

" >appens in pac'age nachos.thr"as" #ll Nachos 'ernel-le%el threads are instances o)

nachos.thr"a.Thr"a or su.classes" Thr"a

< Status8 Ne,+ 6eady+ 6unning+ &loc'ed+ Ainished< nachos.machin".T0 responsi.le )or thread-le%el

conte/t s,itching" Internally implemented .y $a%a threads

< Uses 2ava.lang.3unnabl" inter)ace< *hread is implemented .y 7a%a class implementing

6unna.le inter)ace< *hreadBs logic is implemented in run method

Page 17: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 17/22

Creating and 6unning *hreads

< Create a thread class implementing

2ava.lang.3unnabl"< Instantiate a Thr"a o.7ect using an instance o) this

thread class

< Call thr"a:s for$ method4< /ample8

  class *rint"r im*l"m"nts 3unnabl" 4

  *ublic voi run(# 4  // 3un r"al fast5

  6

  6

  *rint"r s 7 n"1 *rint"r(#8

  n"1 Thr"a(s#.for$(#8

Page 18: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 18/22

Scheduling

" Implemented .y nachos.thr"as.ch"ul"r and

nachos.thr"as.Thr"a9u"u"

< Control access o) threads to rocessor+ to synchroni?ation

o.7ects4

< Thr"a9u"u" o.7ect decides ,hat thread to run ne/t4< e)ault scheduler8 3oun3obinch"ul"r

< Custom scheduler8 speci)y in con)iguration4

" *o implement a speci)ic scheduling policy

< /tend ch"ul"r and Thr"a9u"u" classes4

< Implement scheduling policy logic .y implementing

methods such as n"xtThr"a: g"t/s"tPriorit!:

etc4

< See 3oun3obinch"ul"r class as an e/ample4

Page 19: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 19/22

User rocesses

" Nachos can run .inaries compiled )or MIS as userprocesses4" rite code in C+ cross-compile to MIS+ and run as a

user process< 9ou ,ill need MIS cross compiler see #0< na.le machin".*roc"ssor )lag in con)ig )ile

" Supports only .asic )unctionalities< Can e/ecute .asic MIS instructions no )loating point4< Console class pro%ides inter)ace to stdin and stdout4

< halt is the only syscall implemented )or you4

Page 20: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 20/22

Aurther 6eading

" Nachos $a%a #I documentation8http8DDinst4eecs4.er'eley4eduDEcs1F2Dsp1GDNachosDdocDinde/4html

" &er'eley:s CS 1F2 Nachos *utorial note our pro7ects ,ill

.e di))erent )rom theirs8

http8DDinst4eecs4.er'eley4eduDEcs1F2Dsp1GDNachosDnachos4pd) 

"The source code.

Page 21: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 21/22

Heneral #d%ice

" 6ead the source code

" #s' and answer general ;uestions on the )orum4

" o not rely on o))ice hours or emails to the *# )or

de.ugging4

" Start early4

Page 22: Introduction to Nachos

8/9/2019 Introduction to Nachos

http://slidepdf.com/reader/full/introduction-to-nachos 22/22

Juestions!