Skip to contentSkip to conversation

ktimers subsystem

PATCH Oleg Nesterov 2 participants 2 messages Sep 21, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 15 lines · Thomas Gleixner
(quoted diff) +14 -0
+static int internal_restart_ktimer(struct ktimer *timer, nsec_t *tim,
+				   int mode)
+{
+	struct ktimer_base *base, *new_base;
+  	unsigned long flags;
+	int ret;
+
+	BUG_ON(!timer->function);
+
+ retry:
+	base = lock_ktimer_base(timer, &flags);
+
+	/* Remove an active timer from the queue */
+	ret = remove_ktimer(timer, base);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+	/* Switch the timer base, if necessary */
+	new_base = switch_ktimer_base(timer, base);
+
+	/* SMP  */
+	if (ktimer_base_can_change && unlikely(!new_base)){
+		spin_unlock_irqrestore(&base->lock, flags);
+		wait_for_ktimer(timer);
+		goto retry;
+	}

This is deadlockable.

The caller of modify_ktimer()->internal_restart_ktimer() can hold locks which would prevent the completion of the ktimer->function().

Also, I don't understand why the timer is deleted _before_ checking that new_base != NULL. This way you can delete the timer (ret == 1), then goto retry, then get ret == 0.

Oleg.

#1 lore raw
Quoted 4 lines · Oleg Nesterov

This is deadlockable.

The caller of modify_ktimer()->internal_restart_ktimer() can hold locks which would prevent the completion of the ktimer->function().

True. You are right it is a potential source of dead locking. The initial reason to implement it that way was that I wanted to avoid cross cpu enqueueing for the high resolution timer case as I thought it would make cross cpu timer event reprogramming necessary. But this is actually a non issue, as the reprogramming check can be done after the timer function has completed on the CPU where the function is running.

The loop is not necessary. I'll fix that up.

Quoted 3 lines

Also, I don't understand why the timer is deleted _before_ checking that new_base != NULL. This way you can delete the timer (ret == 1), then goto retry, then get ret == 0.

Right. The return value must only be set on the first call to remove_ktimer, but this is a non issue after removing the loop anyway.

Thanks for pointing this out,

tglx