LKML Archive on
help / color / mirror / Atom feed
From: Tejun Heo <>
To: Peter Zijlstra <>
Cc: Thomas Gleixner <>,
	Linux Kernel Mailing List <>,
	Jens Axboe <>,
	Faisal Latif <>,
	Roland Dreier <>,
	Sean Hefty <>,
	Hal Rosenstock <>,
	Dmitry Torokhov <>,
	Alessandro Rubini <>,
	Trond Myklebust <>,
	Mark Fasheh <>, Joel Becker <>,
	"David S. Miller" <>,
	"John W. Linville" <>,
	Johannes Berg <>,
	Yong Zhang <>
Subject: Re: [PATCH 4/4] workqueue: Remove now superfluous cancel_delayed_work() calls
Date: Fri, 4 Feb 2011 12:13:01 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <1296755141.26581.470.camel@laptop>

Hello, Peter.

On Thu, Feb 03, 2011 at 06:45:41PM +0100, Peter Zijlstra wrote:
> On Thu, 2011-02-03 at 17:19 +0100, Tejun Heo wrote:
> > On Thu, Feb 03, 2011 at 03:09:44PM +0100, Peter Zijlstra wrote:
> > > Since queue_delayed_work() can now deal with existing timers, we don't
> > > need to explicitly call cancel_delayed_work() anymore.
> > 
> > This is nice but there's small complication with the way
> > queue_delayed_work() behaves.  If a delayed work item is already
> > pending, another queue_delayed_work() doesn't modify the delay whether
> > the new delay is longer or shorter than the current one.  The previous
> > patch doesn't really change the behavior as the whole thing is gated
> > 
> > So, cancel_delayed_work() followed by queue_delayed_work() schedules
> > the work to be executed at the specified time regardless of the
> > current pending state while queue_delayed_work() takes effect iff
> > currently the work item is not pending.
> Right, I didn't think it would matter much, the difference is tiny. Only
> a small window between the timer triggering and the work getting
> scheduled has a different semantics, it used to be the same as before
> that window, now its like after that window.
> Since its all timing the code needs to deal with those cases anyway, no?

No, AFAICS the change from add_timer() to mod_timer() doesn't make any
difference.  The control never reaches there if the work item is
already pending.  Please consider the following two sequences.

seq1.	queue_delayed_work(wq, dwork, 10*HZ);
	queue_delayed_work(wq, dwork, 5*HZ);

seq2.	queue_delayed_work(wq, dwork, 10*HZ);
	queue_delayed_work(wq, dwork, 5*HZ);

With or without the patch, dwork in seq1 will execute in 5 seconds,
and, again, with our without the patch dwork in seq2 will execute in
10 seconds, because queueing is gated by WORK_STRUCT_PENDING_BIT and
if the bit is already set the timer isn't modified at all.

IOW, those cancel_delayed_work()'s are there not because
queue_delayed_work() calls add_timer() instead of mod_timer().
They're there because queue_delayed_work() always uses the first
timeout duration and the users want to change it to a new value.

As I wrote before, I'm not a fan of the current behavior but that's
how it is currently.  This patch series doesn't change the behavior
because the timers are guaranteed to be offline when
queue_delayed_work_on() calls add_timer().  To actually change the
behavior, queue_delayed_work_on() needs to be restructured and all its
users audited.

Thank you.


      reply	other threads:[~2011-02-04 11:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-03 14:09 [PATCH 0/4] del_timer_sync() and queue_delayed_work() Peter Zijlstra
2011-02-03 14:09 ` [PATCH 1/4] lockdep, timer: Fix del_timer_sync() annotation Peter Zijlstra
2011-02-03 15:35   ` Thomas Gleixner
2011-02-05  1:07     ` Nick Bowler
2011-02-04  3:28   ` Yong Zhang
2011-02-04  9:34   ` [tip:timers/urgent] " tip-bot for Peter Zijlstra
2011-02-03 14:09 ` [PATCH 2/4] timer: Provide mod_timer_on() Peter Zijlstra
2011-02-03 14:09 ` [PATCH 3/4] workqueue: Use mod_timer for queue_delayed_work() Peter Zijlstra
2011-02-03 14:09 ` [PATCH 4/4] workqueue: Remove now superfluous cancel_delayed_work() calls Peter Zijlstra
2011-02-03 16:19   ` Tejun Heo
2011-02-03 16:45     ` Dmitry Torokhov
2011-02-03 17:45     ` Peter Zijlstra
2011-02-04 11:13       ` Tejun Heo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).