SlideShare a Scribd company logo
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.
Ad

More Related Content

What's hot (20)

Lecture 37
Lecture 37Lecture 37
Lecture 37
RahulRathi94
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programming
Kartik Sharma
 
Processor Organization
Processor OrganizationProcessor Organization
Processor Organization
Dominik Salvet
 
Cn lab manual
Cn lab manualCn lab manual
Cn lab manual
Vivek Kumar Sinha
 
Pipeline and data hazard
Pipeline and data hazardPipeline and data hazard
Pipeline and data hazard
Waed Shagareen
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
vanamali_vanu
 
Programed I/O Modul..
Programed I/O Modul..Programed I/O Modul..
Programed I/O Modul..
Myster Rius
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
Motaz Saad
 
The structure of process
The structure of processThe structure of process
The structure of process
Abhaysinh Surve
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Riya Choudhary
 
microprocessor
 microprocessor microprocessor
microprocessor
ATTO RATHORE
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
JEEVANANTHAMG6
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
Vinit Raut
 
Shift reduce parser
Shift reduce parserShift reduce parser
Shift reduce parser
TEJVEER SINGH
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
Jyothishmathi Institute of Technology and Science Karimnagar
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
RAMESHBABUA3
 
System software-loaders
System software-loadersSystem software-loaders
System software-loaders
kitturashmikittu
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
RJ Mehul Gadhiya
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
Deepak John
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programming
Kartik Sharma
 
Processor Organization
Processor OrganizationProcessor Organization
Processor Organization
Dominik Salvet
 
Pipeline and data hazard
Pipeline and data hazardPipeline and data hazard
Pipeline and data hazard
Waed Shagareen
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
vanamali_vanu
 
Programed I/O Modul..
Programed I/O Modul..Programed I/O Modul..
Programed I/O Modul..
Myster Rius
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
Motaz Saad
 
The structure of process
The structure of processThe structure of process
The structure of process
Abhaysinh Surve
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
Rajkumar R
 
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
1. Arithmetic Operations - Addition and subtraction of signed numbers.pptx
JEEVANANTHAMG6
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
Vinit Raut
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
RJ Mehul Gadhiya
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
Deepak John
 

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
Aneesh Raveendran
 
Lecture Presentation 8.pdfLecture Presentation 8.pdf
Lecture Presentation 8.pdfLecture Presentation 8.pdfLecture Presentation 8.pdfLecture Presentation 8.pdf
Lecture Presentation 8.pdfLecture Presentation 8.pdf
minamelad457
 
2024_lecture12_come321.pptx..................
2024_lecture12_come321.pptx..................2024_lecture12_come321.pptx..................
2024_lecture12_come321.pptx..................
ghada507476
 
Os lectures
Os lecturesOs lectures
Os lectures
Adnan Ghafoor
 
Windows kernel
Windows kernelWindows kernel
Windows kernel
Sisimon Soman
 
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
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
ButtaRajasekhar2
 
Lec 3
Lec 3 Lec 3
Lec 3
mohamed ali
 
lec12-pipelining.ppt
lec12-pipelining.pptlec12-pipelining.ppt
lec12-pipelining.ppt
ManimegalaM3
 
CPU Architecture
CPU ArchitectureCPU Architecture
CPU Architecture
محمدعبد الحى
 
Os introduction
Os introductionOs introduction
Os introduction
Kanika Garg
 
Os introduction
Os introductionOs introduction
Os introduction
Ravi Ramchandani
 
VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series
VMworld
 
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
AmrutaMehata
 
02-archsupport.ppt Architecture Support for OPS
02-archsupport.ppt Architecture Support for OPS02-archsupport.ppt Architecture Support for OPS
02-archsupport.ppt Architecture Support for OPS
ssuserb53446
 
06 pipeline
06 pipeline06 pipeline
06 pipeline
Master Haui
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
Brendan Gregg
 
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
Peter Tröger
 
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
 
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
LloydMoore
 
Performance Enhancement with Pipelining
Performance Enhancement with PipeliningPerformance Enhancement with Pipelining
Performance Enhancement with Pipelining
Aneesh Raveendran
 
Lecture Presentation 8.pdfLecture Presentation 8.pdf
Lecture Presentation 8.pdfLecture Presentation 8.pdfLecture Presentation 8.pdfLecture Presentation 8.pdf
Lecture Presentation 8.pdfLecture Presentation 8.pdf
minamelad457
 
2024_lecture12_come321.pptx..................
2024_lecture12_come321.pptx..................2024_lecture12_come321.pptx..................
2024_lecture12_come321.pptx..................
ghada507476
 
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
 
