SlideShare a Scribd company logo
1 of 35
Lecture 7
Dealing with Exceptions
Computer Architecture
CNE-301
Lecturer: Irfan Ali
1
2
3
4
5
6
7
Exception Categories
Two Types of Exceptions: Interrupts and Traps
• Interrupts
• Caused by external events:
• Network, Keyboard, Disk I/O, Timer
• Page fault - virtual memory
• System call - user request for OS action
• Asynchronous to program execution
• May be handled between instructions
• Simply suspend and resume user program
• Traps
• Caused by internal events
• Exceptional conditions (overflow)
• Undefined Instruction
• Hardware malfunction
• Usually Synchronous to program execution
• Condition must be remedied by the handler
• Instruction may be retried or simulated and program continued or program may be aborted
8
Synchronous vs Asynchronous
• Definition: If the event occurs at the same place
every time the program is executed with the same
data and memory allocation, the event is
synchronous. Otherwise asynchronous.
• Except for hardware malfunctions, asynchronous
events are caused by devices external to the CPU
and memory.
• Asynchronous events usually are easier to handled
because asynchronous events can be handled after
the completion of the current instruction.
9
Exceptions in Simple five-stage
pipeline
• Instruction Fetch, & Memory stages
• Page fault on instruction/data fetch
• Misaligned memory access
• Memory-protection violation
• Instruction Decode stage
• Undefined/illegal opcode
• Execution stage
• Arithmetic exception
• Write-Back stage
• No exceptions!
10
What happens during an exception
In The Hardware
• The pipeline has to
1) stop executing the offending instruction in midstream,
2) let all preceding instructions complete,
3) flush all succeeding instructions,
4) set a register to show the cause of the exception,
5) save the address of the offending instruction, and
6) then jump to a prearranged address (the address of the exception handler code)
In The Software
• The software (OS) looks at the cause of the exception and “deals” with it
• Normally OS kills the program
11
Exceptions
Exception = non-programmed control transfer
• system takes action to handle the exception
• must record the address of the offending instruction
• record any other information necessary to return afterwards
• returns control to user
• must save & restore user state
user program
normal control flow:
sequential, jumps, branches, calls, returns
System
Exception
Handler
Exception:
return from
exception
12
must record
13
14
15
What Makes Pipelining
Hard?
Examples of interrupts:
• Power failing,
• Arithmetic overflow,
• I/O device request,
• OS call,
• Page fault
Interrupts (also known as: faults, exceptions,
traps) often require
• surprise jump (to vectored address)
• linking return address
• saving of PSW-Program Status Word (including CCs-
Condition Codes)
• state change (e.g., to kernel mode)
Interrupts cause
great havoc!
There are 5 instructions executing
in 5 stage pipeline when an
interrupt occurs:
• How to stop the pipeline?
• How to restart the pipeline?
• Who caused the interrupt?
16
What Makes Pipelining
Hard?
Interrupts cause
great havoc!
What happens on interrupt while in delay slot ?
• Next instruction is not sequential
solution #1: save multiple PCs
• Save current and next PC
• Special return sequence, more complex hardware
solution #2: single PC plus
• Branch delay bit
• PC points to branch instruction
Stage Problem that causes the interrupt
IF Page fault on instruction fetch; misaligned memory
access; memory-protection violation
ID Undefined or illegal opcode
EX Arithmetic interrupt
MEM Page fault on data fetch; misaligned memory
access; memory-protection violation
17
What Makes
Pipelining Hard?
• Simultaneous exceptions in more than one pipeline stage, e.g.,
• Load with data page fault in MEM stage
• Add with instruction page fault in IF stage
• Add fault will happen BEFORE load fault
• Solution #1
• Interrupt status vector per instruction
• Defer check until last stage, kill state update if exception
• Solution #2
• Interrupt ASAP(as soon as possible)
• Restart everything that is incomplete
Another advantage for state update late in pipeline!
Interrupts cause
great havoc!
18
19
20
What Makes
Pipelining Hard?
Here’s what happens on a data page fault.
1 2 3 4 5 6 7 8 9
i F D X M W
i+1 F D X M W < page fault
i+2 F D X M W < squash
i+3 F D X M W < squash
i+4 F D X M W < squash
i+5 trap > F D X M W
i+6 trap handler > F D X M W
Interrupts cause
great havoc!
Exceptions - “Stuff Happens”
• Exceptions definition: “unexpected change in
control flow”
• Another form of control hazard.
For example:
add $1, $2, $1; causing an arithmetic overflow
sw $3, 400($1);
add $5, $1, $2;
Invalid $1 contaminates other registers or memory locations!
21
Additions to MIPS ISA to support Exceptions
• EPC (Exceptional Program Counter)
• A 32-bit register
• Hold the address of the offending instruction
• Cause
• A 32-bit register in MIPS (some bits are unused currently.)
• Record the cause of the exception
• Status - interrupt mask and enable bits and determines what exceptions can occur.
• Control signals to write EPC , Cause, and Status
• Be able to write exception address into PC, increase mux set PC to exception address (MIPS uses 8000
00180hex ).
• May have to undo PC = PC + 4, since want EPC to point to offending instruction (not its successor); PC =
PC – 4
• What else?
flush all succeeding instructions in pipeline
22
Flush instructions in Branch Hazard
36 sub $10, $4, $8
40 beq $1, $3, 7 # taget = 40 + 4 + 7*4 = 72
44 and $12, $2, $5 if($1==$2)
48 or $13, $2, $6 go(PC+4+PC*C)
52 ….
….
72 lw $4, 50($7)
23
24
Pipelining in MIPS
• MIPS architecture was designed to be pipelined
• Simple instruction format (makes IF, ID easy)
• Single-word instructions
• Small number of instruction formats
• Common fields in same place (e.g., rs, rt) in different formats
• Memory operations only in lw, sw instructions
(simplifies EX)
• Memory operands aligned in memory (simplifies MEM)
• Single value for Write-Back (limits forwarding)
• Pipelining is harder in CISC architectures
25
26
27
Key observation: architected state only change in memory and
register write stages.
28
29
Introduction to ILP
• What is ILP?
• Processor and Compiler design techniques that speed up execution by causing
individual machine operations to execute in parallel
• ILP is transparent to the user
• Multiple operations executed in parallel even though the system is handed a
single program written with a sequential processor in mind
• Same execution hardware as a normal RISC machine
• May be more than one of any given type of hardware
31
32
33
34
This allows us to replace the loop above with the following code sequence, which makes
possible overlapping of the iterations of the loop:
a[1] = a[1] + b[1];
for (i=1; i<=99; i= i+1){
b[i+1] = c[i] + d[i];
a[i+1] = a[i+1] + b[i+1];
}
b[101] = c[100] + d[100];
Example 3
for (i=1; i<=100; i= i+1){
a[i+1] = a[i] + c[i]; //S1
b[i+1] = b[i] + a[i+1]; //S2
}
This loop is not parallel it has cycles in the dependencies, namely the statements S1 and S2
depend on themselves!
35
There are a number of techniques for converting such loop-level
parallelism into instruction-level parallelism. Basically, such
techniques work by unrolling the loop.
An important alternative method for exploiting loop-level
parallelism is the use of vector instructions on a vector
processor.

