mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: ulf.hansson@linaro.org
Cc: adrian.hunter@intel.com, rmk+kernel@arm.linux.org.uk,
	shawn.lin@rock-chips.com, dianders@chromium.org, heiko@sntech.de,
	david@protonic.nl, hdegoede@redhat.com,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	broonie@kernel.org, linus.walleij@linaro.org,
	baolin.wang@linaro.org
Subject: [PATCH v4 3/3] mmc: core: Optimize the mmc erase size alignment
Date: Tue,  6 Sep 2016 10:55:12 +0800	[thread overview]
Message-ID: <8f20dfea761960fd9bbcb6a0ce3ae0178e039b31.1473130123.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org>
In-Reply-To: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org>

In most cases the 'card->erase_size' is power of 2, then the round_up/down()
function is more efficient than '%' operation when the 'card->erase_size' is
power of 2.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
---
 drivers/mmc/core/core.c |   34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5f93eef..e014949 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2209,19 +2209,37 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
 {
 	unsigned int from_new = *from, nr_new = nr, rem;
 
-	rem = from_new % card->erase_size;
-	if (rem) {
-		rem = card->erase_size - rem;
-		from_new += rem;
+	/*
+	 * When the 'card->erase_size' is power of 2, we can use round_up/down()
+	 * to align the erase size efficiently.
+	 */
+	if (is_power_of_2(card->erase_size)) {
+		unsigned int temp = from_new;
+
+		from_new = round_up(temp, card->erase_size);
+		rem = from_new - temp;
+
 		if (nr_new > rem)
 			nr_new -= rem;
 		else
 			return 0;
-	}
 
-	rem = nr_new % card->erase_size;
-	if (rem)
-		nr_new -= rem;
+		nr_new = round_down(nr_new, card->erase_size);
+	} else {
+		rem = from_new % card->erase_size;
+		if (rem) {
+			rem = card->erase_size - rem;
+			from_new += rem;
+			if (nr_new > rem)
+				nr_new -= rem;
+			else
+				return 0;
+		}
+
+		rem = nr_new % card->erase_size;
+		if (rem)
+			nr_new -= rem;
+	}
 
 	if (nr_new == 0)
 		return 0;
-- 
1.7.9.5

  parent reply	other threads:[~2016-09-06  2:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06  2:55 [PATCH v4 1/3] mmc: core: Remove some redundant validations in mmc_erase() function Baolin Wang
2016-09-06  2:55 ` [PATCH v4 2/3] mmc: core: Factor out the alignment of erase size Baolin Wang
2016-09-06  4:34   ` Andreas Mohr
2016-09-06  6:26     ` Baolin Wang
2016-09-06  7:19       ` Andreas Mohr
2016-09-06  8:25         ` Baolin Wang
2016-09-06  7:52       ` Adrian Hunter
2016-09-06  8:27         ` Baolin Wang
2016-09-06  2:55 ` Baolin Wang [this message]
2016-09-06 12:17 ` [PATCH v4 1/3] mmc: core: Remove some redundant validations in mmc_erase() function Ulf Hansson
2016-09-06 12:35   ` Baolin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f20dfea761960fd9bbcb6a0ce3ae0178e039b31.1473130123.git.baolin.wang@linaro.org \
    --to=baolin.wang@linaro.org \
    --cc=adrian.hunter@intel.com \
    --cc=broonie@kernel.org \
    --cc=david@protonic.nl \
    --cc=dianders@chromium.org \
    --cc=hdegoede@redhat.com \
    --cc=heiko@sntech.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=shawn.lin@rock-chips.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®