All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][RFC] time: add wait_interruptible_timeout macro to sleep (w. timeout) until wake_up
@ 2010-02-21 14:10 Rafał Miłecki
  2010-02-21 15:01 ` Thomas Hellstrom
  2010-02-26 10:38   ` Rafał Miłecki
  0 siblings, 2 replies; 22+ messages in thread
From: Rafał Miłecki @ 2010-02-21 14:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List, dri-devel; +Cc: Rafał Miłecki

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
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


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2010-03-02 20:32 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-21 14:10 [PATCH][RFC] time: add wait_interruptible_timeout macro to sleep (w. timeout) until wake_up Rafał Miłecki
2010-02-21 15:01 ` Thomas Hellstrom
2010-02-21 15:50   ` Rafał Miłecki
2010-02-24 22:33     ` Rafał Miłecki
2010-02-24 22:33       ` Rafał Miłecki
2010-02-26 10:38 ` Rafał Miłecki
2010-02-26 10:38   ` Rafał Miłecki
2010-02-26 11:55   ` Thomas Gleixner
2010-02-26 12:16     ` Rafał Miłecki
2010-02-26 12:16       ` Rafał Miłecki
2010-02-26 16:14   ` Andrew Morton
2010-02-26 17:33     ` Rafał Miłecki
2010-02-26 17:33       ` Rafał Miłecki
2010-02-26 19:01       ` Ville Syrjälä
2010-02-26 19:01         ` Ville Syrjälä
2010-02-27  9:33         ` Rafał Miłecki
2010-02-27  9:33           ` Rafał Miłecki
2010-03-01 16:37           ` Michel Dänzer
2010-03-01 16:37             ` Michel Dänzer
2010-03-02 20:32             ` Rafał Miłecki
2010-03-02 20:32               ` Rafał Miłecki
2010-02-27  1:04   ` Linus Torvalds

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.