Skip to content

sched/irq: Preserve handlers when extending IRQ chains. - #20162

Open
yushuailong wants to merge 1 commit into
apache:masterfrom
yushuailong:fix/irqchain-handler-append
Open

yushuailong wants to merge 1 commit into
apache:masterfrom
yushuailong:fix/irqchain-handler-append

Conversation

@yushuailong

@yushuailong yushuailong commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix IRQ chain attachment so the third and subsequent handlers are appended to an existing chain instead of being silently ignored.

The change also allocates all nodes needed for the initial chain before publishing it, preventing a partially constructed chain if the pool is exhausted.

Impact

bug fix only

Testing

Wildfire "Compass" board with STM32F103VET6(72 MHz, 512 KB flash, 64 KB RAM), console on USART1 at 115200 8N1, flashed through the on-board CH340 / STM32 ROM bootloader (no debug probe needed).
Host: macOS 27.0 (Apple Silicon), arm-none-eabi-gcc 14.2.1,
CMake 4.0.2 + Ninja 1.12.1.

Configuration: fire-stm32v2:nsh + CONFIG_IRQCHAIN=y, CONFIG_PREALLOC_IRQCHAIN=8. Two images were built from the same tree, the only difference being this patch. The test attaches several handlers to one IRQ line (71 = TIM7, unused in this configuration), pends the line by software (up_trigger_irq() -> NVIC STIR) and counts the invocations of each handler; a stage 0 sanity check first confirms that this trigger reaches a plain vector handler on this board.

  • before (unpatched) - irq_attach() was called four times and returned 0 every time, but only the first two handlers ever ran: handler call counts: h0=3 h1=3 h2=0 h3=0 -> RESULT: FAIL
  • after (patched) - all four handlers run: h0=3 h1=3 h2=3 h3=3; single handler detach, full chain rebuild and chain-pool exhaustion (irq_attach(#9) = -12 (ENOMEM), pool fully recovered afterwards) all pass -> RESULT: PASS

10 rounds per image (2 runs x 5 rounds), all with identical results.
Build: flash 95976 B / 512 KB, SRAM 7080 B, [1163/1163] Generating nuttx.hex.

Allocate the new handler node independently of the initial chain
conversion so handlers beyond the second are appended instead of silently
dropped.  Delay vector conversion until both required nodes are available
to avoid leaving a partially constructed chain on allocation failure.

Assisted-by: OpenAI Codex
Signed-off-by: yushuailong <yyyusl@qq.com>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@yushuailong
yushuailong force-pushed the fix/irqchain-handler-append branch from 7c364f1 to 4463d5b Compare September 16, 2026 12:11

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yushuailong changes on core of NuttX (i.e. sched) requires real test on real devices.

@yushuailong

Copy link
Copy Markdown
Contributor Author

PR-20162-test-logs.md

@yushuailong

Copy link
Copy Markdown
Contributor Author

@yushuailong changes on core of NuttX (i.e. sched) requires real test on real devices.

Done

@acassis

acassis commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@yushuailong please rebase to fix the issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants