aboutsummaryrefslogtreecommitdiff
path: root/sys/sys
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2015-07-19 22:14:09 +0000
committerMark Johnston <markj@FreeBSD.org>2015-07-19 22:14:09 +0000
commit32cd0147fafec2d3d2817d733fa70bad9cdf34ce (patch)
treef4dbaff3eee7463b0bc4a1e309dee981d6aaba59 /sys/sys
parentdbfbf7ae92436830b554f69f80d01b19407a2e6a (diff)
downloadsrc-32cd0147fafec2d3d2817d733fa70bad9cdf34ce.tar.gz
src-32cd0147fafec2d3d2817d733fa70bad9cdf34ce.zip
Implement the lockstat provider using SDT(9) instead of the custom provider
in lockstat.ko. This means that lockstat probes now have typed arguments and will utilize SDT probe hot-patching support when it arrives. Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D2993
Notes
Notes: svn path=/head/; revision=285703
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/lockstat.h214
-rw-r--r--sys/sys/mutex.h23
-rw-r--r--sys/sys/rwlock.h9
-rw-r--r--sys/sys/sx.h12
4 files changed, 74 insertions, 184 deletions
diff --git a/sys/sys/lockstat.h b/sys/sys/lockstat.h
index b9a900d9f9e0..e53a7e4b88c8 100644
--- a/sys/sys/lockstat.h
+++ b/sys/sys/lockstat.h
@@ -27,185 +27,81 @@
/*
* DTrace lockstat provider definitions
- *
*/
-#ifndef _SYS_LOCKSTAT_H
+#ifndef _SYS_LOCKSTAT_H
#define _SYS_LOCKSTAT_H
-#ifdef _KERNEL
+#ifdef _KERNEL
-/*
- * Spin Locks
- */
-#define LS_MTX_SPIN_LOCK_ACQUIRE 0
-#define LS_MTX_SPIN_UNLOCK_RELEASE 1
-#define LS_MTX_SPIN_LOCK_SPIN 2
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/sdt.h>
-/*
- * Adaptive Locks
- */
-#define LS_MTX_LOCK_ACQUIRE 3
-#define LS_MTX_UNLOCK_RELEASE 4
-#define LS_MTX_LOCK_SPIN 5
-#define LS_MTX_LOCK_BLOCK 6
-#define LS_MTX_TRYLOCK_ACQUIRE 7
+SDT_PROVIDER_DECLARE(lockstat);
-/*
- * Reader/Writer Locks
- */
-#define LS_RW_RLOCK_ACQUIRE 8
-#define LS_RW_RUNLOCK_RELEASE 9
-#define LS_RW_WLOCK_ACQUIRE 10
-#define LS_RW_WUNLOCK_RELEASE 11
-#define LS_RW_RLOCK_SPIN 12
-#define LS_RW_RLOCK_BLOCK 13
-#define LS_RW_WLOCK_SPIN 14
-#define LS_RW_WLOCK_BLOCK 15
-#define LS_RW_TRYUPGRADE_UPGRADE 16
-#define LS_RW_DOWNGRADE_DOWNGRADE 17
+SDT_PROBE_DECLARE(lockstat, , , adaptive__acquire);
+SDT_PROBE_DECLARE(lockstat, , , adaptive__release);
+SDT_PROBE_DECLARE(lockstat, , , adaptive__spin);
+SDT_PROBE_DECLARE(lockstat, , , adaptive__block);
-/*
- * Shared/Exclusive Locks
- */
-#define LS_SX_SLOCK_ACQUIRE 18
-#define LS_SX_SUNLOCK_RELEASE 19
-#define LS_SX_XLOCK_ACQUIRE 20
-#define LS_SX_XUNLOCK_RELEASE 21
-#define LS_SX_SLOCK_SPIN 22
-#define LS_SX_SLOCK_BLOCK 23
-#define LS_SX_XLOCK_SPIN 24
-#define LS_SX_XLOCK_BLOCK 25
-#define LS_SX_TRYUPGRADE_UPGRADE 26
-#define LS_SX_DOWNGRADE_DOWNGRADE 27
-
-/*
- * Thread Locks
- */
-#define LS_THREAD_LOCK_SPIN 28
+SDT_PROBE_DECLARE(lockstat, , , spin__acquire);
+SDT_PROBE_DECLARE(lockstat, , , spin__release);
+SDT_PROBE_DECLARE(lockstat, , , spin__spin);
-/*
- * Lockmanager Locks
- * According to locking(9) Lockmgr locks are "Largely deprecated"
- * so no support for these have been added in the lockstat provider.
- */
+SDT_PROBE_DECLARE(lockstat, , , rw__acquire);
+SDT_PROBE_DECLARE(lockstat, , , rw__release);
+SDT_PROBE_DECLARE(lockstat, , , rw__block);
+SDT_PROBE_DECLARE(lockstat, , , rw__spin);
+SDT_PROBE_DECLARE(lockstat, , , rw__upgrade);
+SDT_PROBE_DECLARE(lockstat, , , rw__downgrade);
-#define LS_NPROBES 29
-
-#define LS_MTX_LOCK "mtx_lock"
-#define LS_MTX_UNLOCK "mtx_unlock"
-#define LS_MTX_SPIN_LOCK "mtx_lock_spin"
-#define LS_MTX_SPIN_UNLOCK "mtx_unlock_spin"
-#define LS_MTX_TRYLOCK "mtx_trylock"
-#define LS_RW_RLOCK "rw_rlock"
-#define LS_RW_WLOCK "rw_wlock"
-#define LS_RW_RUNLOCK "rw_runlock"
-#define LS_RW_WUNLOCK "rw_wunlock"
-#define LS_RW_TRYUPGRADE "rw_try_upgrade"
-#define LS_RW_DOWNGRADE "rw_downgrade"
-#define LS_SX_SLOCK "sx_slock"
-#define LS_SX_XLOCK "sx_xlock"
-#define LS_SX_SUNLOCK "sx_sunlock"
-#define LS_SX_XUNLOCK "sx_xunlock"
-#define LS_SX_TRYUPGRADE "sx_try_upgrade"
-#define LS_SX_DOWNGRADE "sx_downgrade"
-#define LS_THREAD_LOCK "thread_lock"
-
-#define LS_ACQUIRE "acquire"
-#define LS_RELEASE "release"
-#define LS_SPIN "spin"
-#define LS_BLOCK "block"
-#define LS_UPGRADE "upgrade"
-#define LS_DOWNGRADE "downgrade"
-
-#define LS_TYPE_ADAPTIVE "adaptive"
-#define LS_TYPE_SPIN "spin"
-#define LS_TYPE_THREAD "thread"
-#define LS_TYPE_RW "rw"
-#define LS_TYPE_SX "sx"
-
-#define LSA_ACQUIRE (LS_TYPE_ADAPTIVE "-" LS_ACQUIRE)
-#define LSA_RELEASE (LS_TYPE_ADAPTIVE "-" LS_RELEASE)
-#define LSA_SPIN (LS_TYPE_ADAPTIVE "-" LS_SPIN)
-#define LSA_BLOCK (LS_TYPE_ADAPTIVE "-" LS_BLOCK)
-#define LSS_ACQUIRE (LS_TYPE_SPIN "-" LS_ACQUIRE)
-#define LSS_RELEASE (LS_TYPE_SPIN "-" LS_RELEASE)
-#define LSS_SPIN (LS_TYPE_SPIN "-" LS_SPIN)
-#define LSR_ACQUIRE (LS_TYPE_RW "-" LS_ACQUIRE)
-#define LSR_RELEASE (LS_TYPE_RW "-" LS_RELEASE)
-#define LSR_BLOCK (LS_TYPE_RW "-" LS_BLOCK)
-#define LSR_SPIN (LS_TYPE_RW "-" LS_SPIN)
-#define LSR_UPGRADE (LS_TYPE_RW "-" LS_UPGRADE)
-#define LSR_DOWNGRADE (LS_TYPE_RW "-" LS_DOWNGRADE)
-#define LSX_ACQUIRE (LS_TYPE_SX "-" LS_ACQUIRE)
-#define LSX_RELEASE (LS_TYPE_SX "-" LS_RELEASE)
-#define LSX_BLOCK (LS_TYPE_SX "-" LS_BLOCK)
-#define LSX_SPIN (LS_TYPE_SX "-" LS_SPIN)
-#define LSX_UPGRADE (LS_TYPE_SX "-" LS_UPGRADE)
-#define LSX_DOWNGRADE (LS_TYPE_SX "-" LS_DOWNGRADE)
-#define LST_SPIN (LS_TYPE_THREAD "-" LS_SPIN)
+SDT_PROBE_DECLARE(lockstat, , , sx__acquire);
+SDT_PROBE_DECLARE(lockstat, , , sx__release);
+SDT_PROBE_DECLARE(lockstat, , , sx__block);
+SDT_PROBE_DECLARE(lockstat, , , sx__spin);
+SDT_PROBE_DECLARE(lockstat, , , sx__upgrade);
+SDT_PROBE_DECLARE(lockstat, , , sx__downgrade);
-/*
- * The following must match the type definition of dtrace_probe. It is
- * defined this way to avoid having to rely on CDDL code.
- */
-struct lock_object;
-extern uint32_t lockstat_probemap[LS_NPROBES];
-typedef void (*lockstat_probe_func_t)(uint32_t, uintptr_t arg0, uintptr_t arg1,
- uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
-extern lockstat_probe_func_t lockstat_probe_func;
-extern uint64_t lockstat_nsecs(struct lock_object *);
-extern int lockstat_enabled;
+SDT_PROBE_DECLARE(lockstat, , , thread__spin);
-#ifdef KDTRACE_HOOKS
-/*
- * Macros to record lockstat probes.
- */
-#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) do { \
- uint32_t id; \
- \
- if ((id = lockstat_probemap[(probe)])) \
- (*lockstat_probe_func)(id, (uintptr_t)(lp), (arg1), (arg2), \
- (arg3), (arg4)); \
-} while (0)
+#define LOCKSTAT_WRITER 0
+#define LOCKSTAT_READER 1
-#define LOCKSTAT_RECORD(probe, lp, arg1) \
- LOCKSTAT_RECORD4(probe, lp, arg1, 0, 0, 0)
+#ifdef KDTRACE_HOOKS
-#define LOCKSTAT_RECORD0(probe, lp) \
- LOCKSTAT_RECORD4(probe, lp, 0, 0, 0, 0)
+#define LOCKSTAT_RECORD0(probe, lp) \
+ SDT_PROBE1(lockstat, , , probe, lp)
-#define LOCKSTAT_RECORD1(probe, lp, arg1) \
- LOCKSTAT_RECORD4(probe, lp, arg1, 0, 0, 0)
+#define LOCKSTAT_RECORD1(probe, lp, arg1) \
+ SDT_PROBE2(lockstat, , , probe, lp, arg1)
-#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \
- LOCKSTAT_RECORD4(probe, lp, arg1, arg2, 0, 0)
+#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \
+ SDT_PROBE3(lockstat, , , probe, lp, arg1, arg2)
-#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) \
- LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, 0)
+#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) \
+ SDT_PROBE4(lockstat, , , probe, lp, arg1, arg2, arg3)
-#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \
- uint32_t id; \
- \
- lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \
- if ((id = lockstat_probemap[(probe)])) \
- (*lockstat_probe_func)(id, (uintptr_t)(lp), 0, 0, 0, 0); \
+#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) \
+ SDT_PROBE5(lockstat, , , probe, lp, arg1, arg2, arg3, arg4)
+
+#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \
+ lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \
+ LOCKSTAT_RECORD0(probe, lp); \
} while (0)
-#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do { \
- uint32_t id; \
- \
- lock_profile_release_lock(&(lp)->lock_object); \
- if ((id = lockstat_probemap[(probe)])) \
- (*lockstat_probe_func)(id, (uintptr_t)(lp), 0, 0, 0, 0); \
+#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do { \
+ lock_profile_release_lock(&(lp)->lock_object); \
+ LOCKSTAT_RECORD0(probe, lp); \
} while (0)
-#define LOCKSTAT_WRITER 0
-#define LOCKSTAT_READER 1
+extern int lockstat_enabled;
-#else /* !KDTRACE_HOOKS */
+struct lock_object;
+extern uint64_t lockstat_nsecs(struct lock_object *);
+
+#else /* !KDTRACE_HOOKS */
-#define LOCKSTAT_RECORD(probe, lp, arg1)
#define LOCKSTAT_RECORD0(probe, lp)
#define LOCKSTAT_RECORD1(probe, lp, arg1)
#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2)
@@ -218,8 +114,6 @@ extern int lockstat_enabled;
#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) \
lock_profile_release_lock(&(lp)->lock_object)
-#endif /* !KDTRACE_HOOKS */
-
-#endif /* _KERNEL */
-
-#endif /* _SYS_LOCKSTAT_H */
+#endif /* !KDTRACE_HOOKS */
+#endif /* _KERNEL */
+#endif /* _SYS_LOCKSTAT_H */
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index ec0c24163676..a9ec072f8d7a 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -188,8 +188,8 @@ void thread_lock_flags_(struct thread *, int, const char *, int);
if (!_mtx_obtain_lock((mp), _tid)) \
_mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \
else \
- LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_LOCK_ACQUIRE, \
- mp, 0, 0, (file), (line)); \
+ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(adaptive__acquire, \
+ mp, 0, 0, file, line); \
} while (0)
/*
@@ -209,8 +209,8 @@ void thread_lock_flags_(struct thread *, int, const char *, int);
else \
_mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
} else \
- LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_SPIN_LOCK_ACQUIRE, \
- mp, 0, 0, (file), (line)); \
+ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(spin__acquire, \
+ mp, 0, 0, file, line); \
} while (0)
#else /* SMP */
#define __mtx_lock_spin(mp, tid, opts, file, line) do { \
@@ -231,8 +231,7 @@ void thread_lock_flags_(struct thread *, int, const char *, int);
uintptr_t _tid = (uintptr_t)(tid); \
\
if ((mp)->mtx_recurse == 0) \
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_UNLOCK_RELEASE, \
- (mp)); \
+ LOCKSTAT_PROFILE_RELEASE_LOCK(adaptive__release, mp); \
if (!_mtx_release_lock((mp), _tid)) \
_mtx_unlock_sleep((mp), (opts), (file), (line)); \
} while (0)
@@ -252,21 +251,19 @@ void thread_lock_flags_(struct thread *, int, const char *, int);
if (mtx_recursed((mp))) \
(mp)->mtx_recurse--; \
else { \
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_SPIN_UNLOCK_RELEASE, \
- mp); \
+ LOCKSTAT_PROFILE_RELEASE_LOCK(spin__release, mp); \
_mtx_release_lock_quick((mp)); \
- } \
- spinlock_exit(); \
+ } \
+ spinlock_exit(); \
} while (0)
#else /* SMP */
#define __mtx_unlock_spin(mp) do { \
if (mtx_recursed((mp))) \
(mp)->mtx_recurse--; \
else { \
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_SPIN_UNLOCK_RELEASE, \
- mp); \
+ LOCKSTAT_PROFILE_RELEASE_LOCK(spin__release, mp); \
(mp)->mtx_lock = MTX_UNOWNED; \
- } \
+ } \
spinlock_exit(); \
} while (0)
#endif /* SMP */
diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h
index b638d3efa0bf..960d4af7e263 100644
--- a/sys/sys/rwlock.h
+++ b/sys/sys/rwlock.h
@@ -95,12 +95,12 @@
/* Acquire a write lock. */
#define __rw_wlock(rw, tid, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
- \
+ \
if (!_rw_write_lock((rw), _tid)) \
_rw_wlock_hard((rw), _tid, (file), (line)); \
else \
- LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_RW_WLOCK_ACQUIRE, \
- rw, 0, 0, (file), (line)); \
+ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(rw__acquire, rw, \
+ 0, 0, file, line); \
} while (0)
/* Release a write lock. */
@@ -110,8 +110,7 @@
if ((rw)->rw_recurse) \
(rw)->rw_recurse--; \
else { \
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_WUNLOCK_RELEASE, \
- (rw)); \
+ LOCKSTAT_PROFILE_RELEASE_LOCK(rw__release, rw); \
if (!_rw_write_unlock((rw), _tid)) \
_rw_wunlock_hard((rw), _tid, (file), (line)); \
} \
diff --git a/sys/sys/sx.h b/sys/sys/sx.h
index 1da4356bebc6..c01735c75f51 100644
--- a/sys/sys/sx.h
+++ b/sys/sys/sx.h
@@ -153,8 +153,8 @@ __sx_xlock(struct sx *sx, struct thread *td, int opts, const char *file,
if (!atomic_cmpset_acq_ptr(&sx->sx_lock, SX_LOCK_UNLOCKED, tid))
error = _sx_xlock_hard(sx, tid, opts, file, line);
else
- LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_SX_XLOCK_ACQUIRE,
- sx, 0, 0, file, line);
+ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(sx__acquire, sx,
+ 0, 0, file, line);
return (error);
}
@@ -166,7 +166,7 @@ __sx_xunlock(struct sx *sx, struct thread *td, const char *file, int line)
uintptr_t tid = (uintptr_t)td;
if (sx->sx_recurse == 0)
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_XUNLOCK_RELEASE, sx);
+ LOCKSTAT_PROFILE_RELEASE_LOCK(sx__release, sx);
if (!atomic_cmpset_rel_ptr(&sx->sx_lock, tid, SX_LOCK_UNLOCKED))
_sx_xunlock_hard(sx, tid, file, line);
}
@@ -182,8 +182,8 @@ __sx_slock(struct sx *sx, int opts, const char *file, int line)
!atomic_cmpset_acq_ptr(&sx->sx_lock, x, x + SX_ONE_SHARER))
error = _sx_slock_hard(sx, opts, file, line);
else
- LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_SX_SLOCK_ACQUIRE, sx, 0,
- 0, file, line);
+ LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(sx__acquire, sx,
+ 0, 0, file, line);
return (error);
}
@@ -200,7 +200,7 @@ __sx_sunlock(struct sx *sx, const char *file, int line)
{
uintptr_t x = sx->sx_lock;
- LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_SUNLOCK_RELEASE, sx);
+ LOCKSTAT_PROFILE_RELEASE_LOCK(sx__release, sx);
if (x == (SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS) ||
!atomic_cmpset_rel_ptr(&sx->sx_lock, x, x - SX_ONE_SHARER))
_sx_sunlock_hard(sx, file, line);