linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h
@ 2012-12-21  9:27 Chunhe Lan
  2012-12-21  9:28 ` [v4 2/2] mmc: Use mmc_delay() instead of mdelay() for time delay Chunhe Lan
  2012-12-21 19:39 ` [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: Chunhe Lan @ 2012-12-21  9:27 UTC (permalink / raw)
  To: linux-mmc; +Cc: cjb, Chunhe Lan, Kumar Gala, Arnd Bergmann

Move mmc_delay() from drivers/mmc/core/core.h to
include/linux/mmc/core.h. So when other functions
call it with include syntax using <linux/mmc/core.h>
of absolute path rather than "../core/core.h" of
relative path.

At the same time, change code, so schedule subsystem
has more chances to call other threads.

Signed-off-by: Chunhe Lan <Chunhe.Lan@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Chris Ball <cjb@laptop.org>
---
 drivers/mmc/core/core.h  |   12 ------------
 include/linux/mmc/core.h |   17 +++++++++++++++++
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 3bdafbc..5f63d00 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -11,8 +11,6 @@
 #ifndef _MMC_CORE_CORE_H
 #define _MMC_CORE_CORE_H
 
-#include <linux/delay.h>
-
 #define MMC_CMD_RETRIES        3
 
 struct mmc_bus_ops {
@@ -46,16 +44,6 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing);
 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
 void mmc_power_off(struct mmc_host *host);
 
-static inline void mmc_delay(unsigned int ms)
-{
-	if (ms < 1000 / HZ) {
-		cond_resched();
-		mdelay(ms);
-	} else {
-		msleep(ms);
-	}
-}
-
 void mmc_rescan(struct work_struct *work);
 void mmc_start_host(struct mmc_host *host);
 void mmc_stop_host(struct mmc_host *host);
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 5bf7c22..e051c5b 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -10,6 +10,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/completion.h>
+#include <linux/delay.h>
 
 struct request;
 struct mmc_data;
@@ -198,6 +199,22 @@ static inline void mmc_claim_host(struct mmc_host *host)
 	__mmc_claim_host(host, NULL);
 }
 
+static inline void mmc_delay(unsigned int ms)
+{
+	ktime_t end = ktime_add_us(ktime_get(), ms * 1000);
+
+	while (1) {
+		s64 remaining;
+
+		cond_resched();
+		remaining = ktime_to_us(ktime_sub(end, ktime_get()));
+		if (remaining < 0)
+			break;
+
+		udelay(min_t(u32, remaining, 100));
+	}
+}
+
 extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
 
 #endif /* LINUX_MMC_CORE_H */
-- 
1.7.6.5



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [v4 2/2] mmc: Use mmc_delay() instead of mdelay() for time delay
  2012-12-21  9:27 [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Chunhe Lan
@ 2012-12-21  9:28 ` Chunhe Lan
  2012-12-21 19:39 ` [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Chunhe Lan @ 2012-12-21  9:28 UTC (permalink / raw)
  To: linux-mmc; +Cc: cjb, Chunhe Lan, Kumar Gala, Arnd Bergmann

The mmc_delay() is a wrapper function for cond_resched() and udelay().

    o mdelay()
		block the system when busy-waiting.
    o cond_resched()
		suspend the currently running task to enable CPU
                to process other tasks, so it is non-blocking
                regarding the whole system.

Change mdelay() to mmc_delay() to avoid chewing CPU when busy wait.

Signed-off-by: Chunhe Lan <Chunhe.Lan@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Chris Ball <cjb@laptop.org>
---
 drivers/mmc/host/sdhci-esdhc.h |    4 ++--
 drivers/mmc/host/sdhci.c       |   10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc.h b/drivers/mmc/host/sdhci-esdhc.h
index d25f9ab..5e33732 100644
--- a/drivers/mmc/host/sdhci-esdhc.h
+++ b/drivers/mmc/host/sdhci-esdhc.h
@@ -1,7 +1,7 @@
 /*
  * Freescale eSDHC controller driver generics for OF and pltfm.
  *
- * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ * Copyright (c) 2007, 2012 Freescale Semiconductor, Inc.
  * Copyright (c) 2009 MontaVista Software, Inc.
  * Copyright (c) 2010 Pengutronix e.K.
  *   Author: Wolfram Sang <w.sang@pengutronix.de>
@@ -73,7 +73,7 @@ static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
 		| (div << ESDHC_DIVIDER_SHIFT)
 		| (pre_div << ESDHC_PREDIV_SHIFT));
 	sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-	mdelay(1);
+	mmc_delay(1);
 out:
 	host->clock = clock;
 }
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 6f0bfc0..a20c4f0 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -206,7 +206,7 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
 			return;
 		}
 		timeout--;
-		mdelay(1);
+		mmc_delay(1);
 	}
 
 	if (host->ops->platform_reset_exit)
@@ -998,7 +998,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 			return;
 		}
 		timeout--;
-		mdelay(1);
+		mmc_delay(1);
 	}
 
 	mod_timer(&host->timer, jiffies + 10 * HZ);
@@ -1179,7 +1179,7 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
 			return;
 		}
 		timeout--;
-		mdelay(1);
+		mmc_delay(1);
 	}
 
 	clk |= SDHCI_CLOCK_CARD_EN;
@@ -1244,7 +1244,7 @@ static int sdhci_set_power(struct sdhci_host *host, unsigned short power)
 	 * can apply clock after applying power
 	 */
 	if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER)
-		mdelay(10);
+		mmc_delay(10);
 
 	return power;
 }
