Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Krste Asanovic
Electrical Engineering and Computer Sciences University of California at Berkeley http://www.eecs.berkeley.edu/~krste http://inst.eecs.berkeley.edu/~cs152
2/5/2009
CS152-Spring09
PC Calculation Bubbles
time t0 t1 t2 t3 (I1) r1 (r0) + 10 IF1 ID1 EX1 MA1 (I2) r3 (r2) + 17 IF2 IF2 ID2 (I3) IF3 (I4)
Resource Usage
IF ID EX MA WB
t3
t5
t7
....
2/5/2009
CS152-Spring09
stall
Add 0x4
Add
nop
Jump?
IR
I1
IR
PC 104
addr
inst
IR I2
Inst Memory
I1 I2 I3 I4
2/5/2009
kill
Pipelining Jumps
PCSrc (pc+4 / jabs / rind/ br)
stall
Add 0x4
Add
nop
Jump? IRSrcD
IR
I2 I1
IR
I1
PC 304 104
addr
inst
nop
IR nop I2
Inst Memory
I1 I2 I3 I4
2/5/2009
kill
CS152-Spring09
Resource Usage
IF ID EX MA WB
time t0 t1 I1 I2 I1
t2 I3 I2 I1
t3 I4 nop I2 I1
t4 I5 I4 nop I2 I1
t5
t6
t7
....
I5 pipeline bubble
7
2/5/2009
CS152-Spring09
stall
Add 0x4
Add
M IR
nop
BEQZ? IRSrcD
IR I1
zero?
PC 104
addr
inst
nop
IR I2
A
ALU
Inst Memory
I1 I2 I3 I4
Branch condition is not known until the execute stage what action should be taken in the decode stage ?
CS152-Spring09 8
stall
?
Add 0x4
Add
BEQZ?
M IR I1
nop
IR I2
zero?
nop
IR I3
A
ALU
Inst Memory
I1 I2 I3 I4
If the branch is taken ADD - kill the two following instructions BEQZ r1 +200 - the instruction at the decode stage ADD is not valid ADD stall signal is not valid
CS152-Spring09 9
stall
Add
0x4
Add
nop
Jump?
PC
IRSrcE
E IR I2
BEQZ?
M IR I1
zero?
PC 108
addr
inst
nop
IRSrcD IR I3 A
ALU
Inst Memory
I1 I2 I3 I4
If the branch is taken ADD - kill the two following instructions BEQZ r1 +200 - the instruction at the decode stage ADD is not valid ADD stall signal is not valid
CS152-Spring09 10
Dont stall if the branch is taken. Why? Instruction at the decode stage is invalid
2/5/2009
CS152-Spring09
11
IRSrcD = Case opcodeE BEQZ.z, BNEZ.!z nop ... Case opcodeD J, JAL, JR, JALR nop ... IM IRSrcE = Case opcodeE BEQZ.z, BNEZ.!z nop ... stall.nop + !stall.IRD
2/5/2009 CS152-Spring09
Give priority to the older instruction, i.e., execute stage instruction over decode stage instruction
12
WB2 nop nop nop nop nop ID5 EX5 MA5 WB5
Resource Usage
IF ID EX MA WB
t2 I3 I2 I1
t3 I4 I3 I2 I1
t4 I5 nop nop I2 I1
t5
t6
t7
....
2/5/2009
CS152-Spring09
Add
nop
0x4
Add
IR
PC
addr
nop
inst IR D
Inst Memory
GPRs
Other techniques include more advanced branch prediction, which can dramatically reduce the branch penalty... to come later
2/5/2009
CS152-Spring09
15
Resource Usage
IF ID EX MA WB
time t0 t1 I1 I2 I1
t2 I3 I2 I1
t3 I4 I3 I2 I1
t4 I4 I3 I2 I1
t5
t6
t7
....
I4 I3 I2
I4 I3
I4
16
2/5/2009
CS152-Spring09
CS152 Administrivia
PS 1 due Tuesday Feb 10 in class Section covering PS 1 on Wednesday Feb 11
Room/time TBD
Lecture 7, Tuesday Feb 17 in 320 Soda Lecture 8, Thursday Feb 19 back in 306 Soda See website for full schedule
2/5/2009
CS152-Spring09
18
Interrupts:
program
Ii
HI2
Ii+1
HIn
An external or internal event that needs to be processed by another (system) program. The event is usually unexpected or rare from programs point of view.
2/5/2009 CS152-Spring09 19
Causes of Interrupts
Interrupt: an event that requests the attention of the processor Asynchronous: an external event
input/output device service-request timer expiration power disruptions, hardware failure
2/5/2009
CS152-Spring09
20
QuickTime and a TIFF (Uncompressed) decompressor are needed to see this picture.
Carried in two tractor trailers, 12 tons + 8 tons Built for US Army Signal Corps
[Courtesy Mark Smotherman]
2/5/2009 CS152-Spring09 22
Asynchronous Interrupts:
invoking the interrupt handler
An I/O device requests attention by asserting one of the prioritized interrupt request lines When the processor decides to process the interrupt
It stops the current program at instruction I , completing all i the instructions up to Ii-1 (precise interrupt)
It saves the PC of instruction I in a special register (EPC) i It disables interrupts and transfers control to a designated interrupt handler running in the kernel mode
2/5/2009
CS152-Spring09
23
Interrupt Handler
Saves EPC before enabling interrupts to allow nested interrupts
need an instruction to move EPC into GPRs need a way to mask further interrupts at least until EPC can be saved
Needs to read a status register that indicates the cause of the interrupt Uses a special indirect jump instruction RFE (returnfrom-exception) which
enables interrupts restores the processor to the user mode restores hardware status and control state
2/5/2009
CS152-Spring09
24
Synchronous Interrupts
A synchronous interrupt (exception) is caused by a particular instruction In general, the instruction cannot be completed and needs to be restarted after the exception has been handled
requires undoing the effect of one or more partially executed instructions
In the case of a system call trap, the instruction is considered to have been completed
a special jump instruction involving a change to privileged kernel mode
2/5/2009
CS152-Spring09
25
Overflow
Asynchronous Interrupts
How to handle multiple simultaneous exceptions in different pipeline stages? How and where to handle external asynchronous interrupts?
2/5/2009
CS152-Spring09
26
Overflow
Exc E PC E Exc M
Exc D PC D
Select Handler PC
Kill F Stage
Kill D Stage
Kill E Stage
PC M Asynchronous
Interrupts
Kill Writeback
2/5/2009
CS152-Spring09
27
EPC
Cause
2/5/2009
CS152-Spring09
28
Speculating on Exceptions
Prediction mechanism
Exceptions are rare, so simply predicting no exceptions is very accurate!
Recovery mechanism
Only write architectural state at commit point, so can throw away partially executed instructions after exception Launch exception handler after flushing pipeline
096: ADD 100: XOR 104: SUB 108: ADD Exc. Handler code
nop nop nop nop nop nop ID5 EX5 MA5 WB5
Resource Usage
IF ID EX MA WB
time t0 t1 I1 I2 I1
t2 I3 I2 I1
t3 I4 I3 I2 I1
t5
t6
t7
....
2/5/2009
CS152-Spring09
Acknowledgements
These slides contain material developed and copyright by:
Arvind (MIT) Krste Asanovic (MIT/UCB) Joel Emer (Intel/MIT) James Hoe (CMU) John Kubiatowicz (UCB) David Patterson (UCB)
MIT material derived from course 6.823 UCB material derived from course CS252
2/5/2009
CS152-Spring09
31