mmc: sdio: avoid waking idle host during suspend/resume
Subsystems (4)
cover mmc: sdio: avoid waking idle host during suspend/resume
mmc_sdio_suspend() and mmc_sdio_resume() always claim the host, which runtime-resumes it. If the card keeps power, uses no SDIO IRQs, and nobody holds the host, neither function does bus I/O, so an idle host is woken for nothing.
Skip the host claim in that case, saving cycles and reducing suspend and resume latency.
Patch 1/3 and 2/3 are setup patches for patch 3/3. They remove the hidden dependency that relied on the SDIO core always waking the host during suspend and resume. Patch 3/3 ensures that the host is woken only when it needs to be.
Comparing with and without this patchseries on a Pixel Watch 4:
- mmc1 suspend + resume: 11.59 ms -> 0.01 ms
- sdhci suspend: 3.75 ms -> 0.002 ms
- dpm_suspend median: 38.79 ms -> 32.51 ms
Samuel Wu (3):
mmc: sdhci-s3c: runtime-resume host before system suspend
mmc: dw_mmc: restore IOS on runtime resume whenever card power is on
mmc: sdio: avoid waking idle host on keep-power suspend/resume
drivers/mmc/core/sdio.c | 36 ++++++++++++++++++++++++++++++++---- drivers/mmc/host/dw_mmc.c | 2 +- drivers/mmc/host/sdhci-s3c.c | 2 ++ 3 files changed, 35 insertions(+), 5 deletions(-)
Signature · 1 line
2.56.1.831.g720f3f5937-goog
PATCH 1/3 mmc: sdhci-s3c: runtime-resume host before system suspend
sdhci_s3c_suspend() calls sdhci_suspend_host() directly without ensuring the controller is runtime-resumed. If the host is already runtime-suspended, SDHCI registers are accessed with clocks off.
Call pm_runtime_resume() prior to accessing host registers.
--- drivers/mmc/host/sdhci-s3c.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-s3c.c +2 -0
@@ -685,6 +685,8 @@ static int sdhci_s3c_suspend(struct device *dev) {struct sdhci_host *host =dev_get_drvdata (dev); +pm_runtime_resume (dev); +if (host->tuning_mode !=SDHCI_TUNING_MODE_3 )mmc_retune_needed (host->mmc);
Signature · 1 line
2.56.1.831.g720f3f5937-goog
PATCH 2/3 mmc: dw_mmc: restore IOS on runtime resume whenever card power is on
In reply to Samuel Wudw_mci_runtime_resume() resets the controller, so the I/O settings must be restored. It does this only when MMC_PM_KEEP_POWER is set. That flag is set for a system suspend and is cleared at the end of resume, so a runtime resume at any other time does not restore the I/O settings.
Restore the I/O settings whenever the card is powered, similar to sdhci_runtime_resume_host().
--- drivers/mmc/host/dw_mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/dw_mmc.c +1 -1
@@ -3487,7 +3487,7 @@ int dw_mci_runtime_resume(struct device *dev)mci_writel (host,CTRL ,SDMMC_CTRL_INT_ENABLE ); -if (host->mmc->pm_flags &MMC_PM_KEEP_POWER ) +if (host->mmc->ios.power_mode ==MMC_POWER_ON )dw_mci_set_ios (host->mmc, &host->mmc->ios);/* Force setup bus to guarantee available clock output */
Signature · 1 line
2.56.1.831.g720f3f5937-goog
PATCH 3/3 mmc: sdio: avoid waking idle host on keep-power suspend/resume
In reply to Samuel Wummc_sdio_suspend() and mmc_sdio_resume() always claim the host, which runtime-resumes it. If the card keeps power, uses no SDIO IRQs, and nobody holds the host, neither function does bus I/O, so an idle host is woken for nothing.
Skip the host claim in that case, saving cycles and reducing suspend and resume latency.
Comparing with and without this patch on a Pixel Watch 4:
- mmc1 suspend + resume: 11.59 ms -> 0.01 ms
- sdhci suspend: 3.75 ms -> 0.002 ms
- dpm_suspend median: 38.79 ms -> 32.51 ms
--- drivers/mmc/core/sdio.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/mmc/core/sdio.c +32 -4
@@ -7,6 +7,7 @@#include <linux/err.h> #include <linux/pm_runtime.h> +#include <linux/spinlock.h> #include <linux/sysfs.h> #include <linux/mmc/host.h>
@@ -1048,18 +1049,41 @@ static int mmc_sdio_pre_suspend(struct mmc_host *host)return 0 ; } +/* +* The host must be claimed for SDIO suspend/resume unless the card keeps +* power, uses no SDIO IRQs and nobody holds the host. In that case no bus +* I/O is needed, so skip the claim to avoid waking a runtime-suspended host. +* +* If somebody holds the host, claim it to wait for them, as before. A claim +* taken after this check is not waited for, same as a claim taken after +* mmc_release_host() before. +*/ +static bool mmc_sdio_need_claim_host (struct mmc_host *host) +{ +if (!mmc_card_keep_power (host) ||mmc_card_wake_sdio_irq (host) || + host->sdio_irqs) +return true; + +guard (spinlock_irqsave)(&host->lock); +return host->claimed; +} +/* * SDIO suspend. Suspend all functions separately. */ static int mmc_sdio_suspend (struct mmc_host *host) { +bool need_claim; +WARN_ON (host->sdio_irqs && !mmc_card_keep_power (host));/* Prevent processing of SDIO IRQs in suspended state. */ mmc_card_set_suspended (host->card);cancel_work_sync (&host->sdio_irq_work); -mmc_claim_host (host); + need_claim =mmc_sdio_need_claim_host (host); +if (need_claim) +mmc_claim_host (host);if (mmc_card_keep_power (host) &&mmc_card_wake_sdio_irq (host))sdio_disable_4bit_bus (host->card);
@@ -1071,17 +1095,20 @@ static int mmc_sdio_suspend(struct mmc_host *host)mmc_retune_needed (host); } -mmc_release_host (host); +if (need_claim) +mmc_release_host (host);return 0 ; }static int mmc_sdio_resume (struct mmc_host *host) { +bool need_claim =mmc_sdio_need_claim_host (host);int err =0 ;/* Basic card reinitialization. */ -mmc_claim_host (host); +if (need_claim) +mmc_claim_host (host);/* * Restore power and reinitialize the card when needed. Note that a
@@ -1127,7 +1154,8 @@ static int mmc_sdio_resume(struct mmc_host *host) } out: -mmc_release_host (host); +if (need_claim) +mmc_release_host (host); host->pm_flags &= ~MMC_PM_KEEP_POWER ;return err;
Signature · 1 line
2.56.1.831.g720f3f5937-goog