15 213 Introduction to Computer Systems Exam 2 April 10 2007 Name Andrew User ID Recitation Section This is an open book exam Notes and calculators are permitted but not computers Write your answer legibly in the space provided You have 80 minutes for this exam We will drop your lowest score among questions 1 6 Problem Max Score Symbols and Linking 1 15 Virtual Address Translation 2 15 Process Control 3 15 Signals 4 15 Garbage Collection 5 15 Cyclone 6 15 Total 75 1 1 Symbols and Linking 15 points In this problem we consider issues of symbols and linking Consider the following three files File polygon h struct Node float pos 2 int marked struct Node next struct Node prev typedef struct Node node only for GC node alloc void init void gc allocated new node initialize store call garbage collector File main c with portions of the function elided include polygon h node root ptr int main node p init p alloc root ptr p gc return 0 root pointer for GC GC root is first allocated pointer File gc c with function bodies elided include polygon h define N 1 20 static node polygon N static node free ptr static node root ptr polygon array free list root pointer for GC void mark node v void sweep void gc void init node alloc 2 Possible definition of the functions in gc c are revisited in Problems 5 and 6 although this is not relevant here Recall that a line include file will literally be replaced by the contents of file by the C preprocessor We compile the files to obtain an executable object file polygon with gcc o polygon main c gc c Questions related to symbols and linking therefore refer to the expanded versions of the files 1 9 points Fill in the following tables by stating for each name whether it is local or global and whether it is strong or weak Cross out any box in the table that does not apply For example cross out the first box in a line if the symbol is not in the symbol table or cross out the second box in a line if the symbol is not global and therefore neither weak nor strong main c Local or Global Strong or Weak root ptr init main gc c Local or Global Strong or Weak N polygon root ptr alloc 3 2 3 points Explain why linking succeeds to create an executable despite the fact that some symbols are declared in both files 3 3 points Explain why the executable fails to be correct despite the fact that it compiles and links without warning Propose how to fix the bug Be clear in your suggestion correction for example replace the line with 4 2 Virtual Address Translation 15 points In this problem we consider virtual address translation using a two level page table The parameters of the machine are as follows The memory is byte addressable Virtual addresses are 32 bits wide The 32 bits of the virtual address are divided into 8 bits for VPN1 8 bits for VPN2 and 16 bits for the VPO Physical addresses are 24 bits wide 1 3 pts Given the parameters above fill in the blanks below i The page size is ii The maximal physical memory size is iii Assuming a page table entry is 32 bits the size of a page table is Next we consider the behavior of address translation using the two level page table We assume that page table entries have the following form where unspecified bits are irrelevant for this problem Level 1 Bits 31 16 High 16 bits of level 2 page table physical base address Bit 0 1 Present in physical memory Level 2 Bits 31 24 PPN Bit 0 1 Present in physical memory For the following questions assume that the VPN is not cached in the TLB so we have to consult the page tables The PTBR is set at 0xC80000 Address Content Address Content 0xC80000 0xC80004 0xC80008 0xC8000C 0xCA1C0001 0xCA1B0000 0xCA1D0001 0xCA1B0001 0xCA1B00 0xCA1B04 0xCA1B08 0xCA1B0C 0x07000001 0xFF000000 0x08000001 0xCA000001 0xC80010 0xC80014 0xC80018 0xC8001C 0x00000000 0xCA1B0001 0xC8000000 0xCA1B0001 0xCA1B10 0xCA1B14 0xCA1B18 0xCA1B1C 0x01000000 0x00000000 0x09000001 0xCA000000 5 2 6 points For the virtual address 0x0300F218 indicate the physical address and various results of the translation If there is a page fault enter for the answer and all subsequent results All answers should be given in hexadecimal Parameter Value VPN1 VPN2 PTE level 1 Page Fault Y N PTE level 2 Page Fault Y N PPN Physical Address 3 6 points For the virtual address 0x0507EE00 indicate the physical address and various results of the translation If there is a page fault enter for the PPN and Physical Address All answers should be given in hexadecimal Parameter Value VPN1 VPN2 PTE level 1 Page Fault Y N PTE level 2 Page Fault Y N PPN Physical Address 6 3 Process Control 15 points Consider the following C program For space reasons we do not check return codes so assume that all functions return normally Also assume that printf is unbuffered and that each process successfully runs to completion int main int pid pid fork fork if pid printf A n else printf B n exit 0 Mark each column that represents a valid possible output of this program with Yes and each column which is impossible with No A A A A A A A A A A A B B A B B 7 4 Signals 15 points Consider the following code int val 1 void handler int sig waitpid 1 NULL 0 val int main int pid signal SIGCHLD handler pid fork if pid 0 val 0 exit 0 printf d n val exit 0 Assume that all system calls succeed and that all processes terminate normally List all possible outputs of this program 8 5 Garbage Collection 15 points In this problem we consider code for a specialized mark and sweep garbage collector a skeleton of which was introduced in Problem 1 We first explain the data structures A polygon is implemented as a doubly linked list of vertices where each vertex has a link to its successor and predecessor vertices the next and prev pointers respectively In addition the x and y position of each vertex are stored in pos 0 and pos 1 struct Node float pos 2 int marked struct Node next struct Node prev typedef struct Node node only for GC Finally we have a mark field marked which is used exclusively by the garbage collector and should not be touched by the user program For simplicity we store this as a whole int instead of as a bit There is a static array polygon of size N containing all vertices There is also a pointer to the beginning of a list of free vertices free ptr and a single root pointer root ptr pointing to the polygon The free pointer must be maintained by the garbage collector the root pointer is maintained by the user program and may not be changed by the garbage collector define N 1 20 node …
View Full Document