CS560 Midterm Exam, March 12, 2009

Answer all questions

Question 1

Recall the solution to the Dining Philosophers which specifies that each philosopher may only pick up the chopsticks when both are available to be picked up. With this solution, it is possible for a philosopher to starve. Give a specific example (sequence of actions/outcomes) where this happens.

Question 2

Compare the similarities and differences between User-Level (many-to-one) and System-Level (many-to-many) thread implementations in the following contexts: Explain the implementations in each case, and think about performance and functionality.

Question 3

Give a description of the exact operations performed when cbthread_exit() is called.

Question 4

Part 1: Describe the effectiveness of the following scheduling policies and blend of jobs. In each, explain the way in which the policy is effective and the way in which is is ineffective. Use proper performance metrics.

Part 2: Explain two tweaks to the SJF algorithm that would make it much more effective in this situation.


Question 5

You are programming JOS, and you decide to implement a named zero-buffering interprocess messaging system. You will support the following two system calls:

When a process calls send_zb_message(name, p1, s1), it will block until another process has called receive_zb_message(name, p2, s2). At that point, the operating system copies min(s1,s2) bytes from the sender's address space directly to the receiver's address space, and both processes unblock, returning the number of bytes copied. Obviously, if receive_zb_message() is called first, it blocks until there is a matching sender.

For example the following code would send the string "Jim Plank" from a sender to a receiver. The receiver is ready to receive up to 100 bytes, and ends up receiving ten:







Sending process
sent = send_zb_message("quick message", "Jim Plank", 10);
Receiving process
received = receive_zb_message("quick message", buffer, 100);

Here is jos.h:


#include "simulator.h"
#include "dllist.h"
#include "jrb.h"
#include "cbthread.h"

typedef struct {
  int regs[NumTotalRegs];
} PCB;

typedef struct {
  char *name;
  char *physical_ptr;
  int size;
  PCB *caller;
  int send_or_receive;  /* 'S' or 'R' */
} ZB_call; 

typedef struct {
  Dllist readyq;     /* Ready queue */
  PCB *running;     /* Pointer to the currently running process's PCB */
  PCB *nulljob;     /* Pointer to a 'null' job -- we'll set running to 
                       this when we run noop() */
} JOS_GLOBALS;

extern JOS_GLOBALS JG;

extern void JOS_Scheduler();

extern void process_zb(void *arg);

You have already written the exceptionHandler() code so that when send_zb_message() is caught in the operating system, it performs the proper error checking, converts the ptr to the correct physical address, and initializes a ZB_Call struct called zb with the proper information filled in (send_or_receive is set to 'S'). It then calls cbthread_fork(process_zb, (void *) zb) before calling cbthread_joinall(JOS_Scheduler, NULL).

When exceptionHandler() catches a receive_zb_message() call, it does the same thing, except the zb's send_or_receive field is set to 'R'.

Write the procedure process_zb(). To make it work, you will have to augment jos.h, and if you need initialization when the machine first boots up, state what that is. Feel free to add to the ZB_call struct if you want, although in my answer, I did not. You are not allowed to have execptionHandler() do anything other than what I've stated above.

On the answer sheet, I have included jos.h from above -- simply write on that sheet to add things to jos.h.

Finally, there is a semantic issue of what happens when multiple processes call send_zb_message() with the same name before any process calls receive_zb_message(). (And similarly when multiple processes call receive_zb_message() with the same name before any process calls send_zb_message().) To receive full credit, your answer must order those in FIFO order. If you do not have time to deal with this issue, you will lose about 20% on this question, so if you are running short on time, don't worry about this issue -- just get the question answered.