Modify lockstat_nsecs() to just return unless lockstat probes are actually

enabled. The cost of a timecounter read can be quite significant, and the
problem became more apparent after r284297, since that change resulted in
a call to lockstat_nsecs() for each acquisition of an rwlock read lock.

PR:		201642
Reviewed by:	avg
Tested by:	Jason Unovitch
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D3073
This commit is contained in:
Mark Johnston 2015-07-18 00:22:00 +00:00
parent eacbeb2b95
commit efe8b26b82
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285663
3 changed files with 9 additions and 1 deletions

View File

@ -159,6 +159,8 @@ lockstat_enable(void *arg, dtrace_id_t id, void *parg)
ASSERT(!lockstat_probemap[probe->lsp_probe]);
lockstat_enabled++;
lockstat_probemap[probe->lsp_probe] = id;
#ifdef DOODAD
membar_producer();
@ -182,6 +184,8 @@ lockstat_disable(void *arg, dtrace_id_t id, void *parg)
ASSERT(lockstat_probemap[probe->lsp_probe]);
lockstat_enabled--;
lockstat_probemap[probe->lsp_probe] = 0;
#ifdef DOODAD
lockstat_hot_patch();

View File

@ -45,7 +45,7 @@
uint32_t lockstat_probemap[LS_NPROBES];
void (*lockstat_probe_func)(uint32_t, uintptr_t, uintptr_t,
uintptr_t, uintptr_t, uintptr_t);
int lockstat_enabled = 0;
uint64_t
lockstat_nsecs(void)
@ -53,6 +53,9 @@ lockstat_nsecs(void)
struct bintime bt;
uint64_t ns;
if (!lockstat_enabled)
return (0);
binuptime(&bt);
ns = bt.sec * (uint64_t)1000000000;
ns += ((uint64_t)1000000000 * (uint32_t)(bt.frac >> 32)) >> 32;

View File

@ -154,6 +154,7 @@ 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(void);
extern int lockstat_enabled;
#ifdef KDTRACE_HOOKS
/*