Author: attilio
Date: Mon Nov 21 12:59:52 2011
New Revision: 227788
URL: http://svn.freebsd.org/changeset/base/227788

Log:
  Introduce the same mutex-wise fix in r227758 for sx locks.
  
  The functions that offer file and line specifications are:
  - sx_assert_
  - sx_downgrade_
  - sx_slock_
  - sx_slock_sig_
  - sx_sunlock_
  - sx_try_slock_
  - sx_try_xlock_
  - sx_try_upgrade_
  - sx_unlock_
  - sx_xlock_
  - sx_xlock_sig_
  - sx_xunlock_
  
  Now vm_map locking is fully converted and can avoid to know specifics
  about locking procedures.
  Reviewed by:  kib
  MFC after:    1 month

Modified:
  head/sys/kern/kern_sx.c
  head/sys/sys/sx.h
  head/sys/vm/vm_map.c

Modified: head/sys/kern/kern_sx.c
==============================================================================
--- head/sys/kern/kern_sx.c     Mon Nov 21 12:23:22 2011        (r227787)
+++ head/sys/kern/kern_sx.c     Mon Nov 21 12:59:52 2011        (r227788)
@@ -256,7 +256,7 @@ _sx_slock(struct sx *sx, int opts, const
 }
 
 int
-_sx_try_slock(struct sx *sx, const char *file, int line)
+sx_try_slock_(struct sx *sx, const char *file, int line)
 {
        uintptr_t x;
 
@@ -300,7 +300,7 @@ _sx_xlock(struct sx *sx, int opts, const
 }
 
 int
-_sx_try_xlock(struct sx *sx, const char *file, int line)
+sx_try_xlock_(struct sx *sx, const char *file, int line)
 {
        int rval;
 
@@ -364,7 +364,7 @@ _sx_xunlock(struct sx *sx, const char *f
  * Return 1 if if the upgrade succeed, 0 otherwise.
  */
 int
-_sx_try_upgrade(struct sx *sx, const char *file, int line)
+sx_try_upgrade_(struct sx *sx, const char *file, int line)
 {
        uintptr_t x;
        int success;
@@ -394,7 +394,7 @@ _sx_try_upgrade(struct sx *sx, const cha
  * Downgrade an unrecursed exclusive lock into a single shared lock.
  */
 void
-_sx_downgrade(struct sx *sx, const char *file, int line)
+sx_downgrade_(struct sx *sx, const char *file, int line)
 {
        uintptr_t x;
        int wakeup_swapper;

Modified: head/sys/sys/sx.h
==============================================================================
--- head/sys/sys/sx.h   Mon Nov 21 12:23:22 2011        (r227787)
+++ head/sys/sys/sx.h   Mon Nov 21 12:59:52 2011        (r227788)
@@ -94,14 +94,14 @@ void        sx_sysinit(void *arg);
 #define        sx_init(sx, desc)       sx_init_flags((sx), (desc), 0)
 void   sx_init_flags(struct sx *sx, const char *description, int opts);
 void   sx_destroy(struct sx *sx);
+int    sx_try_slock_(struct sx *sx, const char *file, int line);
+int    sx_try_xlock_(struct sx *sx, const char *file, int line);
+int    sx_try_upgrade_(struct sx *sx, const char *file, int line);
+void   sx_downgrade_(struct sx *sx, const char *file, int line);
 int    _sx_slock(struct sx *sx, int opts, const char *file, int line);
 int    _sx_xlock(struct sx *sx, int opts, const char *file, int line);
-int    _sx_try_slock(struct sx *sx, const char *file, int line);
-int    _sx_try_xlock(struct sx *sx, const char *file, int line);
 void   _sx_sunlock(struct sx *sx, const char *file, int line);
 void   _sx_xunlock(struct sx *sx, const char *file, int line);
-int    _sx_try_upgrade(struct sx *sx, const char *file, int line);
-void   _sx_downgrade(struct sx *sx, const char *file, int line);
 int    _sx_xlock_hard(struct sx *sx, uintptr_t tid, int opts,
            const char *file, int line);
 int    _sx_slock_hard(struct sx *sx, int opts, const char *file, int line);
@@ -208,30 +208,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 +265,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 +309,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: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c        Mon Nov 21 12:23:22 2011        (r227787)
+++ head/sys/vm/vm_map.c        Mon Nov 21 12:59:52 2011        (r227788)
@@ -466,7 +466,7 @@ _vm_map_lock(vm_map_t map, const char *f
        if (map->system_map)
                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++;
 }
 
@@ -491,7 +491,7 @@ _vm_map_unlock(vm_map_t map, const char 
        if (map->system_map)
                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();
        }
 }
@@ -503,7 +503,7 @@ _vm_map_lock_read(vm_map_t map, const ch
        if (map->system_map)
                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
@@ -513,7 +513,7 @@ _vm_map_unlock_read(vm_map_t map, const 
        if (map->system_map)
                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();
        }
 }
@@ -525,7 +525,7 @@ _vm_map_trylock(vm_map_t map, const char
 
        error = map->system_map ?
            !mtx_trylock_flags_(&map->system_mtx, 0, file, line) :
-           !_sx_try_xlock(&map->lock, file, line);
+           !sx_try_xlock_(&map->lock, file, line);
        if (error == 0)
                map->timestamp++;
        return (error == 0);
@@ -538,7 +538,7 @@ _vm_map_trylock_read(vm_map_t map, const
 
        error = map->system_map ?
            !mtx_trylock_flags_(&map->system_mtx, 0, file, line) :
-           !_sx_try_slock(&map->lock, file, line);
+           !sx_try_slock_(&map->lock, file, line);
        return (error == 0);
 }
 
@@ -560,17 +560,17 @@ _vm_map_lock_upgrade(vm_map_t map, const
        if (map->system_map) {
                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,7 +586,7 @@ _vm_map_lock_downgrade(vm_map_t map, con
        if (map->system_map) {
                mtx_assert_(&map->system_mtx, MA_OWNED, file, line);
        } else
-               _sx_downgrade(&map->lock, file, line);
+               sx_downgrade_(&map->lock, file, line);
 }
 
 /*
@@ -605,7 +605,6 @@ vm_map_locked(vm_map_t map)
                return (sx_xlocked(&map->lock));
 }
 
-/* XXX: INVARIANTS here is still necessary because of sx support. */
 #ifdef INVARIANTS
 static void
 _vm_map_assert_locked(vm_map_t map, const char *file, int line)
@@ -614,28 +613,13 @@ _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);
+               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);
-       else
-               _sx_assert(&map->lock, SA_SLOCKED, 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
 
 /*
@@ -660,7 +644,7 @@ _vm_map_unlock_and_wait(vm_map_t map, in
        if (map->system_map)
                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));
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to