PERFORCE change 99905 for review

Kip Macy kmacy at FreeBSD.org
Fri Jun 23 22:53:20 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=99905

Change 99905 by kmacy at kmacy_storage:sun4v_work_sleepq on 2006/06/23 22:52:43

	add profiling to sx locks

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sx.c#3 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_sx.c#3 (text+ko) ====

@@ -47,6 +47,7 @@
 #include <sys/mutex.h>
 #include <sys/proc.h>
 #include <sys/sx.h>
+#include <sys/lock_profile.h>
 
 #include <ddb/ddb.h>
 
@@ -85,6 +86,8 @@
 	cv_init(&sx->sx_excl_cv, description);
 	sx->sx_excl_wcnt = 0;
 	sx->sx_xholder = NULL;
+
+	lock_profile_init(&sx->sx_object, description);
 	lock_init(&sx->sx_object, &lock_class_sx, description, NULL,
 	    LO_WITNESS | LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE);
 }
@@ -101,6 +104,7 @@
 	cv_destroy(&sx->sx_shrd_cv);
 	cv_destroy(&sx->sx_excl_cv);
 
+	lock_profile_destroy(&sx->sx_object);
 	lock_destroy(&sx->sx_object);
 }
 
@@ -108,6 +112,8 @@
 _sx_slock(struct sx *sx, const char *file, int line)
 {
 
+	int contested;
+
 	mtx_lock(sx->sx_lock);
 	KASSERT(sx->sx_xholder != curthread,
 	    ("%s (%s): slock while xlock is held @ %s:%d\n", __func__,
@@ -119,13 +125,18 @@
 	 */
 	while (sx->sx_cnt < 0) {
 		sx->sx_shrd_wcnt++;
+		lock_profile_obtain_lock_failed(&sx->sx_object, &contested);
 		cv_wait(&sx->sx_shrd_cv, sx->sx_lock);
 		sx->sx_shrd_wcnt--;
 	}
 
+
 	/* Acquire a shared lock. */
 	sx->sx_cnt++;
 
+	if (sx->sx_cnt == 1)
+		lock_profile_obtain_lock_success(&sx->sx_object, file, line);
+
 	LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line);
 	WITNESS_LOCK(&sx->sx_object, 0, file, line);
 
@@ -153,7 +164,9 @@
 void
 _sx_xlock(struct sx *sx, const char *file, int line)
 {
-
+	
+	int contested;
+		
 	mtx_lock(sx->sx_lock);
 
 	/*
@@ -172,6 +185,7 @@
 	/* Loop in case we lose the race for lock acquisition. */
 	while (sx->sx_cnt != 0) {
 		sx->sx_excl_wcnt++;
+		lock_profile_obtain_lock_failed(&sx->sx_object, &contested);
 		cv_wait(&sx->sx_excl_cv, sx->sx_lock);
 		sx->sx_excl_wcnt--;
 	}
@@ -182,6 +196,7 @@
 	sx->sx_cnt--;
 	sx->sx_xholder = curthread;
 
+	lock_profile_obtain_lock_success(&sx->sx_object, file, line);
 	LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line);
 	WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line);
 
@@ -226,6 +241,9 @@
 	 * lockers won't be blocked forever, don't wake shared lock waiters if
 	 * there are exclusive lock waiters.
 	 */
+	if (sx->sx_cnt == 0)
+		lock_profile_release_lock(&sx->sx_object);
+
 	if (sx->sx_excl_wcnt > 0) {
 		if (sx->sx_cnt == 0)
 			cv_signal(&sx->sx_excl_cv);
@@ -251,6 +269,7 @@
 	sx->sx_cnt++;
 	sx->sx_xholder = NULL;
 
+	lock_profile_release_lock(&sx->sx_object);
 	/*
 	 * Wake up waiters if there are any.  Give precedence to slock waiters.
 	 */


More information about the p4-projects mailing list