Commit 6c689886 authored by Baolin Wang's avatar Baolin Wang Committed by Ulf Hansson

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: default avatarBaolin Wang <baolin.wang@linaro.org>
Tested-by: default avatarShawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 71085123
...@@ -2212,19 +2212,37 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card, ...@@ -2212,19 +2212,37 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
{ {
unsigned int from_new = *from, nr_new = nr, rem; unsigned int from_new = *from, nr_new = nr, rem;
rem = from_new % card->erase_size; /*
if (rem) { * When the 'card->erase_size' is power of 2, we can use round_up/down()
rem = card->erase_size - rem; * to align the erase size efficiently.
from_new += rem; */
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) if (nr_new > rem)
nr_new -= rem; nr_new -= rem;
else else
return 0; return 0;
}
rem = nr_new % card->erase_size; nr_new = round_down(nr_new, card->erase_size);
if (rem) } else {
nr_new -= rem; 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) if (nr_new == 0)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment