Skip to content

mfd: macsmc: count a port's dark wake on every board with a sleep policy - #2559

Open
axboe wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
axboe:k116s-dark-wake-count
Open

axboe wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
axboe:k116s-dark-wake-count

Conversation

@axboe

@axboe axboe commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

#2231 replaced the mutex that #2445 took at .prepare with apple_smc_prepare_guard(), which waits for a command in flight only when dark_wakes is set. apple_smc_dark_wake() returns for every board but the J714s before it counts a wake that apple_sleep_port_wake() already made dark, so on the other boards with a sleep policy (the J716c) dark_wakes stays 0. A board without a sleep policy (the J813) never gets there and is not changed.

There the guard at .suspend after a port's wake with the lid closed is a single trylock: if a command of the wake is still running, .suspend returns -EBUSY and the dark wake ends in a full one. That is the refusal the third commit of #2445 fixed.

One commit, on integration/aurora f44bf7a: count the wake first, then keep the J714s's own rule to the J714s. Nothing changes on the J714s.

Found by reading the code after the rebase; I have not reproduced the refusal on this base. checkpatch is clean.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The reorder looks right: it does what the second paragraph of 18b4933's message asked for, and outside the J714s dark_wakes is only read as a flag by apple_smc_prepare_guard() and cleared on the next full wake, so the missing cap there has no effect.

Two small things:

  • The commit message names the K116s, but apple_smc_prepare_guard() only runs with saved_enabled (macsmc.c:1520), which is set for the J714s, J716c and J813 (macsmc.c:649-657). On a K116s the re-entry never takes the trylock path, so the boards this changes are the J716c (and the J813, if it gets port dark wakes).
  • The comment above SMC_DARK_REENTRY_MS (macsmc.c:1491-1495) still says the wait is for "the re-entry right after a J714s dark wake"; it now applies to any counted dark wake.

A J716c run with a USB-C plug wake and the lid closed, showing the dark wake's re-entry: the SMC was busy for N ms line instead of the -EBUSY refusal, would confirm it.

Assisted-by: LLM (Claude:Opus 5.5)

@axboe
axboe force-pushed the k116s-dark-wake-count branch from cfeb58f to 4b663ff Compare November 21, 2026 13:41
@axboe

axboe commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Ryan, both taken at 4b663ff; the code is otherwise unchanged.

I have no J716c for the plug-wake run.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR checklist review at 4b663fffcb1d (§1–§6). Commit attribution, clean-room, naming, and CI (host-tests) are clean, and reordering if (pm_dark_wake()) above the J714s wake_reasons check fixes the J716c path. Requesting changes because J813 is still not fixed by this patch (contrary to the title and commit message) and §5 hardware evidence is missing:

Blockers

  1. Real code bug — J813 (and any saved_enabled board without smc->sleep_policy) still leaves dark_wakes == 0 (drivers/mfd/macsmc.c:1079-1091 at PR head; 1118-1131 on integration/aurora):
    Both the PR title ("count a port's dark wake on every board") and commit message state that this fixes the other boards with the saved-context path: "the J716c, and the J813 if a port wakes it dark".
    However, apple_smc_sleep_wake() only calls apple_smc_dark_wake(smc) inside if (smc->sleep_policy):

    if (apple_smc_port_reasons_only(smc, smc->wake_record))
        apple_sleep_port_wake(apple_sleep_lid_closed_at_wake() > 0);
    if (smc->sleep_policy) {
        apple_smc_dark_wake(smc);
        return;
    }

    In drivers/soc/apple/sleep.c:9524, t8142_sleep_soc (J813) has .smc_policy == NULL (J813 uses apple_sleep_smc_defer_notice() / apple_smc_j813_saved_ops with smc->saved_enabled = true at macsmc.c:656-657). Therefore on J813:

    • apple_smc_dark_wake() is never reached at all;
    • smc->dark_wakes stays 0 after apple_sleep_port_wake() (and after apple_sleep_lid_closed_wake() or apple_sleep_debug_link_cut_wake());
    • on re-entry, apple_smc_prepare() -> apple_smc_sleep_prepare() -> apple_smc_prepare_guard() still runs with limit = 0 (single trylock).

    To actually count dark wakes on every board with the saved-context path, also increment smc->dark_wakes when pm_dark_wake() is set on the non-sleep_policy path of apple_smc_sleep_wake() (after apple_sleep_debug_link_cut_wake()), or drop J813 from the title/commit message if scoping this strictly to sleep_policy boards.

  2. Commit message wording on .prepare vs .suspend (drivers/mfd/macsmc.c:1559-1586):
    On J716c (apple_sleep_smc_policy() != NULL), apple_smc_prepare() takes mutex_lock(&smc->mutex) directly; the apple_smc_prepare_guard() trylock-vs-wait path runs at .suspend (apple_smc_suspend() -> apple_smc_sleep_prepare()). On J813 it runs at .prepare.

  3. §5 Evidence missing:
    No hardware run on any affected board (J716c or J813) and no §5 regression run (0 SELinux denials, 0 failed units, 0 new kernel errors). As @RyanTheTide noted, a J716c (and/or J813, once fixed there) closed-lid USB-C plug-wake run showing dark wake's re-entry: the SMC was busy for N ms (or clean re-entry without -EBUSY) plus a regression check is needed before merge.

