From e8bb42119bac100f0171821401b893f6b663f910 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Wed, 25 Nov 2026 21:41:09 -0500 Subject: [PATCH] soc: apple: mailbox: receive G17 completions in the RT thread again Commit 4fa08b46555a ("soc: apple: mailbox: drain G17 receive interrupts in hard IRQ") moved the ASCWrap v6 GPU receive path out of the oneshot IRQ thread: normal completions are now drained in hard IRQ, and the thread runs only when the receive budget saturates. The thread was doing more than adding a wakeup. It is an RT task, so while it runs schedutil raises its CPU cluster to the top frequency, and the G17 driver steers that through apple_mbox_set_rx_util_min(): Port::rx_update() keeps the RT default for host-bound streams and lowers it only while the GPU is the bottleneck. Since 4fa08b46555a the completion of every light submission runs without that boost, from whichever CPU takes the interrupt. On the MacBook Neo (J700, A18 Pro) gpubench-vk compute.light regressed with that commit alone. Built on its own parent with only its merge reverted, 6 reps each: row with reverted 7.3.0-41 compute.light queue/d2 (us) 52.3 35.3 35.5 submit CPU (us) 12.0 9.6 9.7 latency (us) 110 64 64 reps that lose the overlap 6/6 0/6 0/6 compute.light queue/d1 (us) 106.0 102.1 102.3 render.light queue/d1 (us) 137.8 122.1 127.0 Bisected on J700 from 7.3.0-41 (6f618bccf94f, rebuilt with the same toolchain and config as every other point) to 7c9d9adcda5a: the regression first appears in 3989d21784d1..19ae3124e50e, and reverting merge 99ebf936e6fe (#2980) alone removes it, while reverting #3015 alone, or #2552, #2553 and #2207 together, or #2520, #3010 and #915 together, does not. Restore the threaded receive handler for ASCWrap v6 G17 mailboxes. Keep that commit's exclusion of ASCWrap v8 (T8152) from apple_mbox_is_g17(), so the T8152 GPU mailbox stays on apple_mbox_recv_irq() with its storm guard as it is now, and keep a KUnit case for that exclusion. With "drm/asahi: g17: keep G17P work nodes and compute descriptors firmware-cached" on origin/main 16da00248bc9, a one-shot J700 boot gives compute.light d2 34.5 us (submit CPU 9.5 us, 0/9 reps losing the overlap), d1 104.1 us, render.light d1 124.9 us; the multi_queue CTS family 4266/0 three times, compute CRCs 5/5, Geekbench 6 Vulkan 8/8, and no GPU fault, WARN or AVC. Signed-off-by: Diljit Singh --- drivers/soc/apple/mailbox-g17-test.h | 43 ++++++------------------ drivers/soc/apple/mailbox.c | 50 ++++++++-------------------- include/linux/soc/apple/mailbox.h | 6 ++-- 3 files changed, 27 insertions(+), 72 deletions(-) diff --git a/drivers/soc/apple/mailbox-g17-test.h b/drivers/soc/apple/mailbox-g17-test.h index a7197d411c16d..a6bb6222bc52f 100644 --- a/drivers/soc/apple/mailbox-g17-test.h +++ b/drivers/soc/apple/mailbox-g17-test.h @@ -93,52 +93,29 @@ static void apple_g17_rx_util_min_test(struct kunit *test) #endif } -static void apple_g17_rx_hardirq_dispatch_test(struct kunit *test) +static void apple_g17_v8_excluded_test(struct kunit *test) { - const struct apple_mbox_hw hw = { - .i2a_control = 0, .i2a_recv0 = 8, .i2a_recv1 = 16, - .control_empty = BIT(17), - }; - struct apple_mbox mbox = { .hw = &hw, .rx = apple_g17_test_rx }; - unsigned int count = 0; - void *regs = kunit_kzalloc(test, 32, GFP_KERNEL); - - KUNIT_ASSERT_NOT_NULL(test, regs); - mbox.regs = (void __iomem *)regs; - const struct apple_mbox_hw hw_v8 = { - .i2a_control = 0, .i2a_recv0 = 8, .i2a_recv1 = 16, - .control_empty = BIT(17), - .is_ascwrap_v8 = true, - }; + const struct apple_mbox_hw hw = { .control_empty = BIT(17) }; + const struct apple_mbox_hw hw_v8 = { .control_empty = BIT(17), .is_ascwrap_v8 = true }; + struct apple_mbox mbox = { .hw = &hw }; struct apple_mbox mbox_v8 = { .hw = &hw_v8 }; - mbox.ascwrap_v6.role = APPLE_MBOX_ASCWRAP_V6_ROLE_GFX; - mbox.cookie = &count; - spin_lock_init(&mbox.rx_lock); - - /* ASCWrap v6 GFX/GFX1 use the hard-IRQ split; ASCWrap v8 stays excluded - * so apple_mbox_recv_irq() keeps running apple_mbox_v8_rx_irq_guard(). + /* ASCWrap v6 GFX/GFX1 take the threaded G17 receive handler; ASCWrap v8 + * stays on apple_mbox_recv_irq() with apple_mbox_v8_rx_irq_guard(). */ + mbox.ascwrap_v6.role = APPLE_MBOX_ASCWRAP_V6_ROLE_GFX; + KUNIT_EXPECT_TRUE(test, apple_mbox_is_g17(&mbox)); + mbox.ascwrap_v6.role = APPLE_MBOX_ASCWRAP_V6_ROLE_GFX1; KUNIT_EXPECT_TRUE(test, apple_mbox_is_g17(&mbox)); mbox_v8.ascwrap_v6.role = APPLE_MBOX_ASCWRAP_V6_ROLE_GFX; KUNIT_EXPECT_FALSE(test, apple_mbox_is_g17(&mbox_v8)); mbox_v8.ascwrap_v6.role = APPLE_MBOX_ASCWRAP_V6_ROLE_GFX1; KUNIT_EXPECT_FALSE(test, apple_mbox_is_g17(&mbox_v8)); - - /* Empty FIFO finishes directly in hard IRQ without waking the thread. */ - writel(BIT(17), mbox.regs); - KUNIT_EXPECT_EQ(test, apple_mbox_g17_recv_irq(0, &mbox), IRQ_HANDLED); - KUNIT_EXPECT_EQ(test, count, 0U); - - /* Saturated budget wakes the oneshot throttle thread. */ - writel(0, mbox.regs); - KUNIT_EXPECT_EQ(test, apple_mbox_g17_recv_irq(0, &mbox), IRQ_WAKE_THREAD); - KUNIT_EXPECT_EQ(test, count, (unsigned int)APPLE_G17_MBOX_RX_BUDGET); } static struct kunit_case apple_g17_stall_cases[] = { KUNIT_CASE(apple_g17_rx_flood_bounded_test), - KUNIT_CASE(apple_g17_rx_hardirq_dispatch_test), + KUNIT_CASE(apple_g17_v8_excluded_test), KUNIT_CASE(apple_g17_tx_stall_bounded_test), KUNIT_CASE(apple_g17_rx_util_min_test), { } diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index b550a3eca9369..445e970883fd9 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -913,9 +913,9 @@ static int apple_mbox_poll_locked(struct apple_mbox *mbox) } /* - * Threaded receive handler only (woken on G17 budget saturation): apply the - * consumer's minimum utilization to this thread so flood throttling does not - * leave schedutil raising its CPU cluster to the top RT default frequency. + * Threaded receive handler only: apply the consumer's minimum utilization to + * this thread. As an RT thread it otherwise runs with the RT default, which + * makes schedutil raise its CPU cluster to the top frequency on every message. */ static void apple_mbox_apply_rx_util_min(struct apple_mbox *mbox) { @@ -977,6 +977,10 @@ static irqreturn_t apple_mbox_recv_irq(int irq, void *data) unsigned long flags; int consumed = 0; + /* Only the G17 receive handler is threaded (see apple_mbox_probe()). */ + if (apple_mbox_is_g17(mbox)) + apple_mbox_apply_rx_util_min(mbox); + spin_lock_irqsave(&mbox->rx_lock, flags); if (likely(!READ_ONCE(mbox->removing))) consumed = apple_mbox_poll_locked(mbox); @@ -984,38 +988,13 @@ static irqreturn_t apple_mbox_recv_irq(int irq, void *data) apple_mbox_v8_rx_irq_guard(mbox, consumed); spin_unlock_irqrestore(&mbox->rx_lock, flags); - return IRQ_HANDLED; -} - -static irqreturn_t apple_mbox_g17_recv_irq(int irq, void *data) -{ - struct apple_mbox *mbox = data; - unsigned long flags; - int consumed = 0; - - spin_lock_irqsave(&mbox->rx_lock, flags); - if (likely(!READ_ONCE(mbox->removing))) - consumed = apple_mbox_poll_locked(mbox); - spin_unlock_irqrestore(&mbox->rx_lock, flags); - - /* - * Normal completions drain completely in hard IRQ without waking the - * IRQ thread. Only a saturated budget hands off to the oneshot thread - * to sleep with the level line masked so a firmware flood cannot - * monopolize a CPU. + /* G17 uses a oneshot threaded IRQ. Leave it masked during this sleep + * so a firmware flood cannot monopolize a CPU at IRQ-thread priority. + * The level condition retriggers after return; no message is discarded. */ - if (unlikely(consumed == APPLE_G17_MBOX_RX_BUDGET)) - return IRQ_WAKE_THREAD; - - return IRQ_HANDLED; -} - -static irqreturn_t apple_mbox_g17_recv_thread(int irq, void *data) -{ - struct apple_mbox *mbox = data; + if (apple_mbox_is_g17(mbox) && consumed == APPLE_G17_MBOX_RX_BUDGET) + usleep_range(1000, 2000); - apple_mbox_apply_rx_util_min(mbox); - usleep_range(1000, 2000); return IRQ_HANDLED; } @@ -1659,9 +1638,8 @@ static int apple_mbox_probe(struct platform_device *pdev) return -ENOMEM; if (apple_mbox_is_g17(mbox)) - ret = devm_request_threaded_irq(dev, mbox->irq_recv_not_empty, - apple_mbox_g17_recv_irq, - apple_mbox_g17_recv_thread, + ret = devm_request_threaded_irq(dev, mbox->irq_recv_not_empty, NULL, + apple_mbox_recv_irq, IRQF_ONESHOT | IRQF_NO_AUTOEN | IRQF_NO_SUSPEND, irqname, mbox); diff --git a/include/linux/soc/apple/mailbox.h b/include/linux/soc/apple/mailbox.h index 65f04f556c2df..d543769a6d96a 100644 --- a/include/linux/soc/apple/mailbox.h +++ b/include/linux/soc/apple/mailbox.h @@ -127,9 +127,9 @@ void apple_mbox_set_recv_enabled(struct apple_mbox *mbox, bool enabled); void apple_mbox_hold_rx(struct apple_mbox *mbox); void apple_mbox_release_rx(struct apple_mbox *mbox); /* - * Set the minimum utilization (0..1024) the G17 flood-throttle receive thread - * runs with, or -1 to restore the scheduler's default; the thread applies it - * when it next wakes. Only mailboxes with a threaded receive handler support it. + * Set the minimum utilization (0..1024) the threaded receive handler runs with, + * or -1 to restore the scheduler's default; the handler applies it to itself + * when it next runs. Only mailboxes with a threaded receive handler support it. */ int apple_mbox_set_rx_util_min(struct apple_mbox *mbox, int util_min); int apple_mbox_send(struct apple_mbox *mbox, struct apple_mbox_msg msg,