* [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size
@ 2016-09-07 2:38 Baolin Wang
2016-09-07 2:38 ` [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Baolin Wang
2016-09-09 9:46 ` [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Ulf Hansson
0 siblings, 2 replies; 4+ messages in thread
From: Baolin Wang @ 2016-09-07 2:38 UTC (permalink / raw)
To: ulf.hansson
Cc: adrian.hunter, rmk+kernel, shawn.lin, dianders, heiko, david,
hdegoede, linux-mmc, linux-kernel, broonie, linus.walleij,
baolin.wang
In order to clean up the mmc_erase() function and do some optimization
for erase size alignment, factor out the guts of erase size alignment
into mmc_align_erase_size() function.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
---
Changes since v4:
- Abandon the patch removing the checking if mmc can erase.
- Add missing validations in mmc_erase().
Changes since v3:
- Split into 3 separate patches.
- Add test tag by Shawn.
Changes since v2:
- Add nr checking and other optimization in mmc_erase() function.
Changes since v1:
- Add the alignment if card->erase_size is not power of 2.
---
drivers/mmc/core/core.c | 48 +++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index e55cde6..11b4897 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2202,6 +2202,36 @@ out:
return err;
}
+static unsigned int mmc_align_erase_size(struct mmc_card *card,
+ unsigned int *from,
+ unsigned int *to,
+ unsigned int nr)
+{
+ 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;
+ 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;
+
+ *to = from_new + nr_new;
+ *from = from_new;
+
+ return nr_new;
+}
+
/**
* mmc_erase - erase sectors.
* @card: card to erase
@@ -2240,26 +2270,12 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
return -EINVAL;
}
- if (arg == MMC_ERASE_ARG) {
- rem = from % card->erase_size;
- if (rem) {
- rem = card->erase_size - rem;
- from += rem;
- if (nr > rem)
- nr -= rem;
- else
- return 0;
- }
- rem = nr % card->erase_size;
- if (rem)
- nr -= rem;
- }
+ if (arg == MMC_ERASE_ARG)
+ nr = mmc_align_erase_size(card, &from, &to, nr);
if (nr == 0)
return 0;
- to = from + nr;
-
if (to <= from)
return -EINVAL;
--
1.7.9.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment
2016-09-07 2:38 [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Baolin Wang
@ 2016-09-07 2:38 ` Baolin Wang
2016-09-09 9:46 ` Ulf Hansson
2016-09-09 9:46 ` [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Ulf Hansson
1 sibling, 1 reply; 4+ messages in thread
From: Baolin Wang @ 2016-09-07 2:38 UTC (permalink / raw)
To: ulf.hansson
Cc: adrian.hunter, rmk+kernel, shawn.lin, dianders, heiko, david,
hdegoede, linux-mmc, linux-kernel, broonie, linus.walleij,
baolin.wang
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 11b4897..4264ac6 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size
2016-09-07 2:38 [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Baolin Wang
2016-09-07 2:38 ` [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Baolin Wang
@ 2016-09-09 9:46 ` Ulf Hansson
1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2016-09-09 9:46 UTC (permalink / raw)
To: Baolin Wang
Cc: Adrian Hunter, Russell King, Shawn Lin, Doug Anderson,
Heiko Stübner, David Jander, Hans de Goede, linux-mmc,
linux-kernel, Mark Brown, Linus Walleij
On 7 September 2016 at 04:38, Baolin Wang <baolin.wang@linaro.org> wrote:
> In order to clean up the mmc_erase() function and do some optimization
> for erase size alignment, factor out the guts of erase size alignment
> into mmc_align_erase_size() function.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
Thanks, applied for next!
Kind regards
Uffe
> ---
> Changes since v4:
> - Abandon the patch removing the checking if mmc can erase.
> - Add missing validations in mmc_erase().
>
> Changes since v3:
> - Split into 3 separate patches.
> - Add test tag by Shawn.
>
> Changes since v2:
> - Add nr checking and other optimization in mmc_erase() function.
>
> Changes since v1:
> - Add the alignment if card->erase_size is not power of 2.
> ---
> drivers/mmc/core/core.c | 48 +++++++++++++++++++++++++++++++----------------
> 1 file changed, 32 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index e55cde6..11b4897 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2202,6 +2202,36 @@ out:
> return err;
> }
>
> +static unsigned int mmc_align_erase_size(struct mmc_card *card,
> + unsigned int *from,
> + unsigned int *to,
> + unsigned int nr)
> +{
> + 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;
> + 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;
> +
> + *to = from_new + nr_new;
> + *from = from_new;
> +
> + return nr_new;
> +}
> +
> /**
> * mmc_erase - erase sectors.
> * @card: card to erase
> @@ -2240,26 +2270,12 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
> return -EINVAL;
> }
>
> - if (arg == MMC_ERASE_ARG) {
> - rem = from % card->erase_size;
> - if (rem) {
> - rem = card->erase_size - rem;
> - from += rem;
> - if (nr > rem)
> - nr -= rem;
> - else
> - return 0;
> - }
> - rem = nr % card->erase_size;
> - if (rem)
> - nr -= rem;
> - }
> + if (arg == MMC_ERASE_ARG)
> + nr = mmc_align_erase_size(card, &from, &to, nr);
>
> if (nr == 0)
> return 0;
>
> - to = from + nr;
> -
> if (to <= from)
> return -EINVAL;
>
> --
> 1.7.9.5
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment
2016-09-07 2:38 ` [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Baolin Wang
@ 2016-09-09 9:46 ` Ulf Hansson
0 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2016-09-09 9:46 UTC (permalink / raw)
To: Baolin Wang
Cc: Adrian Hunter, Russell King, Shawn Lin, Doug Anderson,
Heiko Stübner, David Jander, Hans de Goede, linux-mmc,
linux-kernel, Mark Brown, Linus Walleij
On 7 September 2016 at 04:38, Baolin Wang <baolin.wang@linaro.org> wrote:
> 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>
Thanks, applied for next!
Kind regards
Uffe
> ---
> 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 11b4897..4264ac6 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-09 9:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-07 2:38 [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Baolin Wang
2016-09-07 2:38 ` [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Baolin Wang
2016-09-09 9:46 ` Ulf Hansson
2016-09-09 9:46 ` [PATCH v5 1/2] mmc: core: Factor out the alignment of erase size Ulf Hansson
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®