Skip to contentSkip to conversation

migrate_timers: add comment, use spinlock_irq()

PATCH In review Oleg Nesterov 2 participants 2 messages Jun 28, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migrate_timers: add comment, use spinlock_irq()

Add the comment to explain why the double lock in migrate_timers() can't deadlock.

Change the code to use spinlock_irq() instead of local_irq_disable()
+ spin_lock().

kernel/timer.c renamed from kernel/timer.c~MIGRATE_TIMERS +6 -5
@@ -1443,9 +1443,11 @@ static void __cpuinit migrate_timers(int
 	BUG_ON(cpu_online(cpu));
 	old_base = per_cpu(tvec_bases, cpu);
 	new_base = get_cpu_var(tvec_bases);
-
-	local_irq_disable();
-	spin_lock(&new_base->lock);
+	/*
+	 * The caller is globally serialized and nobody else
+	 * takes two locks at once, deadlock is not possible.
+	 */
+	spin_lock_irq(&new_base->lock);
 	spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
 
 	BUG_ON(old_base->running_timer);
@@ -1460,8 +1462,7 @@ static void __cpuinit migrate_timers(int
 	}
 
 	spin_unlock(&old_base->lock);
-	spin_unlock(&new_base->lock);
-	local_irq_enable();
+	spin_unlock_irq(&new_base->lock);
 	put_cpu_var(tvec_bases);
 }
 #endif /* CONFIG_HOTPLUG_CPU */
kernel/hrtimer.c renamed from kernel/hrtimer.c~MIGRATE_TIMERS +6 -5
@@ -1615,9 +1615,11 @@ static void migrate_hrtimers(int cpu)
 	new_base = &get_cpu_var(hrtimer_bases);
 
 	tick_cancel_sched_timer(cpu);
-
-	local_irq_disable();
-	spin_lock(&new_base->lock);
+	/*
+	 * The caller is globally serialized and nobody else
+	 * takes two locks at once, deadlock is not possible.
+	 */
+	spin_lock_irq(&new_base->lock);
 	spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
 
 	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
@@ -1626,8 +1628,7 @@ static void migrate_hrtimers(int cpu)
 	}
 
 	spin_unlock(&old_base->lock);
-	spin_unlock(&new_base->lock);
-	local_irq_enable();
+	spin_unlock_irq(&new_base->lock);
 	put_cpu_var(hrtimer_bases);
 }
 #endif /* CONFIG_HOTPLUG_CPU */