summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorBaolin Wang <baolin.wang@linaro.org>2016-09-07 10:38:25 +0800
committerUlf Hansson <ulf.hansson@linaro.org>2016-09-26 21:31:26 +0200
commit6c689886fbe41b6492bd8ee9334ff66893274810 (patch)
treeaf389ed1f152b5fcb09f3f54ca74743de3aa8c9f /drivers
parent71085123d27dc5d28ce523344f32ac0d20c5f0a5 (diff)
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@linaro.org> Tested-by: Shawn Lin <shawn.lin@rock-chips.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mmc/core/core.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 9ce6c25a8f54..d083d2e57abd 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2212,19 +2212,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;