[PATCH][2.6.9-rc2-mm1] virtual perfctr illegal sleep

From: Mikael Pettersson
Date: Wed Sep 22 2004 - 03:23:22 EST


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?

Signed-off-by: Mikael Pettersson <mikpe@xxxxxxxxx>

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
--- linux-2.6.9-rc2-mm1/drivers/perfctr/virtual.c 2004-09-22 01:00:48.000000000 +0200
+++ linux-2.6.9-rc2-mm1.virtual-perfctr-illegal-sleep-fix/drivers/perfctr/virtual.c 2004-09-22 01:08:41.811834000 +0200
@@ -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
-
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/