Chopsticks - Operating System - Exam, Exams of Operating Systems

These are the Exam of Operating System which includes Caller-Save, Trap Frame, Interrupt Handling, Latest, Processor-Architecture News, Building, Management, Analysis, Management etc.Key important points are: Chopsticks, Programs, User Mode, Kernel Mode, Runnable, Progress, Bus Lock, Closed-Book, Class Exam, Reference

Typology: Exams

2012/2013

Uploaded on 03/28/2013

rohit-sharma
rohit-sharma 🇮🇳

4.3

(11)

200 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 15-410: Operating Systems
Mid-Term Exam (B), Fall 2008
1. Please read the entire exam before starting to write. This should help you
avoid getting bogged down on one problem.
2. Be sure to put your name and Andrew ID below and also put your Andrew ID at the top of
each following page.
3. This is a closed-book in-class exam. You may not use any reference materials during the
exam.
4. If you have a clarification question, please write it down on the card we have provided. Please
don’t ask us questions of the form “If I answered like this, would it be ok?” or “Are you
looking for ...?”
5. The weight of each question is indicated on the exam. Weights of question parts are estimates
which may be revised during the grading process and are for your guidance only.
6. Please be concise in your answers. You will receive partial credit for partially correct answers,
but truly extraneous remarks may count against your grade.
7. Write legibly even if you must slow down to do so! If you spend some time to
think clearly about a problem, you will probably have time to write your answer legibly.
Andrew
Username
Full
Name
Question Max Points Grader
1. 10
2. 15
3. 10
4. 20
5. 15
6. 5
75
Please note that there are system-call and thread-library “cheat sheets”
at the end of the exam.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Chopsticks - Operating System - Exam and more Exams Operating Systems in PDF only on Docsity!

Computer Science 15-410: Operating Systems

Mid-Term Exam (B), Fall 2008

1. Please read the entire exam before starting to write. This should help you

avoid getting bogged down on one problem.

  1. Be sure to put your name and Andrew ID below and also put your Andrew ID at the top of each following page.
  2. This is a closed-book in-class exam. You may not use any reference materials during the exam.
  3. If you have a clarification question, please write it down on the card we have provided. Please don’t ask us questions of the form “If I answered like this, would it be ok?” or “Are you looking for ...?”
  4. The weight of each question is indicated on the exam. Weights of question parts are estimates which may be revised during the grading process and are for your guidance only.
  5. Please be concise in your answers. You will receive partial credit for partially correct answers, but truly extraneous remarks may count against your grade.

7. Write legibly even if you must slow down to do so! If you spend some time to

think clearly about a problem, you will probably have time to write your answer legibly.

Andrew

Username

Full

Name

Question Max Points Grader

Please note that there are system-call and thread-library “cheat sheets”

at the end of the exam.

  1. 10 points Short answer.

(a) 5 points Identify and explain one reason for constructing a program so that it uses mul- tiple threads instead of just one thread. We are expecting two to four sentences of answer.

(b) 5 points Identify and explain a second reason for programs to be multi-threaded.

Suppose now that instead of three diners there will be an arbitrary number, D. Furthermore, each diner may require a different number of chopsticks to eat. For example, it is possible that one of the diners is an octopus, who for some reason refuses to begin eating before acquiring eight chopsticks. The second parameter of this scenario is C, the number of chopsticks which would simultaneously satisfy the needs of all diners at the table. For example, Joshua, Caroline, Matt, and one octopus would result in C = 14. Each diner’s eating protocol will be as displayed below.

int s, nsticks = my_chopstick_requirement();

while (!time_to_grade_P2()) { discuss_grading_plan(); for (s = 0; s < nsticks; ++s) acquire_one_chopstick(); /* may block / eat(); for (s = 0; s < nsticks; ++s) release_one_chopstick(); / does not block */ } (b) 8 points What is the smallest number of chopsticks (in terms of D and C) needed to insure that deadlock cannot occur? Explain. Your answer must be organized and con- vincing.

  1. 10 points Philosophers Dining

Knowing a theoretical chopstick bound is all well and good, but how will such a system actually work?

You will provide us with code for three functions. Because global variables would restrict us to one table per restaurant, your code will use an alternate formulation involving pointers to table objects.

  • typedef struct table { ... } *table p;
  • void table init(table p tp, int nguests, int nsticks)
  • void table acquire one chopstick(table p tp)
  • void table release one chopstick(table p tp)

We will not worry about table destroy(). Your solution can use mutexes and/or condition variables, but may not use semaphores, reader/writer locks, or machine-dependent synchronization instructions. You must comply with the published interfaces of synchronization primitives, i.e., you cannot inspect or modify the internals of any thread-library data objects. You may not use assembly code, inline or otherwise. For the purposes of the exam you should assume an error- free environment (memory allocation will always succeed; thread-library primitives will not detect internal inconsistencies or otherwise “fail,” etc.). You may wish to refer to the “cheat sheets” at the end of the exam.

The remainder of this page is intentionally blank.

(b) 7 points Now please write table acquire one chopstick() and table release one chopstick(), which should, respectively, acquire and release one chopstick at the given table. .

You may use this page as extra space for your table solution if you wish.

