From patchwork Tue Sep 6 02:55:12 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: 9315423 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 8F156600CA for ; Tue, 6 Sep 2016 02:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 843C828B19 for ; Tue, 6 Sep 2016 02:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7627C28B1B; Tue, 6 Sep 2016 02:59:36 +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=-4.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 0570D28B17 for ; Tue, 6 Sep 2016 02:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754666AbcIFC5S (ORCPT ); Mon, 5 Sep 2016 22:57:18 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:35762 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755099AbcIFC4H (ORCPT ); Mon, 5 Sep 2016 22:56:07 -0400 Received: by mail-pf0-f178.google.com with SMTP id w87so11285319pfk.2 for ; Mon, 05 Sep 2016 19:56:07 -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=ylLVNTXn/vgTPfafj1V9NTO7VJ2CELIG05NhdcuNESU=; b=SLJypVf915/Go4uKkOuf5uwiWh2p574pKO6L1NgAxq0oTeyuBAOCFxMjsggH3IDjMc Qzil/BM5UmK21K2PmwxS18VFb0YOfkUQm8N/JAatp7UyVauKfSLgySJsWTgi/ayD7dmN l1i+2MpsXUjcKWcMQqG5J0p3KUfq2YcuVmgvo= 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=ylLVNTXn/vgTPfafj1V9NTO7VJ2CELIG05NhdcuNESU=; b=S7a3cmyu9y+pXPRWxf6BRQuW2zhRgaxlyw62zD0xIkEZISnIO1BX+3gUvBmeTskSxm 0Xqcjz4VxM9SYiiYgnW+r3QWsEodgWcZWWADr1dklWuoxoM7vKU2QlGKS06YQi3d8M+h /0LNyxIu8mr5GyMfRbyjLz/jTo2QE307ZjiPGFWjIGZbPtKYsWRQ6mTuUhlAD0SCbcpe PMaqg7Yi//UxPE8pE8529xIIWtiyvkwNplO8c8enYPXTv74/ywp2yGERs/U/8Fo/MjKv sGyatR++fm5rN0z1yhc57SRb26GFcNcUJqCwtIjRGfSdzA5+Y1vUsB2IVsvSk4c43I0D t13Q== X-Gm-Message-State: AE9vXwO9hTuhAbOk8C9jNGq0T717EDiHExmzvP2nRoimioVaeQJrwDL1tjaB4fX+L6vfVAJq X-Received: by 10.98.104.71 with SMTP id d68mr68680647pfc.163.1473130567184; Mon, 05 Sep 2016 19:56:07 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id g15sm139102pfa.48.2016.09.05.19.56.03 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Sep 2016 19:56:06 -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 v4 3/3] mmc: core: Optimize the mmc erase size alignment Date: Tue, 6 Sep 2016 10:55:12 +0800 Message-Id: <8f20dfea761960fd9bbcb6a0ce3ae0178e039b31.1473130123.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org> References: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org> In-Reply-To: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.git.baolin.wang@linaro.org> References: <2b6b5b930d0f37a219d5786a6b56b17516a90abd.1473130123.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 5f93eef..e014949 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;