More Related Content

What's hot

Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processor
Muhammad Ishaq
 
Dma and dma controller 8237
Dma and dma controller 8237Dma and dma controller 8237
Dma and dma controller 8237
Ashwini Awatare
 
Intro to Buses (Computer Architecture)
Intro to Buses  (Computer Architecture)Intro to Buses  (Computer Architecture)
Intro to Buses (Computer Architecture)
Matthew Levandowski
 

What's hot (20)

Pthread
PthreadPthread
Pthread
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processor
 
Ethernet
EthernetEthernet
Ethernet
 
Superscalar Architecture_AIUB
Superscalar Architecture_AIUBSuperscalar Architecture_AIUB
Superscalar Architecture_AIUB
 
Dma and dma controller 8237
Dma and dma controller 8237Dma and dma controller 8237
Dma and dma controller 8237
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Chapter 8
Chapter 8Chapter 8
Chapter 8
 
Array Processor
Array ProcessorArray Processor
Array Processor
 
Load Balancing In Distributed Computing
Load Balancing In Distributed ComputingLoad Balancing In Distributed Computing
Load Balancing In Distributed Computing
 
Direct Memory Access
Direct Memory AccessDirect Memory Access
Direct Memory Access
 
Token ring
Token ringToken ring
Token ring
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Single &amp;Multi Core processor
Single &amp;Multi Core processorSingle &amp;Multi Core processor
Single &amp;Multi Core processor
 