Checklist summary (§1–§6)

  • §1 No model gating: Incomplete — still gated on smc->sleep_policy, missing J813 (saved_enabled without sleep_policy).
  • §2 Production-ready: Blocked by item 1.
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass — human author/committer and Signed-off-by, zero AI trailers.
  • §5 Evidence: Missing hardware verification and regression run.
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, both points are taken at 4b663ff: the message names the J716c and J813, and the comment at macsmc.c:1492 says "a counted dark wake". The code is the same as before.

I checked the J813 point from the review above and it holds at this head. smc->dark_wakes is only incremented inside apple_smc_dark_wake() (macsmc.c:1027, 1043), and that is only called under if (smc->sleep_policy) (macsmc.c:1083). Only the T6050 sleep SoCs set .smc_policy (sleep-t6050.h:3763, 3892), so on the J813 (saved_enabled from macsmc.c:656) the guard at .prepare still gets limit = 0. Either count pm_dark_wake() on the path without a policy too (after apple_sleep_debug_link_cut_wake(), macsmc.c:1088), or limit the message to the J716c, where the guard runs at .suspend.

Assisted-by: LLM (Claude:Opus 5.5)

apple_smc_prepare_guard() waits for a command in flight only when
dark_wakes is set, and apple_smc_dark_wake() returns for every board but
the J714s before it counts a wake that apple_sleep_port_wake() already
made dark. On the other boards with a sleep policy (the J716c) the guard
at .suspend after a port's wake with the lid closed is then a single
trylock: if a command of the wake is still running, .suspend returns
-EBUSY and the dark wake ends in a full one.

Count the wake first, then keep the J714s's own rule to the J714s. The
comment on the wait no longer names the J714s.

A board without a sleep policy (the J813) does not get here and is not
changed.

Fixes: 18b4933 ("mfd: macsmc: J714s: keep the port and radio dark wakes to the J714s")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
@axboe axboe changed the title mfd: macsmc: count a port's dark wake on every board mfd: macsmc: count a port's dark wake on every board with a sleep policy Nov 22, 2026
@axboe
axboe force-pushed the k116s-dark-wake-count branch from 4b663ff to af97a52 Compare November 22, 2026 15:54
@axboe

axboe commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Ryan, DjDeveloperr, you are both right about the J813: it has no sleep policy, so it never reaches apple_smc_dark_wake() and this commit does nothing there. The message was wrong, not the scope. At af97a52 the code is unchanged and the message and title are limited to boards with a sleep policy (today that adds the J716c), with the J813 named as not changed. It also says .suspend now, which is where the guard runs with a policy.

I did not add counting on the path without a policy. That would change the J813's re-entry, and I have no J813 to run it on.

On the hardware row: I have no J716c either. The closest I have is the K116s with #2201 and this commit, which is not a J714s-table board and so takes the branch this commit moves: a closed-lid charger plug there was a dark wake (woken for a port with the lid closed: dark wake), the re-entry went through without -EBUSY and without the guard having to wait, and the lid woke it later. A J716c closed-lid plug wake needs a J716c owner.

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.

3 participants