Date: Fri, 24 Feb 2006 15:09:05 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 92336 for review Message-ID: <200602241509.k1OF957n098368@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=92336 Change 92336 by jhb@jhb_zion on 2006/02/24 15:08:55 - Make the spin lock too long panic message more useful and more accurate (the "5 seconds" is dubious). - Allow idle threads to spin on sched_lock forever. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#118 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#118 (text+ko) ==== @@ -91,8 +91,9 @@ */ #define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED) -#define mtx_owner(m) (mtx_unowned((m)) ? NULL \ - : (struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) +#define mtx_rawowner(m) ((struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) + +#define mtx_owner(m) (mtx_unowned((m)) ? NULL : mtx_rawowner((m))) #ifdef DDB static void db_show_mtx(struct lock_object *lock); @@ -550,7 +551,8 @@ if (m != &Giant && TD_IS_RUNNING(owner)) { #endif turnstile_release(&m->mtx_object); - while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) { + while (mtx_rawowner(m) == owner && + TD_IS_RUNNING(owner)) { cpu_spinwait(); } continue; @@ -606,7 +608,8 @@ _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { - int i = 0; + int i = 0, idlespin = 0; + struct thread *td; #ifdef __i386__ int apic_hack; #endif @@ -614,6 +617,9 @@ if (LOCK_LOG_TEST(&m->mtx_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); + /* It's ok for the idle loop to spin forever on sched_lock. */ + if (m == &sched_lock && curthread == PCPU_GET(idlethread)) + idlespin = 1; for (;;) { if (_obtain_lock(m, tid)) break; @@ -630,14 +636,17 @@ cpu_spinwait(); continue; } - if (i < 60000000) + if (i < 60000000 || kdb_active || panicstr != NULL || + idlespin) DELAY(1); - else if (!kdb_active && !panicstr) { - printf("spin lock %s held by %p for > 5 seconds\n", - m->mtx_object.lo_name, (void *)m->mtx_lock); + else { + td = mtx_owner(m); + printf( + "spin lock %p (%s) held by %p (tid %d) too long\n", + m, m->mtx_object.lo_name, mtx_rawowner(m), + td ? td->td_tid : -1); #ifdef WITNESS - witness_display_spinlock(&m->mtx_object, - mtx_owner(m)); + witness_display_spinlock(&m->mtx_object, td); #endif panic("spin lock held too long"); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602241509.k1OF957n098368>