Commit 071b638689464c6b39407025eedd810d5b5e6f5d
Committed by
David S. Miller
1 parent
566ec03448
Exists in
master
and in
39 other branches
[WORKQUEUE]: cancel_delayed_work: use del_timer() instead of del_timer_sync()
del_timer_sync() buys nothing for cancel_delayed_work(), but it is less efficient since it locks the timer unconditionally, and may wait for the completion of the delayed_work_timer_fn(). cancel_delayed_work() == 0 means: before this patch: work->func may still be running or queued after this patch: work->func may still be running or queued, or delayed_work_timer_fn->__queue_work() in progress. The latter doesn't differ from the caller's POV, delayed_work_timer_fn() is called with _PENDING bit set. cancel_delayed_work() == 1 with this patch adds a new possibility: delayed_work->work was cancelled, but delayed_work_timer_fn is still running (this is only possible for the re-arming works on single-threaded workqueue). In this case the timer was re-started by work->func(), nobody else can do this. This in turn means that delayed_work_timer_fn has already passed __queue_work() (and wont't touch delayed_work) because nobody else can queue delayed_work->work. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Signed-Off-By: David Howells <dhowells@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 4 additions and 3 deletions Side-by-side Diff
include/linux/workqueue.h
... | ... | @@ -191,14 +191,15 @@ |
191 | 191 | |
192 | 192 | /* |
193 | 193 | * Kill off a pending schedule_delayed_work(). Note that the work callback |
194 | - * function may still be running on return from cancel_delayed_work(). Run | |
195 | - * flush_scheduled_work() to wait on it. | |
194 | + * function may still be running on return from cancel_delayed_work(), unless | |
195 | + * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or | |
196 | + * cancel_work_sync() to wait on it. | |
196 | 197 | */ |
197 | 198 | static inline int cancel_delayed_work(struct delayed_work *work) |
198 | 199 | { |
199 | 200 | int ret; |
200 | 201 | |
201 | - ret = del_timer_sync(&work->timer); | |
202 | + ret = del_timer(&work->timer); | |
202 | 203 | if (ret) |
203 | 204 | work_release(&work->work); |
204 | 205 | return ret; |