Professional Documents
Culture Documents
CPU Internals: SOEN228, Fall 2003
CPU Internals: SOEN228, Fall 2003
CPU Internals: SOEN228, Fall 2003
Writer
data
November 12, 2003
Reader
Serguei Mokhov, mokhov@cs.concordia.ca
old data
2
data
IODR
data
Step 3
Step 4
CPU CPU
Serguei Mokhov, mokhov@cs.concordia.ca
data
November 12, 2003
old data
copy #0 -> IOSCR
3
data
IODR
data
CPU Acknowledges the Interrupt
data
November 12, 2003
CPU
Serguei Mokhov, mokhov@cs.concordia.ca
old data
copy #0 -> IOSCR
10
Interrupt Processing
Interrupt I/O involves the use of hardware signals:
when an I/O port needs CPU attention, an interrupt signal is sent and later received by the CPU. The CPU can acknowledge the interrupt by returning an INTA (interrupt acknowledge signal) and subsequently jumps to the interrupt service routine (ISR) to process/serve the I/O port. The key feature is the asynchrony: the CPU is free to do something else until attention is needed. Hence the busy-wait is avoided.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 11
Return from
Interrupt Yes
Done?
Key Observations
Since the CPU is freed from busy-wait, it could be switched to perform other useful program executions. Thus, it improves the utilization of the system, leading to a much better response time for all users. I/O can proceed asynchronously. There is no assumption on the exact timing of events.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 13
call ISR
Interrupt?
No
Instruction Cycle:
Interrupt Request (INTR) is tested at end of Cycle If INTR is true, then a hardwired subroutine jump to the interrupt service routine (ISR) will be used as the next instruction to be executed. Notice that the current program is interrupted and the return address is pushed on the stack as part of the subroutine call.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 14
Interrupt Acknowledge
Interrupt Acknowledge Interrupt CPU
Memory Unit 2
Device
Priority
Can we allow an interrupt to interrupt an interrupt handler? Why? Which interrupt should be served next?
Usually, priorities can be assigned to various sources of interrupt according to some criteria, such as the penalty of not reacting in time, or the expected return if served. So, the following priority assignment is quite typical:
Power failure; Timer; Error; I/O.
Each sub-class of priority may correspond to a single bit of signal sent to the CPU interface.
This is the interrupt signal of that sub-class. In implementation, the instruction cycle of the CPU is changed such that at the end of a cycle, the existence of an unmasked (enabled) interrupt forces the CPU to execute the equivalence of jump:subroutine interrupt_handler.
18
Interrupt Identification
The choice of interrupt_handler can be resolved in a number of ways. In general, the CPU must identify the source of the interrupt (with the highest priority). This identification can be achieved using
Software polling: the interrupt handler can be programmed to poll through the various I/O interfaces (status registers), highest priority interface first. Once it comes across an interface that indicates its interrupt status, then the handler proceeds to execute the corresponding handler for that interface.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 19
Yes
ISR for 1
No
Interface 2 ready?
Yes
ISR for 2
No
Interface N ready?
Yes
ISR for N
No
To Data Bus
Interrupt Vector
INTA
22
Interrupt Vector
A typical way is to associate an interrupt vector with entries for each interrupt source. Entries in this interrupt vector actually point to (directly or indirectly) the starting address of the required interrupt service routine. For example, the interrupt handler for the keyboard is immediately executed once the interrupt source is known to the CPU.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 23
Enabling/Disabling of Interrupts
Even though the use of priority in some sense already disables lower priority interrupts from interrupting a higher priority interrupt service routine, it is often necessary to disable certain interrupts dynamically. An example would involve an input process and an output process from before.
The input process reads a character from the keyboard and the output process writes the character to the display. The input and output must be done in a sequence alternately. To synchronize the two processes, we could use the enabling/disabling feature in interrupts.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 24
: : :
Drawbacks?
Is there any drawback using interrupt processing?
Interrupt is asynchronous and frees the CPU to perform other tasks via proper context switching. However, there is a price being paid every time context switching takes place.
Alternative:
Why not free the CPU entirely from doing the work of the interrupt handler, except once-in-a-while?
28
29
Motivation
I/O transfer often involves transferring a large chunk of data to or from the computer, for example, disk transfer involves multiple sectors. Much of the interrupt handler for such a disk transfer involves moving memory pointers and transferring the data until the needed number of bytes are transferred. The software managed transfer can be replaced by a hardware component called DMA controller.
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca 30
DMA Controller
A DMA controller is a hardware interface containing:
data register:
data to be transmitted
Data Lines
Address Lines
DMAR DMAA INTR Read Write
November 12, 2003 Serguei Mokhov, mokhov@cs.concordia.ca
Control Logic
32
33
DMA
DMA CPU
Memory Unit
Device
37
CPU
6 5 4 3
2 1
Memory
7 2
2 6 5 4
1 2 7
2 7 1
DMA I/O
1: 2: 3: 4: 5: 6: 7: Data Address INTR INTA DMAR DMAA Read / Write
November 12, 2003
Interrupt I/O
4
Programmed I/O
Interrupt I/O
:::
Serguei Mokhov, mokhov@cs.concordia.ca
Daisy Chain
38
39