Operating Systems CS240
Dr. Axel Krings
JEB 320 208 885-4078
[email protected] http://www.cs.uidaho.edu/~krings
Sequence 1
CS 240
Computer System Overview
Chapter 1
Sequence 1
CS 240
Operating System
Exploits the hardware resources of one or more processors Provides a set of services to system users Manages secondary memory and I/O devices
Sequence 1
CS 240
Basic Elements
Processor Main Memory volatile referred to as real memory or primary memory I/O modules secondary memory devices communications equipment terminals System bus communication among processors, memory, and I/O modules
Sequence 1 CS 240 4
Processor
Two internal registers
Memory address register (MAR)
Specifies the address for the next read or write
Memory buffer register (MBR)
Contains data written into memory or receives data read from memory
I/O address register I/O buffer register
Sequence 1
CS 240
Top-Level Components
CPU System Bus Main Memory
PC IR
MAR MBR I/O AR
0 1 2
Instruction Instruction Instruction Data Data Data Data
Execution unit
I/O BR
I/O Module
n-2 n-1
Buffers
PC
=
IR
=
MAR
=
MBR
=
I/O AR
=
I/O BR
=
Program counter Instruction register Memory address register Memory buffer register Input/output address register Input/output buffer register
Figure 1.1 Computer Components: Top-Level View
Sequence 1
CS 240
Processor Registers
User-visible registers
Enable programmer to minimize mainmemory references by optimizing register use
Control and status registers
Used by processor to control operating of the processor Used by privileged operating-system routines to control the execution of programs
Sequence 1 CS 240 7
User-Visible Registers
May be referenced by machine language Available to all programs - application programs and system programs Types of registers
Data Address
Index Segment pointer Stack pointer
Sequence 1 CS 240 8
User-Visible Registers
Address Registers
Index
Involves adding an index to a base value to get an address
Segment pointer
When memory is divided into segments, memory is referenced by a segment and an offset
Stack pointer
Points to top of stack
Sequence 1 CS 240 9
Control and Status Registers
Program Counter (PC)
Contains the address of an 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
Sequence 1
CS 240
10
Control and Status Registers
Condition Codes or Flags
Bits set by the processor hardware as a result of operations Examples
Positive result Negative result Zero Overflow
Sequence 1
CS 240
11
Instruction Execution
Two steps
Processor reads instructions from memory
Fetches
Processor executes each instruction
Sequence 1
CS 240
12
Instruction Cycle
Sequence 1
CS 240
13
Instruction Fetch and Execute
The processor fetches the instruction from memory Program counter (PC) holds address of the instruction to be fetched next Program counter is incremented after each fetch
Sequence 1
CS 240
14
Instruction Register
Fetched instruction is placed in the instruction register Categories
Processor-memory
Transfer data between processor and memory
Processor-I/O
Data transferred to or from a peripheral device
Data processing
Arithmetic or logic operation on data
Control
Alter sequence of execution
Sequence 1 CS 240 15
Characteristics of a Hypothetical Machine
Sequence 1
CS 240
16
Example of Program Execution
Sequence 1
CS 240
17
Direct Memory Access (DMA)
I/O exchanges occur directly with memory Processor grants I/O module authority to read from or write to memory Relieves the processor responsibility for the exchange
Sequence 1
CS 240
18
Interrupts
Interrupt the normal sequencing of the processor Most I/O devices are slower than the processor
Processor must pause to wait for device
Sequence 1
CS 240
19
Classes of Interrupts
Sequence 1
CS 240
20
10
Program Flow of Control Without Interrupts
Sequence 1
CS 240
21
Program Flow of Control With Interrupts, Short I/O Wait
User Program 1 I/O Program 4 I/O Command
WRITE
2a
2b
Interrupt Handler 5 END
WRITE
3a
3b
WRITE
Sequence 1
CS 240 (b) Interrupts; short I/O wait
22
11
Program Flow of Control With Interrupts; Long I/O Wait
Sequence 1
CS 240
23
Interrupt Handler
Program to service a particular I/O device Generally part of the operating system
Sequence 1
CS 240
24
12
Interrupts
Suspends the normal sequence of execution
Sequence 1
CS 240
25
Interrupt Cycle
Sequence 1
CS 240
26
13
Interrupt Cycle
Processor checks for interrupts If no interrupts, fetch the next instruction for the current program If an interrupt is pending, suspend execution of the current program, and execute the interrupt-handler routine
Sequence 1
CS 240
27
Timing Diagram Based on Short I/O Wait
Sequence 1
CS 240
28
14
Timing Diagram Based on Long I/O Wait
Sequence 1
CS 240
29
Simple Interrupt Processing
Sequence 1
CS 240
30
15
Changes in Memory and Registers for an Interrupt
Sequence 1
CS 240
31
Multiple Interrupts
Disable interrupts while an interrupt is being processed
Sequence 1
CS 240
32
16
Multiple Interrupts
Define priorities for interrupts
Sequence 1
CS 240
33
Multiple Interrupts
Sequence 1
CS 240
34
17
Interrupts
Think of testing or verifying the correctness of a program. What issues or potential problems can you think of w.r.t. user defined interrupts?
Sequence 1
CS 240
35
Multiprogramming
Processor has more than one program to execute The sequence the programs are executed depend on their relative priority and whether they are waiting for I/O After an interrupt handler completes, control may not return to the program that was executing at the time of the interrupt
Sequence 1 CS 240 36
18
Memory Hierarchy
Faster access time, greater cost per bit Greater capacity, smaller cost per bit Greater capacity, slower access speed
Sequence 1
CS 240
37
Memory Hierarchy
Sequence 1
CS 240
38
19
Going Down the Hierarchy
Decreasing cost per bit Increasing capacity Increasing access time Decreasing frequency of access of the memory by the processor
Locality of reference
Sequence 1
CS 240
39
Secondary Memory
Nonvolatile Auxiliary memory Used to store program and data files
Sequence 1
CS 240
40
20
Disk Cache
A portion of main memory used as a buffer to temporarily to hold data for the disk Disk writes are clustered Some data written out may be referenced again. The data are retrieved rapidly from the software cache instead of slowly from disk
Sequence 1 CS 240 41
Cache Memory
Invisible to operating system Increase the speed of memory Processor speed is faster than memory speed Exploit the principle of locality
Sequence 1
CS 240
42
21
Cache Memory
Sequence 1
CS 240
43
Cache Memory
Contains a copy of a portion of main memory Processor first checks cache If not found in cache, the block of memory containing the needed information is moved to the cache and delivered to the processor
Sequence 1
CS 240
44
22
Cache/Main Memory System
Line Number Tag 0 1 2 Block Memory address 0 1 2 3 Block (K words)
C-1
Block Length (K Words)
(a) Cache
Block 2n - 1
Word Length
(b) Main memory
Figure 1.17 Cache/Main-Memory Structure
Cache Read Operation
Sequence 1
CS 240
46
23
Cache Design
Cache size
Small caches have a significant impact on performance
Block size
The unit of data exchanged between cache and main memory Larger block size: what are the consequences? Smaller block sizes: what now?
Sequence 1
CS 240
47
Cache Design
Mapping function
Determines which cache location the block will occupy
Replacement algorithm
Determines which block to replace E.g. Least-Recently-Used (LRU) algorithm
Sequence 1
CS 240
48
24
Cache Design
Write policy
When the memory write operation takes place Can occur every time block is updated Can occur only when block is replaced
Minimizes memory write operations Leaves main memory in an obsolete state
Sequence 1
CS 240
49
Programmed I/O
I/O module performs the action, not the processor Sets appropriate bits in the I/O status register No interrupts occur Processor checks status until operation is complete
this is polling
Sequence 1
CS 240
50
25
Interrupt-Driven I/O
Processor is interrupted when I/O module ready to exchange data Processor saves context of program executing and begins executing interrupt-handler No needless waiting However, still consumes a lot of processor time because every word read or written passes through the processor
Sequence 1
CS 240
51
Direct Memory Access
Transfers a block of data directly to or from memory An interrupt is sent when the transfer is complete Processor continues with other work
Sequence 1
CS 240
52
26