Final

22C:116, Spring 1995

Douglas W. Jones
Please write your answers in the exam booklet provided. Make sure your name is on the front cover of the booklet, in the same form as it appears in the official class list! Illegible and overly long answers are difficult to grade. Please leave margins around your answers!
  1. Background: Consider a typical memory management unit that permits pages to be marked as read-only, read-write, or invalid. When an instruction references an invalid page, a page fault trap occurs; the saved program counter and registers available to the trap-service routine reflect the state of the machine immediately prior to executing the instruction that caused the trap. In addition, the memory management unit reports the virtual address that was referenced to cause the trap.

    Most page-fault service routines merely virtualize the memory address space by copying pages from disk in response to page faults. In theory, though, the software could do many other things with invalid pages. One option that has not been exploited by any system I know of is the option of implementing access to Unix-like pipes (interprocess communication channels) using load and store instructions interpreted by the page fault service routine. To implement this option, invalid pages in the address map must be able to be marked as representing pipes, and the page fault service routine must be modified to perform pipe operations when it detects a load or store operation on such a page.

    Problem, part A: Write example code for a process that reads and copies data from one pipe to another using this implementation, assuming that the necessary pipes have already been created outside your code and that the stream of data to be copied is of infinite length.

    Problem, part B: If you were designing the pipe interface, how would you handle the problem of special pipe operations such as writing an end-of-file mark on the pipe, and how would your implementation signal end-of-file to users reading from a pipe.

    Problem, part C: Give a brief outline of how the page fault service routine would implement this pipe interface, with an emphasis on those areas that both differ from conventional page fault service and from conventional pipe implementations.

  2. Background: Consider a file server that offers locking services defined as follows: The operation lock(u,f,a,b) waits until none of the bytes in the range a to b (inclusive) are locked, and then locks those bytes on behalf of user u before returning a reply message. The operation unlock(u,f) unlocks all locks held by user u on file f. Users may issue multiple lock commands on the same file.

    Problem, part A: Formally speaking, what are the resources this system allows to be locked and what deadlock model applies?

    Problem, part B: Assuming that only one file server is involved, what problems would you encounter in implementing a reasonable deadlock detection algorithm for the server.

  3. Background: Consider the problem of implementing a timed wait for I/O completion. One implementation of this rests on a non-blocking read operation and a non-blocking time-delay operation.

    read(b,s) reads from standard input into buffer b and signals the semaphore s when the operation is complete.

    delay(t,s) causes semaphore s to be signaled after a delay of t seconds.

    Problem, part A: What behavior would you expect from the following code:

        S: semaphore with S.count=0
        loop
           read(b,S)
           delay(1.0,S)
           wait(S)
           process(b)
        end loop
    
    Problem, part B: Given that the desired operation is a timed read that either returns the input data or gives up on reading after one second, will the following version of this operate correctly? Please assume that infinite memory is available.
        loop
           S = pointer to new semaphore with S.count=0
           read(b,S^)
           delay(1.0,S^)
           wait(S^)
           process(b)
        end loop
    
  4. Background: In the study questions, the following nondeterministic code fragment was given:
    main()
       {
         printf("%d\n",
                foo() + (foo()<<1) + (foo()<<2) + (foo()<<3)
               );
       }
    
       foo()
       {
         return(fork() ? 1 : 0);
       }
    

    Problem: When you run this ten times, you will most likely get a different answer each time. Given that the computer system itself is basically deterministic, for example, it has a deterministic scheduling algorithm running on a deterministic CPU, what is the source of the nondeterministic behavior in this program?

  5. The problem: Why is it that user level thread packages are generally only implemented on shared memory multiprocessors?

  6. Background: Consider a system that offers users access to encrypted capabilities for pages of virtual memory, with the primitives getcap and putcap, defined as in the study questions. (getcap(va) returns a bit pattern representing the capability for the page at va, and putcap(va,cap) takes a bit pattern cap and installs the corresponding page at va.)

    Furthermore, assume that makepage(va) creates a new page in the user's address space, and that killpage(va) irreversably deallocates a page. In addition, assume that the system uses demand paged virtual memory, so that pages can be moved to and from disk by the system, at will.

    The problem, part A: What storage management problems must the user and system face in using this capability system? Can these problems be solved? Would you rely on this system for critical applications?

    The problem, part B: Propose a representation of the capabilities given to the user by getcap.

  7. Background: A virtual resource is a resource seen by a user of a system that is really implemented by higher level software and not by the underlying system. The traditional example is virtual memory, but there are other examples.

    For example, consider the idea of a virtual file server. This would use some real underlying file server to implement its operations, but it might change the semantics, for example by replicating files in order to provide fault tolerance.

    The problem, part A: Explain how you would implement such a file server under a system such as DEMOS or Amoeba.

    The problem, part B: Explain how you would design the system so that a user process would be unable to tell whether it was running under a real or virtual file server.