dtrace: depessimize dtmalloc when dtrace is active
Each malloc/free was testing dtrace_malloc_enabled and forcing extra reads from the malloc type struct to see if perhaps a dtmalloc probe was on. Treat it like lockstat and sdt: have a global bolean.
This commit is contained in:
parent
4c5209cb21
commit
7cd794214a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=332901
@ -36,6 +36,9 @@
|
||||
#include <sys/dtrace.h>
|
||||
#include <sys/dtrace_bsd.h>
|
||||
|
||||
extern bool dtrace_malloc_enabled;
|
||||
static uint32_t dtrace_malloc_enabled_count;
|
||||
|
||||
static d_open_t dtmalloc_open;
|
||||
static int dtmalloc_unload(void);
|
||||
static void dtmalloc_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
|
||||
@ -152,6 +155,9 @@ dtmalloc_enable(void *arg, dtrace_id_t id, void *parg)
|
||||
{
|
||||
uint32_t *p = parg;
|
||||
*p = id;
|
||||
dtrace_malloc_enabled_count++;
|
||||
if (dtrace_malloc_enabled_count == 1)
|
||||
dtrace_malloc_enabled = true;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -159,6 +165,9 @@ dtmalloc_disable(void *arg, dtrace_id_t id, void *parg)
|
||||
{
|
||||
uint32_t *p = parg;
|
||||
*p = 0;
|
||||
dtrace_malloc_enabled_count--;
|
||||
if (dtrace_malloc_enabled_count == 0)
|
||||
dtrace_malloc_enabled = false;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -93,7 +93,8 @@ __FBSDID("$FreeBSD$");
|
||||
#ifdef KDTRACE_HOOKS
|
||||
#include <sys/dtrace_bsd.h>
|
||||
|
||||
dtrace_malloc_probe_func_t dtrace_malloc_probe;
|
||||
bool __read_frequently dtrace_malloc_enabled;
|
||||
dtrace_malloc_probe_func_t __read_mostly dtrace_malloc_probe;
|
||||
#endif
|
||||
|
||||
#if defined(INVARIANTS) || defined(MALLOC_MAKE_FAILURES) || \
|
||||
@ -376,7 +377,7 @@ malloc_type_zone_allocated(struct malloc_type *mtp, unsigned long size,
|
||||
mtsp->mts_size |= 1 << zindx;
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
if (dtrace_malloc_probe != NULL) {
|
||||
if (__predict_false(dtrace_malloc_enabled)) {
|
||||
uint32_t probe_id = mtip->mti_probes[DTMALLOC_PROBE_MALLOC];
|
||||
if (probe_id != 0)
|
||||
(dtrace_malloc_probe)(probe_id,
|
||||
@ -415,7 +416,7 @@ malloc_type_freed(struct malloc_type *mtp, unsigned long size)
|
||||
mtsp->mts_numfrees++;
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
if (dtrace_malloc_probe != NULL) {
|
||||
if (__predict_false(dtrace_malloc_enabled)) {
|
||||
uint32_t probe_id = mtip->mti_probes[DTMALLOC_PROBE_FREE];
|
||||
if (probe_id != 0)
|
||||
(dtrace_malloc_probe)(probe_id,
|
||||
|
Loading…
Reference in New Issue
Block a user