Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions arch/arm64/boot/dts/apple/t6050-die0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@
/*
* T6050 GPU busy-share memory-state ladder (common across
* M5 Pro/Max/Ultra die 0): DCS 1, 2, 4, 6 and fabric
* 0, 0, 0, 2 at 160, 500 and 800 permille. The top
* column matches apple_clpc_hw_t6050's DCS 6 / fabric 2
* GPU floor; lower columns keep light compositing below
* the CPU floor while long/saturated bursts lift to the
* top column. Validated on J716c (16-inch M5 Max).
* 0, 0, 0, 3 at 160, 500 and 800 permille. The top
* column uses T6050's top DCS 6 / fabric 3 states;
* lower columns keep light compositing below the CPU
* floor while long/saturated bursts lift to the top
* column. Validated on J716c (16-inch M5 Max).
*/
apple,gpu-busy-memory-states = <1 2 4 6>, <0 0 0 2>;
apple,gpu-busy-memory-states = <1 2 4 6>, <0 0 0 3>;
apple,gpu-busy-permille = <160 500 800>;
};
};
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/boot/dts/apple/t6050-j775c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,10 +1053,10 @@
apple,cpu-busy-floor = <6 3>;
/*
* GPU busy-share memory-state ladder split at 160, 500, and
* 800 permille; top column matches apple_clpc_hw_t6050's
* DCS 6 / fabric 2 floor.
* 800 permille; top column uses T6050's top DCS 6 / fabric 3
* states.
*/
apple,gpu-busy-memory-states = <1 2 4 6>, <0 0 0 2>;
apple,gpu-busy-memory-states = <1 2 4 6>, <0 0 0 3>;
apple,gpu-busy-permille = <160 500 800>;
};
};
Expand Down
81 changes: 75 additions & 6 deletions drivers/soc/apple/clpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ enum apple_clpc_rail {
* percent of its maximum frequency
* @gpu_demand: streaming GPU work requests @gpu
* @gpu: state of each rail for streaming GPU work
* @gpu_max: optional per-rail ceiling for DT GPU busy-share ladders when
* higher than @map top and @gpu; 0 uses @map/@gpu
* @gpu_sustain_ms: time graphics stays powered without a break before it
* counts as streaming, see apple_clpc_gpu_streaming(); 0 counts it at once
* @pmp_backoff: release that GPU floor while the PMP, voter agent
Expand Down Expand Up @@ -141,6 +143,7 @@ struct apple_clpc_hw {
u8 map[APPLE_CLPC_RAILS][APPLE_CLPC_LEVELS];
bool gpu_demand;
u8 gpu[APPLE_CLPC_RAILS];
u8 gpu_max[APPLE_CLPC_RAILS];
unsigned int gpu_sustain_ms;
bool pmp_backoff;
unsigned int pmp_agent;
Expand Down Expand Up @@ -1885,8 +1888,9 @@ static int apple_clpc_dt_map(struct apple_clpc_hw *hw, const u32 *cells, int n)
if (n != APPLE_CLPC_RAILS * APPLE_CLPC_LEVELS)
return -EINVAL;
for (rail = 0; rail < APPLE_CLPC_RAILS; rail++) {
u32 top = max(hw->map[rail][APPLE_CLPC_LEVELS - 1],
hw->gpu[rail]);
u32 top = max(max(hw->map[rail][APPLE_CLPC_LEVELS - 1],
hw->gpu[rail]),
hw->gpu_max[rail]);

for (level = 0; level < APPLE_CLPC_LEVELS; level++) {
u32 state = cells[rail * APPLE_CLPC_LEVELS + level];
Expand Down Expand Up @@ -3409,13 +3413,75 @@ static void apple_clpc_gpu_busy_clear_test(struct kunit *test)
kref_put(&gpu->ref, apple_clpc_gpu_free);
}

static void apple_clpc_t6050_gpu_fabric_test(struct kunit *test)
{
static const u32 ladder[APPLE_CLPC_RAILS * APPLE_CLPC_LEVELS] = {
1, 2, 4, 6,
0, 0, 0, 3,
};
static const u32 too_high[APPLE_CLPC_RAILS * APPLE_CLPC_LEVELS] = {
1, 2, 4, 6,
0, 0, 0, 4,
};
static const u32 permille[3] = { 160, 500, 800 };
struct apple_clpc_hw hw = {};
struct apple_clpc_gpu *gpu = kzalloc_obj(*gpu);
unsigned int demand[APPLE_CLPC_RAILS] = {};
struct device dev = {};

KUNIT_ASSERT_NOT_NULL(test, gpu);
kref_init(&gpu->ref);
spin_lock_init(&gpu->lock);

KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6050.gpu[APPLE_CLPC_DCS], 6u);
KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6050.gpu[APPLE_CLPC_SOC], 2u);
KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6050.gpu_max[APPLE_CLPC_DCS], 6u);
KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6050.gpu_max[APPLE_CLPC_SOC], 3u);
KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6050.ane[APPLE_CLPC_SOC], 2u);

