1 / 73

Problems discussed in the review session for the second midterm

Problems discussed in the review session for the second midterm. COSC 4330/6310 Summer 2012. Scheduling. How would you simulate a round-robin policy with a time slice of 100 ms on a System V R 4 system? #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL. Answer.

elaina
Download Presentation

Problems discussed in the review session for the second midterm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problems discussed in the review session for the second midterm COSC 4330/6310 Summer 2012

  2. Scheduling • How would you simulate a round-robin policy with a time slice of 100 ms on a System V R 4 system? #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL

  3. Answer How would you simulate a round-robin policy with a time slice of 100 ms on a System V R 4 system? #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 100 0 0 100000 0 #0

  4. Scheduling • Consider the following System V Release 4 scheduler: #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 1000 0 1 8000 1 # 0 500 0 2 4000 2 # 1 200 1 3 2000 3 # 2 100 2 3 1000 3 # 3 and assume that a process at priority level 2 receives 800 ms of CPU time before doing an I/O.

  5. Answer • Start at priority 2 and get 200 ms of CPU time before returning to the ready queue • New priority given by __________

  6. Answer • Start at priority 2 and get 200 ms of CPU time before returning to the ready queue • New priority given by ts_tqexp • Move to priority 1 and get 500 ms of CPU time before returning to the ready queue • New priority given by _______

  7. Answer • Start at priority 2 and get 200 ms of CPU time before returning to the ready queue • New priority given by ts_tqexp • Move to priority 1 and get 500 ms of CPU time before returning to the ready queue • New priority given by ts_tqexp • Move to priority 0 and get 100ms of CPU time before doing an I/O • New priority given by _______

  8. Answer • Start at priority 2 and get 200 ms of CPU time before returning to the ready queue • New priority given by ts_tqexp • Move to priority 1 and get 500 ms of CPU time before returning to the ready queue • New priority given by ts_tqexp • Move to priority 0 and get 200ms of CPU time before doing an I/O • New priority given by ts_slpret: level 1

  9. Another answer to the problem (I) • Step 1: Process is at priority level 2 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 1000 0 1 8000 1 # 0 500 0 2 4000 2 # 1 200 1 3 2000 3 # 2 100 2 3 1000 3 # 3 and requests 800 ms of CPU time • It gets only 200 ms and returns to the CPU queue at the level indicated by ts_tqexp

  10. Another answer to the problem (II) • Step 2: Process is now at priority level 1 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 1000 0 1 8000 1 # 0 500 0 2 4000 2 # 1 200 1 3 2000 3 # 2 100 2 3 1000 3 # 3 and requests 600 ms of CPU time • It gets only 500 ms and returns to the CPU queue at the level indicated by ts_tqexp

  11. Another answer to the problem (III) • Step 3: Process is now at priority level 0 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 1000 0 1 8000 1 # 0 500 0 2 4000 2 # 1 200 1 3 2000 3 # 2 100 2 3 1000 3 # 3 and requests 100 ms of CPU time • It gets only the 100 ms then goes to the waiting state

  12. Another answer to the problem (IV) • Step 4: Process is still at priority level 0 #ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait LVL 1000 0 1 8000 1 # 0 500 0 2 4000 2 # 1 200 1 3 2000 3 # 2 100 2 3 1000 3 # 3 • When it returns to the ready queue, it gets upgraded to the priority level specified by ts_slpret • Goes to priority level 1

  13. Short question • What is the major limitation of non-preemptive scheduling policies?

  14. Answer • Non-preemptive policies allow processes to monopolize the CPU.

  15. Short question • What does the System V Release 4 scheduler do to avoid process starvation?

  16. Answer • It increases the priority of processes that have waited more than ts_maxwait time units in the ready queue.

  17. Short question • What is the idea behind penalizing processes that have already got their share of the CPU?

  18. Answer • To ensure that the other processes can get their fair share of the CPU.

  19. Short question What is the difference between blocking sends and non-blocking sends?

  20. Answer • A blocking send waits until the message has been received by the process to which it was addressed • A non-blocking send returns as soon as the message has been accepted for delivery. • Like a letter dropped in a mailbox.

  21. Short question Can you simulate a non-blocking send—or receive—using only blocking sends and receives?

  22. Answer No, but you can simulate blocking sends—or receives—using only non-blocking sends and receives.

  23. Short question • What is the difference betweenvirtual circuits anddatagrams?

  24. Answer • Virtual circuits are connection-oriented and ensure that all messages will arrive in the right order without any of them being lost, damaged or duplicated. • Datagrams are sent individually.

  25. Short question • How would you pass a linked list to a remote procedure?

  26. B C D LL 4 A B C D Answer • By storing it in array along with unpacking instructions. A

  27. Short question • How can we solve the big-endian/little endian issue?

  28. Answer • We can require all transfers to use an arbitrary network order, the same for all computers.

  29. Short question • What is the major advantage of idempotent procedures?

  30. Answer • Idempotent procedures can be repeated an arbitrary number of times without causing any harm. • Hence, we do not have to worry about incomplete executions. • We restart the procedure.

  31. Short question • What is the main disadvantage ofatomic transactions?

  32. Answer • Their cost. • At the same time they remainindispensable in financial transactions.

  33. Short question • What is the difference between the at most onceand the all or nothingsemantics in RPCs?

  34. Answer • The at most once semantics guarantees that no RPC call will be executed more than once but does not prevent partial executions, which the all or nothing semantics does.

  35. Busy waits • Why should we avoid busy waits? • Is this always true?

  36. Answer • Busy waits waste computing cycles. There are especially bad on single processor architectures because the process doing the busy wait will repeatedly interrupt the process on which it is waiting. • They are the best solution for short waits on multiprocessor/multicore architectures as long as the expected wait time is less than to context switches.

  37. Problem • Consider the function transfer(int *from, int *to, int amount) { *from -= amount; *to += amount;} // transfer and assume the calling sequence: alpha = 100; beta = 200;transfer (&alpha, &alpha, 10)

  38. Problem (continued) • What will be the value of alpha after the call assuming that (a)the call was a regular procedure call? (b) the call was a remote procedure call?

  39. Solution (a) If the call was a regular procedure call, a = 100 (b) If the call was a remote procedure call, a = 90 or 110

  40. Explanation • With a regular procedure call &alpha, &alpha, 10 Calling Program doubletrouble Debits &alpha alpha = 100 Credits same amount to &alpha

  41. Explanation (cont'd) • With a remote procedure call 100, 100, 10 Calling Program doubletrouble 90, 110 alpha = 90 or 110

  42. What is wrong? • shared int reserved[2] = {0, 0}; void enter_region(int pid) { while (reserved[1-pid]); // busy wait reserved[pid] = 1; } // enter_region void leave_region(int pid) { reserved[pid] = 0;} // leave_region

  43. Answer • The functions do not guarantee mutual exclusion when processes 0 and 1 enter in lockstep. • The two critical steps are: while (reserved[1-pid]); // test lock reserved[pid] = 1; // set lock

  44. The ice-cream parlor • An ice-cream parlor has two employees selling ice cream and six seats for its customers. Each employee can only serve one customer at a time and each seat can only accommodate one customer at a time. Add the required semaphores to the following program skeleton to guarantee that customers will never have to wait for a chair with a melting ice-cream in their hand.

  45. The ice-cream parlor (cont'd) semaphore _______________ = ______;semaphore _______________ = ______;customer (int who) { ______________________________order_ice_cream();______________________________eat_it(); ______________________________} // customer

  46. Sketching a solution • Two resources are shared by all customers • Six seats • Two employees • Questions to ask are • When should we request a resource? • In which order? (very important) • When should we release it?

  47. Solution semaphore _seats__________ = __6___;semaphore _employees______ = _ 2___;customer (int who) { ______________________________order_ice_cream();______________________________eat_it(); ______________________________} // customer

  48. Solution (cont'd) semaphore _seats__________ = __6___;semaphore _employees_____ = __2___;customer (int who) {P(&seats); P(&employees);________;order_ice_cream();______________________________;eat_it(); ______________________________; // customer Get seat first

  49. Solution (cont'd) semaphore _seats__________ = __6___;semaphore _employees______ = __2___;customer (int who) {P(&seats); P(&employees);________order_ice_cream();V(&employees);_________________eat_it(); ______________________________} // customer What is missing?

  50. Solution (cont'd) semaphore _seats__________ = __6___;semaphore _employees______ = __2___;customer (int who) { P(&seats); P(&employees);________order_ice_cream();V(&employees);_________________eat_it();V(&seat);______________________} // customer

More Related