Date: Sat, 15 May 2010 21:21:40 +0000 (UTC) From: Kip Macy <kmacy@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r208121 - in user/kmacy/stable_7_page_lock/sys: amd64/amd64 kern sys Message-ID: <201005152121.o4FLLejW094348@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kmacy Date: Sat May 15 21:21:40 2010 New Revision: 208121 URL: http://svn.freebsd.org/changeset/base/208121 Log: MFH 207140: generalize lock stack operations and move to subr_lock.c Modified: user/kmacy/stable_7_page_lock/sys/amd64/amd64/pmap.c user/kmacy/stable_7_page_lock/sys/kern/kern_mutex.c user/kmacy/stable_7_page_lock/sys/kern/subr_lock.c user/kmacy/stable_7_page_lock/sys/sys/lock.h Directory Properties: user/kmacy/stable_7_page_lock/sys/ (props changed) user/kmacy/stable_7_page_lock/sys/cddl/contrib/opensolaris/ (props changed) user/kmacy/stable_7_page_lock/sys/contrib/dev/acpica/ (props changed) user/kmacy/stable_7_page_lock/sys/contrib/pf/ (props changed) Modified: user/kmacy/stable_7_page_lock/sys/amd64/amd64/pmap.c ============================================================================== --- user/kmacy/stable_7_page_lock/sys/amd64/amd64/pmap.c Sat May 15 21:18:15 2010 (r208120) +++ user/kmacy/stable_7_page_lock/sys/amd64/amd64/pmap.c Sat May 15 21:21:40 2010 (r208121) @@ -295,73 +295,6 @@ static vm_offset_t pmap_kmem_choose(vm_o CTASSERT(1 << PDESHIFT == sizeof(pd_entry_t)); 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; -} - -static void -ls_push(struct lock_stack *ls, struct mtx *lock) -{ - - KASSERT(ls->ls_top < LS_MAX, ("lock stack overflow")); - - ls->ls_array[ls->ls_top] = lock; - ls->ls_top++; - mtx_lock(lock); -} - - -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 @@ -3453,14 +3386,18 @@ 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)); 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)); } } @@ -3484,8 +3421,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)); opalocked = FALSE; opa = 0; goto restart; @@ -3494,17 +3433,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)); goto restart; } } Modified: user/kmacy/stable_7_page_lock/sys/kern/kern_mutex.c ============================================================================== --- user/kmacy/stable_7_page_lock/sys/kern/kern_mutex.c Sat May 15 21:18:15 2010 (r208120) +++ user/kmacy/stable_7_page_lock/sys/kern/kern_mutex.c Sat May 15 21:21:40 2010 (r208121) @@ -88,6 +88,8 @@ __FBSDID("$FreeBSD$"); 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); static int unlock_mtx(struct lock_object *lock); static int unlock_spin(struct lock_object *lock); @@ -103,6 +105,10 @@ struct lock_class lock_class_mtx_sleep = #endif .lc_lock = lock_mtx, .lc_unlock = unlock_mtx, + .lc_lock_full = lock_full_mtx, + .lc_trylock = trylock_mtx, + + }; struct lock_class lock_class_mtx_spin = { .lc_name = "spin mutex", @@ -142,6 +148,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) { @@ -154,7 +179,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/stable_7_page_lock/sys/kern/subr_lock.c ============================================================================== --- user/kmacy/stable_7_page_lock/sys/kern/subr_lock.c Sat May 15 21:18:15 2010 (r208120) +++ user/kmacy/stable_7_page_lock/sys/kern/subr_lock.c Sat May 15 21:21:40 2010 (r208121) @@ -354,3 +354,69 @@ void _lock_profile_release_lock(struct l l->lpo_contest_holding = 0; } #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/stable_7_page_lock/sys/sys/lock.h ============================================================================== --- user/kmacy/stable_7_page_lock/sys/sys/lock.h Sat May 15 21:18:15 2010 (r208120) +++ user/kmacy/stable_7_page_lock/sys/sys/lock.h Sat May 15 21:21:40 2010 (r208121) @@ -60,6 +60,8 @@ struct lock_class { void (*lc_ddb_show)(struct lock_object *lock); void (*lc_lock)(struct lock_object *lock, int how); 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. */ @@ -248,6 +250,29 @@ void witness_display_spinlock(struct loc int witness_line(struct lock_object *); const char *witness_file(struct lock_object *); + +#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(). */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005152121.o4FLLejW094348>