/* Without a DT ladder, the fallback GPU floor stays at DCS 6 / fabric 2. */
apple_clpc_gpu_set_active(gpu, true);
apple_clpc_gpu_set_busy(gpu, 850);
KUNIT_EXPECT_TRUE(test, apple_clpc_gpu_input_demand(&apple_clpc_hw_t6050,
gpu, demand));
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_DCS], 6u);
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_SOC], 2u);

KUNIT_EXPECT_TRUE(test, apple_clpc_dt_apply(&dev, &apple_clpc_hw_t6050,
&hw, ladder,
ARRAY_SIZE(ladder),
permille,
ARRAY_SIZE(permille)));
/* Saturated GPU work (>= 800 permille) lifts fabric to 3; lighter work stays at 0. */
memset(demand, 0, sizeof(demand));
apple_clpc_gpu_set_busy(gpu, 600);
KUNIT_EXPECT_TRUE(test, apple_clpc_gpu_input_demand(&hw, gpu, demand));
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_DCS], 4u);
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_SOC], 0u);

memset(demand, 0, sizeof(demand));
apple_clpc_gpu_set_busy(gpu, 850);
KUNIT_EXPECT_TRUE(test, apple_clpc_gpu_input_demand(&hw, gpu, demand));
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_DCS], 6u);
KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_SOC], 3u);

/* Fabric state 4 does not exist on T6050 and stays rejected. */
KUNIT_EXPECT_FALSE(test, apple_clpc_dt_apply(&dev, &apple_clpc_hw_t6050,
&hw, too_high,
ARRAY_SIZE(too_high),
permille,
ARRAY_SIZE(permille)));
kref_put(&gpu->ref, apple_clpc_gpu_free);
}

