public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] timer: Introduce mod_timer_msec()
@ 2010-01-02 18:48 Arjan van de Ven
  2010-01-02 18:50 ` users of mod_timer_msec() Arjan van de Ven
  0 siblings, 1 reply; 7+ messages in thread
From: Arjan van de Ven @ 2010-01-02 18:48 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel

>From 247f568d09e22fb5041f49b23bf2d5414c1299db Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Sat, 2 Jan 2010 10:37:57 -0800
Subject: [PATCH] timer: Introduce mod_timer_msec()

It is a common paradigm in drivers to want to set/change a timer
for a relative amount of milliseconds.

This patch adds a mod_timer_msec() API function to make this easier
and to remove the awareness of both "jiffies" and the HZ value from
various drivers that don't care about such implementation detail.

Conversion of various users of the API are done in separate patches
that will go via the various maintainers separately.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 include/linux/timer.h |    1 +
 kernel/timer.c        |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/include/linux/timer.h b/include/linux/timer.h
index a2d1eb6..763f58f 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -162,6 +162,7 @@ static inline int timer_pending(const struct timer_list * timer)
 extern void add_timer_on(struct timer_list *timer, int cpu);
 extern int del_timer(struct timer_list * timer);
 extern int mod_timer(struct timer_list *timer, unsigned long expires);
+extern int mod_timer_msec(struct timer_list *timer, unsigned long delay_ms);
 extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
 extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires);
 
diff --git a/kernel/timer.c b/kernel/timer.c
index 15533b7..c061cc2 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -749,6 +749,26 @@ int mod_timer(struct timer_list *timer, unsigned long expires)
 EXPORT_SYMBOL(mod_timer);
 
 /**
+ * mod_timer_msec - modify a timer's timeout, using relative milliseconds
+ * @timer: the timer to be modified
+ * @delay_ms: the desired minimum delay in milliseconds
+ *
+ * Changes the timeout of a timer similar to mod_timer().
+ *
+ * mod_timer_msec() takes relative milliseconds rather than absolute
+ * jiffies as argument.
+ *
+ * The function returns whether it has modified a pending timer or not.
+ * (ie. mod_timer_msec() of an inactive timer returns 0, mod_timer_msec() of
+ * an active timer returns 1.)
+ */
+int mod_timer_msec(struct timer_list *timer, unsigned long delay_ms)
+{
+	return mod_timer(timer, msecs_to_jiffies(delay_ms));
+}
+EXPORT_SYMBOL(mod_timer_msec);
+
+/**
  * mod_timer_pinned - modify a timer's timeout
  * @timer: the timer to be modified
  * @expires: new timeout in jiffies
-- 
1.6.2.5



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

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

end of thread, other threads:[~2010-01-02 19:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-02 18:48 [PATCH] timer: Introduce mod_timer_msec() Arjan van de Ven
2010-01-02 18:50 ` users of mod_timer_msec() Arjan van de Ven
2010-01-02 19:11   ` Andi Kleen
2010-01-02 19:19     ` Arjan van de Ven
2010-01-02 19:21     ` [PATCH v2] timer: Introduce mod_timer_msec() Arjan van de Ven
2010-01-02 19:30       ` Dmitry Torokhov
2010-01-02 19:36         ` Arjan van de Ven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox