From patchwork Wed Sep 7 02:38:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 9318137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7D8360752 for ; Wed, 7 Sep 2016 02:39:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA55628F89 for ; Wed, 7 Sep 2016 02:39:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EFC128F8D; Wed, 7 Sep 2016 02:39:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2778928F89 for ; Wed, 7 Sep 2016 02:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934248AbcIGCjU (ORCPT ); Tue, 6 Sep 2016 22:39:20 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:33057 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932768AbcIGCjT (ORCPT ); Tue, 6 Sep 2016 22:39:19 -0400 Received: by mail-pf0-f179.google.com with SMTP id g202so1145808pfb.0 for ; Tue, 06 Sep 2016 19:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+YM5zwd8o6RT52LaPsTYXZa5R1xEx3TxemBKIXtJz5I=; b=MYW5VVzzSla19BHDC4OzwDHX7ND6JuXO52hdQiIzPWrFDap2OpIEmfnnEYdMQK98gz NqYTgFH2UrksNaRf4eyQoO1NPyOcrXUd/GfMiaZJEHudBABz8Z/FHj648FZpja01kkBl 0Xgx/Y07+WOBik0VdxIhk7YQiiBs7KV1dLQew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=+YM5zwd8o6RT52LaPsTYXZa5R1xEx3TxemBKIXtJz5I=; b=R2CKVsPkqWjeAhGGmYgNu2mZBaA6NKDRLcHyMyLmNyXlRu9skERJI63D3OwefIpAPg OK22QxjvRrjOcvRbpskHHMbkApRMxxOjQXw3HgY+J5IsK+sMzDeq4wefjZxbpZK12Fp4 q2cBxkYIPkvYrOZN+s/L3/DGskXRIrH7Fo+pe1jxxLk47jDiumjwyMrGjio4AofESpUD NEBARDXSQI6yV7O5j4M/vZ/7DRb8gzh9NaNuolibTiNDRUBG9ZoDX4zXoM3lhZzqL+6I DDPgWbVXTJSrPpf4XiJW0OFQwBlz3z3Z1Pbx+aS2mtEp9mWfWf/h6xaN3LSx2gAlEyMe eHLw== X-Gm-Message-State: AE9vXwNO8UdBtlxXTY4iEOJJ/bioagE+HIP6XAC3bXBRrul1Ja8rX6x3Xrh4JnwFhjviOFug X-Received: by 10.98.11.65 with SMTP id t62mr46286589pfi.51.1473215958404; Tue, 06 Sep 2016 19:39:18 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id v124sm43985971pfb.14.2016.09.06.19.39.14 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Sep 2016 19:39:18 -0700 (PDT) From: Baolin Wang To: ulf.hansson@linaro.org Cc: adrian.hunter@intel.com, rmk+kernel@arm.linux.org.uk, shawn.lin@rock-chips.com, dianders@chromium.org, heiko@sntech.de, david@protonic.nl, hdegoede@redhat.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, linus.walleij@linaro.org, baolin.wang@linaro.org Subject: [PATCH v5 2/2] mmc: core: Optimize the mmc erase size alignment Date: Wed, 7 Sep 2016 10:38:25 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <48ff46b96e01df36aa5d1c2daf1091d2ec2e729f.1473215578.git.baolin.wang@linaro.org> References: <48ff46b96e01df36aa5d1c2daf1091d2ec2e729f.1473215578.git.baolin.wang@linaro.org> In-Reply-To: <48ff46b96e01df36aa5d1c2daf1091d2ec2e729f.1473215578.git.baolin.wang@linaro.org> References: <48ff46b96e01df36aa5d1c2daf1091d2ec2e729f.1473215578.git.baolin.wang@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Shawn Lin --- 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;