Intel Pentium Pro
Intel Pentium ProIntel Pentium Pro
Intel Pentium Pro
 
CN Unit 3
CN Unit 3 CN Unit 3
CN Unit 3
 
OSI MODEL
    OSI MODEL    OSI MODEL
OSI MODEL
 
Intro to Buses (Computer Architecture)
Intro to Buses  (Computer Architecture)Intro to Buses  (Computer Architecture)
Intro to Buses (Computer Architecture)
 
Ethernet protocol
Ethernet protocolEthernet protocol
Ethernet protocol
 
Operating System Lecture Notes
Operating System Lecture NotesOperating System Lecture Notes
Operating System Lecture Notes
 

Similar to Dealing with Exceptions Computer Architecture part 1

Exploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
Exploiting Modern Microarchitectures: Meltdown, Spectre, and other AttacksExploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
Exploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
inside-BigData.com
 
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdfnotes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
SatyamMishra828076
 

Similar to Dealing with Exceptions Computer Architecture part 1 (20)

Performance Enhancement with Pipelining
Performance Enhancement with PipeliningPerformance Enhancement with Pipelining
Performance Enhancement with Pipelining
 
Os lectures
Os lecturesOs lectures
Os lectures
 
Windows kernel
Windows kernelWindows kernel
Windows kernel
 
Exploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
Exploiting Modern Microarchitectures: Meltdown, Spectre, and other AttacksExploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
Exploiting Modern Microarchitectures: Meltdown, Spectre, and other Attacks
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
 
Lec 3
Lec 3 Lec 3
Lec 3
 
lec12-pipelining.ppt
lec12-pipelining.pptlec12-pipelining.ppt
lec12-pipelining.ppt
 
CPU Architecture
CPU ArchitectureCPU Architecture
CPU Architecture
 
Os introduction
Os introductionOs introduction
Os introduction
 
Os introduction
Os introductionOs introduction
Os introduction
 
VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series
 
Computer Organization: Introduction to Microprocessor and Microcontroller
Computer Organization: Introduction to Microprocessor and MicrocontrollerComputer Organization: Introduction to Microprocessor and Microcontroller
Computer Organization: Introduction to Microprocessor and Microcontroller
 
06 pipeline
06 pipeline06 pipeline
06 pipeline
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
 
Operating Systems 1 (11/12) - Input / Output
Operating Systems 1 (11/12) - Input / OutputOperating Systems 1 (11/12) - Input / Output
Operating Systems 1 (11/12) - Input / Output
 
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdfnotes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
notes_Lecture-8 (Computer Architecture) 3rd Semester 2k11 (1).pdf
 
Real Time Debugging - What to do when a breakpoint just won't do
Real Time Debugging - What to do when a breakpoint just won't doReal Time Debugging - What to do when a breakpoint just won't do
Real Time Debugging - What to do when a breakpoint just won't do
 
QCon 2015 Broken Performance Tools
QCon 2015 Broken Performance ToolsQCon 2015 Broken Performance Tools
QCon 2015 Broken Performance Tools
 
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
Fast and Furious: Handling Edge Computing Data With Oracle 19c Fast Ingest an...
 
Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012
Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012
Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012
 

More from Gaditek

More from Gaditek (20)

Digital marketing strategy and planning | About Business
Digital marketing strategy and planning | About BusinessDigital marketing strategy and planning | About Business
Digital marketing strategy and planning | About Business
 
