Docsity

ECE 398SSL Final Exam, Fall 2004, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 398SSL Final Exam, Fall 2004
Friday, December 17th, 2004
Name:
• Be sure that your exam booklet has 10 pages.
• Write your name at the top of each page.
• This is a closed book exam.
• You are allowed three 8.5 x 11” sheets of handwritten notes.
• Absolutely no interaction between students is allowed.
• Show all of your work.
• Challenge questions are marked with ***.
• Don’t panic, and good luck!
Problem 1 20 points
Problem 2 20 points
Problem 3 20 points
Problem 4 20 points
Problem 5 20 points
Total 100 points
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download ECE 398SSL Final Exam, Fall 2004 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

ECE 398SSL Final Exam, Fall 2004

Friday, December 17th^ , 2004

Name:

• Be sure that your exam booklet has 10 pages.

• Write your name at the top of each page.

• This is a closed book exam.

• You are allowed three 8.5 x 11” sheets of handwritten notes.

• Absolutely no interaction between students is allowed.

• Show all of your work.

• Challenge questions are marked with ***.

• Don’t panic, and good luck!

Problem 1 20 points

Problem 2 20 points

Problem 3 20 points

Problem 4 20 points

Problem 5 20 points

Total 100 points

Problem 1 (20 points): Short Answers

Answer the following questions concisely. You should not need to write more than a sentence or two; if

you are writing more, it is probably wrong.

Part A (5 points): You are working with a team to develop a hash table that speeds up mapping from

physical page addresses in an x86-based machine into virtual addresses (via a memory region structure

to be found using the hash table). A hash table of 1,024 elements is appropriate for this task. Is the

function hash_value = ((physical address) % 1024) a good choice or a bad choice for the

hash function used to decide in which element to search for the memory region structure? Explain your

answer.

Part B (5 points): Under what conditions should a process that has masked a certain signal be forced to

receive that signal immediately ( i.e. , without waiting for the process to unmask it)?

Part C (5 points): You are required to port a large program to a new operating system that supports only

one choice of signal handler for all possible signals. In particular, a call to the function

set_signal_handler ((void) (*new_handler) (int));

installs the new handler for the process, and the handler is called for any signal delivered to the program.

The argument to the handler is the number of the signal being delivered. What data structure can you

use to extend this interface to allow separate handlers for each type of signal? Explain how a handler for

a specific signal can be installed and invoked using that data structure.

Part D (5 points): How does the Linux kernel track the number of uses of a file structure (or memory

map)? Why does it do so?

Problem 2, continued:

One possible strategy for synchronization is to simply add a lock to the data structure and to require that

all methods acquire the lock (for the entirety of the method). Alternatively, one can use more than one

lock.

Part B (4 points): What are the advantages of using more than one lock?

Part C (4 points): What are the hazards of using more than one lock, and how can you avoid them?

Part D (4 points): Using the two locks added to the data structure, add the necessary lock and unlock

calls ( e.g. , lock (&s->lock_1)) into the code for the two-lock synchronization strategy.

typedef struct { lock_t lock_1; lock_t lock_2; int A; int B; } score_t;

void normalize (score_t* s) {

if (s->A < s->B) { s->A = 0; s->B = s->B – s->A; } else { s->B = 0; s->A = s->A – s->B; }

void A_scores (score_t* s) {

s->A = s->A + 1;

void handicap (score_t* s) {

if (s->A < s->B) { s->A = s->A + 2; } else { s->B = s->B + 2; }

void B_scores (score_t* s) {

s->B = s->B + 1;

Problem 3 (20 points): Analyzing a Synchronization Strategy

As part of developing a new operating system, you have defined the following structures to track the

files opened by a program and to synchronize changes to this table.

/* statically allocated file descriptor table with up to 1,024 entries / typedef struct { file elt[1024]; } file_table_t;

task structure includes pointer to file descriptor table and lock to synchronize changes to the table / typedef struct { / (lots of other stuff omitted) / lock_t file_lock; / lock to protect file descriptor table / file_table_t files; /* pointer to file descriptor table / / (possibly shared) */ } task_t;

Unfortunately, you have run into a problem. In some situations, two threads in a single program (the two

threads share a file descriptor table) open two different files and have the open system call return

success, but both system calls return the same file descriptor, and only one of the files is accessible (by

both threads).

Based on the data structures above, explain how this problem occurs and how it can be solved.

Problem 4, continued:

*** Part B (8 points): A friend of yours has developed wrappers for setjmp and longjmp that allow

the caller to setjmp to specify the (non-zero) return value rather than the longjmp. The return value is

stored in a new data structure that also holds the jmp_buf, and is used when the new version of

longjmp is called. Unfortunately, your friend’s implementation doesn’t seem to work. Look at the

code below and explain why. Hint: it may help to draw the stack during the two calls.

typedef struct { jmp_buf jb; /* jump buffer for setjmp/longjmp / int rval; / return value for longjmp */ } my_jmp_buf;

int my_setjmp (my_jmpbuf* env, int val) { env->rval = val; setjmp (env->jb); }

void my_longjmp (my_jmpbuf* env) { longjmp (env->jb, env->rval); }

Problem 5 (20 points): Virtual Memory and Page Tables

In this problem, you must write code to walk an x86 page table and find the swap disk block number

corresponding to a virtual address. Your code will be called by the page fault handler after it determines

that the fault corresponds to a virtual address that has been allocated for the current process. The

missing page may be at any level of the page table hierarchy below the page directory (which is always

in memory), so you will need to handle all such cases.

Use the helper functions on the next page to simplify your code (you can tear them off).

/* call this function once your function finds the swap block number */ extern void load_swap_block (u32 virt_addr, u32 block_num);

  • given a virtual address for which the page is not present in memory,
  • find the swap (disk) block number for the page and invoke the
  • load_swap_block function to load it into memory. page_dir_virt_addr
  • is the virtual address of the page directory. */ void find_missing_block_number (u32 virt_addr, u32 page_dir_virt_addr) {

(scratch paper)