Intro, Threads & Concurrency -
-
-
-
-
-
What What are are the thr three ee views views of an oper operat ating ing syst system? em? Desc Describ ribe e them. them. - pp pp!ic !icat ation ion view view"" What servi services ces the the #$ provi provides des app! app!ica icatio tions ns - $yste $ystem m %iew %iew"" What What the #$ #$ does does as a who!e, who!e, what prob prob!ems !ems foes it so!ve so!ve - Imp Imp!em !ement entati ation on %iew %iew"" ow does does it it wor' wor' behind behind the the scene scenes? s? De(ne De(ne the 'erne! 'erne! of the #$. What What thing things s are are conside considered red part of the #$ but but not the 'erne!? - Centr Centra! a! core core of the #$, hand! hand!es es sysca sysca!!s, !!s, e) e)cept ceptions, ions, and inte interrup rrupts ts What are some advantag advantages es of of a!!owin a!!owing g more more than than one one thread thread to e)ist e)ists s simu!taneous!y? - Concurrency Concurrency,, threads can interact, mu!titas'ing, wastes !ess C*+ time What is contai contained ned in a thread thread conte conte)t? )t? What What is is the the thread thread contro! contro! b!oc'? b!oc'? - Thr Thread ead cont conte) e)tt a thre threads ads C*+ sta state te regi registe sters rs etc etc - Thre Thread ad Contro Contro!! /!oc' /!oc' struct struct stori storing ng thread thread conte conte)t, )t, a!ong a!ong with other thre thread ad data Describe Describe what happens happens during during a conte)t conte)t switc switch? h? What What is dispa dispatchin tching? g? - Conte Conte)t )t $witch" $witch" thread0 thread0s s conte)t conte)t is bac' bac'ed ed up, up, and a di1eren di1erentt threads threads conte)t is restored a!!owing the #$ to switch threads - Disp Dispatchi atching" ng" the proc process, ess, choos choosing ing a new new threa thread d and and restori restoring ng it it What is the di1erence di1erence between between thread2yi thread2yie!d e!d and and threa thread2s! d2s!eep eep? ? - Thre Thread2y ad2yie!d ie!d,, thread thread gives gives up contro! contro! of the proc processo essor, r, goes goes bac' bac' to ready ready 3ueue - Thre Thread2s ad2s!eep !eep thre thread ad needs needs to wait wait for some other even even,, b!oc's b!oc's on on an addr address ess unti! that event occurs so another thread can run ow is an an invo! invo!untar untary y conte conte)t )t switc switch h accomp accomp!ish !ished? ed? De(ne De(ne 3uantum 3uantum.. - When a thread thread has has run run for its its share share of time, time, it is switc switched hed out out by the the 'erne 'erne!! after a timer interrupt - 4uant 4uantum um is the !ength !ength of time time a threa thread d gets gets to run run before before being being swit switched ched out Describe Describe what happens happens when when an an interrup interruptt occurs. occurs. Where Where do interr interrupts upts come come from? from? - The proc processor essor imme immediate diate!y !y switc switched hed to prive! prive!edge edged d more more and and 5umps 5umps to a speci(ed address where the 'erne! hand!er is, the hand!er then hand!es the interrupt and returns contro! to the t he process - In Inte terr rrup upts ts com come e from from har hardw dwar are e devi device ces s
$ynchroni6ation -
-
-
Can the #$ 'now 'now whe when n a pro progra gram m is in a cri critic tica! a! sect section ion? ? - 7es, if the the progra program m says says that that it it is a cri critic tica! a! sect section ion When is it appr appropria opriate te to disa disab!e b!e inter interrupts rupts? ? What What happens happens when you disab disab!e !e interrupts on a mu!ti-proces mu!ti-processor? sor? 8ive pros and cons of disab!ing interrupts. - When you need need to do a sma! sma!!! amount amount of wor' and don0t don0t want a conte)t conte)t swit switch ch to occur - *ro *ros s easy easy,, not hard hardwar ware e speci( speci(c, c, wor's wor's for any any number number of threa threads ds - Cons can scre screw w up timi timing, ng, disab disab!es !es 99 99 interru interrupts, pts, not not 5ust 5ust timer timer ones, ones, over'i!!, doesn0t wor' on mu!tiprocessors Describe Desc ribe *eters *eterson:s on:s !gori !gorithm. thm. What What are are some some restri restriction ctions s on its app app!ica !ication? tion? Is Is it starvation free? - $ay you you want want in the critic critica! a! secti section, on, set set it to be the other other threa threads ds turn, turn, wait wait unti! your turn or the other thread doesn0t want in to enter - #n #n!y !y wo wor' r's s fo forr two two th thrrea eads ds - $t $tar arva vati tion on is no nott pos possi sib! b!e e ow does does Test and and $et wor'? wor'? ow ow wou!d wou!d you use it in a progra program? m? What What is a potent potentia! ia! prob!em with Test and $et?
-
-
-
-
-
-
-
tomica!!y stores a va!ue in an address and returns the va!ue that was there +se in a whi!e !oop, testnd$et a !oc' to true, when another thread is done, it wi!! testnd$et to fa!se, causing the whi!e !oop to fai! so you can enter the critica! section ie the !oc' is true if a thread is in the critica! section What is a semaphore? Which two operations does it support? re they atomic? - *, %, yes they0re atomic - variab!e that is incremented and decremented and can be used to do synchroni6ation Describe how you wou!d synchroni6e producer and consumer threads using a semaphore. - Ca!! % each time something is produced - Ca!! * each time something is consumed What is the primary di1erence between a !oc' and a binary semaphore? - The threads that gets the !oc' is the on!y one that can re!ease it, any thread can modify a semaphore Is the imp!ementation of semaphores given in the notes starvation free? Why or why not? - *robab!y not, depends on what its used for What is a condition variab!e? ow are they used in con5unction with !oc's? - condition that a thread can wait on inside a critica! section - ;ust be in a !oc' to use a C% Describe, at a high !eve!, what a monitor does. ow can we simu!ate their behaviour in C? - n ob5ect where on!y one method can be running at a time mutua! e)c!usion - $imu!ate with a struct and set of functions a!! covered by a sing!e !oc' De(ne dead!oc'. ow does the system recover from a dead!oc'? - When mu!tip!e threads need resources that the others ho!d, no one can move -
*rocesses and the >erne! -
What information is contained within a process? - *rocess contains data, stac', and code - ddress space What is the di1erence between a se3uentia! process and a concurrent process? - $e3uentia! process has one thread, concurrent has many Can threads from one process access memory from another process?
-
-
-
-
- =o, un!ess some memory is e)p!icit!y shared What can the 'erne! do in privi!eged e)ecution mode that user programs can not direct!y accomp!ish? - Communicate with hardware, use specia! instructions, access any memory, create new threadsprocesses, anything you need a system ca!! for Describe what happens when a system ca!! in invo'ed. - C !ibrary ta'es care of ca!!ing, uses $7$C99 instruction which causes processor to switch to 'erne! mode and 5ump to a speci(c address where the hand!er is. The hand!er then does whatever the sysca!! needs In which registers does a system ca!! e)pect the system ca!! code? rguments? - Code" v@ - rguments" a@-aA In which registers wi!! the system ca!! p!ace the return resu!t?
-
%irtua! ;emory -
system uses physica! address and virtua! addresses. ow many physica! address spaces are there in a computer? ow many virtua! address spaces? - #ne physica! address space for the entire system, one %$ for each process What is a simp!e method of address trans!ation? ow does this wor'? What are its disadvantages? - Dynamic re!ocation" each %$ has an o1set that is simp!y added to the vaddr to get the paddr. Cons" need continguous memory, e)terna! fragmentation, a!! vaddrs must be in physica! memory
-
-
-
-
-
-
-
In dynamic re!ocation, when does the va!ue of the re!ocation register in the ;;+ change? - When you switch processes What are three a!gorithms that can be used to (nd an a!!ocation space? Why wou!d anyone ever want to use the worst (t a!gorithm? - = What is the di1erence between e)terna! fragmentation and interna! fragmentation? - )terna! is between a!!ocated b!oc's in memory, Interna! is when a!!ocated b!oc's must be a certain si6e but an a!!ocation doesn0t use its entire b!oc' What advantages does paging give over dynamic re!ocation? - *ages don0t need to be contiguous, removes e)terna! fragmentation, a!!ows for demand paging etc ow does the 'erne! use a page tab!e to he!p trans!ate virtua! addresses to physica! addresses? - 9oo's up vaddr in the page tab!e to get the corresponding paddr and then puts this entry in the T9/ add o1set to paddr 8iven a virtua! address and a page tab!e, how do you ca!cu!ate its physica! address? In reverse? - Ta'e o1 the o1set and !oo' up in page tab!e, then add bac' o1set to paddr -
-
-
$aves memory and time, simp!y map mu!tip!e vaddrs to the same paddr, eg two processes sharing the same code What are three approaches for !ocating the 'erne!:s address space? ow do #$BB and 9inu) do this? - *art of every vaddr space, its own vaddr space, or 5ust in physica! memory Describe the di1erent parts of an 9E (!e. Why doesn:t the 9E (!e describe the stac'? - eaders describe each section .te)t code, read on!y .rodata read on!y g!oba! data Hte)t .data initia!i6ed g!oba! data .bss uninitia!i6ed !arge g!oba! data .sbss uninitia!i6ed sma!! g!oba! data Hdata =o stac' because program doesn0t care where it is, 5ust needs a pointer, de(nied by #$ What are the di1erent sections in an 9E (!e? What are the di1erent segments? - $ee above >now which 'ind of variab!es map to which section. What functionssystem ca!!s can be used to share virtua! memory? *age tab!es for !arge address spaces may be very !arge. #ne prob!em is that they must be in memory, and must be physica!!y contiguous. What are two so!utions to this prob!em? - Two 9eve! *age Tab!es, Inverted *age Tab!es What are the 'ey di1erences between norma! and inverted page tab!es? - =orma! !oo' up vaddr to possib!y get paddr, on!y per address space - Inverted !oo' up paddr to get vaddr maps physica! memory, on!y one What is the di1erence between a g!oba! page rep!acement po!icy and a !oca! page rep!acement po!icy? - 8!oba! you can rep!ace any page, !oca! you can on!y rep!ace pages within the same process What steps must the #$ ta'e to hand!e a page fau!t e)ception? - 8et the fau!t addr, !oo' it up in the page tab!e, !oad it if needed, add the entry to the T9/ What are the di1erent page rep!acement po!icies discussed in !ecture? Describe and compare them. - EIE# rep!ace page that has been in memory the !ongest - 9<+ trac' usage and rep!ace the on!y that hasn0t been used in the !ongest time - 9E+ trac' fre3uency of use and rep!ace the on!y that is used !east - C9#C> cyc!e around s'ipping pages where use bit is set and turning it o1 - ;#DIEID C9#C> use, modi(ed, !oo' for @, @, !oo' for @, B turning o1 use, repeat What is the de(nition of a compu!sory fau!t? What are the two types of !oca!ity to consider when designing a page rep!acement po!icy? - Tempora!" if a page is used once, its !i'e!y to be used again - $patia!" pages !ocated together are !i'e!y to be used together In practice, fre3uency based page rep!acement po!icies don:t wor' very we!!. Why is this? 9<+ page rep!acement is considered impractica! in virtua! memory systems. Why is this? Does the ;I*$ T9/ inc!ude a use bit? modi(ed bit? Why is simu!ating a use bit e)pensive? Why are modi(ed pages more e)pensive to rep!ace than a c!ean page? Describe how you wou!d simu!ate a modi(ed bit in software?
-
-
-
-
-
-
-
De(ne page c!eaning, and e)p!ain the di1erence between synchronous and asynchronous page c!eaning. What is /e!ady:s noma!y, and what is a stac' po!icy? What is one way you can te!! if a rep!acement po!icy is a stac' po!icy? #f 9<+, EIE#, and C9#C>, which a!gorithms are stac' po!icies and which are not? What is prefetching and what is its goa!? What are the ha6ards of prefetching? Which 'ind of !oca!ity does prefetching try and e)p!oit?