Re: [PATCH][RFC] time: add wait_interruptible_timeout macro tosleep (w. timeout) until wake_up

From: Ville Syrjälä
Date: Fri Feb 26 2010 - 14:09:17 EST


On Fri, Feb 26, 2010 at 06:33:57PM +0100, RafaÅ MiÅecki wrote:
> W dniu 26 lutego 2010 17:14 uÅytkownik Andrew Morton
> <akpm@xxxxxxxxxxxxxxxxxxxx> napisaÅ:
> > On Fri, 26 Feb 2010 11:38:59 +0100 Rafa Miecki <zajec5@xxxxxxxxx> wrote:
> >
> >> +#define wait_interruptible_timeout(wq, timeout)
> >> Â Â \
> >> +({ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> >> + Â Âlong ret = timeout; Â Â Â Â Â Â Â Â Â Â Â\
> >> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> >> + Â ÂDEFINE_WAIT(wait); Â Â Â Â Â Â Â Â Â Â Â\
> >> + Â Âprepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE); Â Â Â \
> >> + Â Âif (!signal_pending(current)) Â Â Â Â Â Â Â Â Â\
> >> + Â Â Â Âret = schedule_timeout(ret); Â Â Â Â Â Â\
> >> + Â Âfinish_wait(&wq, &wait); Â Â Â Â Â Â Â Â Â \
> >> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> >> + Â Âret; Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> >> +})
> >
> > It's often a mistake to use signals in-kernel. ÂSignals are more a
> > userspace thing and it's better to use the lower-level kernel-specific
> > messaging tools in-kernel. ÂBear in mind that userspace can
> > independently and asynchronously send, accept and block signals.
>
> Can you point me to something kernel-level please?
>
>
> > Can KMS use wait_event_interruptible_timeout()?
>
> No. Please check definition of this:
>
> #define wait_event_interruptible_timeout(wq, condition, timeout) \
> ({ \
> long __ret = timeout; \
> if (!(condition)) \
> __wait_event_interruptible_timeout(wq, condition, __ret); \
> __ret; \
> })
>
> It uses condition there, but that's not a big issue. We just need to
> pass 0 (false) there and it will work so far.

Disabling the condition check doesn't make sense.

You could use a completion.

init_completion(vbl_irq);
enable_vbl_irq();
wait_for_completion(vbl_irq);
disable_vbl_irq();
and call complete(vbl_irq) in the interrupt handler.

The same would of course work with just some flag or counter
and a wait queue. Isn't there already a vbl counter that you could
compare in the condition?

--
Ville SyrjÃlÃ
syrjala@xxxxxx
http://www.sci.fi/~syrjala/
--
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/