Skip to contentSkip to conversation

mmc: core: Extend runtime PM support for sd/mmc

PATCH New Ulf Hansson 1 participant 5 messages Oct 11, 2013 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

cover mmc: core: Extend runtime PM support for sd/mmc

This patchset is step by step improving support for runtime PM in the mmc core layer for sd and mmc. The sequence for how to handle suspend/resume while using MMC_CAP_AGGRESSIVE_PM is now optimized to only perform actions when needed and thus improving especially the suspend time.

The two first patches has been sent earlier to the mmc-list, but for convenience I have decided to fold them in here instead. The old versions of these can be dropped.

The final patch is adding a new host cap, MMC_CAP_RUNTIME_RESUME, which means the resume is moved to be finalized at the runtime_resume. Using this feature will have great impact on the total resume time for the platform.

Patches has been tested on ux500, using a various of combination of MMC_CAP_RUNTIME_RESUME, MMC_CAP_AGGRESSIVE_PM and MMC_CAP_NONREMOVABLE. The needed CONFIG_MMC_UNSAFE_RESUME has also been set.

Ulf Hansson (4):
mmc: Don't force card to active state when entering suspend/shutdown
mmc: core: Remove redundant mmc_power_up|off at runtime callbacks
mmc: core: Improve runtime PM support during suspend/resume for
sd/mmc
mmc: core: Add MMC_CAP_RUNTIME_RESUME to resume at runtime_resume

 drivers/mmc/card/block.c |    2 -
 drivers/mmc/core/mmc.c   |   94 ++++++++++++++++++++++++++++++++--------------
 drivers/mmc/core/sd.c    |   79 ++++++++++++++++++++++++++------------
 include/linux/mmc/card.h |    4 ++
 include/linux/mmc/host.h |    1 +
 5 files changed, 125 insertions(+), 55 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 mmc: Don't force card to active state when entering suspend/shutdown

By adding a card state that records if it is suspended or resumed, we can accept asyncronus suspend/resume requests for the mmc and sd bus_ops.

MMC_CAP_AGGRESSIVE_PM, will at request inactivity through the runtime bus_ops callbacks, execute a suspend of the the card. In the state were this has been done, we can receive a suspend request for the mmc bus, which for sd and mmc forced the card to active state by a pm_runtime_get_sync. In other words, the card was resumed and then immediately suspended again, completely unnecessary.

Since the suspend/resume bus_ops callbacks for sd and mmc are now capable of handling asynchronous requests, we no longer need to force the card to active state before executing suspend. Evidently preventing the above sequence for MMC_CAP_AGGRESSIVE_PM.

---
 drivers/mmc/card/block.c |    2 --
 drivers/mmc/core/mmc.c   |   45 ++++++++++++++++++++++++++++++++++-----------
 drivers/mmc/core/sd.c    |   21 +++++++++++++++++----
 include/linux/mmc/card.h |    4 ++++
 4 files changed, 55 insertions(+), 17 deletions(-)
drivers/mmc/card/block.c +0 -2
index 1a3163f..29d5d98 100644
@@ -2448,7 +2448,6 @@ static int _mmc_blk_suspend(struct mmc_card *card)
 	struct mmc_blk_data *md = mmc_get_drvdata(card);
 
 	if (md) {
-		pm_runtime_get_sync(&card->dev);
 		mmc_queue_suspend(&md->queue);
 		list_for_each_entry(part_md, &md->part, part) {
 			mmc_queue_suspend(&part_md->queue);
@@ -2483,7 +2482,6 @@ static int mmc_blk_resume(struct mmc_card *card)
 		list_for_each_entry(part_md, &md->part, part) {
 			mmc_queue_resume(&part_md->queue);
 		}
-		pm_runtime_put(&card->dev);
 	}
 	return 0;
 }
drivers/mmc/core/mmc.c +34 -11

82 lines not on this page · raw message

drivers/mmc/core/sd.c +17 -4
index 5e8823d..ef302f3 100644
@@ -1075,13 +1075,20 @@ static int mmc_sd_suspend(struct mmc_host *host)
 	BUG_ON(!host->card);
 
 	mmc_claim_host(host);
