Repository navigation
kernel (pc): act on a pending task switch on return from LAPIC exceptions - #2377
Open
terminills wants to merge 1 commit into
Open
terminills wants to merge 1 commit into
terminills wants to merge 1 commit into
Conversation
…ions The LAPIC timer and the IPIs are the only interrupts an AP takes, and they arrive as exceptions: core_IRQHandle() passed them to their handlers and returned. The heartbeat sets the CPU's quantum and switch flags, but only the device IRQ path called core_ExitInterrupt() to act on them, so an AP did not act on its own quantum running out on the way back from the interrupt: it switched tasks only when the running task made a system call or left Disable(), or when another CPU sent it IPI_RESCHEDULE. In test/smp's SMP-Preempt, of two busy tasks pinned to one CPU the second was never scheduled, on every CPU but the first. The LAPIC exceptions up to the system call vector now go through core_ExitInterrupt() on the way back to user mode, as device IRQs do. core_ExitInterrupt() may return with interrupts on, since SoftIntDispatch() ends in KrnSti(), so interrupts are masked again before the frame is restored, on both paths.
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.
On pc the LAPIC timer and the IPIs reach
core_IRQHandle()as exceptions. It ran their handlers and returned; only the device IRQ path went on tocore_ExitInterrupt(), where a quantum that has run out or a pending switch is acted on. An AP takes no other interrupts, so it switched tasks only when the running task made a system call or leftDisable(), or when another CPU sent itIPI_RESCHEDULE. A busy task kept its AP, and a second task pinned to that CPU never ran.With this change the LAPIC exceptions below the system call vector go through
core_ExitInterrupt()on the way back to user mode, as device IRQs do. Interrupts are masked again before the frame is restored, becausecore_ExitInterrupt()can return with them on (SoftIntDispatch()ends inKrnSti()).Tested
pc-x86_64 (SMP build) and pc-i386, GCC 15.2.0, QEMU/KVM. The guests are full builds of master 5792c0f without and with the commit. The pc-x86_64 SMP build of later master stops in
rom/m68kemu, whose layout table namesExecBasefields that the SMPexecbase.hreplaces;arch/all-pc/kernel,arch/all-pc/exec,rom/kernelandrom/execare the same at that commit and at this branch's base.The
test/smpprograms were run one per boot, 28 boots of each build on x86_64 at 4 and 16 CPUs.What the change is for:
core_DoCallIPI: Failed to allocate IPIHook entryafter 10 s; 1 froze during startupWhat it does not change. On master the SMP tests freeze the guest in a good part of the boots, and they still do:
[Kernel:TLSF] free-list corruptionThe counts are too small to say whether the freezes are more or less frequent with the change.
In the repeated runs, every CPU's registers and stack were saved from each guest that did not finish, before it was stopped: 8 guests of master, 6 with the change. Both builds show the same pictures:
core_Schedule()/core_Switch(), or walking a task list inAPICHeartbeatServer()that does not end.core_DoCallIPI()takes, called fromSignal(), one of them fromsignal_hookinside the IPI handler. On master a trap frame shows that IPI arriving incore_DoIPI(). The boot with the change that froze during startup is this one.core_ExitInterrupt()is on none of the saved stacks. One SMP-DoIO boot with the change had all four CPUs idle and the test's workers not running; that did not occur in master's six.pc-i386 (one CPU): the image boots, a task that spins without a system call is switched out by the scheduler, and a second task goes on counting, as on master.
32, 64 and 128 CPUs
8 GB guests on a 128-thread host that other VMs were using, so a 128-CPU guest never had the host to itself. One boot per cell.
[Kernel:TLSF] free-list corruptionand the test stopscore_DoCallIPI: Failed to allocate IPIHook entrySo at these counts the change removes the SMP-Preempt failures as far as a run gets, and it is not enough for a clean run at 64 or 128 CPUs. SMP-SigRace at 32 and 128 CPUs and SMP-Affinity at 32 are worse with it in these single boots.
"Did not reach the test": at 128 CPUs both builds often stop during startup, master in 8 of 18 boots and the build with the change in 10 of 17. Booted alternately six times each with SMP-Sched as the test, master stopped during startup 4 times and the build with the change once; the boots that got through passed (3 PASS), except one with the change that froze in the test after TLSF free-list corruption.
State was saved from 17 guests of master and 18 with the change. The IPI hook lock picture above is the most frequent one in both (8 and 7 guests), and the task list lock pictures occur in both. Two things were seen at these counts only with the change:
TaskRunningSpinLockincore_Switch()while a few CPUs are inAPICHeartbeatServer(): 5 guests (SMP-SigRace at 32 and 128 CPUs, SMP-Preempt at 64, two during startup at 128). Master shows this at 4 CPUs in SMP-Timer.Enable()with the same stack pointer, which is on the stack of the Exec housekeeper task, while each CPU's current task is its idle task: 2 boots at 128 CPUs (18 CPUs in one, which stopped; one CPU in the other, which went on and passed its test). None of master's 36 boots at these counts logged a page fault. It was also seen once at 64 CPUs in a build that does not have this change.The counts do not show whether the change causes these or makes faults that are already there show more often.
core_ExitInterrupt()is on none of the saved stacks here either.Not tested: real hardware and a non-SMP pc-x86_64 build.