Commit d018d84
committed
extmod/zephyr_kernel: Override arch_irq_lock to use PRIMASK for complete interrupt masking.
Zephyr's default arch_irq_lock() uses BASEPRI register on Cortex-M4/M7, which
masks only interrupts with priority >= threshold (0x10). This allows priority 0
interrupts to fire during critical sections, potentially corrupting thread state
during mutex operations, context switches, and scheduler operations.
This commit overrides arch_irq_lock() and arch_irq_unlock() to use PRIMASK
register, which masks ALL configurable interrupts (except NMI and HardFault).
Implementation:
- Created arch_irq_primask.h header with PRIMASK-based implementations
- Included after Zephyr headers to override BASEPRI versions
- Uses __get_PRIMASK/__disable_irq for complete masking
- Matches MicroPython's disable_irq() approach in ports/stm32/irq.h
Trade-offs:
- Slightly longer interrupt latency for priority 0 interrupts during critical sections
- Eliminates race conditions from high-priority interrupts during critical sections
- More conservative approach: complete masking vs threshold-based masking
Testing: 23/34 thread tests passing (same as before). Override doesn't improve
pass rate but provides architectural correctness - eliminates potential corruption
vector from priority 0 interrupts.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>1 parent 68ed70c commit d018d84
File tree
2 files changed
+64
-0
lines changed- extmod/zephyr_kernel
- arch/cortex_m
- include
2 files changed
+64
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments