Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1477939 > unrolled thread
| Started by | Baolin Wang <baolin.wang@linaro.org> |
|---|---|
| First post | 2016-09-07 04:40 +0200 |
| Last post | 2016-09-09 11:50 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Baolin Wang <baolin.wang@linaro.org> - 2016-09-07 04:40 +0200
Re: [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Ulf Hansson <ulf.hansson@linaro.org> - 2016-09-09 11:50 +0200
| From | Baolin Wang <baolin.wang@linaro.org> |
|---|---|
| Date | 2016-09-07 04:40 +0200 |
| Subject | [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment |
| Message-ID | <seAWm-2bR-5@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | Ulf Hansson <ulf.hansson@linaro.org> |
|---|---|
| Date | 2016-09-09 11:50 +0200 |
| Message-ID | <sfqBA-18C-21@gated-at.bofh.it> |
| In reply to | #1477939 |
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
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web