





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Name (Last, First):
This exam consists of 5 questions on 9 pages; be sure you have the entire exam before starting. The point value of each question is indicated at its beginning; the entire exam is worth 100 points. Individual parts of a multi-part question are generally assigned approximately the same point value: exceptions are noted. This exam is open text and notes. However, you may NOT share material with another student during the exam. Be concise and clearly indicate your answer. Presentation and simplicity of your answers may affect your grade. Answer each question in the space following the question. If you find it necessary to continue an answer elsewhere, clearly indicate the location of its continuation and label its continuation with the question number and subpart if appropriate.
You should read through all the questions first, then pace yourself.
The questions begin on the next page.
Problem Possible Score 1 20 2 20 3 20 4 20 5 20 Total 100
Short answer questions (continuted on next page)
(a) Write a small C code snippet that dynamically determines the maximum number of threads you can create in Pintos. Assume your code will execute in the main thread after Pintos starts up.
(b) Recall the dining philosophers problem. If you have 7 philosophers and 7 plates of food and 7 forks, what is the maximum number of philosophers that can be eating simultaneously?
User-level Memory Allocation Recall your implementation of the user-level memory allocator API from Project 0. Consider the following C code that uses your API:
/* include files omitted */ int main(int argc, char *argv[]) { uint8_t *a, *b, *c, *d;
printf("sizeof(struct used_block) = %u\n", sizeof(struct used_block)); printf("sizeof(struct free_block) = %u\n", sizeof(struct free_block)); mem_init(memory, 128); a = mem_alloc(64); printf("a_rel = %u\n", (unsigned) (a - memory)); b = mem_alloc(16); printf("b_rel = %u\n", (unsigned) (b - memory)); c = mem_alloc(16); printf("c_rel = %u\n", (unsigned) (c - memory)); d = mem_alloc(16); printf("d_rel = %u\n", (unsigned) (d - memory)); mem_free(c); mem_free(a); a = mem_alloc(32); printf("a_rel = %u\n", (unsigned) (a - memory)); exit(0); }
Here is the output from running this program on a 32-bit machine:
sizeof(struct used_block) = 4 sizeof(struct free_block) = 12 a_rel = 64 b_rel = 44 c_rel = X d_rel = 4 a_rel = Y
Determine the values of X and Y. Assume you allocator splits used blocks from the top of free blocks and that you have implemented a first-fit allocation policy. Show your work.
Periodic Functions In operating system kernels it is useful to define functions that wake up at regular intervals to do work. For example, you might want to monitor the network every 4000 ticks. In this problem, you are going to add support for registering periodic functions. Consider the following interface:
int register_periodic_func(int64_t interval, thread_func func, void *aux) int unregister_periodic_func(thread_func func)
You need to implement these functions and the internal support to have a function, func, execute with the aux parameter every interval ticks. You can assume that a periodic function will not block and that a period function will only be registered once. For example, a thread in Pintos could execute the following:
void every_1000(void *aux) { printf("every_1000: fired!"); }
void every_3000(void *aux) { printf("every_3000: fired!"); }
int main(void) { ... thread_init(); .... periodic_timer_init();
register_periodic_func(1000, every_1000, (void *) 1000); register_periodic_func(3000, every_3000, (void *) 3000); timer_sleep(10000); unregister_periodic_func(every_1000); unregister_periodic_func(every_3000); }
This code snippet will register two periodic functions and wait for 10,000 ticks. This will allow every_1000() to fire 9 times and every_3000() to fire 3 times. Give your code for register_periodic_func() and uregister_periodic_func(). Described any new data structures and modifications to existing Pintos data structures. Also, give your internal support code to ensure the registered functions fire at the specified intervals. You need to justify the location of your internal support code. Also, you should properly handle synchronization. (Note: you can assume you have a working blocking timer_sleep() implementation.) Continue your solution on the next page.
Priority Inversion and Priority Donation
Assume you have properly implemented priority scheduling and priority donation in the Pintos ker- nel. Determine the output of the following test code (assume that the main thread is running at PRI_DEFAULT):
static void a_thread_func (void *lock_) { struct lock *lock = lock_;
msg ("AAA"); lock_acquire (lock); msg ("AAA Lock a"); lock_release (lock); }
static void b_thread_func (void *lock_) { struct lock *lock = lock_;
msg ("BBB"); lock_acquire (lock); msg ("BBB Lock b"); lock_release (lock); }
void test_priority_donate_multiple (void) { struct lock a, b;
lock_init (&a); lock_init (&b);
lock_acquire (&a); lock_acquire (&b);
msg ("Main 1"); thread_create ("a", PRI_DEFAULT + 1, a_thread_func, &a); msg ("Main 2");
thread_create ("b", PRI_DEFAULT + 2, b_thread_func, &b); msg ("Main 3");
lock_release (&b); msg ("Main 4"); lock_release (&a); msg ("Main 5"); }
VTRR Scheduling For project 1 you needed to implement different forms of VTRR (Virtual-Time Round-Robin) schedul- ing in Pintos. (10 points) Simple VTRR Consider 4 clients, A, B, C, and D. Now consider the following full scheduling cycle for these clients scheduled with simple VTRR:
If Q = 1, what are the share values for each client?
(10 points) Static VTRR Now assume two clients, A (with share = 2) and B (with share = 1). Show the first two steps of a scheduling cycle with static VTRR (Assume Q = 1). Determine the initial counter values and VFT values. Show the results of the time counter invariant check and the VFT inequality check. (You can leave you calculation in fractions).
Step 0 A.counter = ____ A.vft = ____ B.counter = ____ B.vft = ____ QVT = ___
Schedule Client ____
Step 1 A.counter = ____ A.vft = ____ B.counter = ____ B.vft = ____ QVT = ___
Schedule Client ____