linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: core: don't return 1 for max_discard
@ 2013-12-18 22:27 Stephen Warren
       [not found] ` <1387405663-14253-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  2013-12-19  8:39 ` Dong Aisheng
  0 siblings, 2 replies; 18+ messages in thread
From: Stephen Warren @ 2013-12-18 22:27 UTC (permalink / raw)
  To: Chris Ball
  Cc: linux-mmc, linux-tegra, Stephen Warren, Adrian Hunter,
	Dong Aisheng, Ulf Hansson, Vladimir Zapolskiy

From: Stephen Warren <swarren@nvidia.com>

In mmc_do_calc_max_discard(), if only a single erase block can be
discarded within the host controller's timeout, don't allow discard
operations at all.

Previously, the code allowed sector-at-a-time discard (rather than
erase-block-at-a-time), which was chronically slow.

Without this patch, on the NVIDIA Tegra Cardhu board, the loops result
in qty == 1, which is immediately returned. This causes discard to
operate a single sector at a time, which is chronically slow. With this
patch in place, discard operates a single erase block at a time, which
is reasonably fast.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Dong Aisheng <dongas86@gmail.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Fixes: e056a1b5b67b "(mmc: queue: let host controllers specify maximum discard timeout")
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/mmc/core/core.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 57a2b403bf8e..eb952ca634ea 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2150,8 +2150,25 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
 	if (!qty)
 		return 0;
 
-	if (qty == 1)
-		return 1;
+	/*
+	 * Discard operations may not be aligned to an erase block. In an
+	 * unaligned case, we need to issue 1 more discard operation to HW
+	 * than strictly calculated by:
+	 *     sectors_to_erase / sectors_per_discard_operation
+	 *
+	 * To account for this in the timeout calculations, we assume we can
+	 * actually discard one less erase block than fits into the HW
+	 * timeout. This explains the --qty below.
+	 *
+	 * When only a single discard block operation fits into the timeout,
+	 * disallow any discard operations at all. For example, discarding one
+	 * sector at a time is so chronically slow as to be useless. However,
+	 * make an exception for SD cards without an erase shift, since qty
+	 * isn't multiplied up by an erase block size in the code below for
+	 * that case.
+	 */
+	if (qty == 1 && !(!card->erase_shift && mmc_card_sd(card)))
+		return 0;
 
 	/* Convert qty to sectors */
 	if (card->erase_shift)
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-12-20  7:17 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-18 22:27 [PATCH] mmc: core: don't return 1 for max_discard Stephen Warren
     [not found] ` <1387405663-14253-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-18 23:00   ` Stephen Warren
2013-12-19  8:22     ` Vladimir Zapolskiy
     [not found]     ` <52B22906.4010704-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-19  9:01       ` Adrian Hunter
2013-12-19  9:14         ` Vladimir Zapolskiy
     [not found]           ` <52B2B8F7.1000905-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2013-12-19  9:42             ` Adrian Hunter
     [not found]               ` <52B2BF95.302-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-12-19 10:26                 ` Ulf Hansson
2013-12-19 11:18                   ` Dong Aisheng
2013-12-19 13:04                     ` Ulf Hansson
     [not found]                   ` <CAPDyKFoiGzspgrtRwXruPqOODxbfKA4AAZHj_VF8H7rpwm7eTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-19 12:28                     ` Adrian Hunter
2013-12-19 13:29                       ` Ulf Hansson
     [not found]                         ` <CAPDyKFp1B6r+WyAO9PocL13LvzjsZDJ3HOUbXwJ+uTQ2Ayv-ug-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-19 13:49                           ` Adrian Hunter
2013-12-19 19:11         ` Stephen Warren
     [not found]           ` <52B344E0.5080009-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-12-20  7:17             ` Adrian Hunter
2013-12-19  9:05       ` Dong Aisheng
2013-12-19 19:15         ` Stephen Warren
2013-12-19  8:39 ` Dong Aisheng
     [not found]   ` <CAA+hA=StHAna46_356Gfpaa+4Y3yt6KO15W6E7dS8uoz8TPqxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-12-19 19:08     ` Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).