@@ -1895,7 +1895,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 		ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
 		tuning_loop_counter--;
 		timeout--;
-		mdelay(1);
+		mmc_delay(1);
 	} while (ctrl & SDHCI_CTRL_EXEC_TUNING);
 
 	/*
-- 
1.7.6.5



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h
  2012-12-21  9:27 [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Chunhe Lan
  2012-12-21  9:28 ` [v4 2/2] mmc: Use mmc_delay() instead of mdelay() for time delay Chunhe Lan
@ 2012-12-21 19:39 ` Arnd Bergmann
  2012-12-25  8:13   ` Chunhe Lan
  1 sibling, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2012-12-21 19:39 UTC (permalink / raw)
  To: Chunhe Lan; +Cc: linux-mmc, cjb, Kumar Gala

On Friday 21 December 2012, Chunhe Lan wrote:
> 
> +static inline void mmc_delay(unsigned int ms)
> +{
> +       ktime_t end = ktime_add_us(ktime_get(), ms * 1000);
> +
> +       while (1) {
> +               s64 remaining;
> +
> +               cond_resched();
> +               remaining = ktime_to_us(ktime_sub(end, ktime_get()));
> +               if (remaining < 0)
> +                       break;
> +
> +               udelay(min_t(u32, remaining, 100));
> +       }
> +}

The new logic is more accurate than the old one, but it still wastes
a lot of energy and CPU cycles. Could you perhaps use an hrtimer to
set the exact timeout and actually sleep?

	Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h
  2012-12-21 19:39 ` [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Arnd Bergmann
@ 2012-12-25  8:13   ` Chunhe Lan
  0 siblings, 0 replies; 4+ messages in thread
From: Chunhe Lan @ 2012-12-25  8:13 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: Chunhe Lan, linux-mmc, cjb, Kumar Gala

On 12/22/2012 03:39 AM, Arnd Bergmann wrote:
> On Friday 21 December 2012, Chunhe Lan wrote:
>> +static inline void mmc_delay(unsigned int ms)
>> +{
>> +       ktime_t end = ktime_add_us(ktime_get(), ms * 1000);
>> +
>> +       while (1) {
>> +               s64 remaining;
>> +
>> +               cond_resched();
>> +               remaining = ktime_to_us(ktime_sub(end, ktime_get()));
>> +               if (remaining < 0)
>> +                       break;
>> +
>> +               udelay(min_t(u32, remaining, 100));
>> +       }
>> +}
> The new logic is more accurate than the old one, but it still wastes
> a lot of energy and CPU cycles. Could you perhaps use an hrtimer to
> set the exact timeout and actually sleep?
     I think that does not have to use hrtimer, and it makes a fuss.
     And mmc structure has not included the hrtimer variable.

Thanks,
Chunhe
>
> 	Arnd
>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-25  8:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-21  9:27 [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Chunhe Lan
2012-12-21  9:28 ` [v4 2/2] mmc: Use mmc_delay() instead of mdelay() for time delay Chunhe Lan
2012-12-21 19:39 ` [v4 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h Arnd Bergmann
2012-12-25  8:13   ` Chunhe Lan

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).