Solutions to quiz I cse120 Operating System

If you got partial points (like 1/2 or 1/3 point), I rounded your final score to the nearest point. For example, 21 2/3 => 22.
Note the total score is 43 not 40!


       q1:   disable all interrupts    Y
              
             read time-of-day clock    N
             
             Set time-of-day clock     Y
             
             change the memory map     Y
             
 
             1 point for each correct answer.            
             
       q2:  TSL is a low level operation used by the kernel to
            implement semaphores or other high-level blocking
            primitives. TSL is a busy-wait lock and is used only
            for very short period of time. It is not suitable for
            long-term waiting.
             
             4 points if you have something like above.
             2 points if you said that TSL is "inefficient" but didn't
                      say anything about how semaphore is different.
         
              
       q3:        putzero in register r;
              L1: SWAP(r,LOCKVAR)
                  if r is 0 then goto L1;
                          
                   /*   ***************
                  critical section code
                     **************** */
                  
                 
                  STORE 1 in LOCKVAR
                  


              4 points if you have the correct code.
              3 points if you described it correctly but small portion
                of the code didn't work.
              2 points if you described it correctly but a significant
                portion of the code didn't work.

                  
       q4:     In the busy wait by TSL to regulate entry to critical
               section, P and Q can preempt R from entering the CS.
               There is no scheduling among the busy-wait processes.

               4 points if you said "starvation" or that one process
                 might never enter the critical section.
               0 point if you said anything about TSL being interrupted
                 in the middle of testing and setting the variable.
                 Remember, TSL is atomic.               

               
       q5:     item     filled in as      remarks
               -----    ------------      --------
               
               TEST-A   aw==1 | ww!=0     an active or a waiting writer
                 
               Z1       readerwaiting     queue for waiting readers
               
               TEST-B   ar==0 && ww!=0    no active reader and writer waiting
               
               TEST-C   ar!=0 || aw==1    reader(s) and/or writer active
               
               Z2       writerwaiting
               
               Z3       readerwaiting     /*clear all waiting readers, if none
               
               Z4       writerwaiting     clear one waiting writer (if any)*/
               
               
	       1 point each.
               -1/2 for TEST-A/B/C if you only have half of the
                    condition.  For example, TEST-C should be
                    "ar!=0||aw==1".  If you only put ar!=0, you get 1/2
                    point off.

               Note: this problem is worth 7 points, not 4!

       q6:     First fit takes 20k, 10k, 18k
               Best fit takes  12k, 10k, 9k
               worst fit takes 20k, 18k, 15k
               Next fit takes  20k, 18k, 9k
  
               -1 1/3 points for each incorrect individual fit.  For
                      example, for best bit of 12k, if you choose the
                      slot 20k instead of 12k, you got 1 1/3 points off.

       q7:     Small quantum is used when you want fast user response 
               time (ie, interactive processes).
    
               Large quantum is used to reduce amount of context
               switching (less CPU time on overhead) and thus more CPU
               time on users jobs. 

               2 points for each explaination.