From: Oleg Nesterov <oleg@redhat.com>
To: Roland Dreier <rdreier@cisco.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Is adding requeue_delayed_work() a good idea
Date: Fri, 21 Aug 2009 13:55:47 +0200 [thread overview]
Message-ID: <20090821115547.GA6901@redhat.com> (raw)
In-Reply-To: <adazl9uw3w1.fsf@cisco.com>
On 08/20, Roland Dreier wrote:
>
> My patch goes back to an open-coded version of delayed work that splits
> the timer and the work struct. However it occurs to me that an API like
> requeue_delayed_work() that does a mod_timer() on the delayed work
> struct might be useful -- OTOH making this fully general and keeping
> track of the work's pending bit etc seems perhaps a bit dicy.
Completely agreed.
We need some simple changes in timer.c. __mod_timer() already has
pending_only, but requeue_delayed_work() needs another flag to prevent
migrating to another CPU. Again, this is simple, let's suppose we have
requeue_timer(timer) which works like mod_timer(pending_only => true)
but never changes timer->base.
The main question is: what should requeue_delayed_work(dwork) do when
dwork->timer is not pending but dwork->work is queued or running?
Should it cancel dwork->work is this case?
If yes, then I don't understand how this new helper (which is good
anyway) can help with this particular problem,
> happens because the mad module does
>
> cancel_delayed_work(&mad_agent_priv->timed_work);
>
> while holding mad_agent_priv->lock. cancel_delayed_work() internally
> does del_timer_sync(&mad_agent_priv->timed_work.timer).
>
> This can turn into a deadlock because mad_agent_priv->lock is taken
> inside cm_id_priv->lock, so we can get the following set of contexts
> that deadlock each other:
>
> A: holding cm_id_priv->lock, waiting for mad_agent_priv->lock
> B: holding mad_agent_priv->lock, waiting for del_timer_sync()
> C: interrupt during mad_agent_priv->timed_work.timer that takes
> cm_id_priv->lock
OK, suppose that we s/cancel_delayed_work/requeue_delayed_work/,
then we seem to have the same deadlock
A: holding cm_id_priv->lock, waiting for mad_agent_priv->lock
B: holding mad_agent_priv->lock, waiting for requeue_delayed_work()
which found !timer_pending() && queued work
C: interrupt during work->func() that takes cm_id_priv->lock
Perhaps, requeue_delayed_work() should cancel the pending work, but do
not wait_on_work(). This is not trivial, we have to avoid livelocks if
cancel_work_no_sync() races with queue_work()/etc. Perhaps,
requeue_delayed_work() could return the error if it can't update the
timer and can't cancel the work without spinning ?
What dou you think?
Oleg.
next prev parent reply other threads:[~2009-08-21 11:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-20 21:51 Is adding requeue_delayed_work() a good idea Roland Dreier
2009-08-21 11:55 ` Oleg Nesterov [this message]
2009-08-21 21:53 ` Roland Dreier
2009-08-22 10:35 ` Stefan Richter
2009-08-24 18:01 ` Oleg Nesterov
2009-08-24 21:11 ` Roland Dreier
2009-08-25 9:39 ` Oleg Nesterov
2009-08-26 18:42 ` Roland Dreier
2009-08-28 17:59 ` [PATCH 0/1] introduce __cancel_delayed_work() Oleg Nesterov
2009-08-28 18:00 ` [PATCH 1/1] " Oleg Nesterov
2009-09-01 16:09 ` Roland Dreier
2009-09-01 16:40 ` Dmitry Torokhov
2009-09-01 22:29 ` Andrew Morton
2009-09-01 0:44 ` Is adding requeue_delayed_work() a good idea Dmitry Torokhov
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090821115547.GA6901@redhat.com \
--to=oleg@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rdreier@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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 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.