1. What is the biggest performance cost in context switching?

    On a machine with a large number of registers, storing the outgoing set of registers (program state) and loading the new set of registers (program state), since this usually requires (slow) memory access. On a machine with a small set of registers, the largest cost may be changing the processor's memory management structures (e.g. page table).

  2. What hardware/architecture support would you need to make context switching "free"? Explain how this support would be used by the OS.

    The processor could store multiple sets of registers in hardware, so that saving and restoring registers is not needed. The processor can also handle saving and restoring registers in hardware, allowing it to happen both more quickly and overlapped with other computation. Finally, the processor can also make it fast to change memory management information (page tables). Only hardware to store multiple sets of registers requires support from the operating system, which can assigning the most frequently running processes to the hardware sets of registers.

  3. What resources are required to create a process?

    A new PCB, address space (including page table entries for code, data, a new stack and heap), and copies of all OS bookkeeping entries (like file handles, etc.).

  4. What resources are required to create a thread? Why or how is this different than process creation?

    A thread needs just a new program counter, register set, and stack. No new memory structures or operating system resources are needed.

  5. What's the advantage of including kernel threads as well as processes in an operating system?

    Kernel threads allow scheduling on a thread level, and prevent all threads in a process from blocking when a single thread (and therefore the process) blocks. The kernel can also schedule threads on different processors of a multiprocessor.

  6. 6.4. Scheduling

    1. FCFS: 8 [for P1] + (12 - 0.4) [for P2] + (13 - 1) [for P3] = 31.6 units total time, or 10.53 units average.
    2. SJF:  8 [for P1] + (9 - 1) [for P3] + (13 - 0.4) [for P2] = 28.6 units total time, or 9.53 units average.
    3. Future-Knowledge: 1 [for P3] + (6 - 0.4) [for P2] + 14 [for P1] = 20.6 units total time, or 6.87 units average.

  7. 6.10. Short Processes

    1. FCFS-discriminates against short jobs since any short jobs arriving after long jobs will have a longer waiting time.
    2. RR-treats all jobs equally (giving them equal bursts of CPU time) so short jobs will be able to leave the system faster since they will finish first.
    3. Multilevel feedback queues-work similar to the RR algorithm-they discriminate favorably toward short jobs.