aboutsummaryrefslogtreecommitdiff
path: root/sys/gnu/fs/xfs/FreeBSD
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2007-03-31 23:23:42 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2007-03-31 23:23:42 +0000
commit4e7f640dfbe1f666c3857534899ee168776fbe67 (patch)
tree6f71182be4d218a6130d92f4c3455591243f0019 /sys/gnu/fs/xfs/FreeBSD
parent511cecafd6f81e86fe43552c72dae3f6e584e71d (diff)
downloadsrc-4e7f640dfbe1f666c3857534899ee168776fbe67.tar.gz
src-4e7f640dfbe1f666c3857534899ee168776fbe67.zip
Optimize sx locks to use simple atomic operations for the common cases of
obtaining and releasing shared and exclusive locks. The algorithms for manipulating the lock cookie are very similar to that rwlocks. This patch also adds support for exclusive locks using the same algorithm as mutexes. A new sx_init_flags() function has been added so that optional flags can be specified to alter a given locks behavior. The flags include SX_DUPOK, SX_NOWITNESS, SX_NOPROFILE, and SX_QUITE which are all identical in nature to the similar flags for mutexes. Adaptive spinning on select locks may be enabled by enabling the ADAPTIVE_SX kernel option. Only locks initialized with the SX_ADAPTIVESPIN flag via sx_init_flags() will adaptively spin. The common cases for sx_slock(), sx_sunlock(), sx_xlock(), and sx_xunlock() are now performed inline in non-debug kernels. As a result, <sys/sx.h> now requires <sys/lock.h> to be included prior to <sys/sx.h>. The new kernel option SX_NOINLINE can be used to disable the aforementioned inlining in non-debug kernels. The size of struct sx has changed, so the kernel ABI is probably greatly disturbed. MFC after: 1 month Submitted by: attilio Tested by: kris, pjd
Notes
Notes: svn path=/head/; revision=168191
Diffstat (limited to 'sys/gnu/fs/xfs/FreeBSD')
-rw-r--r--sys/gnu/fs/xfs/FreeBSD/support/mrlock.c51
-rw-r--r--sys/gnu/fs/xfs/FreeBSD/support/mrlock.h48
2 files changed, 20 insertions, 79 deletions
diff --git a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c
index 950303938a07..7c3f8bfdfb55 100644
--- a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c
+++ b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.c
@@ -1,49 +1,14 @@
#include <sys/param.h>
+#include <machine/pcpu.h>
+#include <support/debug.h>
#include <support/mrlock.h>
-void
-_sx_xfs_destroy(struct sx *sx)
-{
- if (sx->sx_cnt == -1)
- sx_xunlock(sx);
- sx_destroy(sx);
-}
-
-void
-_sx_xfs_lock(struct sx *sx, int type, const char *file, int line)
-{
- if (type == MR_ACCESS)
- _sx_slock(sx, file, line);
- else if (type == MR_UPDATE)
- _sx_sunlock(sx, file, line);
- else
- panic("Invalid lock type passed");
-}
-
-
-void
-_sx_xfs_unlock(struct sx *sx, const char *file, int line)
-{
- if (_sx_xfs_xowned(sx))
- _sx_xunlock(sx, file, line);
- else if (_sx_xfs_sowned(sx))
- _sx_sunlock(sx, file, line);
- else
- panic("lock is not locked");
-}
-
int
ismrlocked(mrlock_t *mrp, int type)
-{
- if (type == MR_ACCESS)
- return _sx_xfs_sowned(mrp); /* Read lock */
- else if (type == MR_UPDATE)
- return _sx_xfs_xowned(mrp); /* Write lock */
- else if (type == (MR_UPDATE | MR_ACCESS))
- return _sx_xfs_sowned(mrp) ||
- _sx_xfs_xowned(mrp); /* Any type of lock held */
- return (mrp->sx_shrd_wcnt > 0 || mrp->sx_excl_wcnt > 0);
-}
-
-
+{
+ sx_assert(mrp, SX_LOCKED);
+ if (type == MR_UPDATE)
+ return sx_xlocked(mrp);
+ return 1;
+}
diff --git a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h
index 4e82d4199118..b41efc57dc4c 100644
--- a/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h
+++ b/sys/gnu/fs/xfs/FreeBSD/support/mrlock.h
@@ -4,62 +4,38 @@
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/lock.h>
-#include <sys/mutex.h>
#include <sys/sx.h>
-#include <support/debug.h>
-
/*
* Implement mrlocks on FreeBSD that work for XFS.
- * Use FreeBSD sx lock and add necessary functions
- * if additional functionality is requested
+ * Map mrlock functions to corresponding equivalents in
+ * sx.
*/
typedef struct sx mrlock_t;
#define MR_ACCESS 1
#define MR_UPDATE 2
-/*
+/*
* Compatibility defines, not really used
*/
#define MRLOCK_BARRIER 0x1
#define MRLOCK_ALLOW_EQUAL_PRI 0x8
-/*
- * mraccessf/mrupdatef take flags to be passed in while sleeping;
- * only PLTWAIT is currently supported.
- */
-#define mrinit(lock, name) sx_init(lock, name)
#define mrlock_init(lock, type, name, seq) sx_init(lock, name)
-#define mrfree(lock) _sx_xfs_destroy(lock)
-#define mraccessf(lock, f) sx_slock(lock)
-#define mrupdatef(lock, f) sx_xlock(lock)
-#define mraccunlock(lock) sx_sunlock(lock)
#define mrtryaccess(lock) sx_try_slock(lock)
#define mrtryupdate(lock) sx_try_xlock(lock)
-#define mraccess(mrp) mraccessf(mrp, 0)
-#define mrupdate(mrp) mrupdatef(mrp, 0)
-#define mrislocked_access(lock) _sx_xfs_xowned(lock)
-#define mrislocked_update(lock) _sx_xfs_sowned(lock)
-#define mrtrypromote(lock) sx_try_upgrade(lock)
+#define mraccess(lock) sx_slock(lock)
+#define mrupdate(lock) sx_xlock(lock)
#define mrdemote(lock) sx_downgrade(lock)
+#define mrunlock(lock) sx_unlock(lock)
-int ismrlocked(mrlock_t *, int);
-void _sx_xfs_lock(struct sx *sx, int type, const char *file, int line);
-void _sx_xfs_unlock(struct sx *sx, const char *file, int line);
-void _sx_xfs_destroy(struct sx *sx);
-#define _sx_xfs_xowned(lock) ((lock)->sx_cnt < 0)
-#define _sx_xfs_sowned(lock) ((lock)->sx_cnt > 0)
-
-/*
- * Functions, not implemented in FreeBSD
- */
-#define mrunlock(lock) \
- _sx_xfs_unlock(lock, __FILE__, __LINE__)
-
-#define mrlock(lock, type, flags) \
- _sx_xfs_lock(lock, type, __FILE__, __LINE__)
-
+#define mrfree(lock) do { \
+ if (sx_xlocked(lock)) \
+ sx_xunlock(lock); \
+ sx_destroy(lock); \
+} while (0)
+int ismrlocked(mrlock_t *mrp, int type);
#endif /* __XFS_SUPPORT_MRLOCK_H__ */