Lec 03
Lec 03
User apps
OS
physical machine interface
hardware
• Basic OS Functionality
• Basic Architecture reminder
• What the OS can do is dictated in part by the
architecture.
• Architectural support can greatly simplify or complicate
the OS.
1
Modern Operating System Functionality
1. Concurrency: Doing many things simultaneously (I/0,
processing, multiple programs, etc.)
– Several users work at the same time as if each has a private machine
– Threads (unit of OS control) - one thread on the CPU at a time, but many
threads active concurrently
2. I/O devices: let the CPU work while a slow I/O device is
working
3. Memory management: OS coordinates allocation of memory
and moving data between disk and main memory.
4. Files: OS coordinates how disk space is used for files, in order
to find files and to store multiple files
5. Distributed systems & networks: allow a group of
workstations to work together on distributed hardware
2
Generic Computer Architecture
System bus
Network
card
3
Protection
Kernel mode vs. User mode: To protect the system from aberrant
users and processors, some instructions are restricted to use only
by the OS. Users may not
– address I/O directly
– use instructions that manipulate the state of memory (page table pointers,
TLB load, etc.)
– set the mode bits that determine user or kernel mode
– disable and enable interrupts
– halt the machine
but in kernel mode, the OS can do all these things.
The hardware must support at least kernel and user mode.
– A status bit in a protected processor register indicates the mode.
– Protected instructions can only be executed in kernel mode.
4
Memory Protection
• Architecture must provide support so that the OS can
– protect user programs from each other, and
– protect the OS from user programs.
• The simplest technique is to use base and limit registers.
• Base and limit registers are loaded by the OS before starting a program.
• The CPU checks each user reference (instruction and data addresses), ensuring
it falls between the base and limit register values
Base register
Limit register
Memory Hierarchy
L1 2-cycle latency
evict
load
D$, I$ separate
L2 7-cycle latency
D$, I$ unified
5
Registers
Caches
6
Traps
• Traps: special conditions detected by the architecture
– Examples: page fault, write to a read-only page, overflow,
systems call
• On detecting a trap, the hardware
– Saves the state of the process (PC, stack, etc.)
– Transfers control to appropriate trap handler (OS routine)
• The CPU indexes the memory-mapped trap vector with the
trap number,
• then jumps to the address given in the vector, and
• starts to execute at that address.
• On completion, the OS resumes execution of the process
Traps
Trap Vector:
0: 0x00080000 Illegal address
1: 0x00100000 Memory violation
7
I/O Control
• Each I/O device has a little processor inside it that enables it to
run autonomously.
• CPU issues commands to I/O devices, and continues
• When the I/0 device completes the command, it issues an
interrupt
• CPU stops whatever it was doing and the OS processes the I/O
device's interrupt
Synchronous Asynchronous
8
Memory-Mapped I/O
• Enables direct access to I/O controller (vs. being required to
move the I/O code and data into memory)
• PCs (no virtual memory), reserve a part of the memory and put
the device manager in that memory (e.g., all the bits for a video
frame for a video controller).
• Access to the device then becomes almost as fast and convenient
as writing the data directly into memory.
9
Timer & Atomic Instructions
Timer
• Time of Day
• Accounting and billing
• CPU protected from being hogged using timer interrupts
that occur at say every 100 microsecond.
• At each timer interrupt, the CPU chooses a new process
to execute.
Interrupt Vector:
0: 0x2ff080000 keyboard
1: 0x2ff100000 mouse
2: 0x2ff100480 timer
3: 0x2ff123010 Disk 1
Synchronization
• Interrupts interfere with executing processes.
• OS must be able to synchronize cooperating, concurrent
processes.
→ Architecture must provide a guarantee that short sequences
of instructions (e.g., read-modify write) execute atomically.
Two solutions:
1. Architecture mechanism to disable interrupts before
sequence, execute sequence, enable interrupts again.
2. A special instruction that executes atomically (e.g.,
test&set)
10
Virtual Memory
Summary
11