homework 3

5

Click here to load reader

Upload: jesse-li

Post on 14-May-2017

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Homework 3

Name:  Dengfeng  Li  PSU  id:  dzl5187    1.       Pros:  

1. Provide  a  simple  but  high  level  operating  system  interface  for  software  developer.  

2. Synthesis  operating  system  uses  the  on-­‐the-­‐fly  (dynamic)  compilation.  The  dynamic  compilation  will  reduce  the  operating  system  overhead.  

3. “Data  in  a  synthetic  machine  are  freely  shared  within  it,  but  are  carefully  protected  from  access  by  other  synthetic  machines.”  

  Cons:  1. Because  of  the  on-­‐the-­‐fly  (dynamic)  compilation,  the  code  is  not  static  

and  it  is  difficult  to  debug.    2. Since  the  synthesis  operating  system  provide  the  user  with  a  high  

level  interface,  it  may  give  programmer  a  superficial  understanding  of  the  system.      

2.    a) The  operating  system  has  the  device  driver  installed  and  the  device  driver  

will  communicate  with  the  controller  of  the  device.  Once  the  CPU  need  transfer  data  to/from  the  device,  CPU  will  let  DMA  issue  send  to  the  device  controller  and  the  device  will  know  what  operation  it  will  perform.    

b) When  the  data  transaction  is  finished,  the  DMA  will  send  an  interrupt  to  the  CPU.  

c) The  process  that  DMA  controller  is  transferring  data  will  not  interfere  with  the  execution  of  the  user  programs.  But  when  the  data  transaction  is  done,  the  interrupt  generated  by  DMA  may  request  CPU  to  resume  previous  operations.  

d)    1. It  will  occupy  the  whole  core  to  manage  the  I/O  activity,  which  

reduces  the  efficiency  of  multi-­‐core  system.    2. There  will  be  a  data  sharing  or  transaction  between  cores,  which  

generate  the  overhead.    e)    

DMA  also  be  used  for  low-­‐speed  I/O  device.  For  low-­‐speed  I/O  device,  DMA  will  manage  the  I/O  activity  while  CPU  can  continue  working  on  other  tasks  until  receive  the  interrupt  from  DMA.  For  high-­‐speed  I/O  device,  DMA  can  adjust  its  frequency  to  match  with  the  high-­‐speed  I/O  device  and  use  buffer  to  temporarily  hold  data  for  CPU.    

 3.    

Page 2: Homework 3

a) Short-­‐term  scheduling:    Operating  system  will  determine  which  of  the  ready  processes  can  have  CPU  resources,  set  the  process  to  running  state  and  allocate  resource  for  them.  Medium-­‐term  scheduling:  Operating  system  will  determine  when  processes  should  be  suspended  and  resumed.  For  example,  if  a  process  requests  an  I/O  request,  operating  system  may  suspend  the  process  until  the  data  is  loaded.    Long-­‐term  scheduling:  Operating  system  will  determine  which  programs  are  admitted  to  the  system  for  execution  and  when,  and  which  ones  should  be  exited.  

b) Yes.  The  distinction  between  short-­‐  and  long-­‐term  is  not  obvious.  Because  the  web  server  will  receive  lots  of  requests  per  second,  the  scheduling  duration  is  small  compared  with  long-­‐term  scheduling.  

c) Since  system  will  pre-­‐allocate  the  process  or  threads  to  handle  new  client  requests,  the  long-­‐term  scheduler  will  first  decide  the  admittance  of  each  request  to  the  process  or  thread  pool.  Then  after  assigning  the  process  or  thread  to  request,  the  short-­‐term  scheduler  will  decide  which  process  or  thread  to  be  the  running  state.    

 4.    

a)    

 b)  

Round  time  =  finishTime-­‐  arrivalTime    First-­‐Come-­‐First-­‐Served  algorithm:     P1  =  8,  P2  =  11,  P3  =  13,  P4  =  16,  P5  =  21  Shortest  Job  Fist  algorithm:       P1  =  21,  P2=  5,  P3=  2,  P4=  8,  P5=  13  Non-­‐preemptive  priority  algorithm:     P1  =  16,  P2=  3,  P3=  21,  P4=  19,  P5=  8  Round  Robin  algorithm:     P1  =  21,  P2=  12,  P3=  8,  P4=  13,  P5=  18  

c)    Waiting  time  =  startTime  –  arrivalTime  

Page 3: Homework 3

 First-­‐Come-­‐First-­‐Served  algorithm:     P1  =  0,  P2  =  8,  P3  =  11,  P4  =  13,  P5  =  16  Shortest  Job  Fist  algorithm:       P1  =  13,  P2  =  2,  P3  =  0,  P4  =  5,  P5  =  8  Non-­‐preemptive  priority  algorithm:     P1  =  8,  P2  =  0,  P3  =  16,  P4  =  18,  P5  =  3  Round  Robin  algorithm:     P1  =  13,  P2  =  9,  P3  =  6,  P4  =  10,  P5  =  13  

