Repository navigation
Conversation
core_Switch() Remove()s/Enqueue()s the outgoing task on TaskReady or TaskWait. Only Wait() reaches it with a Disable() held. Every Schedule() path (Permit(), Enable(), Reschedule() via KrnSchedule/Supervisor(), and ExitIntr preemption) arrives with INTEN set, at IPL 0 or at the level of the exiting interrupt. An interrupt that calls Signal() in the middle of the Enqueue() edits the same list and one task drops off both lists: it never runs again, and anything that walks the lists can crash later. Raise the IPL to 7 before core_Switch(), as cpu_Dispatch() already does before core_Dispatch(); the RTE to the next task restores its SR. Reproduced on a V4 with a stress test (CIA-B timer Signal()s six pri-0 waiters at 5 kHz while a pri-2 echo task is pinged with Signal() and Forbid()/Signal()/Permit(), and the exec lists are checked under Disable()): R9.6-RC06 hangs the board within seconds; with this change it passes 3 runs (150 s, ~1.6M task switches, ~730k interrupt-level Signal()s) and the board stays healthy. The code is unchanged since early AROS m68k, so R9.5 is affected too. AROS has the same fix for its newer Switch() in d0b5fa16ab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ec12438 (ApolloTeam-dev#158) writes INTENA = SETCLR|INTEN on every Paula interrupt exit, so that code which runs Disable() and then turns on the hardware itself (issue #742 demos) gets interrupts back. Done unconditionally, it also fires when the interrupt lands just as the interrupted code enters Disable() (INTENA written, IDNestCnt not yet raised), which turns interrupts back on inside a critical section. On RC06 this showed up as ApolloRadio losing networking after hours; a revert ROM ran overnight without the problem. Restore the bit only when the interrupted context had a Disable() outstanding (IDNestCnt >= 0 at entry) and INTEN is actually clear at exit. That still covers the #742 case (checked on a V4 with a test that does Forbid()+Disable(), sets INTENA, adds a VBL server and waits for VBLs) and no longer touches INTENA in any other case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Maintainer validation is needed for m68k scheduler atomicity and Paula interrupt restoration during nested IRQs and Disable() transitions, which the reported V4 tests cannot establish across supported hardware.
No open issues 🎉
What changed in this PR
Addresses two interrupt-related reliability issues in the m68k kernel: task-list corruption during scheduling and unintended interrupt re-enabling when leaving a Paula interrupt handler.
Changes:
- Masks CPU interrupts before
core_Switch()modifies scheduler task lists. - Restores Paula’s master interrupt bit only when the interrupted context had an outstanding
Disable()and the bit is clear at exit.
| File | Description |
|---|---|
arch/m68k-amiga/kernel/amiga_irq.c |
Records the entry disable state and narrows the INTENA restore condition. |
arch/m68k-all/kernel/kernel_cpu.c |
Raises the CPU interrupt mask before scheduler list updates. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR has two independent fixes, one per commit.
1. Tasks lost from the exec lists (scheduler race)
core_Switch()Remove()s/Enqueue()s ThisTask on TaskReady/TaskWait. OnlyWait()gets there with a Disable() held. AllSchedule()paths (Permit(), Enable(), Reschedule() via KrnSchedule → Supervisor(), and ExitIntr preemption) run it with INTEN set, at IPL 0 or at the level of the exiting interrupt. If an interrupt callsSignal()during the Enqueue(), it edits the same list, and a task drops off both lists. That task never runs again, and anything that walks the lists can crash later. This fits the reports of a game port losing a task and of ApolloOS dying on its own after days.Fix:
ori.w #0x0700,%srincpu_Switch()beforecore_Switch(), the same thingcpu_Dispatch()already does beforecore_Dispatch(). The RTE into the next task restores its SR.The code is unchanged since early AROS m68k, so R9.5 is affected too. AROS has the equivalent fix for its rewritten Switch() in d0b5fa16ab.
2. The Paula INTENA restore from #158 fires too often
ec12438 (#158) writes
INTENA = SETCLR|INTENon every Paula IRQ exit. When an interrupt lands just as the interrupted code enters Disable() (INTENA written, IDNestCnt not yet incremented), that write turns interrupts back on inside a critical section. On RC06 this showed up as ApolloRadio losing networking after hours; a ROM with #158 reverted ran overnight fine.This change restores the bit only if the interrupted context had a Disable() outstanding (
IDNestCnt >= 0at entry) and INTEN is actually clear at exit. The #742 demo case still works.Testing (Vampire V4)
Note for #161 / #162
These PRs port the newer AROS scheduler, so commit 1 will conflict with them. With them the mask has to go in front of
m68k_SwitchTail()(as AROS d0b5fa16ab does). Their new Switch.S drops to IPL 0 before requeueing, which widens the window. Commit 2 merges cleanly with #161.🤖 Generated with Claude Code