COMP 3000 Operating Systems
Further into the Abstractions (part 1)
Lianying Zhao
What Makes Abstraction/Virtualization Possible?
• The abstraction creator/enforcer must be:
• “Omnipotent”, that always has a higher privilege than the target • “Omniscient”, that sees everything about the target
• All this leads to the requirement for hardware support
COMP 3000 (Winter 2021) 2
Virtualizing the CPU
• Recall: the few purposes
• Containing faults (reliability) • Security
• Simplicity
• Also more:
• Maximum CPU utilization
• Therefore, what’s expected from the illusion: • No need to think about others
• No access to others’ resources
COMP 3000 (Winter 2021) 3
The Execution Context
• The computer processor is like a state machine
• A program (a sequence of instructions), as input, just triggers transitions • What determines the machine state?
• Take x86 as an example:
• The program counter – (E/R)IP
• Status/flag registers, e.g., (E/R)Flags
• General-purpose registers, e.g., (E/R)AX, BX, CX, … • Other registers
• Memory info
• Much more in reality
COMP 3000 (Winter 2021) 4
The Process Abstraction (recap)
• Just a running program
• Typically loaded into memory from an executable (binary file) • Or in any other less typical forms
• What is hidden:
• The fact that other processes are also sharing the same CPU
• All the (privileged) software/hardware facilities that back it up
• New semantics:
• Processes with unique identifiers (PIDs)
• API
We will discuss the specifics later
COMP 3000 (Winter 2021) 5
Scheduling
• Principle 1: To keep the CPU busy!
• Principle 2: To finish tasks as soon as possible • Principle 3: To be fair to all processes
• Each process gets a time slice
• The scheduler of modern operating systems can be very complicated
COMP 3000 (Winter 2021)
6
Image source: developer.arm.com
Context Switch
• A fundamental mechanism, simply:
• Saving the context of one process and suspending it
• Restoring the context of another process and getting it to run
• The data structure where a process’s context is stored is (often) called: • Process Control Block (PCB)
• There is a cost!
COMP 3000 (Winter 2021) 7