From e53036fbe08f3eb1b0b2e1e0751653ab17d0cf4f Mon Sep 17 00:00:00 2001 From: Kevin loo Date: Wed, 2 Dec 2026 10:58:27 -0800 Subject: [PATCH] soc: apple: clpc: hold ANE memory and fabric floor on T8152 Apple T8152 (M6) defines DCS states 0-7 and SoC fabric states 0-4 in apple_clpc_hw_t8152 and already accepts G18 GPU demand at the top of that map (DCS 7, fabric 4), but omits "apple,t8152-clpc" from apple_clpc_ane_providers[] and leaves apple_clpc_hw_t8152.ane unset. When CPUs are idle or lightly loaded during ANE execution, both rails drop to low states. Add "apple,t8152-clpc" to apple_clpc_ane_providers[] and set apple_clpc_hw_t8152.ane to { [APPLE_CLPC_DCS] = 7, [APPLE_CLPC_SOC] = 4 }, matching the top states the T8152 table already uses for CPU and G18 GPU demand (with no CPU cluster frequency floor). On J873g (M6 Mac mini) with CPUs pinned at minimum frequency, raising the T8152 PMC agent-1 floor from (0, 0) to (7, 3) cut H18G 256x256 FP16 matvec median kernel execution time 2.2x (643.0 to 290.1 us on ane0; 285.7 us on ane1), bit-exact. Extend the apple-clpc-gpu KUnit suite and clpc-gpu-demand host test to verify T8152 ANE demand (0x47), sub-sample pending capture, vote hold, and idle release. Signed-off-by: Kevin loo --- drivers/soc/apple/clpc.c | 26 ++++++++++++++++++++++++++ tools/asahi/clpc-gpu-demand-tests.py | 24 ++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index f8d5fbbabf8a9..061d23a5d62da 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -573,6 +573,7 @@ static const struct of_device_id apple_clpc_ane_providers[] = { { .compatible = "apple,t6041-clpc" }, { .compatible = "apple,t8140-clpc" }, { .compatible = "apple,t8142-clpc" }, + { .compatible = "apple,t8152-clpc" }, {} }; @@ -2889,6 +2890,7 @@ static void apple_clpc_t6041_policy_test(struct kunit *test) apple_clpc_gpu_put(gpu); } +static const struct apple_clpc_hw apple_clpc_hw_t8152; static const struct apple_clpc_hw apple_clpc_hw_t6050; static void apple_clpc_ane_demand_hold_test(struct kunit *test) @@ -2959,6 +2961,20 @@ static void apple_clpc_ane_demand_hold_test(struct kunit *test) apple_clpc_ane_set_active(&ane, false); memset(demand, 0, sizeof(demand)); KUNIT_EXPECT_FALSE(test, apple_clpc_ane_input_demand(clpc, demand)); + /* T8152 holds DCS 7 and fabric 4 while ANE work is in flight. */ + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8152.ane[APPLE_CLPC_DCS], 7); + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8152.ane[APPLE_CLPC_SOC], 4); + clpc->hw = &apple_clpc_hw_t8152; + clpc->ane_states[APPLE_CLPC_DCS] = clpc->hw->ane[APPLE_CLPC_DCS]; + clpc->ane_states[APPLE_CLPC_SOC] = clpc->hw->ane[APPLE_CLPC_SOC]; + memset(demand, 0, sizeof(demand)); + apple_clpc_ane_set_active(&ane, true); + KUNIT_EXPECT_TRUE(test, apple_clpc_ane_input_demand(clpc, demand)); + KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_DCS], 7u); + KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_SOC], 4u); + apple_clpc_ane_set_active(&ane, false); + memset(demand, 0, sizeof(demand)); + KUNIT_EXPECT_FALSE(test, apple_clpc_ane_input_demand(clpc, demand)); } static void apple_clpc_ane_cluster_test(struct kunit *test) @@ -2981,6 +2997,7 @@ static void apple_clpc_ane_cluster_test(struct kunit *test) KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8142.ane_cluster, 1u); KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8142.ane_cluster_khz, 4176000u); KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8140.ane_cluster_khz, 0u); + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8152.ane_cluster_khz, 0u); } static void apple_clpc_ane_states_test(struct kunit *test) @@ -3640,6 +3657,15 @@ static const struct apple_clpc_hw apple_clpc_hw_t8152 = { [APPLE_CLPC_SOC] = { 1, 2, 3, 4 }, }, .gpu_input = true, + /* + * ANE demand (J873g, H18G; other T8152 boards sharing the compatible + * are untested): DCS 7 and fabric 4, the top states this table already + * uses for CPU and G18 GPU demand. On J873g with CPUs pinned at + * minimum frequency, raising the PMC floor from (0, 0) to (7, 3) cut + * 256x256 FP16 matvec median kernel time 2.2x (643.0 to 290.1 us on + * ane0, 285.7 us on ane1). + */ + .ane = { [APPLE_CLPC_DCS] = 7, [APPLE_CLPC_SOC] = 4 }, }; /* diff --git a/tools/asahi/clpc-gpu-demand-tests.py b/tools/asahi/clpc-gpu-demand-tests.py index ddd233902d569..80cfa665caadd 100644 --- a/tools/asahi/clpc-gpu-demand-tests.py +++ b/tools/asahi/clpc-gpu-demand-tests.py @@ -299,8 +299,9 @@ def main(): 'struct apple_clpc_hw {', 'struct apple_clpc_vote {']) tables = '\n'.join(item(source, 'static const struct apple_clpc_hw ' + n + ' =') + ';' for n in ['apple_clpc_hw_t8132', 'apple_clpc_hw_t8140', - 'apple_clpc_hw_t8142', 'apple_clpc_hw_t6040', - 'apple_clpc_hw_t6041', 'apple_clpc_hw_t6050']) + 'apple_clpc_hw_t8142', 'apple_clpc_hw_t8152', + 'apple_clpc_hw_t6040', 'apple_clpc_hw_t6041', + 'apple_clpc_hw_t6050']) # When t6041.dtsi supplies the GPU busy-share properties, parse and test them directly; # otherwise exercise the DT parsers and ladder against the reference values. @@ -700,6 +701,24 @@ def main(): jiffies=3040; apple_clpc_sample(&c); assert(published==0 && c.last_reason==0 && queued_idle); } +// T8152 ANE work holds DCS 7 and fabric 4 while it runs, sees a sub-sample +// request once, and releases after HOLD_MS. +static void check_t8152_ane(void) { + struct apple_clpc_ane ane={0}; + struct apple_clpc c={.hw=&apple_clpc_hw_t8152,.has_pmc=true,.agent=1,.mask=3,.ane=&ane}; + c.ane_states[APPLE_CLPC_DCS]=c.hw->ane[APPLE_CLPC_DCS]; + c.ane_states[APPLE_CLPC_SOC]=c.hw->ane[APPLE_CLPC_SOC]; + assert(c.hw->ane[APPLE_CLPC_DCS]==7 && c.hw->ane[APPLE_CLPC_SOC]==4 && !c.hw->ane_cluster_khz); + read_error=vote_error=0; pmgr_status=0; pmp_floor=0; jiffies=4000; published=~0u; + apple_clpc_sample(&c); assert(published==0 && c.last_reason==0); + ane.active=true; jiffies=4004; apple_clpc_sample(&c); + assert(published==0x47 && c.last_reason==32); + ane.active=false; ane.pending=true; jiffies=4008; apple_clpc_sample(&c); + assert(published==0x47 && c.last_reason==32 && !ane.pending); + jiffies=4039; apple_clpc_sample(&c); assert(published==0x47 && c.last_reason==16); + jiffies=4040; apple_clpc_sample(&c); assert(published==0 && c.last_reason==0 && queued_idle); +} + // T6040 ANE work also holds the second P cluster at its qualified frequency, // added on first use, for the vote hold after the last request, then drops it. static void check_t6040_ane(void) { @@ -1081,6 +1100,7 @@ def main(): check_t8140_dense(); check_t8140_ane(); check_t6050_ane(); + check_t8152_ane(); check_low_power(); check_t6040_ane(); puts("PASS: T6040, T6041 and T8132 host demand; DT GPU busy share and down-step hold; T8140/T604x ANE, streaming, dense work, read errors and PMP backoff; idle release");