3 분 소요

Chapter 6: Mechanism Limited Direct Execution

Theme: OS sets up the trap handler and starting an interrupt timer, and then by only running processes in a restricted mode.

  • many jobs running seemingly at the same time.
    • Time Sharing
  • Question:
    • Performance
    • Control
  • Concurrency?
    • OS disable interrupt during interrupt processing
    • number of sophisticated locking schemes to protect concurrent access to internal data structures
  • Switching between processes
    • Cooperative approach
      • OS trust the processes of the system to behave reasonably
      • transfer control of the CPU to the OS by making a system call
        • The only thing that can transfer control is explicit yield system call
      • So, OS regains control of the CPU by waiting for a system call or an illegal operation of some kind to take place
      • If infinite loop → reboot is the option
    • Non-Cooperative Approach
      • Timer interrupt
        • raise an interrupt every so many milliseconds
        • pre-configured interrupt handler in the OS runs
      • OS role
        • OS must inform the hardware, so OS must start the timer (privileged operation)
        • Hardware is also responsible for saving the state of the program on the switching
    • Saving and Restoring
      • Scheduling
        • switching to other by scheduler
        • Contest swich
          • OS has to do is save a few register values for the currently-executing process and restore a few for the soon-to-be-executing process
          • So, OS has to ensure when the return-from-trap instruction is finally executed, and system resumes execution of another process
          • soon-to-be-executing process become the currently-running process
          • switch routine → carefully saves current register values, restores the register of Process B, and then switches context, by changing the stack pointer to use B’s kernel stack. Then restores B’s register state and starts running
        • PC
          • save PC and switch to the kernel stack for the soon-to-be-executing process
        • The kernel enters to call the switch code in the context of one process and returns in the context of another
      • The protocol of saves/restores
        • timer interrupt occurs ⇒ user register state of the running process is implicitly saved by the hardware
        • OS decides to switch from A to B, the kernel register state is explicitly saved by the software, but this time into memory in the process structure of the process.
  • Limited Direct Execution
    • run the program directly on the CPU
      • Then how can the OS make sure the program doesn’t do anything that we don’t want it to do
      • How does the operating system stop it from running and switch to another process
        • time sharing
      • OS → just library!
    • Restricted Operations
      • let any process do whatever it wants in terms of I/O and other related operations
      • User mode
        • No privileged operations
      • Kernel mode
        • can do what it likes
        • OS runs on
      • System call
        • When the user mode wants to execute some kind of privileged operations.
        • allow the kernel to carefully expose certain key pieces of functionailty to user programs
      • Trap instruction
        • This instruction simultaneously jumps into the kernel and raises the privilege level to kernel mode
      • Return from trap instruction
        • save enough of the caller’s register state in order to be able to return correctly
      • The processor will push the register values to the kernel stack
        • pop these values will be required to resume the execution
      • Trap table
        • set at the boot time
        • tell the hardware what code to run when certain exceptional event occurs
      • Trap handlers
        • OS informs the hardware of the location of these trap handlers, usually with some kind of special instruction → remember until the machine is rebooted
      • Privileged operations
        • Two phases of LDE protocol
          • First, the kernel initializes the trap table, and the CPU remembers its location for subsequent use via privileged instructions
          • Second, the kernel sets up a few things before using a return-trap instruction to start the execution of the process; this switches the CPU to user mode and begins running the process
        • Overall,
          • the process wishes to issue a system call, traps back into OS, and again return control to process via return-from-process
          • exit call → OS cleans up

태그:

카테고리:

업데이트: