svn commit: r207140 - in user/kmacy/head_page_lock_2/sys: amd64/amd64 kern sys

Kip Macy kmacy at FreeBSD.org
Sat Apr 24 05:03:42 UTC 2010


Author: kmacy
Date: Sat Apr 24 05:03:42 2010
New Revision: 207140
URL: http://svn.freebsd.org/changeset/base/207140

Log:
  generalize lock stack operations and move to subr_lock.c

Modified:
  user/kmacy/head_page_lock_2/sys/amd64/amd64/pmap.c
  user/kmacy/head_page_lock_2/sys/kern/kern_mutex.c
  user/kmacy/head_page_lock_2/sys/kern/subr_lock.c
  user/kmacy/head_page_lock_2/sys/sys/lock.h

Modified: user/kmacy/head_page_lock_2/sys/amd64/amd64/pmap.c
==============================================================================
--- user/kmacy/head_page_lock_2/sys/amd64/amd64/pmap.c	Sat Apr 24 03:11:35 2010	(r207139)
+++ user/kmacy/head_page_lock_2/sys/amd64/amd64/pmap.c	Sat Apr 24 05:03:42 2010	(r207140)
@@ -305,77 +305,6 @@ CTASSERT(1 << PDESHIFT == sizeof(pd_entr
 CTASSERT(1 << PTESHIFT == sizeof(pt_entry_t));
 
 
-#define LS_MAX		4
-struct lock_stack {
-	struct mtx *ls_array[LS_MAX];
-	int ls_top;
-};
-
-static void
-ls_init(struct lock_stack *ls)
-{
-
-	ls->ls_top = 0;
-}
-
-#define ls_push(ls, m)	_ls_push((ls), (m), LOCK_FILE, LOCK_LINE)
-
-static void
-_ls_push(struct lock_stack *ls, struct mtx *lock, char *file, int line)
-{
-
-	KASSERT(ls->ls_top < LS_MAX, ("lock stack overflow"));
-	
-	ls->ls_array[ls->ls_top] = lock;
-	ls->ls_top++;
-#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE)	
-	_mtx_lock_flags(lock, 0, file, line);
-#else
-	_get_sleep_lock(lock, curthread, 0, file, line);
-#endif
-}
-
-static int
-ls_trypush(struct lock_stack *ls, struct mtx *lock)
-{
-
-	KASSERT(ls->ls_top < LS_MAX, ("lock stack overflow"));
-
-	if (mtx_trylock(lock) == 0)
-		return (0);
-	
-	ls->ls_array[ls->ls_top] = lock;
-	ls->ls_top++;
-	return (1);
-}
-
-#ifdef notyet
-static void
-ls_pop(struct lock_stack *ls)
-{
-	struct mtx *lock;
-
-	KASSERT(ls->ls_top > 0, ("lock stack underflow"));
-
-	ls->ls_top--;
-	lock = ls->ls_array[ls->ls_top];
-	mtx_unlock(lock);
-}
-#endif
-
-static void
-ls_popa(struct lock_stack *ls)
-{
-	struct mtx *lock;
-
-	KASSERT(ls->ls_top > 0, ("lock stack underflow"));
-
-	while (ls->ls_top > 0) {
-		ls->ls_top--;
-		lock = ls->ls_array[ls->ls_top];
-		mtx_unlock(lock);
-	}
-}
 #ifdef INVARIANTS
 extern void kdb_backtrace(void);
 #endif
@@ -3464,15 +3393,19 @@ pmap_enter(pmap_t pmap, vm_offset_t va, 
 	opa = 0;
 	opalocked = FALSE;
 	ls_init(&ls);
-	ls_push(&ls, PA_LOCKPTR(lockedpa));
-	ls_push(&ls, PMAP_LOCKPTR(pmap));
+	ls_push(&ls, &lock_class_mtx_sleep,
+	    (struct lock_object *)PA_LOCKPTR(lockedpa));
+	ls_push(&ls, &lock_class_mtx_sleep,
+	    (struct lock_object *)PMAP_LOCKPTR(pmap));
 	PMAP_UPDATE_GEN_COUNT(pmap);
 	if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) == 0) {
 		while ((pv = get_pv_entry(pmap)) == NULL) {
 			ls_popa(&ls);
 			VM_WAIT;
-			ls_push(&ls, PA_LOCKPTR(lockedpa));
-			ls_push(&ls, PMAP_LOCKPTR(pmap));
+			ls_push(&ls, &lock_class_mtx_sleep,
+			    (struct lock_object *)PA_LOCKPTR(lockedpa));
+			ls_push(&ls, &lock_class_mtx_sleep,
+			    (struct lock_object *)PMAP_LOCKPTR(pmap));
 			PMAP_UPDATE_GEN_COUNT(pmap);
 		}
 	}
@@ -3497,8 +3430,10 @@ restart:
 	origpte = *pte;
 	if (opa && (opa != (origpte & PG_FRAME))) {
 		ls_popa(&ls);
-		ls_push(&ls, PA_LOCKPTR(lockedpa));
-		ls_push(&ls, PMAP_LOCKPTR(pmap));
+		ls_push(&ls, &lock_class_mtx_sleep,
+			    (struct lock_object *)PA_LOCKPTR(lockedpa));
+		ls_push(&ls, &lock_class_mtx_sleep,
+			    (struct lock_object *)PMAP_LOCKPTR(pmap));
 		PMAP_UPDATE_GEN_COUNT(pmap);
 		opalocked = FALSE;
 		opa = 0;
@@ -3508,17 +3443,23 @@ restart:
 	opa = origpte & PG_FRAME;
 	if (opa && (opa != lockedpa) && (opalocked == FALSE)) {
 		opalocked = TRUE;
-		if (ls_trypush(&ls, PA_LOCKPTR(opa)) == 0) {
+		if (ls_trypush(&ls, &lock_class_mtx_sleep,
+			(struct lock_object *)PA_LOCKPTR(opa)) == 0) {
 			ls_popa(&ls);
 			if ((uintptr_t)PA_LOCKPTR(lockedpa) <
 			    (uintptr_t)PA_LOCKPTR(opa)) {
-				ls_push(&ls, PA_LOCKPTR(lockedpa));
-				ls_push(&ls, PA_LOCKPTR(opa));
+				ls_push(&ls, &lock_class_mtx_sleep,
+				    (struct lock_object *)PA_LOCKPTR(lockedpa));
+				ls_push(&ls, &lock_class_mtx_sleep,
+				    (struct lock_object *)PA_LOCKPTR(opa));
 			} else {
-				ls_push(&ls, PA_LOCKPTR(opa));
-				ls_push(&ls, PA_LOCKPTR(lockedpa));
+				ls_push(&ls, &lock_class_mtx_sleep,
+				    (struct lock_object *)PA_LOCKPTR(opa));
+				ls_push(&ls, &lock_class_mtx_sleep,
+				    (struct lock_object *)PA_LOCKPTR(lockedpa));
 			}
-			ls_push(&ls, PMAP_LOCKPTR(pmap));
+			ls_push(&ls, &lock_class_mtx_sleep,
+			    (struct lock_object *)PMAP_LOCKPTR(pmap));
 			PMAP_UPDATE_GEN_COUNT(pmap);
 			goto restart;
 		}

Modified: user/kmacy/head_page_lock_2/sys/kern/kern_mutex.c
==============================================================================
--- user/kmacy/head_page_lock_2/sys/kern/kern_mutex.c	Sat Apr 24 03:11:35 2010	(r207139)
+++ user/kmacy/head_page_lock_2/sys/kern/kern_mutex.c	Sat Apr 24 05:03:42 2010	(r207140)
@@ -90,6 +90,8 @@ static void	assert_mtx(struct lock_objec
 static void	db_show_mtx(struct lock_object *lock);
 #endif
 static void	lock_mtx(struct lock_object *lock, int how);
+static void	lock_full_mtx(struct lock_object *lock, char *file, int line);
+static int	trylock_mtx(struct lock_object *lock);
 static void	lock_spin(struct lock_object *lock, int how);
 #ifdef KDTRACE_HOOKS
 static int	owner_mtx(struct lock_object *lock, struct thread **owner);
@@ -112,6 +114,10 @@ struct lock_class lock_class_mtx_sleep =
 #ifdef KDTRACE_HOOKS
 	.lc_owner = owner_mtx,
 #endif
+	.lc_lock_full = lock_full_mtx,
+	.lc_trylock = trylock_mtx,
+	
+	
 };
 struct lock_class lock_class_mtx_spin = {
 	.lc_name = "spin mutex",
@@ -148,6 +154,25 @@ lock_mtx(struct lock_object *lock, int h
 }
 
 void
+lock_full_mtx(struct lock_object *lock, char *file, int line)
+{
+
+#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE)
+	_mtx_lock_flags((struct mtx *)lock, 0, file, line);
+#else
+	_get_sleep_lock((struct mtx *)lock, curthread, 0, file, line);
+#endif	
+	
+}
+
+int
+trylock_mtx(struct lock_object *lock)
+{
+
+	return (mtx_trylock((struct mtx *)lock));
+}
+
+void
 lock_spin(struct lock_object *lock, int how)
 {
 
@@ -160,7 +185,7 @@ unlock_mtx(struct lock_object *lock)
 	struct mtx *m;
 
 	m = (struct mtx *)lock;
-	mtx_assert(m, MA_OWNED | MA_NOTRECURSED);
+	mtx_assert(m, MA_OWNED);
 	mtx_unlock(m);
 	return (0);
 }

Modified: user/kmacy/head_page_lock_2/sys/kern/subr_lock.c
==============================================================================
--- user/kmacy/head_page_lock_2/sys/kern/subr_lock.c	Sat Apr 24 03:11:35 2010	(r207139)
+++ user/kmacy/head_page_lock_2/sys/kern/subr_lock.c	Sat Apr 24 05:03:42 2010	(r207140)
@@ -667,3 +667,69 @@ SYSCTL_PROC(_debug_lock_prof, OID_AUTO, 
     NULL, 0, enable_lock_prof, "I", "Enable lock profiling");
 
 #endif
+
+void
+ls_init(struct lock_stack *ls)
+{
+
+	ls->ls_top = 0;
+}
+
+void
+_ls_push(struct lock_stack *ls, struct lock_class *class, struct lock_object *lock,
+    char *file, int line)
+{
+
+	KASSERT(ls->ls_top < LS_MAX, ("lock stack overflow"));
+	
+	ls->ls_array[ls->ls_top].lse_lock = lock;
+	ls->ls_array[ls->ls_top].lse_class = class;
+	ls->ls_top++;
+	class->lc_lock_full(lock, file, line);
+}
+
+int
+ls_trypush(struct lock_stack *ls, struct lock_class *class, struct lock_object *lock)
+{
+
+	KASSERT(ls->ls_top < LS_MAX, ("lock stack overflow"));
+
+	if (class->lc_trylock(lock) == 0)
+		return (0);
+	
+	ls->ls_array[ls->ls_top].lse_lock = lock;
+	ls->ls_array[ls->ls_top].lse_class = class;
+	ls->ls_top++;
+	return (1);
+}
+
+void
+ls_pop(struct lock_stack *ls)
+{
+	struct lock_object *lock;
+	struct lock_class *class;
+
+	KASSERT(ls->ls_top > 0, ("lock stack underflow"));
+
+	ls->ls_top--;
+	lock = ls->ls_array[ls->ls_top].lse_lock;
+	class = ls->ls_array[ls->ls_top].lse_class;	
+	class->lc_unlock(lock);
+}
+
+void
+ls_popa(struct lock_stack *ls)
+{
+	struct lock_object *lock;
+	struct lock_class *class;
+
+	KASSERT(ls->ls_top > 0, ("lock stack underflow"));
+
+	while (ls->ls_top > 0) {
+		ls->ls_top--;
+		lock = ls->ls_array[ls->ls_top].lse_lock;
+		class = ls->ls_array[ls->ls_top].lse_class;
+		class->lc_unlock(lock);
+	}
+}
+

Modified: user/kmacy/head_page_lock_2/sys/sys/lock.h
==============================================================================
--- user/kmacy/head_page_lock_2/sys/sys/lock.h	Sat Apr 24 03:11:35 2010	(r207139)
+++ user/kmacy/head_page_lock_2/sys/sys/lock.h	Sat Apr 24 05:03:42 2010	(r207140)
@@ -63,6 +63,8 @@ struct lock_class {
 	void	(*lc_lock)(struct lock_object *lock, int how);
 	int	(*lc_owner)(struct lock_object *lock, struct thread **owner);
 	int	(*lc_unlock)(struct lock_object *lock);
+	void	(*lc_lock_full)(struct lock_object *lock, char *file, int line);
+	int	(*lc_trylock)(struct lock_object *lock);
 };
 
 #define	LC_SLEEPLOCK	0x00000001	/* Sleep lock. */
@@ -222,6 +224,29 @@ void	witness_releaseok(struct lock_objec
 const char *witness_file(struct lock_object *);
 void	witness_thread_exit(struct thread *);
 
+
+#define LS_MAX		4
+struct lock_stack_entry {
+	struct lock_object	*lse_lock;
+	struct lock_class	*lse_class;
+};
+
+struct lock_stack {
+	struct lock_stack_entry ls_array[LS_MAX];
+	int ls_top;
+};
+
+
+#define ls_push(ls, class, m)	_ls_push((ls), (class), (m), LOCK_FILE, LOCK_LINE)
+
+void	ls_init(struct lock_stack *ls);
+void 	_ls_push(struct lock_stack *ls, struct lock_class *class,
+    struct lock_object *lock, char *file, int line);
+int 	ls_trypush(struct lock_stack *ls, struct lock_class *class,
+    struct lock_object *lock);
+void 	ls_pop(struct lock_stack *ls);
+void 	ls_popa(struct lock_stack *ls);
+
 #ifdef	WITNESS
 
 /* Flags for witness_warn(). */


More information about the svn-src-user mailing list