+
+	if (mmc_card_suspended(host->card))
+		goto out;
+
 	if (!mmc_host_is_spi(host))
 		err = mmc_deselect_cards(host);
 	host->card->state &= ~MMC_STATE_HIGHSPEED;
-	if (!err)
+	if (!err) {
 		mmc_power_off(host);
-	mmc_release_host(host);
+		mmc_card_set_suspended(host->card);
+	}
 
+out:
+	mmc_release_host(host);
 	return err;
 }
 
@@ -1093,17 +1100,23 @@ static int mmc_sd_suspend(struct mmc_host *host)
  */
 static int mmc_sd_resume(struct mmc_host *host)
 {
-	int err;
+	int err = 0;
 
 	BUG_ON(!host);
 	BUG_ON(!host->card);
 
 	mmc_claim_host(host);
+
+	if (!mmc_card_suspended(host->card))
+		goto out;
+
 	mmc_power_up(host);
 	mmc_select_voltage(host, host->ocr);
 	err = mmc_sd_init_card(host, host->ocr, host->card);
-	mmc_release_host(host);
+	mmc_card_clr_suspended(host->card);
 
+out:
+	mmc_release_host(host);
 	return err;
 }
 
include/linux/mmc/card.h +4 -0
index f42cdbd..111a199 100644
@@ -257,6 +257,7 @@ struct mmc_card {
 #define MMC_CARD_REMOVED	(1<<7)		/* card has been removed */
 #define MMC_STATE_HIGHSPEED_200	(1<<8)		/* card is in HS200 mode */
 #define MMC_STATE_DOING_BKOPS	(1<<10)		/* card is doing BKOPS */
+#define MMC_STATE_SUSPENDED	(1<<11)		/* card is suspended */
 	unsigned int		quirks; 	/* card quirks */
 #define MMC_QUIRK_LENIENT_FN0	(1<<0)		/* allow SDIO FN0 writes outside of the VS CCCR range */
 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)	/* use func->cur_blksize */
@@ -423,6 +424,7 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
 #define mmc_card_removed(c)	((c) && ((c)->state & MMC_CARD_REMOVED))
 #define mmc_card_doing_bkops(c)	((c)->state & MMC_STATE_DOING_BKOPS)
+#define mmc_card_suspended(c)	((c)->state & MMC_STATE_SUSPENDED)
 
 #define mmc_card_set_present(c)	((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
@@ -435,6 +437,8 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
 #define mmc_card_set_doing_bkops(c)	((c)->state |= MMC_STATE_DOING_BKOPS)
 #define mmc_card_clr_doing_bkops(c)	((c)->state &= ~MMC_STATE_DOING_BKOPS)
