Re: [PATCH] add function spin_event_timeout()

From: Timur Tabi
Date: Fri Mar 06 2009 - 20:25:33 EST


On Fri, Mar 6, 2009 at 7:11 PM, Roland Dreier <rdreier@xxxxxxxxx> wrote:
> > The function spin_event_timeout() takes a condition and timeout value
> > (in jiffies) as parameters. It spins until either the condition is true
> > or the timeout expires. It returns non-zero if the condition is true,
> > zero otherwise.
>
> What's the motivation for this? Where do you plan to use it?

I expect it would be useful for drivers that need to wait until a
specific register has changed its value, but don't want to risk an
infinite loop if the hardware is not functioning. For example, to
replace the while loop and subsequent check in this code:

long timeout = jiffies + 10;

setbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE);

/* Wait until the SSI has filled its FIFO. Without this
* delay, ALSA complains about overruns. When the FIFO
* is full, the DMA controller initiates its first
* transfer. Until then, however, the DMA's DAR
* register is zero, which translates to an
* out-of-bounds pointer. This makes ALSA think an
* overrun has occurred.
*/
while (!(in_be32(&ssi->sisr) & CCSR_SSI_SISR_RFF0) &&
(jiffies < timeout));
if (!(in_be32(&ssi->sisr) & CCSR_SSI_SISR_RFF0))
return -EIO;

> If we're going to make this core infrastructure, it seems we should
> implement it with all best practices... eg I would think the while loop
> should include cpu_relax().

Ok. I'll post version 2 on Monday. Anything else I'm missing?

--
Timur Tabi
Linux kernel developer at Freescale
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/