Search code examples
embeddedrtos

Why is it not possible to signal a task from inside an NMI handler using kernel services?


While reading through uCOS-II documentation, I read that one can't use kernel-provided mechanisms to signal a task from inside an NMI, and I am not clear why.

Thank you.

Edit:

Source: uc/OS-II The Real Time Kernel User's Manual, Chapter 2: Real Time Systems Concepts, Page 86:

When you are servicing an NMI, you cannot use kernel services to signal a task because NMIs cannot be disabled to access critical sections of code. However you can still pass parameters to and from the NMI.


Solution

  • The book MicroC/OS-II The Real Time Kernel 2nd ed. explains the reasoning (albeit rather briefly):

    2.31 Nonmaskable Interrupts

    [...] When you are servicing an NMI, you cannot use kernel services to signal a task because NMIs cannot be disabled to access critical sections of code. [...]

    It is perhaps not obvious why this might be a problem, but if a thread enters a critical section and the NMI occurs, calling a kernel service that signals a task will cause the scheduler to be invoked and will cause a context switch within the interrupted critical section.