UNIT 3 - General Purpose Processors
UNIT 3 - General Purpose ProcessorsUNIT 3 - General Purpose Processors
UNIT 3 - General Purpose Processors
ButtaRajasekhar2
 
lec12-pipelining.ppt
lec12-pipelining.pptlec12-pipelining.ppt
lec12-pipelining.ppt
ManimegalaM3
 
VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series VMworld 2014: Extreme Performance Series
VMworld 2014: Extreme Performance Series
VMworld
 
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
AmrutaMehata
 
02-archsupport.ppt Architecture Support for OPS
02-archsupport.ppt Architecture Support for OPS02-archsupport.ppt Architecture Support for OPS
02-archsupport.ppt Architecture Support for OPS
ssuserb53446
 
Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016Broken Linux Performance Tools 2016
Broken Linux Performance Tools 2016
Brendan Gregg
 
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
Peter Tröger
 
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
 
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
LloydMoore
 
Ad

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
Gaditek
 
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...
Gaditek
 
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
Gaditek
 
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?
Gaditek
 
The marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediariesThe marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediaries
Gaditek
 
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
Gaditek
 
Digital marketing | what is marketing?
Digital marketing | what is marketing?Digital marketing | what is marketing?
Digital marketing | what is marketing?
Gaditek
 
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...
Gaditek
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
Gaditek
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
Gaditek
 
differential equation Lecture#14
differential equation  Lecture#14differential equation  Lecture#14
differential equation Lecture#14
Gaditek
 
differential equation Lecture#12
differential equation Lecture#12differential equation Lecture#12
differential equation Lecture#12
Gaditek
 
differential equation Lecture#11
differential equation Lecture#11differential equation Lecture#11
differential equation Lecture#11
Gaditek
 
differential equation Lecture#13
differential equation Lecture#13differential equation Lecture#13
differential equation Lecture#13
Gaditek
 
differential equation Lecture#10
differential equation Lecture#10differential equation Lecture#10
differential equation Lecture#10
Gaditek
 
differential equation Lecture#9
differential equation  Lecture#9differential equation  Lecture#9
differential equation Lecture#9
Gaditek
 
differential equation Lecture#8
differential equation Lecture#8differential equation Lecture#8
differential equation Lecture#8
Gaditek
 
differential equation Lecture#7
differential equation Lecture#7differential equation Lecture#7
differential equation Lecture#7
Gaditek
 
differential equation Lecture#5
differential equation Lecture#5 differential equation Lecture#5
differential equation Lecture#5
Gaditek
 
differential equation Lecture#3
differential equation  Lecture#3differential equation  Lecture#3
differential equation Lecture#3
Gaditek
 
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
Gaditek
 
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...
Gaditek
 
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
Gaditek
 
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?
Gaditek
 
The marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediariesThe marketing environment | Suppliers | Marketing intermediaries
The marketing environment | Suppliers | Marketing intermediaries
Gaditek
 
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
Gaditek
 
Digital marketing | what is marketing?
Digital marketing | what is marketing?Digital marketing | what is marketing?
Digital marketing | what is marketing?
Gaditek
 
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...
Gaditek
 
Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
Gaditek
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
Gaditek
 
differential equation Lecture#14
differential equation  Lecture#14differential equation  Lecture#14
differential equation Lecture#14
Gaditek
 
differential equation Lecture#12
differential equation Lecture#12differential equation Lecture#12
differential equation Lecture#12
Gaditek
 
differential equation Lecture#11
differential equation Lecture#11differential equation Lecture#11
differential equation Lecture#11
Gaditek
 
differential equation Lecture#13
differential equation Lecture#13differential equation Lecture#13
differential equation Lecture#13
Gaditek
 
differential equation Lecture#10
differential equation Lecture#10differential equation Lecture#10
differential equation Lecture#10
Gaditek
 
differential equation Lecture#9
differential equation  Lecture#9differential equation  Lecture#9
differential equation Lecture#9
Gaditek
 
differential equation Lecture#8
differential equation Lecture#8differential equation Lecture#8
differential equation Lecture#8
Gaditek
 
differential equation Lecture#7
differential equation Lecture#7differential equation Lecture#7
differential equation Lecture#7
Gaditek
 
differential equation Lecture#5
differential equation Lecture#5 differential equation Lecture#5
differential equation Lecture#5
Gaditek
 
differential equation Lecture#3
differential equation  Lecture#3differential equation  Lecture#3
differential equation Lecture#3
Gaditek
 
Ad

Recently uploaded (20)

Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 

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.
  翻译: