Date: Tue, 31 Jan 2012 01:45:20 +0000 (UTC) From: Attilio Rao <attilio@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r230799 - in stable/9/sys: dev/ppbus sys vm Message-ID: <201201310145.q0V1jKx7012357@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: attilio Date: Tue Jan 31 01:45:20 2012 New Revision: 230799 URL: http://svn.freebsd.org/changeset/base/230799 Log: MFC r227758,227759,227788: Introduce macro stubs in the mutex and sxlock implementation that will be always defined and will allow consumers, willing to provide options, file and line to locking requests, to not worry about options redefining the interfaces. This is typically useful when there is the need to build another locking interface on top of the mutex one. Requested by: kib Modified: stable/9/sys/dev/ppbus/ppb_base.c stable/9/sys/sys/mutex.h stable/9/sys/sys/sx.h stable/9/sys/vm/vm_map.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/amd64/include/xen/ (props changed) stable/9/sys/boot/ (props changed) stable/9/sys/boot/i386/efi/ (props changed) stable/9/sys/boot/ia64/efi/ (props changed) stable/9/sys/boot/ia64/ski/ (props changed) stable/9/sys/boot/powerpc/boot1.chrp/ (props changed) stable/9/sys/boot/powerpc/ofw/ (props changed) stable/9/sys/cddl/contrib/opensolaris/ (props changed) stable/9/sys/conf/ (props changed) stable/9/sys/contrib/dev/acpica/ (props changed) stable/9/sys/contrib/octeon-sdk/ (props changed) stable/9/sys/contrib/pf/ (props changed) stable/9/sys/contrib/x86emu/ (props changed) Modified: stable/9/sys/dev/ppbus/ppb_base.c ============================================================================== --- stable/9/sys/dev/ppbus/ppb_base.c Tue Jan 31 01:43:03 2012 (r230798) +++ stable/9/sys/dev/ppbus/ppb_base.c Tue Jan 31 01:45:20 2012 (r230799) @@ -236,11 +236,8 @@ ppb_unlock(device_t bus) void _ppb_assert_locked(device_t bus, const char *file, int line) { -#ifdef INVARIANTS - struct ppb_data *ppb = DEVTOSOFTC(bus); - _mtx_assert(ppb->ppc_lock, MA_OWNED, file, line); -#endif + mtx_assert_(DEVTOSOFTC(bus)->ppc_lock, MA_OWNED, file, line); } void Modified: stable/9/sys/sys/mutex.h ============================================================================== --- stable/9/sys/sys/mutex.h Tue Jan 31 01:43:03 2012 (r230798) +++ stable/9/sys/sys/mutex.h Tue Jan 31 01:45:20 2012 (r230799) @@ -81,6 +81,10 @@ * of the kernel via macros, thus allowing us to use the cpp LOCK_FILE * and LOCK_LINE. These functions should not be called directly by any * code using the API. Their macros cover their functionality. + * Functions with a `_' suffix are the entrypoint for the common + * KPI covering both compat shims and fast path case. These can be + * used by consumers willing to pass options, file and line + * informations, in an option-independent way. * * [See below for descriptions] * @@ -109,6 +113,11 @@ void _mtx_assert(struct mtx *m, int what #endif void _thread_lock_flags(struct thread *, int, const char *, int); +#define mtx_trylock_flags_(m, opts, file, line) \ + _mtx_trylock((m), (opts), (file), (line)) + +#define thread_lock_flags_(tdp, opts, file, line) \ + _thread_lock_flags((tdp), (opts), (file), (line)) #define thread_lock(tdp) \ _thread_lock_flags((tdp), 0, __FILE__, __LINE__) #define thread_lock_flags(tdp, opt) \ @@ -290,27 +299,48 @@ extern struct mtx_pool *mtxpool_sleep; #error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/mutex.h> #endif #if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE) -#define mtx_lock_flags(m, opts) \ - _mtx_lock_flags((m), (opts), LOCK_FILE, LOCK_LINE) -#define mtx_unlock_flags(m, opts) \ - _mtx_unlock_flags((m), (opts), LOCK_FILE, LOCK_LINE) -#define mtx_lock_spin_flags(m, opts) \ - _mtx_lock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE) -#define mtx_unlock_spin_flags(m, opts) \ - _mtx_unlock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_lock_flags_(m, opts, file, line) \ + _mtx_lock_flags((m), (opts), (file), (line)) +#define mtx_unlock_flags_(m, opts, file, line) \ + _mtx_unlock_flags((m), (opts), (file), (line)) +#define mtx_lock_spin_flags_(m, opts, file, line) \ + _mtx_lock_spin_flags((m), (opts), (file), (line)) +#define mtx_unlock_spin_flags_(m, opts, file, line) \ + _mtx_unlock_spin_flags((m), (opts), (file), (line)) #else /* LOCK_DEBUG == 0 && !MUTEX_NOINLINE */ +#define mtx_lock_flags_(m, opts, file, line) \ + __mtx_lock((m), curthread, (opts), (file), (line)) +#define mtx_unlock_flags_(m, opts, file, line) \ + __mtx_unlock((m), curthread, (opts), (file), (line)) +#define mtx_lock_spin_flags_(m, opts, file, line) \ + __mtx_lock_spin((m), curthread, (opts), (file), (line)) +#define mtx_unlock_spin_flags_(m, opts, file, line) \ + __mtx_unlock_spin((m)) +#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */ + +#ifdef INVARIANTS +#define mtx_assert_(m, what, file, line) \ + _mtx_assert((m), (what), (file), (line)) + +#define GIANT_REQUIRED mtx_assert_(&Giant, MA_OWNED, __FILE__, __LINE__) + +#else /* INVARIANTS */ +#define mtx_assert_(m, what, file, line) (void)0 +#define GIANT_REQUIRED +#endif /* INVARIANTS */ + #define mtx_lock_flags(m, opts) \ - __mtx_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE) + mtx_lock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) #define mtx_unlock_flags(m, opts) \ - __mtx_unlock((m), curthread, (opts), LOCK_FILE, LOCK_LINE) + mtx_unlock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) #define mtx_lock_spin_flags(m, opts) \ - __mtx_lock_spin((m), curthread, (opts), LOCK_FILE, LOCK_LINE) + mtx_lock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE) #define mtx_unlock_spin_flags(m, opts) \ - __mtx_unlock_spin((m)) -#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */ - + mtx_unlock_spin_flags_((m), (opts), LOCK_FILE, LOCK_LINE) #define mtx_trylock_flags(m, opts) \ - _mtx_trylock((m), (opts), LOCK_FILE, LOCK_LINE) + mtx_trylock_flags_((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_assert(m, what) \ + mtx_assert_((m), (what), __FILE__, __LINE__) #define mtx_sleep(chan, mtx, pri, wmesg, timo) \ _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (timo)) @@ -398,17 +428,6 @@ struct mtx_args { #define MA_NOTRECURSED LA_NOTRECURSED #endif -#ifdef INVARIANTS -#define mtx_assert(m, what) \ - _mtx_assert((m), (what), __FILE__, __LINE__) - -#define GIANT_REQUIRED mtx_assert(&Giant, MA_OWNED) - -#else /* INVARIANTS */ -#define mtx_assert(m, what) (void)0 -#define GIANT_REQUIRED -#endif /* INVARIANTS */ - /* * Common lock type names. */ Modified: stable/9/sys/sys/sx.h ============================================================================== --- stable/9/sys/sys/sx.h Tue Jan 31 01:43:03 2012 (r230798) +++ stable/9/sys/sys/sx.h Tue Jan 31 01:45:20 2012 (r230799) @@ -115,6 +115,15 @@ void _sx_assert(struct sx *sx, int what, int sx_chain(struct thread *td, struct thread **ownerp); #endif +#define sx_downgrade_(sx, file, line) \ + _sx_downgrade((sx), (file), (line)) +#define sx_try_slock_(sx, file, line) \ + _sx_try_slock((sx), (file), (line)) +#define sx_try_xlock_(sx, file, line) \ + _sx_try_xlock((sx), (file), (line)) +#define sx_try_upgrade_(sx, file, line) \ + _sx_try_upgrade((sx), (file), (line)) + struct sx_args { struct sx *sa_sx; const char *sa_desc; @@ -208,30 +217,50 @@ __sx_sunlock(struct sx *sx, const char * #error "LOCK_DEBUG not defined, include <sys/lock.h> before <sys/sx.h>" #endif #if (LOCK_DEBUG > 0) || defined(SX_NOINLINE) -#define sx_xlock(sx) (void)_sx_xlock((sx), 0, LOCK_FILE, LOCK_LINE) -#define sx_xlock_sig(sx) \ - _sx_xlock((sx), SX_INTERRUPTIBLE, LOCK_FILE, LOCK_LINE) -#define sx_xunlock(sx) _sx_xunlock((sx), LOCK_FILE, LOCK_LINE) -#define sx_slock(sx) (void)_sx_slock((sx), 0, LOCK_FILE, LOCK_LINE) -#define sx_slock_sig(sx) \ - _sx_slock((sx), SX_INTERRUPTIBLE, LOCK_FILE, LOCK_LINE) -#define sx_sunlock(sx) _sx_sunlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_xlock_(sx, file, line) \ + (void)_sx_xlock((sx), 0, (file), (line)) +#define sx_xlock_sig_(sx, file, line) \ + _sx_xlock((sx), SX_INTERRUPTIBLE, (file), (line)) +#define sx_xunlock_(sx, file, line) \ + _sx_xunlock((sx), (file), (line)) +#define sx_slock_(sx, file, line) \ + (void)_sx_slock((sx), 0, (file), (line)) +#define sx_slock_sig_(sx, file, line) \ + _sx_slock((sx), SX_INTERRUPTIBLE, (file) , (line)) +#define sx_sunlock_(sx, file, line) \ + _sx_sunlock((sx), (file), (line)) #else -#define sx_xlock(sx) \ - (void)__sx_xlock((sx), curthread, 0, LOCK_FILE, LOCK_LINE) -#define sx_xlock_sig(sx) \ - __sx_xlock((sx), curthread, SX_INTERRUPTIBLE, LOCK_FILE, LOCK_LINE) -#define sx_xunlock(sx) \ - __sx_xunlock((sx), curthread, LOCK_FILE, LOCK_LINE) -#define sx_slock(sx) (void)__sx_slock((sx), 0, LOCK_FILE, LOCK_LINE) -#define sx_slock_sig(sx) \ - __sx_slock((sx), SX_INTERRUPTIBLE, LOCK_FILE, LOCK_LINE) -#define sx_sunlock(sx) __sx_sunlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_xlock_(sx, file, line) \ + (void)__sx_xlock((sx), curthread, 0, (file), (line)) +#define sx_xlock_sig_(sx, file, line) \ + __sx_xlock((sx), curthread, SX_INTERRUPTIBLE, (file), (line)) +#define sx_xunlock_(sx, file, line) \ + __sx_xunlock((sx), curthread, (file), (line)) +#define sx_slock_(sx, file, line) \ + (void)__sx_slock((sx), 0, (file), (line)) +#define sx_slock_sig_(sx, file, line) \ + __sx_slock((sx), SX_INTERRUPTIBLE, (file), (line)) +#define sx_sunlock_(sx, file, line) \ + __sx_sunlock((sx), (file), (line)) #endif /* LOCK_DEBUG > 0 || SX_NOINLINE */ -#define sx_try_slock(sx) _sx_try_slock((sx), LOCK_FILE, LOCK_LINE) -#define sx_try_xlock(sx) _sx_try_xlock((sx), LOCK_FILE, LOCK_LINE) -#define sx_try_upgrade(sx) _sx_try_upgrade((sx), LOCK_FILE, LOCK_LINE) -#define sx_downgrade(sx) _sx_downgrade((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_slock(sx) sx_try_slock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_xlock(sx) sx_try_xlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_upgrade(sx) sx_try_upgrade_((sx), LOCK_FILE, LOCK_LINE) +#define sx_downgrade(sx) sx_downgrade_((sx), LOCK_FILE, LOCK_LINE) +#ifdef INVARIANTS +#define sx_assert_(sx, what, file, line) \ + _sx_assert((sx), (what), (file), (line)) +#else +#define sx_assert_(sx, what, file, line) (void)0 +#endif + +#define sx_xlock(sx) sx_xlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_xlock_sig(sx) sx_xlock_sig_((sx), LOCK_FILE, LOCK_LINE) +#define sx_xunlock(sx) sx_xunlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_slock(sx) sx_slock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_slock_sig(sx) sx_slock_sig_((sx), LOCK_FILE, LOCK_LINE) +#define sx_sunlock(sx) sx_sunlock_((sx), LOCK_FILE, LOCK_LINE) +#define sx_assert(sx, what) sx_assert_((sx), (what), __FILE__, __LINE__) /* * Return a pointer to the owning thread if the lock is exclusively @@ -245,13 +274,15 @@ __sx_sunlock(struct sx *sx, const char * (((sx)->sx_lock & ~(SX_LOCK_FLAGMASK & ~SX_LOCK_SHARED)) == \ (uintptr_t)curthread) -#define sx_unlock(sx) do { \ +#define sx_unlock_(sx, file, line) do { \ if (sx_xlocked(sx)) \ - sx_xunlock(sx); \ + sx_xunlock_(sx, file, line); \ else \ - sx_sunlock(sx); \ + sx_sunlock_(sx, file, line); \ } while (0) +#define sx_unlock(sx) sx_unlock_((sx), LOCK_FILE, LOCK_LINE) + #define sx_sleep(chan, sx, pri, wmesg, timo) \ _sleep((chan), &(sx)->lock_object, (pri), (wmesg), (timo)) @@ -287,12 +318,6 @@ __sx_sunlock(struct sx *sx, const char * #define SX_NOTRECURSED LA_NOTRECURSED #endif -#ifdef INVARIANTS -#define sx_assert(sx, what) _sx_assert((sx), (what), LOCK_FILE, LOCK_LINE) -#else -#define sx_assert(sx, what) (void)0 -#endif - #endif /* _KERNEL */ #endif /* !_SYS_SX_H_ */ Modified: stable/9/sys/vm/vm_map.c ============================================================================== --- stable/9/sys/vm/vm_map.c Tue Jan 31 01:43:03 2012 (r230798) +++ stable/9/sys/vm/vm_map.c Tue Jan 31 01:45:20 2012 (r230799) @@ -464,9 +464,9 @@ _vm_map_lock(vm_map_t map, const char *f { if (map->system_map) - _mtx_lock_flags(&map->system_mtx, 0, file, line); + mtx_lock_flags_(&map->system_mtx, 0, file, line); else - (void)_sx_xlock(&map->lock, 0, file, line); + sx_xlock_(&map->lock, file, line); map->timestamp++; } @@ -489,9 +489,9 @@ _vm_map_unlock(vm_map_t map, const char { if (map->system_map) - _mtx_unlock_flags(&map->system_mtx, 0, file, line); + mtx_unlock_flags_(&map->system_mtx, 0, file, line); else { - _sx_xunlock(&map->lock, file, line); + sx_xunlock_(&map->lock, file, line); vm_map_process_deferred(); } } @@ -501,9 +501,9 @@ _vm_map_lock_read(vm_map_t map, const ch { if (map->system_map) - _mtx_lock_flags(&map->system_mtx, 0, file, line); + mtx_lock_flags_(&map->system_mtx, 0, file, line); else - (void)_sx_slock(&map->lock, 0, file, line); + sx_slock_(&map->lock, file, line); } void @@ -511,9 +511,9 @@ _vm_map_unlock_read(vm_map_t map, const { if (map->system_map) - _mtx_unlock_flags(&map->system_mtx, 0, file, line); + mtx_unlock_flags_(&map->system_mtx, 0, file, line); else { - _sx_sunlock(&map->lock, file, line); + sx_sunlock_(&map->lock, file, line); vm_map_process_deferred(); } } @@ -524,8 +524,8 @@ _vm_map_trylock(vm_map_t map, const char int error; error = map->system_map ? - !_mtx_trylock(&map->system_mtx, 0, file, line) : - !_sx_try_xlock(&map->lock, file, line); + !mtx_trylock_flags_(&map->system_mtx, 0, file, line) : + !sx_try_xlock_(&map->lock, file, line); if (error == 0) map->timestamp++; return (error == 0); @@ -537,8 +537,8 @@ _vm_map_trylock_read(vm_map_t map, const int error; error = map->system_map ? - !_mtx_trylock(&map->system_mtx, 0, file, line) : - !_sx_try_slock(&map->lock, file, line); + !mtx_trylock_flags_(&map->system_mtx, 0, file, line) : + !sx_try_slock_(&map->lock, file, line); return (error == 0); } @@ -558,21 +558,19 @@ _vm_map_lock_upgrade(vm_map_t map, const unsigned int last_timestamp; if (map->system_map) { -#ifdef INVARIANTS - _mtx_assert(&map->system_mtx, MA_OWNED, file, line); -#endif + mtx_assert_(&map->system_mtx, MA_OWNED, file, line); } else { - if (!_sx_try_upgrade(&map->lock, file, line)) { + if (!sx_try_upgrade_(&map->lock, file, line)) { last_timestamp = map->timestamp; - _sx_sunlock(&map->lock, file, line); + sx_sunlock_(&map->lock, file, line); vm_map_process_deferred(); /* * If the map's timestamp does not change while the * map is unlocked, then the upgrade succeeds. */ - (void)_sx_xlock(&map->lock, 0, file, line); + sx_xlock_(&map->lock, file, line); if (last_timestamp != map->timestamp) { - _sx_xunlock(&map->lock, file, line); + sx_xunlock_(&map->lock, file, line); return (1); } } @@ -586,11 +584,9 @@ _vm_map_lock_downgrade(vm_map_t map, con { if (map->system_map) { -#ifdef INVARIANTS - _mtx_assert(&map->system_mtx, MA_OWNED, file, line); -#endif + mtx_assert_(&map->system_mtx, MA_OWNED, file, line); } else - _sx_downgrade(&map->lock, file, line); + sx_downgrade_(&map->lock, file, line); } /* @@ -615,30 +611,15 @@ _vm_map_assert_locked(vm_map_t map, cons { if (map->system_map) - _mtx_assert(&map->system_mtx, MA_OWNED, file, line); - else - _sx_assert(&map->lock, SA_XLOCKED, file, line); -} - -#if 0 -static void -_vm_map_assert_locked_read(vm_map_t map, const char *file, int line) -{ - - if (map->system_map) - _mtx_assert(&map->system_mtx, MA_OWNED, file, line); + mtx_assert_(&map->system_mtx, MA_OWNED, file, line); else - _sx_assert(&map->lock, SA_SLOCKED, file, line); + sx_assert_(&map->lock, SA_XLOCKED, file, line); } -#endif #define VM_MAP_ASSERT_LOCKED(map) \ _vm_map_assert_locked(map, LOCK_FILE, LOCK_LINE) -#define VM_MAP_ASSERT_LOCKED_READ(map) \ - _vm_map_assert_locked_read(map, LOCK_FILE, LOCK_LINE) #else #define VM_MAP_ASSERT_LOCKED(map) -#define VM_MAP_ASSERT_LOCKED_READ(map) #endif /* @@ -661,9 +642,9 @@ _vm_map_unlock_and_wait(vm_map_t map, in mtx_lock(&map_sleep_mtx); if (map->system_map) - _mtx_unlock_flags(&map->system_mtx, 0, file, line); + mtx_unlock_flags_(&map->system_mtx, 0, file, line); else - _sx_xunlock(&map->lock, file, line); + sx_xunlock_(&map->lock, file, line); return (msleep(&map->root, &map_sleep_mtx, PDROP | PVM, "vmmaps", timo)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201310145.q0V1jKx7012357>