From: Peter Zijlstra <peterz@infradead.org>
To: Timur Tabi <timur@freescale.com>
Cc: linux-kernel@vger.kernel.org, rdreier@cisco.com, jirislaby@gmail.com
Subject: Re: [PATCH v2] add function spin_event_timeout()
Date: Mon, 09 Mar 2009 17:06:15 +0100 [thread overview]
Message-ID: <1236614775.8389.692.camel@laptop> (raw)
In-Reply-To: <1236611904-9843-1-git-send-email-timur@freescale.com>
On Mon, 2009-03-09 at 10:18 -0500, Timur Tabi 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.
This changelog utterly fails to justify this interface. And to me it
seems a rather bad one. Why would we ever be wanting to spin in order of
jiffies?
> Signed-off-by: Timur Tabi <timur@freescale.com>
> ---
>
> v2: changes based on feedback
>
> include/linux/delay.h | 22 ++++++++++++++++++++++
> 1 files changed, 22 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/delay.h b/include/linux/delay.h
> index fd832c6..235ca25 100644
> --- a/include/linux/delay.h
> +++ b/include/linux/delay.h
> @@ -51,4 +51,26 @@ static inline void ssleep(unsigned int seconds)
> msleep(seconds * 1000);
> }
>
> +/**
> + * spin_event_timeout - spin until a condition gets true or a timeout elapses
> + * @condition: a C expression for the event to wait for
> + * @timeout: timeout, in jiffies
> + *
> + * The process spins until the @condition evaluates to true or the @timeout
> + * elapses.
> + *
> + * The function returns non-zero if the @condition evaluated to true, or
> + * zero if the @timeout elapsed. If both occurs (e.g. the loop was
> + * pre-empted and the @condition became true in the meantime, but when the
> + * loop resumed the @timeout had already elapsed), then non-zero will be
> + * returned.
> + */
> +#define spin_event_timeout(condition, timeout) \
> +({ \
> + unsigned long __timeout = jiffies + (timeout); \
> + while (!(condition) && time_before(jiffies, __timeout)) \
> + cpu_relax(); \
> + (condition); \
> +})
> +
> #endif /* defined(_LINUX_DELAY_H) */
next prev parent reply other threads:[~2009-03-09 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-09 15:18 [PATCH v2] add function spin_event_timeout() Timur Tabi
2009-03-09 15:31 ` Will Newton
2009-03-09 15:34 ` Timur Tabi
2009-03-09 16:06 ` Peter Zijlstra [this message]
2009-03-09 18:16 ` Timur Tabi
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=1236614775.8389.692.camel@laptop \
--to=peterz@infradead.org \
--cc=jirislaby@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rdreier@cisco.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox