lecture3 os support

Upload: hanhnd

Post on 05-Jul-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/16/2019 Lecture3 Os Support

    1/20

    CMPT 431

    Dr. Alexandra Fedorova

    Lecture III: OS Support

  • 8/16/2019 Lecture3 Os Support

    2/20

    2CMPT 431 © A. Fedorova

     Te !ole o" te OS

    # Te operat$n% &'&te( need& to prov$de&upport "or $(ple(entat$on o"

    d$&tr$)uted &'&te(&# *e +$ll loo, at o+ d$&tr$)uted &'&te(&

    &erv$ce& $nteract +$t te operat$n%&'&te(&

    # *e +$ll d$&cu&& te &upport tat teoperat$n% &'&te( need& to prov$de

  • 8/16/2019 Lecture3 Os Support

    3/20

    3CMPT 431 © A. Fedorova

    D$rect Interact$on +$t te OS

    OS

    Proce&&:a DS

    co(ponent

    &'&te(call&

    • A proce&& d$rectl'$nteract& +$t te OS v$a&'&te( call&

    • -xa(ple: a +e) )ro+&era +e) &erver

  • 8/16/2019 Lecture3 Os Support

    4/20

    4CMPT 431 © A. Fedorova

    Interact$on v$a M$ddle+are La'er

    OS

    Proce&&:a DS

    co(ponent

    &'&te(

    call&

    M$ddle+are

    Funct$on call&or IPC

    • A proce&& d$rectl'$nteract& +$t te OS v$aa ($ddle+are la'er

    • A ($ddle+are la'erd$rectl' $nteract& +$tte OS

    • -xa(ple: a peer/to/peer0le &'&te( $(ple(ented

    over a d$&tr$)uted a&ta)le

  • 8/16/2019 Lecture3 Os Support

    5/20

    5CMPT 431 © A. Fedorova

    Interact$on v$a Inclu&$on

    OS DSco(ponent

    • A DS co(ponent $& a part o" te operat$n% &'&te( $.e.an operat$n% &'&te( daemon

    • -xa(ple: et+or, F$le S'&te( 2FS dae(on• !un& a& a ,ernel tread &are& addre&& &pace +$t te

    ,ernel $nteract& +$t te re&t o" te OS v$a "unct$oncall&

    • *' +ould one +ant to )u$ld a DS co(ponent tat$nteract& +$t te OS v$a $nclu&$on

  • 8/16/2019 Lecture3 Os Support

    6/20

    6CMPT 431 © A. Fedorova

    D$%re&&$on: Protect$on

    I(ple(entat$on In te 5ernel# S'&te( call& are expen&$ve

    # *' 6 Protect$on do(a$n&

    # !e"re& (e(or' protect$on "ro( 'ourOS cla&&

    # 7ood t$n%: +e %et (e(or' protect$on

    # 8ad t$n%: cro&&$n% protect$on do(a$n&$& expen&$ve. *'

    # So $& t$& te )e&t &olut$on

  • 8/16/2019 Lecture3 Os Support

    7/207CMPT 431 © A. Fedorova

    Alternat$ve: Protect$on 9$a

    Lan%ua%e# Sa"et' "eature& are %uaranteed )' lan%ua%erunt$(e

    # Co(p$ler cec,& &a"e (e(or' acce&&

    # In add$t$on tere are (an$"e&t& +.r.t. +at te

    proce&& +$ll and +$ll not do

    #  T$& +a' 'ou %et protect$on

    # And no need "or ard+are protect$on do(a$n& 6ever't$n% can run $n a &$n%le addre&& &pace

    # S$n%ular$t': an OS "ro( M$cro&o"t $(ple(ented te&econcept&

    # ... -nd d$%re&&$on

  • 8/16/2019 Lecture3 Os Support

    8/208CMPT 431 © A. Fedorova

    In"ra&tructure Prov$ded )' te

    OS# et+or,$n%

    6 Inter"ace to net+or, dev$ce&

    6 I(ple(entat$on o" co((on protocol&: TPC;DP IP

    # Proce&&e& and tread&

    6 -

  • 8/16/2019 Lecture3 Os Support

    9/209CMPT 431 © A. Fedorova

     Te eed "or 7ood

    Proce&&Tread Support

    • Man' d$&tr$)uted appl$cat$on& are $(ple(ented u&$n%(ult$ple tread& or proce&&e&

    • *'

  • 8/16/2019 Lecture3 Os Support

    10/2010CMPT 431 © A. Fedorova

    Mot$vat$on "or Mult$treaded

    De&$%n&# Server& prov$de acce&& to lar%e

    data &et& 2+e) &erver& e/co((erce &erver&

    # -ven $n te pre&ence o" cac$n%

    te' o"ten need to do IO 2toacce&& 0le& on d$&, or a net+or,FS

    # IO ta,e& (uc lon%er tanco(putat$on

    # Overlapp$n% IO +$t co(putat$on

    to $(prove re&pon&e t$(e#  Tread& (a,e $t ea&' to overlap IO

    +$t co(putat$on

    # *$le one tread )loc,& on IOanoter can per"or( co(putat$on

    Singlethread

    Multiple

    threads

    1request

    1.6requests

  • 8/16/2019 Lecture3 Os Support

    11/2011CMPT 431 © A. Fedorova

    Proce&& or Tread Scedul$n%

    # *$ll u&e >proce&&? and >tread? $ntercan%ea)l'6 A &$n%le/treaded proce&& (ap& to a ,ernel tread

    6 -ac tread $n a (ult$treaded proce&& 2u&uall' (ap& to a

    ,ernel tread# A &ceduler dec$de& +$c tread run& next on te

    CP;

    #  To en&ure %ood &upport "or DS co(ponent& a&ceduler (u&t:

    6 8e &cala)le

    6 8alance te load +ell

    6 -n&ure %ood $nteract$ve re&pon&e

    6 5eep context &+$tce& to a ($n$(u( 2+'

  • 8/16/2019 Lecture3 Os Support

    12/2012CMPT 431 © A. Fedorova

    Ca&e Stud': Solar$&@ 1 OS

    # Solar$& $& o"ten u&ed on &erver &'&te(&

    # 5no+n "or $t& %ood &cala)$l$t' %ood load

    )alanc$n% and $nteract$ve per"or(ance# *e +$ll loo, at Solar$& runqueues and

    o+ te' are (ana%ed

    6 A runqueue $& a &cedul$n% Bueue

    6 A &tructure conta$n$n% po$nter& to runna)letread& 6 $.e. tread& tat are +a$t$n% "orCP;

  • 8/16/2019 Lecture3 Os Support

    13/2013CMPT 431 © A. Fedorova

    !unBueue& $n Solar$&

    7lo)al ,ernelpr$or$t' Bueue

    kpqueue

    ;&er pr$or$t'Bueue& "or CP;

    disp_q &

    ;&er pr$or$t'Bueue& "or CP;1

    disp_q &

    Pri

    0

    Pri

    1

    Pri

    N

    Pri

    0

    Pri

    1

    Pri

    N

    •  Tere $& a u&er/level Bueue "or eac pr$or$t' level• A dispatcher run& te tread "ro( te $%e&t/pr$or$t' non/e(pt'

    Bueue

  • 8/16/2019 Lecture3 Os Support

    14/2014CMPT 431 © A. Fedorova

    Proce&&or Load 8alanc$n%

    # Load )alanc$n% en&ure& tat te load $& evenl'd$&tr$)uted a(on% te CP;& on a (ult$proce&&or

    #  T$& $(prove& te overall re&pon&e t$(e

    # Solar$& ,ernel en&ure& tat Bueue& are +ell )alanced+en $t enBueue& a tread $nto a runBueue

    /*

    * setbackdq() keeps runqs balanced such that the difference in length

    * between the chosen runq and the next one is no more than RUNQ!"#$%&&'

    * () */

    A comment from Solaris source code. Source:ttp:cv&.open&olar$&.or%&ourcexre"onnvonnv/%ateu&r&rcut&co((ond$&pd$&p.c l$ne 1

  • 8/16/2019 Lecture3 Os Support

    15/2015CMPT 431 © A. Fedorova

     Tun$n% Tread Pr$or$t$e& For

    I(proved !e&pon&e T$(e# I" a tread a& +a$ted too lon% "or a proce&&or $t&

    pr$or$t' $& elevated &o no tread $& &tarved

    #  Tread& old$n% cr$t$cal re&ource& are put to te front  o"

    te Bueue &o tat te' relea&e to&e re&ource& a&Bu$c,l' a& po&&$)le

    /*

    * ut the specified thread on the front of the dispatcher

    * queue corresponding to its current priorit'

    *

    * +alled with the thread in transition, onproc or stopped state

    * and locked (transition implies locked) and at high spl'* Returns with the thread in -.RUN state and still locked'

    */

    A comment on setfrontdq  from Solaris source code. Source:ttp:cv&.open&olar$&.or%&ourcexre"onnvonnv/%ateu&r&rcut&co((ond$&pd$&p.c l$ne 13E1

  • 8/16/2019 Lecture3 Os Support

    16/2016CMPT 431 © A. Fedorova

    -n&ur$n% 7ood !e&pon&$vene&&

    $n T$(e/Sar$n% Sceduler# Solar$&& t$(e/&ar$n% &ceduler 2te de"ault

    &ceduler a&&$%n& pr$or$t$e& &o a& to en&ure %ood$nteract$ve per"or(ance

    #  T$(e&l$ce: te a(ount o" t$(e a tread can run onCP; )e"ore $t $& pre/e(pted

    # I" tread T u&ed up $t& ent$re t$(e&l$ce on CP;:6 pr$or$t'2TG t$(e&l$ce2TH

    # I" tread T a& %$ven up CP; )e"ore u&$n% up $t&t$(e&l$ce:6 pr$or$t'2T H t$(e&l$ce 2T G

    # *' $& t$& done

  • 8/16/2019 Lecture3 Os Support

    17/2017CMPT 431 © A. Fedorova

     T$(e/Sar$n% Sceduler:

    An&+er&# M$n$($=$n% context &+$tc co&t&:

    6 CP;/)ound tread& &ta' on CP; lon%er +$tout a context &+$tc

    6 In co(pen&at$on te' are &ceduled le&& o"ten due to decrea&edpr$or$t'

    6 !educ$n% te nu()er o" context &+$tce& $(prove& per"or(ance

    # -n&ur$n% %ood re&pon&e "or $nteract$ve appl$cat$on&6 Interact$ve appl$cat$on& u&uall' dont u&e up te$r ent$re t$(e&l$ce

    6 -xa(ple: proce&& a net+or, (e&&a%e and relea&e te CP; )e"orete t$(e&l$ce exp$re&

    6  To&e appl$cat$on& +$ll ave te$r pr$or$t' elevated &o te' +$llre&pond Bu$c,l' +en re&pon&e $& needed 2e.%. te next net+or,pac,et arr$ve&

  • 8/16/2019 Lecture3 Os Support

    18/2018CMPT 431 © A. Fedorova

    *at L$($t& Per"or(ance o"

    MPMT Appl$cat$on&#  Te co&t o" context &+$tc$n% 6 depend& on te

    ard+are te OS cannot 0x $t alone

    6 Savere&tore te re%$&ter&

    6 Flu& te CP; p$pel$ne6 I" &+$tc$n% addre&& &pace&

    # Ma' need to Ju& te TL8 2depend& on te proce&&or

    # Ma' need to Ju& te cace 2depend& on te proce&&or

    #  Te co&t o" $nter/proce&& co((un$cat$on2IPC: reBu$re&

    context &+$tc$n%#  Te co&t o" $nter/tread &'ncron$=at$on 6 )' and lar%e

    depend& on te pro%ra( &tructure OS can 0x &o(e o"$t )ut not all

  • 8/16/2019 Lecture3 Os Support

    19/2019CMPT 431 © A. Fedorova

     Tread S'ncron$=at$on

    I" loc, $& not ava$la)le

    tread& +a$t

  • 8/16/2019 Lecture3 Os Support

    20/20

    20CMPT 431 © A Fedorova

    ext

    # Tal, a)out &'ncron$=at$on

    # Operat$n% &'&te( &upport "or e