Skip to contentSkip to conversation

virtual perfctr illegal sleep

PATCH New Mikael Pettersson 1 participant 1 message Sep 22, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtual perfctr illegal sleep

Andrew,

This patch fixes an illegal sleep issue in perfctr's virtualised per-process counters: a spinlock is taken around calls to perfctr_cpu_{reserve,release}() which sleeps on a mutex. Change the spinlock to a mutex too.

The problem was reported by Sami Farin.

Strangely enough, DEBUG_SPINLOCK_SLEEP only triggers if I also have PREEMPT enabled. Is it supposed to be like that?

drivers/perfctr/virtual.c +5 -5
diff -rupN linux-2.6.9-rc2-mm1/drivers/perfctr/virtual.c linux-2.6.9-rc2-mm1.virtual-perfctr-illegal-sleep-fix/drivers/perfctr/virtual.c
@@ -91,7 +91,7 @@ static inline void vperfctr_init_bad_cpu
  ****************************************************************/
 
 /* XXX: perhaps relax this to number of _live_ perfctrs */
-static spinlock_t nrctrs_lock = SPIN_LOCK_UNLOCKED;
+static DECLARE_MUTEX(nrctrs_mutex);
 static int nrctrs;
 static const char this_service[] = __FILE__;
 
@@ -100,13 +100,13 @@ static int inc_nrctrs(void)
 	const char *other;
 
 	other = NULL;
-	spin_lock(&nrctrs_lock);
+	down(&nrctrs_mutex);
 	if (++nrctrs == 1) {
 		other = perfctr_cpu_reserve(this_service);
 		if (other)
 			nrctrs = 0;
 	}
-	spin_unlock(&nrctrs_lock);
+	up(&nrctrs_mutex);
 	if (other) {
 		printk(KERN_ERR __FILE__
 		       ": cannot operate, perfctr hardware taken by '%s'\n",
@@ -119,10 +119,10 @@ static int inc_nrctrs(void)
 
 static void dec_nrctrs(void)
 {
-	spin_lock(&nrctrs_lock);
+	down(&nrctrs_mutex);
 	if (--nrctrs == 0)
 		perfctr_cpu_release(this_service);
-	spin_unlock(&nrctrs_lock);
+	up(&nrctrs_mutex);
 }
 
 /* Allocate a `struct vperfctr'. Claim and reserve