PERFORCE change 100182 for review

Kip Macy kmacy at FreeBSD.org
Wed Jun 28 03:37:18 UTC 2006


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

Change 100182 by kmacy at kmacy_storage:sun4v_work_sleepq on 2006/06/28 03:36:26

	add timeout functionality to sxu locks
	and sxu.h header as a base

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#2 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#1 add

Differences ...

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

@@ -110,13 +110,16 @@
 	lock_destroy(&sx->sx_object);
 }
 
-void
-_sx_slock(struct sx *sx, const char *file, int line)
+int
+_sx_slock(struct sx *sx, int timo, const char *file, int line)
 {
 
-	int contested;
-	uint64_t waittime = 0;
-
+	int contested, error;
+	uint64_t waittime;
+	
+	waittime = 0;
+	error = 0;
+	
 	mtx_lock(sx->sx_lock);
 	KASSERT(sx->sx_xholder != curthread,
 	    ("%s (%s): slock while xlock is held @ %s:%d\n", __func__,
@@ -131,8 +134,13 @@
 	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);
+		if (timo)
+			error = cv_timedwait(&sx->sx_shrd_cv, sx->sx_lock, timo);
+		else
+			cv_wait(&sx->sx_shrd_cv, sx->sx_lock);
 		sx->sx_shrd_wcnt--;
+		if (error)
+			goto fail;
 	}
 
 
@@ -145,7 +153,9 @@
 	LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line);
 	WITNESS_LOCK(&sx->sx_object, 0, file, line);
 
+ fail:
 	mtx_unlock(sx->sx_lock);
+	return (error);
 }
 
 int
@@ -166,12 +176,15 @@
 	}
 }
 
-void
-_sx_xlock(struct sx *sx, const char *file, int line)
+int
+_sx_xlock(struct sx *sx, int timo, const char *file, int line)
 {
 	
-	int contested;
-	uint64_t waittime = 0;
+	int contested, error;
+	uint64_t waittime;
+	
+	error = 0;
+	waittime= 0;
 	
 	mtx_lock(sx->sx_lock);
 
@@ -194,8 +207,14 @@
 	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);
+		if (timo)
+			error = cv_timedwait(&sx->sx_excl_cv, sx->sx_lock, timo);
+		else
+			cv_wait(&sx->sx_excl_cv, sx->sx_lock);
 		sx->sx_excl_wcnt--;
+		
+		if (error)
+			goto fail;
 	}
 
 	MPASS(sx->sx_cnt == 0);
@@ -208,7 +227,9 @@
 	LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line);
 	WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line);
 
+ fail:
 	mtx_unlock(sx->sx_lock);
+	return (error);
 }
 
 int
@@ -255,7 +276,7 @@
 	if (sx->sx_excl_wcnt > 0) {
 		if (sx->sx_cnt == 0)
 			cv_signal(&sx->sx_excl_cv);
-	} else if (sx->sx_shrd_wcnt > 0)
+	} else if (sx->sx_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */
 		cv_broadcast(&sx->sx_shrd_cv);
 
 	LOCK_LOG_LOCK("SUNLOCK", &sx->sx_object, 0, 0, file, line);


More information about the p4-projects mailing list