Re: [PATCH] make cancel_rearming_delayed_work() reliable

Jarek Poplawski
2007-05-08T14:26:08Z

On Tue, May 08, 2007 at 06:05:17PM +0400, Oleg Nesterov wrote:
> On 05/08, Jarek Poplawski wrote:
> >
> > On Tue, May 08, 2007 at 04:31:02PM +0400, Oleg Nesterov wrote:
> > >
> > > I thought about adding such a parameter, and I don't like this. This is
> > > a matter of taste, of course, but _imho_ this uglifies the code.
> > >
> > > In any case, unless we do completely different patch, the sequence should be
> > >
> > > del_timer() - a pending timer is the most common case
> > >
> > > test_and_set_bit(WORK_STRUCT_PENDING) - the work is idle
> > >
> > > try-to-steal-the-queued-work
> > >
> > > This is what we are doing now.
> >
> > I simply don't like to call del_timer(), where not needed, but maybe
> > it's not so expensive and we can afford it...
>
> But this is the most common case, that was my point.

And I agree it should start...

>
> Look, we can add
>
> if (!get_wq_data(work))
> /* it was never queued */
> return;
>
> at the very start of cancel_xxx() functions. This will optimize out
> del_timer + try_to_grab_pending() _sometimes_. Should we do this?
> I don't think so. I think it is better to save a couple of bytes
> from i-cache, but not to try to optimize the unlikely case.

But the most of our test is already done in test_and_set_bit.
I think it's more about taste, so let's forget...

> > > So, we should either return 0, or add BUG_ON(!cwq).
> >
> > ...And you prefer endless loop. Seems brave!
>
> No, no, the loop won't be endless. Why do you think so? We spin until the timer
> is started, or until the work is queued.

Probably you are right - I was afraid about some inactive
work with no timer to come.

So, I think this all looks fine, and maybe one more needless ack
won't do any harm here:

Acked-by: Jarek Poplawski <jarkao2@o2.pl>