Repository navigation
soc: apple: clpc: test the frequency step, ceiling order, vote hold and floor word - #2821
RyanTheTide wants to merge 2 commits into
Conversation
…nd floor word The low-power ceiling and the rail floors are built from four small helpers that had no test: apple_clpc_step_khz() (the next cpufreq table entry up or down, and the low-power top round-up), apple_clpc_steps_first() (which cluster's ceiling moves next), apple_clpc_vote() (the demand hold) and apple_clpc_floor() (the PMC floor word). Add a KUnit suite, apple-clpc-policy, next to apple-clpc-gpu: - step_khz on an unordered table with an invalid entry: one step either way, off-table values, both ends, and the first entry at or above low_power_khz (exact and in between, and none above the table). - steps_first: down takes the higher ceiling (the faster cluster on a tie), up the lower (the slower), and identical clusters keep the pick. - vote: a demand replaces the state at once, down as well as up; with no demand it holds for APPLE_CLPC_HOLD_MS and then drops, across the jiffies wrap. - floor: each rail's state in the nibble its table rail number names, masked so a wide state cannot spill into another rail. No functional change. A mutant that flips the steps_first tie-break, uses time_after() for the hold, drops the nibble mask and lets a down step return @khz itself fails all four new tests. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Review at 309a55f. All four tests call the real static helpers in
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial §1–§6 review at 309a55f9c7d147d26852732ffb43b5273c341d9c: REQUEST_CHANGES (not ready for MERGETRAIN-LINUX4).
Diff & Scope Verification
- Zero functional kernel change: Adds 137 lines strictly inside the existing
#if IS_ENABLED(CONFIG_KUNIT)block ofdrivers/soc/apple/clpc.c, calling the real static production helpers (apple_clpc_step_khz(),apple_clpc_steps_first(),apple_clpc_vote(),apple_clpc_floor()). - CI: All 7 checks green (
host-tests,SEP source checks), though note that none of the CI jobs build or executeapple-clpc-policy(the SEPkunitjob only runs SEP KUnit suites).
Blocking Findings
- Broken jiffies-wrap coverage in
apple_clpc_vote_test()(drivers/soc/apple/clpc.c:2165-2177):- With
APPLE_CLPC_HOLD_MS = 32,hold = msecs_to_jiffies(32)is even (4,8, or32at HZ 100/250/1000), andt0 = ULONG_MAX - hold / 2. - Every hold/drop sample checked after
t0(t0 + hold - 1,t0 + hold,t0 + 2 * hold) has already wrapped past0along withvote->last_demand + hold(e.g., forhold = 8:last_demand + hold == 3, and the samples are2,3,11). - As a result, a completely wrap-unsafe implementation (
now >= vote->last_demand + hold) passes 100% of the assertions inapple_clpc_vote_test()(the PR's negative control only mutatedtime_after_eq()totime_after(), which tests the off-by-one boundary rather than wrap safety). - Fix: Sample at least one hold check before the wrap while
last_demand + holdhas already wrapped (e.g., sett0 = ULONG_MAX - (hold - 1)sot0 + hold - 1 == ULONG_MAXwhilelast_demand + hold == 0, or also assert att0 + hold / 2 == ULONG_MAX), and add a wrap-unsafenow >= last_demand + holdmutant to the negative control.
- With
- In-tree KUnit link dependency (
drivers/soc/apple/clpc.kunitconfig+ #2693):
Should-Fix / Minor Findings
- Misplaced invalid-entry comment (
clpc.c:2119-2120):CPUFREQ_ENTRY_INVALID(~0u) is greater than1200000, so stepping down from1200000can never select it even ifcpufreq_for_each_valid_entrywere broken. The cases that actually catchCPUFREQ_ENTRY_INVALIDare the upward steps at2000000and2100000(clpc.c:2125, 2127). Please move/update the comment accordingly. - Overstated
apple_clpc_profile_limit()comment & weak<check (clpc.c:2131-2139):apple_clpc_profile_limit()'s fallback (if (cl->top_khz < low_power_khz) cl->top_khz = max_freqatclpc.c:887-890) is not exercised here, onlyapple_clpc_step_khz(..., low_power_khz - 1, true). Also, line 2139 usesKUNIT_EXPECT_LT(..., 2100000u)whereKUNIT_EXPECT_EQ(..., 2100000u - 1)is strictly tighter (a buggy return of600000or0would passLT).
§1–§6 Checklist
- §1 No model gating: Pass (synthetic test frequencies only; zero driver changes).
- §2 Production-ready / no hacks: Needs fix on the jiffies-wrap test and #2693 ordering so the suite actually tests what it claims and links from the tree.
- §3 Safety: Pass (test-only).
- §4 Clean-room & attribution: Pass (human author/committer + human
Signed-off-by:only, zero AI trailers in commit; PR body disclosesAssisted-by:). - §5 Evidence: Local KUnit run reported (15/15), but negative control missed wrap-unsafe comparison and CI does not execute
apple-clpc-policy. - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
t0 = ULONG_MAX - hold / 2 puts every held sample past the wrap together with last_demand + hold, so a plain 'now >= last_demand + hold' passes the test. Start at ULONG_MAX - (hold - 1) instead: the last held sample is ULONG_MAX while the deadline has wrapped to 0. Also move the invalid-entry comment to the up steps that can pick it, say the max_freq fallback of apple_clpc_profile_limit() is not covered, and expect the exact value above the table instead of a bound. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Ran apple-clpc-policy at 309a55f merged onto integration/aurora 120d6aa (clean merge), kunit.py arm64/qemu, LLVM=1, HZ=250.
fb37343 (pushed on top, test only) starts the vote test at t0 = ULONG_MAX - (hold - 1), so the last held sample is ULONG_MAX while the deadline has wrapped to 0, and asserts that. It also moves the invalid-entry comment to the up steps, says the profile_limit() max_freq fallback is not covered, and uses EXPECT_EQ above the table. Results with it: real code 4/4 (all suites 17 pass, 1 skip); the wrap-unsafe mutant now fails at t0 + hold - 1; the time_after() and invalid-entry mutants still fail. checkpatch clean. This still needs #2693 first (or MFD_MACSMC in the kunitconfig) before the suite runs from the tree as is. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial §1–§6 re-review at fb37343c17f8466efbd278dd256d25b6015b3fa6 (following Wave 36B REQUEST_CHANGES on 309a55f9c7d1): REQUEST_CHANGES (code is clean, but still blocked on #2693 before MERGETRAIN-LINUX4).
Verification of Prior Findings
- Prior Blocker 1 (
apple_clpc_vote_test()wraparound coverage) — RESOLVED:drivers/soc/apple/clpc.c:2177-2189now starts att0 = ULONG_MAX - (hold - 1)and assertshold > 1andt0 + hold - 1 == ULONG_MAX.- With
vote.last_demand = t0, the hold deadlinet0 + holdwraps to0while the final held samplet0 + hold - 1is stillULONG_MAX: realtime_after_eq(ULONG_MAX, 0)evaluates false (holds5), whereas a wrap-unsafenow >= last_demand + holdevaluatesULONG_MAX >= 0(drops early to0) and is reliably killed. Thet0 + hold == 0check continues to killtime_after().
- Prior Minor Items 3 & 4 — RESOLVED:
- The
CPUFREQ_ENTRY_INVALIDcomment was moved to the upward-step cases that actually exercise it (clpc.c:2125-2131). - The
apple_clpc_profile_limit()comment accurately states itsmax_freqfallback is not covered (clpc.c:2134-2137), and line2143is tightened toKUNIT_EXPECT_EQ(..., 2100000u - 1).
- The
- Prior Blocker 2 (standalone in-tree
clpc.kunitconfiglink dependency on#2693) — STILL OPEN:aurora-silicon/linux#2693(soc: apple: clpc: link without the SMC driver) is still open (merged=False), and stockdrivers/soc/apple/clpc.kunitconfigstill fails to link (undefined apple_smc_read/apple_smc_write) from the tree without it (as also confirmed in your latest run comment).- All 7 CI checks are green at
fb37343c, though none of the CI jobs build/runclpc.kunitconfig.
Readiness & §1–§6 Checklist
- Code quality: Ready — zero driver changes, test logic and negative controls are sound at
fb37343c. - Merge /
MERGETRAIN-LINUX4gate: Hold until#2693lands (ordrivers/soc/apple/clpc.kunitconfigbuilds and links standalone) soapple-clpc-policyis runnable directly fromintegration/aurora. - §1 No model gating: Pass (synthetic test frequencies only).
- §2 Production-ready / no hacks: Test code passes; blocked only on
#2693ordering for in-treeclpc.kunitconfigbuildability. - §3 Safety: Pass (test-only).
- §4 Clean-room & attribution: Pass (both commits
309a55f9c7d1andfb37343c17f8have human author/committer + humanSigned-off-by:only, zero AI commit trailers; PR body disclosesAssisted-by:). - §5 Evidence: Local KUnit run (4/4
apple-clpc-policy, 17 pass / 1 skip overall) + wrap-unsafe /time_after()/ invalid-entry mutation checks verified; CI 7/7 green. - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
Problem. The CLPC low-power ceiling and the rail floors are built from four small helpers:
apple_clpc_step_khz(),apple_clpc_steps_first(),apple_clpc_vote()andapple_clpc_floor(). None of them had a test. The existingapple-clpc-gpusuite covers the GPU/ANE demand inputs only.Change. A new KUnit suite,
apple-clpc-policy, sits in the existing KUnit block ofclpc.c:step_khz, on an unordered table with an invalid entry: one step either way, off-table values, both ends, and the low-power top round-up (low_power_khz - 1, up), for an exact entry, a value in between, and nothing above the table.steps_first: going down, the higher ceiling steps first (the faster cluster on a tie); going up, the lower one (the slower cluster). Identical clusters keep the pick.vote: a new demand replaces the state at once, down as well as up. With no demand the state holds forAPPLE_CLPC_HOLD_MSand then drops, including across the jiffies wrap.floor: each rail's state goes in the nibble its table rail number names, masked so it can't spill into another rail.Tests only, no functional change.
Testing.
kunit.py run --arch=arm64(qemu, LLVM=1, KASAN + UBSAN fromclpc.kunitconfig), filterapple-clpc*: 15/15 (11 existing + 4 new).steps_firsttie-break, usestime_after()for the hold, drops the nibble mask and lets a down step return@khzmakes all four new tests fail (plus the existingane_demand_holdtest).tools/asahi/clpc-gpu-demand-tests.pyandclpc-high-power-cleanup-tests.pystill pass. They extract code fromclpc.c.Still to run. Nothing on hardware: the change is test-only.
Note on the kunitconfig
The stock
drivers/soc/apple/clpc.kunitconfigcurrently fails to link becauseapple_smc_read/apple_smc_writeare undefined without the SMC driver. #2693 fixes that separately. These runs addedCONFIG_MFD_MACSMC=yplusARCH_APPLE,MAILBOX,APPLE_MAILBOXandAPPLE_RTKITto it.Assisted-by: LLM (Claude:Opus 5.5)