From: David Howells <dhowells@redhat.com>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Miller <davem@davemloft.net>,
ebiederm@xmission.com, containers@lists.osdl.org,
hch@infradead.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: Getting the new RxRPC patches upstream
Date: Tue, 24 Apr 2007 17:58:27 +0100 [thread overview]
Message-ID: <16575.1177433907@redhat.com> (raw)
In-Reply-To: <20070424164001.GA328@tv-sign.ru>
Oleg Nesterov <oleg@tv-sign.ru> wrote:
> > > The current code uses del_timer_sync(). It will also return 0. However,
> > > it will spin waiting for timer->function() to complete. So we are just
> > > wasting CPU.
> >
> > That's my objection to using cancel_delayed_work() as it stands, although in
> > most cases it's a relatively minor waste of time. However, if the timer
> > expiry routine gets interrupted then it may not be so minor... So, yes, I'm
> > in full agreement with you there.
>
> Great. I'll send the s/del_timer_sync/del_timer/ patch.
I didn't say I necessarily agreed that this was a good idea. I just meant that
I agree that it will waste CPU. You must still audit all uses of
cancel_delayed_work().
> Aha, now I see what you mean. However. Why the code above is better then
>
> cancel_delayed_work(&afs_server_reaper);
> schedule_delayed_work(&afs_server_reaper, 0);
>
> ? (I assume we already changed cancel_delayed_work() to use del_timer).
Because calling schedule_delayed_work() is a waste of CPU if the timer expiry
handler is currently running at this time as *that* is going to also schedule
the delayed work item.
> If delayed_work_timer_fn() is not running - both variants (let's denote them
> as 1 and 2) do the same.
Yes, but that's not the point.
> Now suppose that delayed_work_timer_fn() is running.
>
> 1: lock_timer_base(), return -1, skip schedule_delayed_work().
>
> 2: check timer_pending(), return 0, call schedule_delayed_work(),
> return immediately because test_and_set_bit(WORK_STRUCT_PENDING)
> fails.
I don't see what you're illustrating here. Are these meant to be two steps in
a single process? Or are they two alternate steps?
> So I still don't think try_to_del_timer_sync() can help in this particular
> case.
It permits us to avoid the test_and_set_bit() under some circumstances.
> To some extent, try_to_cancel_delayed_work is
>
> int try_to_cancel_delayed_work(dwork)
> {
> ret = cancel_delayed_work(dwork);
> if (!ret && work_pending(&dwork->work))
> ret = -1;
> return ret;
> }
>
> iow, work_pending() looks like a more "precise" indication that work->func()
> is going to run soon.
Ah, but the timer routine may try to set the work item pending flag *after* the
work_pending() check you have here. Furthermore, it would be better to avoid
the work_pending() check entirely because that check involves interacting with
atomic ops done on other CPUs. try_to_del_timer_sync() returning -1 tells us
without a shadow of a doubt that the work item is either scheduled now or will
be scheduled very shortly, thus allowing us to avoid having to do it ourself.
David
next prev parent reply other threads:[~2007-04-24 16:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <11769696211263-git-send-email-ebiederm@xmission.com>
[not found] ` <m1slawn9eb.fsf@ebiederm.dsl.xmission.com>
[not found] ` <29341.1176975158@redhat.com>
[not found] ` <m1lkgoms4j.fsf@ebiederm.dsl.xmission.com>
2007-04-19 14:18 ` Getting the new RxRPC patches upstream David Howells
2007-04-19 15:50 ` Eric W. Biederman
2007-04-19 16:18 ` David Howells
2007-04-19 19:14 ` Eric W. Biederman
2007-04-19 20:14 ` David Miller
2007-04-20 1:15 ` Herbert Xu
2007-04-20 8:02 ` David Howells
2007-04-20 8:58 ` David Miller
2007-04-20 10:41 ` David Howells
2007-04-20 18:38 ` Andrew Morton
2007-04-20 21:28 ` Oleg Nesterov
2007-04-23 8:32 ` David Howells
2007-04-23 17:11 ` Oleg Nesterov
2007-04-24 13:37 ` David Howells
2007-04-24 14:22 ` Oleg Nesterov
2007-04-24 15:51 ` David Howells
2007-04-24 16:40 ` Oleg Nesterov
2007-04-24 16:58 ` David Howells [this message]
2007-04-24 17:33 ` Oleg Nesterov
2007-04-24 18:22 ` David Howells
2007-04-24 19:34 ` Oleg Nesterov
2007-04-25 8:10 ` David Howells
2007-04-25 10:41 ` Oleg Nesterov
2007-04-25 10:45 ` David Howells
2007-04-25 13:48 ` David Howells
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=16575.1177433907@redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=containers@lists.osdl.org \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oleg@tv-sign.ru \
/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 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).