Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module: Handling Exceptions

Similar presentations


Presentation on theme: "Module: Handling Exceptions"— Presentation transcript:

1 Module: Handling Exceptions
ECE 4100/6100 Spring 2005 © Krishna V. Palem, Weng Fai Wong, and Sudhakar Yalamanchili, Georgia Institute of Technology (slides contributed by Prof. Weng Fai Wong were prepared while visiting, and employed by, Georgia Tech)

2 Reading for this Module
General Section 3.1, pp , Appendix A: A42-A44 History Buffer, Future File, Software recovery A-54-A-56 Re-order Buffer Section 3.7, pp. 232 Section 4.5, pp Spring 2005

3 Exceptions Unexpected situations encountered during the execution of an instruction Related terms Faults Unexpected situation caused by the execution of a particular instruction Traps Means by which the user can get OS attention Interrupts Asynchronous external hardware event Spring 2005

4 Process State When an exception occurs, the state of the interrupted process must be saved Exception handler is invoked May be inside or outside or both in and out of user space Spring 2005

5 Precise Exception An exception is precise if the following conditions are met: All the instructions preceding the instruction pointed to by the saved PC has been executed and have modified the process state correctly All instructions following the instruction pointed to by the saved PC have not yet been executed and have done no modification to the process state. If the exception is caused by the execution of an instruction in a program, then the saved PC points to that instruction. This instruction may or may not have been executed. This will depend on the definition of the architecture and the cause of the exception. Spring 2005

6 Sources of Precise Exceptions
In I/O and timer exceptions, it is necessary to restart the execution of the instruction after the exception has been processed. Precise exceptions make this possible. Almost all processors today support virtual memory. In virtual memory, a page fault has to be serviced and this has to be precise so as to guarantee correctness. Precise exceptions is very useful in debugging as the exact (logical) situation of the exception can be reflected to the programmer. Spring 2005

7 Sources of Precise Exception
In the IEEE standard for binary floating point, for example, certain exceptions are recoverable. For gradual underflow, for example, a floating point number may have gone into underflow. Then an exception handler is invoked to convert this floating point number into a denormalized number. Again, for ease of restart, precise exception is necessary. Unimplemented opcodes can be simulated in software if exceptions are precise. Privileged instructions will cause exceptions and these too should be precise. Spring 2005

8 Exceptions and Speculative Execution
It is useful to distinguish between terminating and non-terminating exceptions The former typically correspond to program errors Exceptions should not be raised on instructions that will never execute For example control dependent speculative instructions For example, memory exceptions Spring 2005

9 Techniques to Support Precise Exceptions
Reorder Buffer History buffer Future File Software Recovery Spring 2005

10 Reorder Buffer Additional info:
Did the instruction generate an exception What sort of exception? Commit results if only there is no exception Else halt instruction processing, flush pipeline and bring in the handler Exceptions can be handled in commitment order Spring 2005

11 History Buffer The history buffer is a queue. Each entry contains:
The program counter of the associated instruction; The number of the register in the register file to be overwritten by the associated instruction; The old value of that register; Any exception caused by the instruction; A flag to indicate the completion of the instruction Spring 2005

12 History Buffer Spring 2005

13 How It Works When an instruction is dispatched, an entry at the tail of the history buffer is allocated. The destination register number of the instruction, its current value and the PC value of the instruction are written into the allocated entry. The result of the instruction's execution is written directly into the register file. Spring 2005

14 How It Works Any exception in the execution of the instruction is noted in the associated history buffer entry. When a completed instruction reaches the head of the history buffer, and there is no exception, the entry is simply deleted. When an instruction having an exception reaches the head of the history buffer, instruction issue is immediately halted. Spring 2005

15 How It Works The processor then waits for all on-going computation to complete. The history buffer is scanned from head to tail and the old values of the registers in the history buffer entry are written back into the register file. Spring 2005

16 Future File A future file is duplicate set of registers
Main register files maintained by reorder buffer No restrictions on how the future file is written Spring 2005

17 Future File Spring 2005

18 How It Works Upon dispatch, an instruction is allocated a reorder buffer entry at the tail of the reorder buffer. Operands are read from the future file. When an instruction completes, it will write into the reorder buffer and the future file. Spring 2005

19 How It Works When an instruction at the head of the reorder buffer completes without exception, it is committed to the architectural register file and its reorder buffer entry is simply deleted If an instruction at the head of the reorder buffer goes into exception, then instruction issue is halted and the pipelines are flushed and the content of the architectural register file is copied into the future file. Spring 2005

20 Software Recovery Exception handlers execute incomplete instructions to bring the machine to a known state Execution continues from the known state Example Spring 2005

21 How It Works The PCs of all instructions are available
.. Instruction n-1 Instruction n Instruction causing the exception execution not completed execution completed The PCs of all instructions are available Goal: Restart at instruction n+1 Simulate the execution of instructions 1 through n Complex software implementation Complexity can be reduced by constraining the value of n Spring 2005

22 Concluding Remarks Imprecise vs. precise exceptions
Precise exception handling benefits from architectural techniques for handling speculative execution For example, the reorder buffer Hardware and software can cooperate in the handling of exceptions Spring 2005

23 Study Guide What are the relative advantages and disadvantages of the techniques for handling precise exceptions? Find examples where it would be acceptable to support imprecise exceptions Track a speculative FP instruction that raised a FP exception through the ROB Build an example code sequence with conditionals Prediction indicates this instruction is executed The instruction raises an exception It reaches the head of the ROB before the branch condition is known For the preceding example, show the evolution of state of the history buffer and future file Spring 2005


Download ppt "Module: Handling Exceptions"

Similar presentations


Ads by Google