[PATCH 3/4] workqueue: Use mod_timer for queue_delayed_work()

From: Peter Zijlstra
Date: Thu Feb 03 2011 - 09:18:07 EST


Use mod_timer for queue_delayed_work(), this allows us to avoid
calling cancel_delayed_work() prior to calling queue_delayed_work()
when changing a work's expiration time.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
LKML-Reference: <new-submission>
---
Index: linux-2.6/kernel/workqueue.c
===================================================================
--- linux-2.6.orig/kernel/workqueue.c
+++ linux-2.6/kernel/workqueue.c
@@ -1107,8 +1107,15 @@ static void delayed_work_timer_fn(unsign
int queue_delayed_work(struct workqueue_struct *wq,
struct delayed_work *dwork, unsigned long delay)
{
- if (delay == 0)
+ if (delay == 0) {
+ /*
+ * If the timer callback is currently running the work
+ * is already being enqueued and we don't actually have
+ * to do anything to make it run now...
+ */
+ __cancel_delayed_work(dwork);
return queue_work(wq, &dwork->work);
+ }

return queue_delayed_work_on(-1, wq, dwork, delay);
}
@@ -1160,9 +1167,9 @@ int queue_delayed_work_on(int cpu, struc
timer->function = delayed_work_timer_fn;

if (unlikely(cpu >= 0))
- add_timer_on(timer, cpu);
+ mod_timer_on(timer, cpu);
else
- add_timer(timer);
+ mod_timer(timer);
ret = 1;
}
return ret;


--
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/