linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Figa <tomasz.figa@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Ben Dooks <ben-linux@fluff.org>, Chris Ball <chris@printf.net>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Seungwon Jeon <tgih.jun@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Tomasz Figa <tomasz.figa@gmail.com>
Subject: [PATCH 1/6] mmc: sdhci-s3c: Use shifts to divide by powers of two
Date: Sat, 11 Jan 2014 22:39:01 +0100	[thread overview]
Message-ID: <1389476346-20396-2-git-send-email-tomasz.figa@gmail.com> (raw)
In-Reply-To: <1389476346-20396-1-git-send-email-tomasz.figa@gmail.com>

Current implementation of sdhci_s3c_consider_clock() is highly
inefficient due to multiple integer divisions by variable performed in a
loop. Since only divisors that are powers of two are considered, this
patch replaces them with respective shifts, removing all the integer
divisions.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>
---
 drivers/mmc/host/sdhci-s3c.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 6debda9..52770d5 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -144,7 +144,7 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
 {
 	unsigned long rate;
 	struct clk *clksrc = ourhost->clk_bus[src];
-	int div;
+	int shift;
 
 	if (!clksrc)
 		return UINT_MAX;
@@ -160,15 +160,15 @@ static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
 
 	rate = clk_get_rate(clksrc);
 
-	for (div = 1; div < 256; div *= 2) {
-		if ((rate / div) <= wanted)
+	for (shift = 0; shift < 8; ++shift) {
+		if ((rate >> shift) <= wanted)
 			break;
 	}
 
 	dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
-		src, rate, wanted, rate / div);
+		src, rate, wanted, rate >> shift);
 
-	return wanted - (rate / div);
+	return wanted - (rate >> shift);
 }
 
 /**
-- 
1.8.5.2

  reply	other threads:[~2014-01-11 21:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-11 21:39 [PATCH 0/6] mmc: sdhci-s3c: Fix base clock source management Tomasz Figa
2014-01-11 21:39 ` Tomasz Figa [this message]
2014-01-11 21:39 ` [PATCH 2/6] mmc: sdhci-s3c: Cache bus clock rates Tomasz Figa
2014-01-11 21:39 ` [PATCH 3/6] mmc: sdhci-s3c: Use correct condition to check for clock presence Tomasz Figa
2014-01-11 21:39 ` [PATCH 4/6] mmc: sdhci-s3c: Simplify min/max clock calculation Tomasz Figa
2014-01-11 21:39 ` [PATCH 5/6] mmc: sdhci-s3c: Fix handling of bus clock switching Tomasz Figa
2014-01-11 21:39 ` [PATCH 6/6] mmc: sdhci-s3c: Do not allow frequencies higher than requested Tomasz Figa
2014-01-12 21:18 ` [PATCH 0/6] mmc: sdhci-s3c: Fix base clock source management Heiko Stübner
2014-01-13  5:47   ` Jaehoon Chung
2014-01-13 12:43     ` Tomasz Figa
2014-02-07  9:58 ` Tomasz Figa
2014-02-20 19:26   ` Tomasz Figa
2014-03-03 15:06     ` Tomasz Figa
2014-03-03 15:24       ` Chris Ball
2014-03-03 15:25         ` Tomasz Figa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389476346-20396-2-git-send-email-tomasz.figa@gmail.com \
    --to=tomasz.figa@gmail.com \
    --cc=ben-linux@fluff.org \
    --cc=chris@printf.net \
    --cc=jh80.chung@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=tgih.jun@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).