Re: [PATCH v4] introduce macro spin_event_timeout()

From: Timur Tabi
Date: Wed Mar 11 2009 - 12:48:20 EST


On Tue, Mar 10, 2009 at 7:37 PM, Alan Cox <alan@xxxxxxxxxxxxxxxxxxx> wrote:

> Given the proposed helper isn't a sane default for x86 I think it needs a
> good deal more work.

Alan, I'm happy to put whatever effort is requirement to make this
code satisfactory. I believe that this is a useful macro to have in
the kernel. I do appreciate the attention you are giving it.

> It also hides details like that timing which is bad
> sometimes.

Are you talking about the udelay() inside the loop? If so, I agree
that this is bad and have removed it in the PowerPC-specific version:

#define spin_event_timeout(condition, timeout) \
({ \
unsigned long __start = get_tbl(); \
unsigned long __loops = tb_ticks_per_usec * timeout; \
int __ret = 1; \
while (!(condition)) { \
if (tb_ticks_since(__start) > __loops) { \
__ret = 0; \
break; \
} \
cpu_relax(); \
} \
__ret; \
})

tb_ticks_since() is a front-end to get_tbl(), which is similar to the
rdtsc instruction. In this case, we're not adding arbitrary delays
into the loop, and we're not using jiffies, but we are
architecture-dependent.

--
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/