Skip to content

irqchip/apple-aic: Report the effective affinity of AICv2+ IRQs - #447

Merged
DjDeveloperr merged 1 commit into
integration/aurorafrom
fix/aic2-effective-affinity-20261025
Oct 26, 2026
Merged

DjDeveloperr merged 1 commit into
integration/aurorafrom
fix/aic2-effective-affinity-20261025

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AICv2+ has no per-IRQ CPU target. Each CPU says in its SIQ_CFG system register whether it accepts IRQs; routing field (bits 1:0) = 3 means it never receives one. On T8140 (Neo) CPU 0 reads 0 and every secondary reads 3, so every hardware IRQ lands on CPU 0. Because the AICv2 irqchip has no irq_set_affinity, the effective affinity stayed empty, and threaded handlers floated to any CPU. The G17 GPU completion thread (irq/65) often ran on the app's CPU, which saturated it and caused a bimodal "slow mode" in latency-sensitive GPU workloads.

On SoCs whose routing has been verified on hardware (currently T8140), and only at EL2, AICv2+ IRQs map to a second irqchip, aic2_routed_chip. It records at CPU bring-up which CPUs accept IRQs and reports them as each IRQ's effective affinity, so genirq binds threaded handlers to the CPU(s) the hard IRQ actually arrives on.

Safety and scope:

  • The register is read only on T8140 and only at EL2, gated by per-SoC match data (apple,t8140-aic3).
  • Every other AIC2 SoC (M1 Pro/Max, M2, M3, M5 T8142, …) keeps the existing aic2_chip byte for byte. smp_affinity writes still fail there, and MSI affinity calls don't reach AIC.
  • AICv1 is unchanged.
  • A SoC joins the list only after a hardware boot test.
  • The accepting set grows as CPUs start, and existing IRQs keep theirs. That is enough while only one CPU accepts IRQs; a SoC with more than one would also need an online refresh, as the code comment says.

Behaviour change on T8140 (at EL2): every ordinary AIC IRQ thread, PCIe MSI ones included, now runs on CPU 0, and smp_affinity writes don't move it. They are accepted and kept only for reporting. The CPU 0 load numbers below cover this for gpubench.

Hardware evidence (Neo, T8140)

  • Routing probe on a spare AIC line:

    • all 32×6 triggers landed on CPU 0, from any firing CPU, even with CPU 0 masked for 35 ms;
    • setting a secondary's field to 2 made it a fallback, and 1 made it preferred.
  • New core: irq/65 on CPU 0 in 100% of 50 ms samples, and /proc/irq/65/effective_affinity_list = 0. On the old core it was on CPU 5 64–99% of the time, with an empty effective affinity.

  • Benchmarks (gpubench, µs/submit, 2 new-core boots vs 3 old-core boots; slow rounds in brackets):

    row old new
    compute d2, unpinned 47.9 / 46.9 / 49.2 (10, 10, 7 of 10 slow) 37.5 / 36.9 (0, 0)
    compute d2, app on CPU 5 57.4 (7) 37.9 (0)
    render d32, app on CPU 5 38.4 (7) 30.5 (0)
    render d1, app on CPU 0 127.9 107.6

    Slow rows overall: 20/30 + 20/30 + 54/80 → 8/30 + 12/80. Other rows are unchanged.

  • CPU 0 load: not overloaded (69–70% busy under render d32 vs 54–57% before), and its 1 ms timer lateness improved (p99 81–83 µs vs 105–115).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review notes from a static read of 28ceabdc (build gates are queued and not yet run). Looks right for the native Apple path. AICv1 is unchanged, and SIQ_CFG is read only on T8140 at EL2. The effective-affinity mask capability is always selected on arm64, so the update isn't a no-op.

