PERFORCE change 97913 for review
Kip Macy
kmacy at FreeBSD.org
Fri May 26 16:47:43 PDT 2006
http://perforce.freebsd.org/chv.cgi?CH=97913
Change 97913 by kmacy at kmacy_storage:sun4v_work on 2006/05/26 23:45:37
Add Kris Kennaway's spinlock profiling
Affected files ...
.. //depot/projects/kmacy_sun4v/src/sys/conf/options#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/lock.h#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/mutex.h#3 edit
Differences ...
==== //depot/projects/kmacy_sun4v/src/sys/conf/options#7 (text+ko) ====
@@ -512,6 +512,7 @@
MUTEX_DEBUG opt_global.h
MUTEX_NOINLINE opt_global.h
MUTEX_PROFILING opt_global.h
+SPIN_PROFILING opt_global.h
MSIZE opt_global.h
REGRESSION opt_global.h
RESTARTABLE_PANICS opt_global.h
==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#5 (text+ko) ====
@@ -116,6 +116,41 @@
struct mtx sched_lock;
struct mtx Giant;
+#ifdef SPIN_PROFILING
+SYSCTL_NODE(_debug, OID_AUTO, spinlock, CTLFLAG_RD, NULL, "spinlock debugging");
+SYSCTL_NODE(_debug_spinlock, OID_AUTO, prof, CTLFLAG_RD, NULL, "spinlock profiling");
+int spin_prof_enable = 0;
+SYSCTL_INT(_debug_spinlock_prof, OID_AUTO, enable, CTLFLAG_RW,
+ &spin_prof_enable, 0, "Enable tracing of spinlock holdtime");
+int spin_total = 0;
+int spin_count = 0;
+SYSCTL_INT(_debug_spinlock_prof, OID_AUTO, total, CTLFLAG_RD,
+ &spin_total, 0, "Number of spinlock spins recorded");
+SYSCTL_INT(_debug_spinlock_prof, OID_AUTO, count, CTLFLAG_RD,
+ &spin_count, 0, "Number of spinlock acquisitions recorded");
+
+static int
+reset_spin_prof_stats(SYSCTL_HANDLER_ARGS)
+{
+ int v = 0, error;
+
+ error = sysctl_handle_int(oidp, &v, 0, req);
+ if (error)
+ return (error);
+ if (req->newptr == NULL)
+ return (error);
+ if (v == 0)
+ return (0);
+
+ spin_total = 0;
+ spin_count = 0;
+ return (0);
+}
+
+SYSCTL_PROC(_debug_spinlock_prof, OID_AUTO, reset, CTLTYPE_INT | CTLFLAG_RW,
+ NULL, 0, reset_spin_prof_stats, "I", "Reset spinlock profiling statistics");
+#endif
+
#ifdef MUTEX_PROFILING
SYSCTL_NODE(_debug, OID_AUTO, mutex, CTLFLAG_RD, NULL, "mutex debugging");
SYSCTL_NODE(_debug_mutex, OID_AUTO, prof, CTLFLAG_RD, NULL, "mutex profiling");
@@ -592,6 +627,12 @@
int line)
{
int i = 0;
+#ifdef SPIN_PROFILING
+ int profiling = 0;
+
+ if (m->mtx_object.lo_flags & LO_PROFILE && spin_prof_enable)
+ profiling = 1;
+#endif
if (LOCK_LOG_TEST(&m->mtx_object, opts))
CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
@@ -622,6 +663,13 @@
}
spinlock_enter();
}
+#ifdef SPIN_PROFILING
+ /* We have the lock, record how many spins it took to get it */
+ if (profiling) {
+ spin_total += i;
+ spin_count++;
+ }
+#endif
if (LOCK_LOG_TEST(&m->mtx_object, opts))
CTR1(KTR_LOCK, "_mtx_lock_spin: %p spin done", m);
@@ -849,6 +897,8 @@
flags |= LO_WITNESS;
if (opts & MTX_DUPOK)
flags |= LO_DUPOK;
+ if (opts & MTX_PROFILE)
+ flags |= LO_PROFILE;
/* Initialize mutex. */
m->mtx_lock = MTX_UNOWNED;
@@ -907,7 +957,7 @@
* Initialize mutexes.
*/
mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
- mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE);
+ mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE | MTX_PROFILE);
mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
mtx_lock(&Giant);
==== //depot/projects/kmacy_sun4v/src/sys/sys/lock.h#4 (text+ko) ====
@@ -69,6 +69,7 @@
#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */
#define LO_ENROLLPEND 0x00800000 /* On the pending enroll list. */
#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */
+#define LO_PROFILE 0x10000000 /* Enable per-lock profiling */
/*
* Lock classes are statically assigned an index into the gobal lock_classes
==== //depot/projects/kmacy_sun4v/src/sys/sys/mutex.h#3 (text+ko) ====
@@ -56,6 +56,7 @@
#define MTX_SPIN 0x00000001 /* Spin lock (disables interrupts) */
#define MTX_RECURSE 0x00000004 /* Option: lock allowed to recurse */
#define MTX_NOWITNESS 0x00000008 /* Don't do any witness checking. */
+#define MTX_PROFILE 0x00000010 /* Enable spinlock profiling for this spin lock */
/*
* Option flags passed to certain lock/unlock routines, through the use
@@ -164,6 +165,9 @@
*/
#ifndef _get_spin_lock
#ifdef SMP
+#ifdef SPIN_PROFILING
+extern int spin_prof_enable;
+extern int spin_count;
#define _get_spin_lock(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
\
@@ -174,7 +178,22 @@
else \
_mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
} \
+ else if ((mp)->mtx_object.lo_flags & LO_PROFILE && spin_prof_enable) \
+ spin_count++; \
} while (0)
+#else /* SPIN_PROFILING */
+#define _get_spin_lock(mp, tid, opts, file, line) do { \
+ uintptr_t _tid = (uintptr_t)(tid); \
+ \
+ spinlock_enter(); \
+ if (!_obtain_lock((mp), _tid)) { \
+ if ((mp)->mtx_lock == _tid) \
+ (mp)->mtx_recurse++; \
+ else \
+ _mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
+ } \
+} while (0)
+#endif /* SPIN_PROFILING */
#else /* SMP */
#define _get_spin_lock(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
More information about the p4-projects
mailing list