Title: COMPUTER SYSTEM OVERVIEW
1COMPUTER SYSTEM OVERVIEW
2What is an Operating System?
- A system that provides users with an abstraction
of the hardware a virtual computer. - Interfaces between user and machine.
- On one side, it manages the hardware resources.
- On the other side, it provides a (more or less)
user-friendly interface.
3Computer System Overview
- Basic components of a computer system
- Interrupts
- Multiprogramming
- Memory hierarchy
- I/O communication techniques
4Top Level Components
- Processor (CPU)
- Main memory
- holds program code and data
- I/O modules
- control movement of data between CPU and devices
e.g. disk, keyboard, monitor - System buses
- carry signals between different components
- address, data control buses
5CPU Registers
- Control and Status Registers
- Used by CPU and OS generally not available to
user programs - Examples program counter (PC), instruction
register (IR), program status word (PSW)
6Control and Status Registers
- Program Counter (PC)
- Contains address of next instruction to be
fetched - Instruction Register (IR)
- Contains the instruction most recently fetched
- Program Status Word (PSW)
- Condition codes
- Interrupt enable/disable
- Supervisor/user mode
7User-Visible CPU Registers
- Used by the operating system and user programs
- Data registers temporarily store values from
memory - Address registers
- contain all or part of a main memory address.
- used to calculate effective addresses
8User Visible Data Registers
- Data registers may be called accumulators
- Many machine language operations require the
operand to be in a register. - Temporary results are stored in registers to
avoid a (slow) memory reference.
9User Visible Address Registers
- Contain a base address or an offset to be added
to a base address during effective address
computation. - Index usually treated as an offset
- Segment for segmented memory systems, designates
the base address of the current segment. - Stack points to top of system stack
10Instruction Execution
- Von Neumann architecture/stored program computers
- Instruction cycle the processing required to
execute one instruction - The cycle repeats until the computer halts for
some reason.
11 Basic Instruction Cycle
- CPU fetches next instruction from memory.
- Instruction is decoded and executed.
- Program counter (PC) is automatically incremented
to get address of next instruction.
12Four Categories of Instructions
- Processor-memory copy data from CPU register to
memory, or vice versa - Processor-I/O transfer data from processor to an
I/O module, or vice versa. - Process data perform an arithmetic or logical
operation (add, compare, etc.) - Control alter normal (sequential) flow of
instruction execution.
13Interrupts
- What is an interrupt?
- Why interrupts are needed
- Interrupts and the instruction cycle
- Interrupt processing
- Classes of interrupts
- Interrupts and multiprogramming
14Interrupts
- An interrupt is a signal to the CPU from some
other module in the system. - For example, when an I/O operation completes, the
I/O module will interrupt. - The CPU will then interrupt its normal flow of
control to process the interrupt. - Interrupts improve CPU efficiency.
- The following example illustrates why.
15Control Flow Without Interrupts
- User program runs (1) until WRITE instruction
transfers control to the I/O program. - I/O program prepares I/O module for printing (4).
- CPU waits for I/O command to complete, which may
take a long time. - I/O program finishes in (5) and report status of
operation. - User program resumes executing (until next
WRITE).
16Why Interrupts are Needed
- In the previous example, the CPU has to wait for
I/O to complete. - It would be more efficient if the processor could
continue to execute instructions while the device
executes in parallel. - Interrupts make this possible.
17Instruction Cycle with Interrupts
- An additional step is added to the instruction
execution cycle to accommodate the
test-for-interrupt operation.
18Interrupts
- Suspend the normal sequence of execution
19Control Flow with Interrupts
- User program executes WRITE. Control branches to
an I/O program,which issues the I/O command. (4) - I/O program returns control to user application
- User code executes during I/O operation no
waiting - User program interrupted (x) when I/O operation
is done. CPU branches to interrupt handler - (2b) Execution of user code resumes
20Interrupt Processing
- Interrupt processing is asynchronous - comes at
unpredictable points in program execution. - The interrupted program must not be affected, so
its state must be temporarily saved and later
restored - Full description of processing is in the text.
21Interrupt Processing
- Hardware steps are automatic details vary
slightly according to CPU architecture. - Software steps exact details depend on nature of
interrupt - Interrupts allow devices and CPU to run in
parallel.
22Classes of Interrupts
- Caused by an execution error, such as divide by
zero or illegal memory reference. - Timers can be set by the OS. When the timer
interrupts, its time to perform some function. - Signals normal or abnormal completion of an I/O
operation. Generated by the associated I/O
controller. - Example power failure
- Program
- Timer
- I/O
- Hardware failure
23Interrupts and I/O
- A program cannot always continue after issuing
I/O command. Example - Program issues a disk read and needs disk data
before continuing - If the user program continues to run during the
I/O operation, it might not get correct answers
since its data wont be available.
24Multiprogramming
- The solution is to have other programs available
to keep the CPU busy. - While one user program waits for input, the
processor can execute commands from another
program. - In this way, two programs can sometimes run in
about the same time it would take one of them.
25Multiprogramming
- Definition Management of multiple programs
within a single processor system - After CPU issues an I/O command, it can switch to
execute another program (no waiting) - A second program runs during I/O operation
- When I/O is completed, interrupt handler may (or
may not) switch back to the first program
26Multiprogramming
- Multiprogramming allows a computer to run several
programs concurrently. - Multiprogramming improves processor efficiency by
keeping the CPU busy during I/O. - Interrupts are essential to support
multiprogramming.
27THE MEMORY HIERARCHY
- Characteristics
- Caching
- Locality of Reference
- Hit Ratio
28Memory Hierarchy
- Three characteristics of memory access time,
cost, capacity. - Fast memory is expensive
- Slow memory is cheap
- The problem how can we build a large memory
with good performance at a reasonable price?
29The Solution Cache Memory
- The cache contains a subset of the information in
main memory. - Small, expensive, fast
- Stores current data instructions
- CPU operates out of the cache
30How Cache Works
- It is invisible to OS and user programs -
interacts with other memory management hardware - On a memory reference the processor first checks
if the word (or byte) referenced is in cache (a
hit) - If not found in cache (a miss), a block of memory
containing the word is moved to the cache
31Caching Hierarchy
- Cache Levels (fastest to slowest)
- L1 (primary)
- L2 (probably)
- L3 (maybe)
- Cache levels mirror memory hierarchy.
- Question why does caching work?
32Locality of Reference
- As a program executes, its memory references to
instructions and data tend to cluster in the same
area of memory - e.g. instructions in a loop, data in an array
- Once a word is referenced it will probably be
referenced again and words in the same area of
memory (locality) will be referenced also. - Consequently, its worthwhile to bring that block
of memory into cache.
33The Hit Ratio
- Hit ratio fraction of accesses where referenced
address is in cache - T1 access time for fast memory (e.g. cache)
- T2 access time for slow memory (e.g. memory)
- T2 gtgt T1
- When hit ratio is close to 1 the average access
time is close to T1
34Formula for Effective System Access Time
- For a two-level memory (M1 M2), letH hit
ratioT1 access time to M1 (e.g., cache)T2
access time to M2 (e.g., memory) - Then Ts (system access time) isTs H T1 (1
- H) (T1 T2)
35Importance of Caching
- Cache misses gt extra memory reference
- Read (write) latency time to read (write) memory
- Memory access time gtgt CPU speed
36Extensions of Caching
- Disk cache (disk buffer)
- Part of main memory is used to temporarily to
hold data from the disk - Locality of reference also applies here.
- Disk caches are managed by the OS (file system)
instead of the hardware. - Disks may have onboard caches to reduce need for
seeks
37I/O COMMUNICATION
- Programmed I/ORequires the processor to poll for
I/O completion and directly transfer the data
between memory and the I/O module. No parallelism - Interrupt-driven I/OCPU must still transfer
data, one word at a time, but can do other things
while the operation is being performed. More
parallelism - DMA (Direct Memory Access)Provides the most
parallelism, therefore the best performance.
38Figure 1.19 three Techniques for Input of a
Block of Data
39DMA I/O
- CPU issues an I/O request to a DMA module
(separate module or incorporated into I/O module) - DMA module transfers a block of data directly to
or from memory (without going through CPU) - An interrupt is sent when the task is complete
- The CPU is only involved at the beginning and end
of the block transfer - not after every word - If the CPU and DMA module clash over memory bus
access, priority is given to the DMA module.