Thread (7 messages) flat view 7 messages, 4 authors, 2012-09-24

Re: [PATCH v3 1/2] mmc: Move mmc_delay() to include/linux/mmc/core.h

From: Arnd Bergmann <arnd@arndb.de>
Date: 2012-09-24 13:17:44
Also in: linux-mmc

On Monday 24 September 2012, Chunhe Lan wrote:
    OK. As you have mentioned, it would been modified to such:

static inline void mmc_delay(unsigned int ms)
{
         if (ms < 1000 / HZ) {
                 cond_resched();
                 msleep(ms);
         } else {
                 msleep(ms);
         }
}
This version would be rather broken, because it compares times
in two different units (ms and jiffies), and because it
does a cond_resched() directly before an msleep: both of which
end up calling schedule() and being away for some time,
cond_resched() for an unknown time, and msleep for a minimum
time on top of that.
OR such:

static inline void mmc_delay(unsigned int ms)
{
          msleep(ms);
}
That would be my preferred choice, unless someone has specific issues with this.
OR other code?
Well, in principle, you could implement something like

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));
	}
}

	Arnd
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help