Re: [PATCH 1/9] timer locking optimization

From: Oleg Nesterov
Date: Tue Nov 29 2005 - 06:51:45 EST


Roman Zippel wrote:
>
> + base = timer->base;
> + spin_lock_irqsave(&base->lock, *flags);
> + while (unlikely(base != timer->base)) {
> + /* The timer has migrated to another CPU */
> + spin_unlock(&base->lock);
> cpu_relax();
> + base = timer->base;
> + spin_lock(&base->lock);

This spins with interrupts disabled, not good, imho.

> int __mod_timer(struct timer_list *timer, unsigned long expires)
> @@ -212,6 +207,7 @@ int __mod_timer(struct timer_list *timer
>
> base = lock_timer_base(timer, &flags);
>
> +restart:
> if (timer_pending(timer)) {
> detach_timer(timer, 0);
> ret = 1;
> @@ -231,11 +227,16 @@ int __mod_timer(struct timer_list *timer
> /* The timer remains on a former base */
> new_base = container_of(base, tvec_base_t, t_base);
> } else {
> - /* See the comment in lock_timer_base() */
> - timer->base = NULL;
> + /*
> + * We shortly release the timer and the timer can
> + * migrate to another cpu, so recheck the base after
> + * getting the lock.
> + */
> + timer->base = &new_base->t_base;
> spin_unlock(&base->lock);
> spin_lock(&new_base->t_base.lock);
> - timer->base = &new_base->t_base;
> + if (unlikely(timer->base != &new_base->t_base))
> + goto restart;

This is not right.

This way you can delete the timer (ret == 1), notice that timer's base
was changed after re-locking, goto restart, and get ret == 0.

Also, you have wrong value of 'base' after 'goto restart'.

Oleg.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/