d)  Average  waiting  time  =  total  waiting  time  /  number  of  prcess    First-­‐Come-­‐First-­‐Served  algorithm:     Average  waiting  time  =  (0  +  8  +  11  +  13  +  16)/5    =9.6  Shortest  Job  Fist  algorithm:       Average  waiting  time  =  (13  +  2  +  0  +  5  +  8)/5  =  5.6  Non-­‐preemptive  priority  algorithm:     Average  waiting  time  =  (8  +  0  +16  +  18  +  3)/5  =  9  Round  Robin  algorithm:     Average  waiting  time  =  (13  +  9  +  6  +  10  +13)/5  10.2      The  result  shows  that  the  Shortest  Job  Fist  algorithm  has  the  minimal  average  waiting  time.    

5.      a) Assume  the  process  that  the  two  pointers  indicate  P1.  If  the  memory  space  is  

enough,  the  scheduler  will  allocate  another  memory  space  for  P1,  which  reduce  the  memory  utilization.  On  the  other  hand,  if  the  memory  space  is  not  enough,  the  scheduler  will  first  swap  out  another  process  and  load  duplicated  P1  into  memory  again.  Either  way  duplicates  the  memory  space  of  P1.    

b)    Advantages:  

1. It  can  implement  priorities.  2. Simple  scheme  can  do  minimal  modification.  

Disadvantages:  1. Overhead  for  managing  pointers.  2. When  a  same  process  running  frequently,  it  will  cause  

unnecessary  context  switch.    c)    

We  can  assign  different  quantum  of  time  to  each  process  according  to  its  priority.  For  example,  for  process  with  low  priority,  it  should  be  assigned  with  one  quantum  of  time,  and  for  process  with  high  priority,  it  can  be  assigned  with  three  quantum  of  time.    

   

Page 4: Homework 3

6.    a) This  may  cause  deadlock.  Suppose  the  agent  produce  tobacco  and  paper,  and  

smoker1  get  the  tobacco  and  smoker3  get  the  paper.  Both  smoker1  and  somker3  are  waiting  for  another  ingredient.  Meanwhile,  agent  is  waiting  one  of  the  smokers  finish  smoking  to  produce  more  ingredient.  Thus,  there  is  a  deadlock  among  somer1,  somker3  and  agent.    

b)    1. More  than  three  smokers  

We  do  not  need  to  change  the  structure  of  the  semaphore  because  each  process  will  still  request  only  one  resource  from  the  agent.  Then,  the  deadlock  between  processes  does  not  exist.    

  PROCEDURE  smoker4      {This  smoker  has  matches}                     BEGIN                           WHILE  (not_dead)  DO                           BEGIN                                 wait(tobacco_paper);                                   smoke;                                 signal(done_smoking);                           END;  

END;    2. More  than  one  agent  

We  do  not  need  to  change  the  code  of  the  agent.  Although  the  agents  may  cause  a  race  condition,  it  is  harmless  to  the  overall  system  and  there  is  no  race  condition.    

3. More  than  three  tobacco-­‐related  products  If  we  keep  the  model  as  the  same  as  before  (each  smoker  still  have  one  infinite  resource  and  agent  generate  N-­‐1  ingredients),  we  need  change  the  structure  of  the  semaphore.      For  example,  if  the  ingredients  are:  tobacco,  paper,  match  and  spice    PROCEDURE  agent                  BEGIN                      WHILE  (making_money)  DO                      BEGIN                          CASE  (random(1,3))  OF                              1:  signal(tobacco_paper_match);                              2:  signal(tobacco_paper_spice);                              3:  signal(tobacco_matches_spice);  END;                          wait(done_smoking);                      END;  END;    

Page 5: Homework 3

PROCEDURE  smoker1      {  This  smoker  has  matches  }                  BEGIN                      WHILE  (not_dead)  DO                      BEGIN                          wait(tobacco_paper_match);                              smoke;                          signal(done_smoking);                      END;  END;    

c) If  we  move  the  wait(done_smoking)  before  the  CASE  statement,  it  may  cause  deadlock  at  the  first  time  where  the  agent  is  waiting  for  done_smoking  and  smokers  are  waiting  for  ingredient.  We  can  change  the  done_smoking  initial  value  to  1  to  prevent  the  deadlock.    

 BEGIN                     tobacco_paper  :=  0;                     tobacco_matches  :=  0;                     paper_matches  :=  0;                     done_smoking  :=  1;  END.