From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Timur Tabi <timur@freescale.com>
Cc: linuxppc-dev@ozlabs.org
Subject: Re: [PATCH v5] introduce macro spin_event_timeout()
Date: Wed, 11 Mar 2009 10:58:48 +1100 [thread overview]
Message-ID: <1236729528.7086.25.camel@pasglop> (raw)
In-Reply-To: <1236723118-3577-1-git-send-email-timur@freescale.com>
On Tue, 2009-03-10 at 17:11 -0500, Timur Tabi wrote:
> The macro spin_event_timeout() takes a condition and timeout value
> (in microseconds) as parameters. It spins until either the condition is true
> or the timeout expires. It returns zero if the timeout expires first, non-zero
> otherwise.
>
> This primary purpose of this macro is to poll on a hardware register until a
> status bit changes. The timeout ensures that the loop still terminates if the
> bit doesn't change as expected. This macro makes it easier for driver
> developers to perform this kind of operation properly.
I've missed the history here but why is that arch code ? it could be
used by more drivers... though there's always the idea that spinning is
bad :-)
Cheers,
Ben.
> Signed-off-by: Timur Tabi <timur@freescale.com>
> ---
>
> v5: ported to arch/powerpc, made it powerpc-specific, eliminated udelay
>
> v4: removed cpu_relax (redundant), changed timeout to unsigned long
>
> v3: eliminated secondary evaluation of condition, replaced jiffies with udelay
>
> v2: added cpu_relax and time_before
>
> arch/powerpc/include/asm/delay.h | 32 ++++++++++++++++++++++++++++++++
> 1 files changed, 32 insertions(+), 0 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/delay.h b/arch/powerpc/include/asm/delay.h
> index f9200a6..aadec70 100644
> --- a/arch/powerpc/include/asm/delay.h
> +++ b/arch/powerpc/include/asm/delay.h
> @@ -2,6 +2,8 @@
> #define _ASM_POWERPC_DELAY_H
> #ifdef __KERNEL__
>
> +#include <asm/time.h>
> +
> /*
> * Copyright 1996, Paul Mackerras.
> *
> @@ -30,5 +32,35 @@ extern void udelay(unsigned long usecs);
> #define mdelay(n) udelay((n) * 1000)
> #endif
>
> +/**
> + * spin_event_timeout - spin until a condition gets true or a timeout elapses
> + * @condition: a C expression to evalate
> + * @timeout: timeout, in microseconds
> + *
> + * The process spins until the @condition evaluates to true (non-zero) or
> + * the @timeout elapses.
> + *
> + * This primary purpose of this macro is to poll on a hardware register
> + * until a status bit changes. The timeout ensures that the loop still
> + * terminates if the bit never changes.
> + *
> + * The return value is non-zero if the condition evaluates to true first, or
> + * zero if the timeout elapses first.
> + */
> +#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; \
> +})
> +
> #endif /* __KERNEL__ */
> #endif /* _ASM_POWERPC_DELAY_H */
prev parent reply other threads:[~2009-03-10 23:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 22:11 [PATCH v5] introduce macro spin_event_timeout() Timur Tabi
2009-03-10 22:33 ` Scott Wood
2009-03-10 22:37 ` Josh Boyer
2009-03-10 22:58 ` Scott Wood
2009-03-11 0:32 ` Josh Boyer
2009-03-10 23:59 ` Benjamin Herrenschmidt
2009-03-11 0:22 ` Timur Tabi
2009-03-11 0:24 ` Benjamin Herrenschmidt
2009-03-11 17:10 ` Grant Likely
2009-03-11 21:49 ` Benjamin Herrenschmidt
2009-03-11 21:54 ` Timur Tabi
2009-03-11 22:49 ` Scott Wood
2009-03-11 5:09 ` Roland Dreier
2009-03-11 16:31 ` Timur Tabi
2009-03-11 16:51 ` Scott Wood
2009-03-11 19:14 ` Timur Tabi
2009-03-11 19:22 ` Scott Wood
2009-03-11 20:45 ` Timur Tabi
2009-03-11 21:00 ` Scott Wood
2009-03-11 21:02 ` Timur Tabi
2009-03-11 21:03 ` Scott Wood
2009-03-11 0:44 ` Josh Boyer
2009-03-10 23:58 ` Benjamin Herrenschmidt [this message]
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=1236729528.7086.25.camel@pasglop \
--to=benh@kernel.crashing.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=timur@freescale.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.