Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill. What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data.

Similar presentations


Presentation on theme: "MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill. What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data."— Presentation transcript:

1 MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill

2 What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data structure is used to represent a process in the kernel? What does it contain? What information do threads share? What is a context switch? Example? What is a system call? Examples? You should be able to walk through with the example rather than just giving it. Basics 2

3 SYNCHRONIZATION

4 Shared resources, critical sections, race conditions etc. What are the critical section requirements? Be sure to know the motivation behind each Locks, Semaphores, Monitors, Messages etc. Peterson’s algorithm Does this work when scheduling is pre-emptive? Non pre- emptive? Producer-Consumer problem Monitors Semaphores Types? Dining philosophers problem Synchronization 4

5 Question Using locks and condition variables I attempted to implement the following function: do_exchange(void *arg), which allows pairs of threads to exchange values. After two processes have called do_exchange, they swap the values of the arguments. The function should continue to operate correctly with successive pairs of callers. The following code is my attempt at implementing the this function. Assume that the lock and condition variable are initialized correctly before do_exchange is called. 5 struct lock *entry; struct cv *got_first; /* first and second hold the values to exchange */ int first = -1; int second = -1; int got_one = 0; void *do_exchange(void *arg) { int value = *(int *)arg; lock_acquire(entry); if (!got_one) { got_one = 1; first = value; cv_wait(got_first, &entry); *(int *)arg = second; } else { got_one = 0; second = value; cv_signal(got_first); *(int *)arg = first; } lock_release(entry); fprintf(stderr,"%d -> %d\n", value, *(int *)arg); return NULL; } If I set up a program that creates 6 threads that all call exchange, then I expect the following output: 1  0 0  1 3  2 2  3 5  4 4  5 but I get 1  0 3  2 0  3 2  3 5  4 4  5

6 1. Explain what happens 2. Does this behavior follow Hoare or Mesa semantic? Explain 3. Describe how you would fix the problem. You don’t have to implement any changes. Assume that the behavior of the locks and condition variables is the same as shown in the output of the above program. 6

7 SCHEDULING

8 Scheduling Goals? Fairness, no starvation, policy enforcement, balance Batch vs. Interactive vs. Real-Time systems Types? Preemptive vs. non preemptive Scheduling algorithms FCFS; problems? SJF Round-Robin; problems? Priority scheduling Multi-level scheduling Feedback scheduling 8

9 Questions: 1. You are given 3 batch jobs X, Y, Z with arrival times 1s, 4s and 7.5s respectively and corresponding service times as 5s, 7s, and 10s. Their priorities are 1,5,2 respectively. Schedule the threads using: a. Round Robin with time quantum = 2s b. Priority Scheduling c. Calculate the avg. waiting time for the above 2. RR scheduling doesn’t give preference to processes with higher priority. Propose and describe two different schemes to extend it to handle priorities. 3. Describe two factors you would use to determine the length of quantum for RR scheduling algorithm. 9

10 VIRTUAL MEMORY

11 Virtual Memory Requirements for memory management: 1. Relocation 2. Logical organization 3. Protection 4. Sharing 5. Physical organization When to translate addresses? Execution time Ques: What part of the CPU is responsible for these translations? Allocating memory to processes: Fixed partitioning; cons? Dynamic partitioning; cons? Address translation uses base and limit registers 11

12 Virtual Memory Tracking memory allocation Bitmaps Free lists Implicit lists Placement algorithms First-fit, best-fit, worst-fit, quick-fit, etc. Paging Pages vs. Frames (size of each is the same) Is there any fragmentation in paging? Example Address translation uses page tables 12

13 Virtual Memory Page lookups How many references needed for a lookup? Use TLB to reduce the lookup 13

14 Virtual Memory TLB How many references needed now? TLB maps virtual address to PTE Exploit locality Can be managed by hardware or software 14

15 Virtual Memory Managing page tables Hierarchical page tables, hashed page tables, inverted page tables Example: Two-level page table 15

16 Virtual Memory Policies for VM management: Fetch: prepaging, demand paging Placement Replacement Belady aka OPT, LRU, LFU, MFU, FIFO, CLOCK Example Working set size Page fault frequency Thrashing 16

17 Questions 1. A memory system has 22 bit virtual addresses with 2 16 byte pages. How many entries are in a process’s page table i.e. PTEs? If a PTE takes 8 bytes, how many entries can be stored in one page? 2. What physical address does 0x03BEEF map to? What virtual address does physical address 0x6BF070 map to? 17 Page numberFrame number 10x3F 20x4D 30x6B 40x5D ……

18 Questions 3. Suppose we have a dynamic partitioning system with 10 units of memory. Sketch the memory space after the sequence of events. Assume best-fit placement is being used. Allocate 3 units for P1 Allocate 5 units for P2 Free P1’s allocation Allocate 4 units for P3 4. We have four page frames and the following reference string: 4,1,3,4,4,5,6,5,1,2,3,7. Demonstrate the page replacements with the following algorithms: a. MRU b. FIFO c. OPT d. CLOCK 18

19 GOOD LUCK! 19


Download ppt "MIDTERM REVIEW CSCC69 Winter 2016 Kanwar Gill. What is an OS? What are processes and threads? Process states? Diagram showing the state changes What data."

Similar presentations


Ads by Google