Intro to social network analysis | What is Network Analysis? | History of (So...
Intro to social network analysis | What is Network Analysis? | History of (So...Intro to social network analysis | What is Network Analysis? | History of (So...
Intro to social network analysis | What is Network Analysis? | History of (So...
 
Marketing ethics and social responsibility | Criticisms of Marketing
Marketing ethics and social responsibility | Criticisms of MarketingMarketing ethics and social responsibility | Criticisms of Marketing
Marketing ethics and social responsibility | Criticisms of Marketing
 
understanding and capturing customer value | What Is a Price?
understanding and capturing customer value | What Is a Price?understanding and capturing customer value | What Is a Price?
understanding and capturing customer value | What Is a Price?
 
The marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediariesThe marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediaries
 
strategic planning | Customer Relationships | Partnering to Build
strategic planning | Customer Relationships | Partnering to Build strategic planning | Customer Relationships | Partnering to Build
strategic planning | Customer Relationships | Partnering to Build
 
Digital marketing | what is marketing?
Digital marketing | what is marketing?Digital marketing | what is marketing?
Digital marketing | what is marketing?
 
Fundamentals of Computer Design including performance measurements & quantita...
Fundamentals of Computer Design including performance measurements & quantita...Fundamentals of Computer Design including performance measurements & quantita...
Fundamentals of Computer Design including performance measurements & quantita...
 
Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
differential equation Lecture#14
differential equation  Lecture#14differential equation  Lecture#14
differential equation Lecture#14
 
differential equation Lecture#12
differential equation Lecture#12differential equation Lecture#12
differential equation Lecture#12
 
differential equation Lecture#11
differential equation Lecture#11differential equation Lecture#11
differential equation Lecture#11
 
differential equation Lecture#13
differential equation Lecture#13differential equation Lecture#13
differential equation Lecture#13
 
differential equation Lecture#10
differential equation Lecture#10differential equation Lecture#10
differential equation Lecture#10
 
differential equation Lecture#9
differential equation  Lecture#9differential equation  Lecture#9
differential equation Lecture#9
 
differential equation Lecture#8
differential equation Lecture#8differential equation Lecture#8
differential equation Lecture#8
 
differential equation Lecture#7
differential equation Lecture#7differential equation Lecture#7
differential equation Lecture#7
 
differential equation Lecture#5
differential equation Lecture#5 differential equation Lecture#5
differential equation Lecture#5
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Dealing with Exceptions Computer Architecture part 1

  • 1. Lecture 7 Dealing with Exceptions Computer Architecture CNE-301 Lecturer: Irfan Ali 1
  • 2. 2
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 8. Two Types of Exceptions: Interrupts and Traps • Interrupts • Caused by external events: • Network, Keyboard, Disk I/O, Timer • Page fault - virtual memory • System call - user request for OS action • Asynchronous to program execution • May be handled between instructions • Simply suspend and resume user program • Traps • Caused by internal events • Exceptional conditions (overflow) • Undefined Instruction • Hardware malfunction • Usually Synchronous to program execution • Condition must be remedied by the handler • Instruction may be retried or simulated and program continued or program may be aborted 8
  • 9. Synchronous vs Asynchronous • Definition: If the event occurs at the same place every time the program is executed with the same data and memory allocation, the event is synchronous. Otherwise asynchronous. • Except for hardware malfunctions, asynchronous events are caused by devices external to the CPU and memory. • Asynchronous events usually are easier to handled because asynchronous events can be handled after the completion of the current instruction. 9
  • 10. Exceptions in Simple five-stage pipeline • Instruction Fetch, & Memory stages • Page fault on instruction/data fetch • Misaligned memory access • Memory-protection violation • Instruction Decode stage • Undefined/illegal opcode • Execution stage • Arithmetic exception • Write-Back stage • No exceptions! 10
  • 11. What happens during an exception In The Hardware • The pipeline has to 1) stop executing the offending instruction in midstream, 2) let all preceding instructions complete, 3) flush all succeeding instructions, 4) set a register to show the cause of the exception, 5) save the address of the offending instruction, and 6) then jump to a prearranged address (the address of the exception handler code) In The Software • The software (OS) looks at the cause of the exception and “deals” with it • Normally OS kills the program 11
  • 12. Exceptions Exception = non-programmed control transfer • system takes action to handle the exception • must record the address of the offending instruction • record any other information necessary to return afterwards • returns control to user • must save & restore user state user program normal control flow: sequential, jumps, branches, calls, returns System Exception Handler Exception: return from exception 12 must record
  • 13. 13
  • 14. 14
  • 15. 15 What Makes Pipelining Hard? Examples of interrupts: • Power failing, • Arithmetic overflow, • I/O device request, • OS call, • Page fault Interrupts (also known as: faults, exceptions, traps) often require • surprise jump (to vectored address) • linking return address • saving of PSW-Program Status Word (including CCs- Condition Codes) • state change (e.g., to kernel mode) Interrupts cause great havoc! There are 5 instructions executing in 5 stage pipeline when an interrupt occurs: • How to stop the pipeline? • How to restart the pipeline? • Who caused the interrupt?
  • 16. 16 What Makes Pipelining Hard? Interrupts cause great havoc! What happens on interrupt while in delay slot ? • Next instruction is not sequential solution #1: save multiple PCs • Save current and next PC • Special return sequence, more complex hardware solution #2: single PC plus • Branch delay bit • PC points to branch instruction Stage Problem that causes the interrupt IF Page fault on instruction fetch; misaligned memory access; memory-protection violation ID Undefined or illegal opcode EX Arithmetic interrupt MEM Page fault on data fetch; misaligned memory access; memory-protection violation
  • 17. 17 What Makes Pipelining Hard? • Simultaneous exceptions in more than one pipeline stage, e.g., • Load with data page fault in MEM stage • Add with instruction page fault in IF stage • Add fault will happen BEFORE load fault • Solution #1 • Interrupt status vector per instruction • Defer check until last stage, kill state update if exception • Solution #2 • Interrupt ASAP(as soon as possible) • Restart everything that is incomplete Another advantage for state update late in pipeline! Interrupts cause great havoc!
  • 18. 18
  • 19. 19
  • 20. 20 What Makes Pipelining Hard? Here’s what happens on a data page fault. 1 2 3 4 5 6 7 8 9 i F D X M W i+1 F D X M W < page fault i+2 F D X M W < squash i+3 F D X M W < squash i+4 F D X M W < squash i+5 trap > F D X M W i+6 trap handler > F D X M W Interrupts cause great havoc!
  • 21. Exceptions - “Stuff Happens” • Exceptions definition: “unexpected change in control flow” • Another form of control hazard. For example: add $1, $2, $1; causing an arithmetic overflow sw $3, 400($1); add $5, $1, $2; Invalid $1 contaminates other registers or memory locations! 21
  • 22. Additions to MIPS ISA to support Exceptions • EPC (Exceptional Program Counter) • A 32-bit register • Hold the address of the offending instruction • Cause • A 32-bit register in MIPS (some bits are unused currently.) • Record the cause of the exception • Status - interrupt mask and enable bits and determines what exceptions can occur. • Control signals to write EPC , Cause, and Status • Be able to write exception address into PC, increase mux set PC to exception address (MIPS uses 8000 00180hex ). • May have to undo PC = PC + 4, since want EPC to point to offending instruction (not its successor); PC = PC – 4 • What else? flush all succeeding instructions in pipeline 22
  • 23. Flush instructions in Branch Hazard 36 sub $10, $4, $8 40 beq $1, $3, 7 # taget = 40 + 4 + 7*4 = 72 44 and $12, $2, $5 if($1==$2) 48 or $13, $2, $6 go(PC+4+PC*C) 52 …. …. 72 lw $4, 50($7) 23
  • 24. 24
  • 25. Pipelining in MIPS • MIPS architecture was designed to be pipelined • Simple instruction format (makes IF, ID easy) • Single-word instructions • Small number of instruction formats • Common fields in same place (e.g., rs, rt) in different formats • Memory operations only in lw, sw instructions (simplifies EX) • Memory operands aligned in memory (simplifies MEM) • Single value for Write-Back (limits forwarding) • Pipelining is harder in CISC architectures 25
  • 26. 26
  • 27. 27 Key observation: architected state only change in memory and register write stages.
  • 28. 28
  • 29. 29
  • 30. Introduction to ILP • What is ILP? • Processor and Compiler design techniques that speed up execution by causing individual machine operations to execute in parallel • ILP is transparent to the user • Multiple operations executed in parallel even though the system is handed a single program written with a sequential processor in mind • Same execution hardware as a normal RISC machine • May be more than one of any given type of hardware
  • 31. 31
  • 32. 32
  • 33. 33
  • 34. 34 This allows us to replace the loop above with the following code sequence, which makes possible overlapping of the iterations of the loop: a[1] = a[1] + b[1]; for (i=1; i<=99; i= i+1){ b[i+1] = c[i] + d[i]; a[i+1] = a[i+1] + b[i+1]; } b[101] = c[100] + d[100]; Example 3 for (i=1; i<=100; i= i+1){ a[i+1] = a[i] + c[i]; //S1 b[i+1] = b[i] + a[i+1]; //S2 } This loop is not parallel it has cycles in the dependencies, namely the statements S1 and S2 depend on themselves!
  • 35. 35 There are a number of techniques for converting such loop-level parallelism into instruction-level parallelism. Basically, such techniques work by unrolling the loop. An important alternative method for exploiting loop-level parallelism is the use of vector instructions on a vector processor.