QMCS 360
Class Notes, # 2
Dr. Rick Smith
Quantitative Methods
and
Computer Science
Dr. Smith Home
|
Research
|
Classes
|
Blackboard
|
Cryptosmith
|
QMCS Home
|
UST A-Z
|
UST Home
last update:
Tuesday, September 13, 2005
Homework - worked solutions
Overview of Topics
New context - CPU vs Bus vs RAM vs IO
Interrupts
Direct Memory Access
Context
Last lecture was about the CPU
The internal "BUS" moved stuff around inside the CPU
RAM and I/O were '
outside
' the CPU
This lecture is about the "system" outside the CPU
How do RAM and I/O talk to the CPU?
Instruction execution still matters
Ignore Cache for Now
Bus Architecture Diagram
The I/O Problem
Speed mismatches
Hard drive spins, moves its heads
Printer moves paper, moves its print head
Keyboard awaits a human touch
How to keep the computer busy while waiting for slow, physical processes?
How to deal with a device quickly when it (finally!) finishes its slow, physical action?
Moving Data for an I/O Device
The "data transfer loop" program - Input Example
Wait for the input device to have a byte ready
Read the byte
Write it to the next location in RAM
Loop
Similar for output
Polling
"Non-preemptive multiprogramming"
Hardware component: a row of "flags" that indicate if an I/O device needs attention
Software component: "Strip" architecture
All programs are broken into SHORT pieces ("strips")
Each strip visits a central point that chooses the highest priority strip to do next
Deciding priorities
"What will fail if not handled immediately?"
Spinning hard drive data to be retrieved
CDROM data to be written while the "burn" is in progress
Interrupts
Give the CPU a way to run a pre-selected program when an event occurs
Basic Components
"Interrupt Vector" - a pointer to the program to run
Hardware in the I/O system to send the interrupt signal from the device to the CPU
Hardware in the CPU to make the interrupt program run
What the interrupt program does
Save the "state" of the interrupted program
State = program counter, AC contents, other CPU registers, if any
Handle the device problem
Restore the "state" of the interrupted program
"Return from interrupt" to resume the interrupted program
What else happens
The interrupt program is chosen according to the "cause" of the interrupt
Each interrupt vector is assigned to a particular type of interrupting event
Other interrupts are disabled when the interrupt program runs
If one tries to happen, the CPU "remembers" it till later
Other interrupts are re-enabled after the interrupt program finishes
The "return from interrupt" turns them back on
The next pending interrupt takes place, if any
If no interrupts, the main program resumes
Direct Memory Access (DMA)
The essence of modern I/O systems, and lots of other things in modern systems
Eliminates the I/O loop program
Allows I/O devices to move lots of data to or from RAM without waiting for a program.
Device does the data transfer "itself"
Hardware requirements
Both the CPU
and
I/O devices are allowed to transfer data across the bus
"Bus Protocol" lets them take turns
I/O devices get more complicated: each one needs MAR and MDR registers.
Interrupts indicate when a multi-word DMA transfer is done
How it works
Load the MAR with the RAM address for the transfer
When data is ready, the device requests the bus
Available at the end of whatever is happening (instruction fetch, data fetch, other I/O)
Device does its own data transfer to RAM
No "interruption" of the program, except for one RAM cycle.
Software requirements
NO I/O loop program
I/O software (device driver) must set up the device's MAR and tell device what to do.