Search code examples
interruptriscv

exceptions vs interrupts in RiscV?


I read that exceptions are raised by instructions and interrupts are raised by external events.

But I couldn't understand few things:

  1. In which type we stop immediately and in which we let the current line of code finish?

  2. In both cases and after doing 1 we run the next program, is that right?


Solution

  • The terminology is used differently by different authors.

    The hardware exception mechanism is used by both software caused exceptions, and by external interrupts.

    In which type we stop immediately and in which we let the current line of code finish?

    The processor can do what its designers want up to a point.

    If there is an external interrupt, the processor may choose to finish some of the work in progress before taking the interrupt.

    If there is a software caused interrupt, the processor simply cannot execute that instruction (or any instructions after) and must abort its execution, and take the exception without completing the offending instruction.

    In both cases and after doing 1 we run the next program, is that right?

    In the case of external interrupt, the most efficient is to resume the program that was interrupted, as the caches and page tables are hot for that process.  However, an external interrupt may change the runnable status of another higher priority process, or may end the timeslice of the interrupted process, indicating another process should now get CPU time instead of the one interrupted.

    In the case of a software caused exception, it is could be a non-resumable situation (null pointer dereference), in which case, yes another process get the CPU after.  It could be a resumable situation, like I/O request or page fault.  If servicing the situation requires interfacing with peripherals, that may block the interrupted process, so another process would get some CPU time.