+#define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
+#define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
 
 /*
  * Quirk add/remove for MMC products.
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/4 mmc: core: Remove redundant mmc_power_up|off at runtime callbacks

In reply to Ulf Hansson

Commit "mmc: core: Push common suspend|resume code into each bus_ops" moved the responsibility for doing mmc_power_up|off into each suspend/resume bus_ops. When using MMC_CAP_AGGRESSIVE_PM, through the runtime callbacks, calls to mmc_power_up|off became redundant.

When removing them, we are also able to remove the calls to mmc_claim|release_host, thus simplifing code a bit more.

---
 drivers/mmc/core/mmc.c |   13 +------------
 drivers/mmc/core/sd.c  |   13 +------------
 2 files changed, 2 insertions(+), 24 deletions(-)
drivers/mmc/core/mmc.c +1 -12
index f7722d2..907f0a0 100644
@@ -1575,18 +1575,11 @@ static int mmc_runtime_suspend(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	mmc_claim_host(host);
-
 	err = mmc_suspend(host);
-	if (err) {
+	if (err)
 		pr_err("%s: error %d doing aggessive suspend\n",
 			mmc_hostname(host), err);
-		goto out;
-	}
-	mmc_power_off(host);
 
-out:
-	mmc_release_host(host);
 	return err;
 }
 
@@ -1600,15 +1593,11 @@ static int mmc_runtime_resume(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	mmc_claim_host(host);
-
-	mmc_power_up(host);
 	err = mmc_resume(host);
 	if (err)
 		pr_err("%s: error %d doing aggessive resume\n",
 			mmc_hostname(host), err);
 
-	mmc_release_host(host);
 	return 0;
 }
 
drivers/mmc/core/sd.c +1 -12
index ef302f3..2287ceb 100644
@@ -1130,18 +1130,11 @@ static int mmc_sd_runtime_suspend(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	mmc_claim_host(host);
-
 	err = mmc_sd_suspend(host);
-	if (err) {
+	if (err)
 		pr_err("%s: error %d doing aggessive suspend\n",
 			mmc_hostname(host), err);
-		goto out;
-	}
-	mmc_power_off(host);
 
-out:
-	mmc_release_host(host);
 	return err;
 }
 
@@ -1155,15 +1148,11 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	mmc_claim_host(host);
-
-	mmc_power_up(host);
 	err = mmc_sd_resume(host);
 	if (err)
 		pr_err("%s: error %d doing aggessive resume\n",
 			mmc_hostname(host), err);
 
-	mmc_release_host(host);
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/4 mmc: core: Improve runtime PM support during suspend/resume for sd/mmc

In reply to Ulf Hansson

The card device is considered as in-active after it has been suspended. To prevent any further runtime PM requests in suspend state, we then disable runtime PM.

After the card device has been resumed, we shall consider it as active, like we also do after a probe sequence. When resumed, we can safely enable runtime PM again.

This will make sure the PM core can request the card device to go to in-active state after a resume has been completed. Previously we had to wait for new pm_runtime_get->pm_runtime_put cycle to be executed.

Additionally, once a resume has been carried out, update the last busy mark. At the moment this will have no effect but if the PM core will respect autosuspend enabled devices, when it directly triggers a runtime_suspend from a runtime_idle, it will mean the card device will be scheduled for a delayed runtime_suspend instead of done immediately.

---
 drivers/mmc/core/mmc.c |   38 ++++++++++++++++++++++++++++++--------
 drivers/mmc/core/sd.c  |   45 ++++++++++++++++++++++++++++++++++++---------
 2 files changed, 66 insertions(+), 17 deletions(-)
drivers/mmc/core/mmc.c +30 -8
index 907f0a0..1e29dbc 100644
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/stat.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -1509,20 +1510,26 @@ out:
 }
 
 /*
- * Suspend callback from host.
+ * Suspend callback
  */
 static int mmc_suspend(struct mmc_host *host)
 {
-	return _mmc_suspend(host, true);
+	int err;
+
+	err = _mmc_suspend(host, true);
+	if (!err) {
+		pm_runtime_disable(&host->card->dev);
+		pm_runtime_set_suspended(&host->card->dev);
+	}
+
+	return err;
 }
 
 /*
- * Resume callback from host.
- *
  * This function tries to determine if the same card is still present
  * and, if so, restore all state to it.
  */
-static int mmc_resume(struct mmc_host *host)
+static int _mmc_resume(struct mmc_host *host)
 {
 	int err = 0;
 
@@ -1557,7 +1564,7 @@ static int mmc_shutdown(struct mmc_host *host)
 	 */
 	if (mmc_can_poweroff_notify(host->card) &&
 		!(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE))
-		err = mmc_resume(host);
+		err = _mmc_resume(host);
 
 	if (!err)
 		err = _mmc_suspend(host, false);
@@ -1566,6 +1573,21 @@ static int mmc_shutdown(struct mmc_host *host)
 }
 
 /*
+ * Callback for resume.
+ */
+static int mmc_resume(struct mmc_host *host)
+{
+	int err;
+
+	err = _mmc_resume(host);
+	pm_runtime_set_active(&host->card->dev);
+	pm_runtime_mark_last_busy(&host->card->dev);
+	pm_runtime_enable(&host->card->dev);
+
+	return err;
+}
+
+/*
  * Callback for runtime_suspend.
  */
 static int mmc_runtime_suspend(struct mmc_host *host)
