Homework 4 Solutions

22C:116, Fall 1999

Douglas W. Jones

  1. The Problem: Keeping in mind that we are using longjmp() and setjmp() for context switching, what feature of sigvector() prevents us from using setitimer() to do preemptive scheduling?
    The problem is that sigvector() is advertised as creating a new context for signal handling, distinct from the stack of the user process. The manual gives no hint about how to find the stack of the interrupted process. The thread package uses a separate stack for each thread, and context switching is only possible because we can find the stack of the process that is running.

    Another way of looking at the problem is to examine what would happen if our setjmp()/longjmp() context switching code was run under sigvector(). The call to setjmp() would save the new context of the signal handler instead of saving the context of the preempted thread. This is useless for thread management!

  2. Outline the structure of a page fault handler for the R2000 (Figure 3-22 in Tannenbaum).
    The following outline suffices:
    	page fault handler:
    	   va = virtual address that caused fault
    	   va.page = page number field of virtual address
    	   if page_table[va.page].legal = false
    	       -- this is an access to an illegal address
    	       -- do something like aborting the current process
    	       -- or send it a signal so it can handle the fault
    	   endif
    	   if page_table[va.page].valid = false
    	       -- this is a real page fault
    	       -- do page replacement
    	   endif
    	   -- assert that page_table[va.page].valid = true
    
    	   -- select slot, the associative memory location to use
    	   associative_memory[slot].virtual_page = va
    	   associative_memory[slot].page_frame = page_table[va].page_frame
    	   associative_memory[slot].ndvg = page_table[va].ndvg
    	return
    	

  3. Assuming you were interested in a pure interrupt driven asynchronous transmitter using EIA flow control, what conditions would you want the hardtware to detect, requesting an interrupt when they occurred?
    We are given that the hardware requests an interrupt on TXREG empty. When this occurs, we get the next character of output and stuff it into TXREG and enable the new TRMT=0 interrupt. If there is no next character because the application hasn't enqueued it yet, we set TXIE to zero.

    We need an interrupt on TRMT=0. When this occurs, we de-assert RTS and disable this interrupt. RTS will be asserted whenever a character is enqueued by the application.

    We need an interrupt whenever CTS changes. If the change is to the asserted state and there is data from the application ready to transfer to TXREG, we set TXIE. If the change is to the unasserted state, we reset TXIE.