[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <8f20dfea761960fd9bbcb6a0ce3ae0178e039b31.1473130123.git.baolin.wang@linaro.org>
Date: Tue, 6 Sep 2016 10:55:12 +0800
From: Baolin Wang <baolin.wang@...aro.org>
To: ulf.hansson@...aro.org
Cc: adrian.hunter@...el.com, rmk+kernel@....linux.org.uk,
shawn.lin@...k-chips.com, dianders@...omium.org, heiko@...ech.de,
david@...tonic.nl, hdegoede@...hat.com, linux-mmc@...r.kernel.org,
linux-kernel@...r.kernel.org, broonie@...nel.org,
linus.walleij@...aro.org, baolin.wang@...aro.org
Subject: [PATCH v4 3/3] mmc: core: Optimize the mmc erase size alignment
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@...aro.org>
Tested-by: Shawn Lin <shawn.lin@...k-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
Powered by blists - more mailing lists