static struct kunit_case apple_clpc_policy_cases[] = {
KUNIT_CASE(apple_clpc_step_khz_test),
KUNIT_CASE(apple_clpc_steps_first_test),
KUNIT_CASE(apple_clpc_vote_test),
KUNIT_CASE(apple_clpc_floor_test),
KUNIT_CASE(apple_clpc_profile_step_busy_test),
KUNIT_CASE(apple_clpc_gpu_busy_clear_test),
KUNIT_CASE(apple_clpc_t6050_gpu_fabric_test),
{}
};
static struct kunit_suite apple_clpc_policy_suite = {
Expand Down Expand Up @@ -3450,10 +3516,12 @@ static const struct apple_clpc_hw apple_clpc_hw_t8152 = {
* needed, as on T6040. macOS's CLPC votes from memory stalls instead, which
* this driver doesn't see (J714sAP, 26A428: no vote for one CPU-bound thread,
* DCS 6 and fabric 2 for memcpy); DCS 5 and fabric 2 keep pointer chasing at
* 110 ns against 300 ns at state 0. The GPU driver reports its work in
* flight and gets DCS 6 and fabric 2 while it has some, the floor macOS's
* PMP holds for GPU compute: bandwidth-bound GPU work runs about 11% slower
* at DCS 5, and none runs faster at fabric 3 (the PMP asks for it for fill).
* 110 ns against 300 ns at state 0. Without a DT GPU busy-share ladder, the
* fallback GPU floor holds DCS 6 and fabric 2 (matching macOS's PMP floor for
* compute: bandwidth-bound GPU work runs about 11% slower at DCS 5). With the
* DT ladder, saturated GPU work (>= 800 permille) lifts fabric to 3 (the top
* T6050 fabric state, validated against @gpu_max) while lighter work stays at
* fabric 0.
*
* Sampling stays on time with no vote held. From a deferrable timer, a CPU
* that went busy after an idle spell waited for the timer's own CPU to wake,
Expand All @@ -3475,6 +3543,7 @@ static const struct apple_clpc_hw apple_clpc_hw_t6050 = {
[APPLE_CLPC_SOC] = { 1, 2, 2, 2 },
},
.gpu = { [APPLE_CLPC_DCS] = 6, [APPLE_CLPC_SOC] = 2 },
.gpu_max = { [APPLE_CLPC_DCS] = 6, [APPLE_CLPC_SOC] = 3 },
/*
* ANE demand, measured on J775c (M5 Max, H17): DCS 6 and fabric 2, the
* top states this table already uses. unet-320 (8 tasks, 200 runs)
Expand Down
29 changes: 17 additions & 12 deletions tools/asahi/clpc-gpu-demand-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ def main():
t8132_states, t8132_busy = parse_t8132_gpu_busy(t8132_dts)
test_dt_negative_controls(t8132_dts, 't8132', parse_t8132_gpu_busy)

# Parse T6050's shared CLPC node directly; both DT properties are required.
# Parse T6050's shared CLPC node and J775c's standalone CLPC node directly.
t6050_dts = (ROOT / 'arch/arm64/boot/dts/apple/t6050-die0.dtsi').read_text()
t6050_states, t6050_busy = parse_t6050_gpu_busy(t6050_dts)
test_dt_negative_controls(t6050_dts, 't6050', parse_t6050_gpu_busy)
j775c_dts = (ROOT / 'arch/arm64/boot/dts/apple/t6050-j775c.dts').read_text()
j775c_states, j775c_busy = parse_t6050_gpu_busy(j775c_dts)
assert j775c_states == t6050_states and j775c_busy == t6050_busy, \
f't6050-j775c.dts ladder ({j775c_states}, {j775c_busy}) diverged from t6050-die0.dtsi'

# Parse T8142's shared M5 Air CLPC node directly; both DT properties are required.
t8142_dts = (ROOT / 'arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi').read_text()
Expand Down Expand Up @@ -480,9 +484,9 @@ def main():
u32 t6041_over_dcs[8] = {1, 2, 4, 7, 0, 0, 0, 3};
u32 t6041_over_dcs6[8] = {1, 2, 4, 6, 0, 0, 0, 3};
u32 t6041_over_soc[8] = {1, 2, 4, 5, 0, 0, 0, 4};
u32 t6050_ok[8] = {1, 2, 4, 6, 0, 0, 0, 2};
u32 t6050_over_dcs[8] = {1, 2, 4, 7, 0, 0, 0, 2};
u32 t6050_over_soc[8] = {1, 2, 4, 6, 0, 0, 0, 3};
u32 t6050_ok[8] = {1, 2, 4, 6, 0, 0, 0, 3};
u32 t6050_over_dcs[8] = {1, 2, 4, 7, 0, 0, 0, 3};
u32 t6050_over_soc[8] = {1, 2, 4, 6, 0, 0, 0, 4};
u32 busy[3] = {500, 160, 800};

dt_warned = 0;
Expand All @@ -502,10 +506,11 @@ def main():
assert(apple_clpc_dt_map(&bad, t6041_over_dcs, 8) == -EINVAL); // DCS 7 > T6041 max 5
assert(apple_clpc_dt_map(&bad, t6041_over_dcs6, 8) == -EINVAL); // DCS 6 > T6041 max 5
assert(apple_clpc_dt_map(&bad, t6041_over_soc, 8) == -EINVAL); // fabric 4 > T6041 max 3
// T6050 rail max uses max(map[rail][top], gpu[rail]): DCS 6 from gpu[DCS], fabric 2.
// T6050 rail max uses max(map[rail][top], gpu[rail], gpu_max[rail]): DCS 6 and fabric 3 from gpu_max[].
assert(apple_clpc_dt_apply(NULL, &apple_clpc_hw_t6050, &out,
t6050_ok, 8, t6041_gpu_busy, 3));
assert(dt_warned == 0 && out.gpu_busy[APPLE_CLPC_DCS][3] == 6);
assert(dt_warned == 0 && out.gpu_busy[APPLE_CLPC_DCS][3] == 6 &&
out.gpu_busy[APPLE_CLPC_SOC][3] == 3);
assert(!apple_clpc_dt_apply(NULL, &apple_clpc_hw_t6050, &out,
t6050_over_dcs, 8, t6041_gpu_busy, 3));
assert(dt_warned == 1 && !memcmp(&out, &apple_clpc_hw_t6050, sizeof(out)));
Expand Down Expand Up @@ -586,7 +591,7 @@ def main():

static struct apple_clpc_hw t6050_dt_hw;
static void t6050_from_dt(void) {
static const u8 cpu[2][4] = {{2, 4, 5, 5}, {1, 2, 2, 2}}, gpu[2][4] = {{1, 2, 4, 6}, {0, 0, 0, 2}};
static const u8 cpu[2][4] = {{2, 4, 5, 5}, {1, 2, 2, 2}}, gpu[2][4] = {{1, 2, 4, 6}, {0, 0, 0, 3}};
int prev = dt_warned;

dt_warned = 0;
Expand All @@ -606,20 +611,20 @@ def main():
assert(c.hw->gpu_busy_mid == 160 && c.hw->gpu_busy_high == 500 && c.hw->gpu_busy_top == 800);
read_error = vote_error = 0; pmgr_status = 0xf0; pmp_floor = 0; published = ~0u;
gpu.active = true; jiffies = 6000; apple_clpc_sample(&c);
assert(published == 0x26 && c.last_reason == 2 && gpu.level == 3);
assert(published == 0x36 && c.last_reason == 2 && gpu.level == 3);
gpu.active = false; jiffies = 6100; apple_clpc_sample(&c); assert(published == 0);
gpu.active = true; gpu.busy_valid = true; gpu.busy = 159; jiffies = 6500;
apple_clpc_sample(&c); assert(published == 0x01 && gpu.level == 0);
gpu.busy = 160; jiffies = 6504; apple_clpc_sample(&c); assert(published == 0x02 && gpu.level == 1);
gpu.busy = 499; jiffies = 6508; apple_clpc_sample(&c); assert(published == 0x02 && gpu.level == 1);
gpu.busy = 500; jiffies = 6512; apple_clpc_sample(&c); assert(published == 0x04 && gpu.level == 2);
gpu.busy = 799; jiffies = 6516; apple_clpc_sample(&c); assert(published == 0x04 && gpu.level == 2);
gpu.busy = 800; jiffies = 6520; apple_clpc_sample(&c); assert(published == 0x26 && gpu.level == 3);
gpu.busy = 800; jiffies = 6520; apple_clpc_sample(&c); assert(published == 0x36 && gpu.level == 3);
gpu.busy = 100;
for (jiffies = 6524; jiffies < 6920; jiffies += 4) {
apple_clpc_sample(&c); assert(published == 0x26 && gpu.level == 3);
apple_clpc_sample(&c); assert(published == 0x36 && gpu.level == 3);
}
jiffies = 6920; apple_clpc_sample(&c); assert(published == 0x21 && gpu.level == 0);
jiffies = 6920; apple_clpc_sample(&c); assert(published == 0x31 && gpu.level == 0);
jiffies = 6952; apple_clpc_sample(&c); assert(published == 0x01 && c.last_reason == 2);
gpu.active = false; jiffies = 7000; apple_clpc_sample(&c); assert(published == 0 && queued_idle);
}
Expand Down Expand Up @@ -1115,7 +1120,7 @@ def main():
('retain-at-idle', code.replace('vote->state = 0;', '')),
('dt-state-unchecked', code.replace('if (state > top || state > 15)', 'if ((void)top, false)')),
('dt-rail-bound-unchecked', code.replace('if (state > top || state > 15)', 'if ((void)top, state > 15)')),
('dt-gpu-rail-max-ignored', code.replace('max(hw->map[rail][APPLE_CLPC_LEVELS - 1],\n\t\t\t hw->gpu[rail])',
('dt-gpu-rail-max-ignored', code.replace('max(max(hw->map[rail][APPLE_CLPC_LEVELS - 1],\n\t\t\t\t hw->gpu[rail]),\n\t\t\t hw->gpu_max[rail])',
'hw->map[rail][APPLE_CLPC_LEVELS - 1]')),
('dt-fallback-keeps-partial', code.replace('\t\t*out = *soc;\n\t\treturn false;', '\t\treturn false;')),
('dt-fallback-silent', code.replace('dev_warn(dev,\n\t\t\t "ignoring invalid GPU busy-share states in the device tree (%d)\\n",\n\t\t\t err);',
Expand Down
Loading