Re: [PATCH] make-cancel_rearming_delayed_work-reliable-fix

Jarek Poplawski
2007-05-07T10:24:57Z

On Sun, May 06, 2007 at 01:32:13AM +0400, Oleg Nesterov wrote:
> on top of
> make-cancel_rearming_delayed_work-reliable-spelling.patch
>
> Add cpu-relax() into spinloops, and a comments update.
>
> Small note. The new implementation has another downside. Suppose that rearming
> work->func() gets a preemtion after setting WORK_STRUCT_PENDING but before
> add_timer/__queue_work. In that case cancel_rearming_delayed_work() will burn
> CPU in a busy-wait loop. Fortunately this can happen only with CONFIG_PREEMPT
> and we spin with preemption enabled.
>
> We can avoid this,
>
> void cancel_rearming_delayed_work(struct delayed_work *dwork)
> {
> int retry;
>
> do {
> retry = !del_timer(&dwork->timer) &&
> !try_to_grab_pending(&dwork->work);
> wait_on_work(&dwork->work);
> } while (retry);
>
> work_clear_pending(&dwork->work);
> }
>
> but I don't think this is worth fixing.

I think so.

There is a lot of new things in the final version of this
patch. I guess, there was no such problem in the previous
version.

I can also see you have new doubts about usefulness, which
I cannot understand:
- even if there are some slowdowns, where does it matter?
- the "old" method uses only one method of cancelling, i.e.
del_timer, not trying to stop requeuing or to remove from
the queue; it seems to be effective only with long delayed
timers, and its real problems are probably mostly invisible.

BTW, I'm still not convinced all additions are needed:
the "old" cancel_rearming_ doesn't care about checking
or waiting on anything after del_timer positive.

Regards,
Jarek P.

PS: I'll try to check this all in the evening and will
write tomorrow, if found something interesting.