23 void unlock() 24 { 25 // figure out who’s next: 26 // active[] set first, starting "to my right" 27 for (k = 1; k < N; k++) { 28 int j = (i + k) % N; 29 if (active[j]) { // j goes next 30 next = j; 31 active[i] = FALSE; 32 locked = FALSE; 33 return; 34 } 35 } 36 // otherwise admit someone from want[] 37 for (k = 1; k < N; k++) { 38 int j = (i + k) % N; 39 if (want[j]) { // j goes next 40 next = j; 41 mygate[j] = TRUE; 42 active[i] = FALSE; 43 mygate[i] = FALSE; 44 locked = FALSE; 45 return; 46 } 47 } 48 // no one is waiting 49 locked = FALSE; 50 gate = TRUE; 51 }

There is a problem with this protocol. That is, it does not ensure that all three requirements (mutual exclusion, progress, and bounded waiting) are always met. Identify a requirement which is not met and lay out a scenario which demonstrates your claim. Use the format presented in class and in the homework assignment, as exemplified below. T0 T w[0] = T w[1] = T

Be sure that the execution trace you provide us with is easy to read and conclusively demonstrates the claim you are making. It is very important that you not depict impossible execution sequences! If you wish to claim that some pattern repeats, you must clearly indicate that. Finally, it is strongly recommended that you draft your solution using the scrap paper at the end of the exam before writing anything here.

Use this page as space for the critical-section protocol question.

  1. 15 points Nuts & Bolts.

Consider the following (abbreviated and edited) code from 410kern/boot/head.S, some of the assembly-language underpinnings of the 15-410 kernel base code. Note that start is the entry point to which the boot loader transfers execution; df handler is the start of the double- fault handler; lgdt() and lidt() inform the hardware of the locations of the Global Descrip- tor Table and Interrupt Descriptor Table respectively; and void mb entry(mbinfo t *info, void *istack) is the first C code run in the 410 code base (it is passed a pointer to a structure filled in by the boot loader and a pointer to the stack which is in use). Also, void blat(uint8 t *bytes) is a function, not shown, which fills the screen with many copies of an error message. The message is specified not in standard string format but in a format more convenient for blat().

.global _start, init_gdt, init_idt, init_tss .text init_idt: .space 64 .long 0x .long 0x00108f

...omitted...

init_gdt: .long 0x .long 0x .long 0x2be .long 0x00c08b

...omitted...

init_tss: .space 8 .word 0x .space 94 /* fills with 0’s / df_handler: cli / We got here because we were in trouble, so be conservative / movl $SEGSEL_KERNEL_DS, %eax # AAA movw %ax, %ds # AAA movw %ax, %es # AAA movw %ax, %fs # AAA movw %ax, %gs # AAA movw %ax, %ss # AAA leal istack, %esp # BBB subl $2048, %esp / attempt at preservation / # CCC / Now we probably have a runtime environment */ leal fbytes, %eax pushl %eax call blat df_handler_loop: jmp df_handler_loop

_start: leal istack, %esp /* Load initial stack pointer / movl $init_gdt, %eax subl $init_idt, %eax subl $1, %eax pushl %eax / idt limit == sizeof(idt)-1 / pushl $init_idt call lidt movl $init_tss, %eax subl $init_gdt, %eax subl $1, %eax pushl %eax / gdt limit == sizeof(gdt)-1 / pushl $init_gdt call lgdt addl $16, %esp pushl %esp / Pass in the top of the initial stack / pushl %ebx / Pass in the multiboot structure / call mb_entry / Call the C entry point */ pushl $pbytes call blat stuck: jmp stuck

.data

fbytes: .asciz "D\ro\ru\rb\rl\re\r \rf\ra\ru\rl\rt\r!\r \r"

pbytes: .asciz "K\re\rr\rn\re\rl\r \rc\ra\rn\rn\ro\rt\r \rr\re\rt\ru\rr\rn\r(\r)\r!\r \r"

/* Initial stack */ .space 4096 istack:

End of file head.S

  1. 5 points Design.

A key component of Project 0, the stack crawler, was safely reading values (or not reading values) via pointers which might be invalid. This task can be accomplished by employing several different techniques. Briefly describe two arguments for using the SIGSEGV approach. Then pick one other approach and briefly describe two arguments for using it instead of SIGSEGV.

System-Call Cheat-Sheet

/* Life cycle */ int fork(void); int exec(char *execname, char *argvec[]); void set_status(int status); void vanish(void) NORETURN; int wait(int *status_ptr); void task_vanish(int status) NORETURN;

/* Thread management / int thread_fork(void); / Prototype for exam reference, not for C calling!!! */ int gettid(void); int yield(int pid); int cas2i_runflag(int tid, int oldp, int ev1, int nv1, int ev2, int nv2); int get_ticks(); int sleep(int ticks); / 100 ticks/sec */

/* Memory management */ int new_pages(void * addr, int len); int remove_pages(void * addr);

/* Console I/O */ char getchar(void); int readline(int size, char *buf); int print(int size, char *buf); int set_term_color(int color); int set_cursor_pos(int row, int col); int get_cursor_pos(int *row, int *col);

/* Miscellaneous */ void halt(); int ls(int size, char *buf);

/* "Special" */ void misbehave(int mode);

If you wish, you may tear this page off and use it for scrap paper. But be sure not to write anything on this page which you want us to grade.