One conditional issue is CPU hotplug. The affinity setter snapshots aic_irq_cpus & cpu_online_mask into each IRQ's effective mask, and aic_init_cpu() only updates the global acceptor mask. When a CPU goes offline, irq_migrate_all_off_this_cpu() drops it from the effective masks correctly. When it comes back, though, genirq's online callback only restores managed IRQs (kernel/irq/cpuhotplug.c), so ordinary IRQs keep the reduced mask and their threads stay excluded from that CPU. It can't happen today, since the Apple DTs use spin-table bring-up with no CPU-off. If hotplug ever lands, it would need an online-stage refresh through genirq (not the STARTING callback). Fine as a follow-up rather than a blocker.

Next: the build gates, then a Neo GPU IRQ affinity check (the completion thread should be held to CPU0 on EL2 T8140) with timeout and lost-device counts compared against the same base, plus M1 Pro and M2 one-shots.

@DjDeveloperr
DjDeveloperr force-pushed the fix/aic2-effective-affinity-20261025 branch from 28ceabd to 6f25fcf Compare October 25, 2026 22:38
AICv2 and later have no per-IRQ CPU target. The controller hands each
hardware IRQ to one of the CPUs that accept IRQs, and each CPU says
whether it does in its SIQ_CFG system register: a CPU whose routing
field (bits 1:0) reads 3 never receives one. On T8140 the boot CPU reads
0 and every secondary reads 3, so every hardware IRQ is taken on CPU 0,
even while CPU 0 holds IRQs masked for tens of milliseconds. Setting a
secondary to 1 or 2 makes the controller deliver to it as well.

The AICv2 irqchip has no irq_set_affinity, so the effective affinity of
its IRQs stays empty and their threaded handlers may run on any CPU. The
scheduler often places them away from the CPU taking the hard IRQ, which
adds a cross-CPU wakeup to every interrupt.

On SoCs where this routing has been verified on hardware, currently
T8140, and only at EL2, since a hypervisor or secure monitor may trap
SIQ_CFG, map AICv2+ IRQs to a second irqchip. It records at CPU bring-up
which CPUs accept IRQs and reports them as each IRQ's effective
affinity, so that genirq binds threaded handlers to the CPUs the hard
IRQ arrives on. The requested mask cannot change delivery; it is
accepted and kept only for reporting. On T8140 every AIC IRQ thread,
PCIe MSI ones included, therefore runs on CPU 0, and smp_affinity writes
do not move it. Every other SoC keeps the existing irqchip unchanged.

The accepting set grows as CPUs start and existing IRQs keep theirs,
which is enough while only one CPU accepts IRQs. A SoC with more than
one accepting CPU would also need the masks refreshed when such a CPU
comes online.

On T8140 the G17 GPU completion thread used to run on CPU 5 most of the
time and now stays on CPU 0. Over two boots of each kernel, compute
submission at depth 2 goes from 47-49 us to 37 us per submit, and render
submission at depth 1 from a CPU 0 submitter from 128 us to 108 us.
Other submission rows are unchanged.
@DjDeveloperr
DjDeveloperr force-pushed the fix/aic2-effective-affinity-20261025 branch from 6f25fcf to 88aebfe Compare October 25, 2026 23:02
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Thanks. On the hotplug point: fixed rather than deferred, and the scope narrowed (88aebfe):

  • The change moved to a separate aic2_routed_chip, which aic_irq_domain_map() uses only when siq_cfg_routing and the kernel is at EL2. Every other AICv2+ SoC keeps the existing aic2_chip unchanged, with no irq_set_affinity.
  • The reported set is the SIQ_CFG acceptors, not intersected with the online mask, so CPU offline can't narrow it.
  • The field comment notes that a SoC with more than one accepting CPU would need an online-stage refresh through genirq.

Next: the Neo GPU IRQ affinity check on this head (irq/65 held to CPU 0, effective_affinity_list) with timeout and lost-device counts against the same base. Since other SoCs no longer change, the M1 Pro / M2 risk is limited to the one domain-map selection line.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants