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

From: RafaÅ MiÅecki
Date: Fri Feb 26 2010 - 05:39:13 EST


Forwarding to ppl I could often notice in git log time.h


---------- WiadomoÅÄ przekazana dalej ----------
From: RafaÅ MiÅecki <zajec5@xxxxxxxxx>
Date: 21 lutego 2010 15:10
Subject: [PATCH][RFC] time: add wait_interruptible_timeout macro to
sleep (w. timeout) until wake_up
To: Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>,
dri-devel@xxxxxxxxxxxxxxxxxxxxx
CC: RafaÅ MiÅecki <zajec5@xxxxxxxxx>


Signed-off-by: RafaÅ MiÅecki <zajec5@xxxxxxxxx>
---
We try to implement some PM in radeon KMS and we need to sync with VLBANK for
reclocking engine/memory. The easiest and cleanest way seems to be sleeping in
timer handler just before reclocking. Then our IRQ handler calls wake_up and we
continue reclocking.

As you see our sleeping is condition-less, we just wait for waking up queue.

We hope this waking will happen from IRQ handler, but for less-happy case we
also use some timeout (this will probably cause some single corruption, but
we can live with it).

Following macro is soemthing that seems to work fine for us, but instead
introducing this to radeon KMS only, I'd like to propose adding this to whole
wait.h. Do you this it's something we should place there? Can someone take this
patch for me? Or maybe you find this rather useless and we should keep this
marco locally?
---
Âinclude/linux/wait.h | Â 25 +++++++++++++++++++++++++
Â1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index a48e16b..998475b 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -332,6 +332,31 @@ do {
            \
   Â__ret;                             Â\
Â})

+/**
+ * wait_interruptible_timeout - sleep until a waitqueue is woken up
+ * @wq: the waitqueue to wait on
+ * @timeout: timeout, in jiffies
+ *
+ * The process is put to sleep (TASK_INTERRUPTIBLE) until the waitqueue
+ * @wq is woken up. It can be done manually with wake_up or will happen
+ * if timeout elapses.
+ *
+ * The function returns 0 if the @timeout elapsed, remaining jiffies
+ * if workqueue was waken up earlier.
+ */
+#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; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
+})
+
Â#define __wait_event_interruptible_exclusive(wq, condition, ret) Â Â Â \
Âdo { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
   ÂDEFINE_WAIT(__wait);                      Â\
--
1.6.4.2
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—