public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign•ru>
To: David Howells <dhowells@redhat•com>
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 18:22:44 +0400	[thread overview]
Message-ID: <20070424142244.GA158@tv-sign.ru> (raw)
In-Reply-To: <9767.1177421824@redhat.com>

On 04/24, David Howells wrote:
>
> Oleg Nesterov <oleg@tv-sign•ru> wrote:
> 
> > > > We only care when del_timer() returns true. In that case, if the timer
> > > > function still runs (possible for single-threaded wqs), it has already
> > > > passed __queue_work().
> > > 
> > > Why do you assume that?
> 
> Sorry, I should have been more clear.  I meant the assumption that we only
> care about a true return from del_timer().
> 
> > If del_timer() returns true, the timer was pending. This means it was
> > started by work->func() (note that __run_timers() clears timer_pending()
> > before calling timer->function). This in turn means that
> > delayed_work_timer_fn() has already called __queue_work(dwork), otherwise
> > work->func() has no chance to run.
> 
> But if del_timer() returns 0, then there may be a problem.  We can't tell the
> difference between the following two cases:
> 
>  (1) The timer hadn't been started.
> 
>  (2) The timer had been started, has expired and is no longer pending, but
>      another CPU is running its handler routine.
> 
> try_to_del_timer_sync() _does_, however, distinguish between these cases: the
> first is the 0 return, the second is the -1 return, and the case where it
> dequeued the timer is the 1 return.

Of course, del_timer() and del_timer_sync() are different. What I meant the
latter buys nothing for cancel_delayed_work() (which in fact could be named
try_to_cancel_delayed_work()).

Let's look at (2). cancel_delayed_work() (on top of del_timer()) returns 0,
and this is correct, we failed to cancel the timer, and we don't know whether
work->func() finished, or not.

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.

I guess I misunderstood you. Perhaps, you propose a new helper which use
try_to_del_timer_sync(), yes? Unless I missed something, this doesn't help.
Because the return value == -1 should be treated as 0. We failed to stop
the timer, and we can't free dwork.

IOW, currently we should do:

	if (!cancel_delayed_work(dwork))
		cancel_work_sync(dwork));

The same if we use del_timer(). If we use try_to_del_timer_sync(),

	if (cancel_delayed_work(dwork) <= 0)
		cancel_work_sync(dwork));

(of course, dwork shouldn't re-arm itself).

Could you clarify if I misunderstood you again?

> BTW, can a timer handler be preempted?  I assume not...  But it can be delayed
> by interrupt processing.

No, it can't be preempted, it runs in softirq context.

Oleg.


  reply	other threads:[~2007-04-24 14:23 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 [this message]
2007-04-24 15:51                             ` David Howells
2007-04-24 16:40                               ` Oleg Nesterov
2007-04-24 16:58                                 ` David Howells
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=20070424142244.GA158@tv-sign.ru \
    --to=oleg@tv-sign$(echo .)ru \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=containers@lists$(echo .)osdl.org \
    --cc=davem@davemloft$(echo .)net \
    --cc=dhowells@redhat$(echo .)com \
    --cc=ebiederm@xmission$(echo .)com \
    --cc=hch@infradead$(echo .)org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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