@@ -1575,7 +1597,7 @@ static int mmc_runtime_suspend(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	err = mmc_suspend(host);
+	err = _mmc_suspend(host, true);
 	if (err)
 		pr_err("%s: error %d doing aggessive suspend\n",
 			mmc_hostname(host), err);
@@ -1593,7 +1615,7 @@ static int mmc_runtime_resume(struct mmc_host *host)
 	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
 		return 0;
 
-	err = mmc_resume(host);
+	err = _mmc_resume(host);
 	if (err)
 		pr_err("%s: error %d doing aggessive resume\n",
 			mmc_hostname(host), err);
drivers/mmc/core/sd.c +36 -9

84 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/4 mmc: core: Add MMC_CAP_RUNTIME_RESUME to resume at runtime_resume

In reply to Ulf Hansson

In some environments it is to prefer to postpone the resume of the card device until runtime_resume is being carried out, since it will mean a signficant decrease of the total system resume time.

The reason of the decreased resume time is simply because of the actual re-initalization of the card, which typically takes hundreds of milliseconds, is performed outside the resume sequence and wont thus affect it.

For removable card, the detect work tries to re-detect the card to make sure it is still present, as a part of that sequence the card will also be runtime_resumed and thus also fully resumed.

For a non-removable card, typically a mmc blk request will trigger a runtime_resume and thus fully resume the card. This also means the first request will likely suffer from an inital latency since the re-initialization of the card needs to be performed.

---
 drivers/mmc/core/mmc.c   |   12 +++++++-----
 drivers/mmc/core/sd.c    |   12 +++++++-----
 include/linux/mmc/host.h |    1 +
 3 files changed, 15 insertions(+), 10 deletions(-)
drivers/mmc/core/mmc.c +7 -5
index 1e29dbc..9825119 100644
@@ -1577,11 +1577,13 @@ static int mmc_shutdown(struct mmc_host *host)
  */
 static int mmc_resume(struct mmc_host *host)
 {
-	int err;
+	int err = 0;
 
-	err = _mmc_resume(host);
-	pm_runtime_set_active(&host->card->dev);
-	pm_runtime_mark_last_busy(&host->card->dev);
+	if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
+		err = _mmc_resume(host);
+		pm_runtime_set_active(&host->card->dev);
+		pm_runtime_mark_last_busy(&host->card->dev);
+	}
 	pm_runtime_enable(&host->card->dev);
 
 	return err;
@@ -1612,7 +1614,7 @@ static int mmc_runtime_resume(struct mmc_host *host)
 {
 	int err;
 
-	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
+	if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
 		return 0;
 
 	err = _mmc_resume(host);
drivers/mmc/core/sd.c +7 -5
index 57940a8..5052d06 100644
@@ -1137,11 +1137,13 @@ out:
  */
 static int mmc_sd_resume(struct mmc_host *host)
 {
-	int err;
+	int err = 0;
 
-	err = _mmc_sd_resume(host);
-	pm_runtime_set_active(&host->card->dev);
-	pm_runtime_mark_last_busy(&host->card->dev);
+	if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
+		err = _mmc_sd_resume(host);
+		pm_runtime_set_active(&host->card->dev);
+		pm_runtime_mark_last_busy(&host->card->dev);
+	}
 	pm_runtime_enable(&host->card->dev);
 
 	return err;
@@ -1172,7 +1174,7 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
 {
 	int err;
 
-	if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
+	if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
 		return 0;
 
 	err = _mmc_sd_resume(host);
include/linux/mmc/host.h +1 -0
index 3b0c33a..a9f7c96 100644
@@ -254,6 +254,7 @@ struct mmc_host {
 #define MMC_CAP_UHS_SDR50	(1 << 17)	/* Host supports UHS SDR50 mode */
 #define MMC_CAP_UHS_SDR104	(1 << 18)	/* Host supports UHS SDR104 mode */
 #define MMC_CAP_UHS_DDR50	(1 << 19)	/* Host supports UHS DDR50 mode */
+#define MMC_CAP_RUNTIME_RESUME	(1 << 20)	/* Resume at runtime_resume. */
 #define MMC_CAP_DRIVER_TYPE_A	(1 << 23)	/* Host supports Driver Type A */
 #define MMC_CAP_DRIVER_TYPE_C	(1 << 24)	/* Host supports Driver Type C */
 #define MMC_CAP_DRIVER_TYPE_D	(1 << 25)	/* Host supports Driver Type D */
Signature · 1 line
1.7.9.5