dtrace: stop using eventhandlers for the part compiled into the kernel

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D27311
This commit is contained in:
mjg 2020-11-23 18:27:21 +00:00
parent 0f4de3e9cc
commit 1766f9223b
5 changed files with 36 additions and 35 deletions

View File

@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <sys/loginclass.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/dtrace_bsd.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/proc.h>
@ -607,6 +608,10 @@ proc0_init(void *dummy __unused)
*/
EVENTHANDLER_DIRECT_INVOKE(process_init, p);
EVENTHANDLER_DIRECT_INVOKE(thread_init, td);
#ifdef KDTRACE_HOOKS
kdtrace_proc_ctor(p);
kdtrace_thread_ctor(td);
#endif
EVENTHANDLER_DIRECT_INVOKE(process_ctor, p);
EVENTHANDLER_DIRECT_INVOKE(thread_ctor, td);

View File

@ -67,21 +67,19 @@ kdtrace_proc_size()
return (KDTRACE_PROC_SIZE);
}
static void
kdtrace_proc_ctor(void *arg __unused, struct proc *p)
void
kdtrace_proc_ctor(struct proc *p)
{
p->p_dtrace = malloc(KDTRACE_PROC_SIZE, M_KDTRACE, M_WAITOK|M_ZERO);
}
static void
kdtrace_proc_dtor(void *arg __unused, struct proc *p)
void
kdtrace_proc_dtor(struct proc *p)
{
if (p->p_dtrace != NULL) {
free(p->p_dtrace, M_KDTRACE);
p->p_dtrace = NULL;
}
free(p->p_dtrace, M_KDTRACE);
p->p_dtrace = NULL;
}
/* Return the DTrace thread data size compiled in the kernel hooks. */
@ -92,38 +90,17 @@ kdtrace_thread_size()
return (KDTRACE_THREAD_SIZE);
}
static void
kdtrace_thread_ctor(void *arg __unused, struct thread *td)
void
kdtrace_thread_ctor(struct thread *td)
{
td->td_dtrace = malloc(KDTRACE_THREAD_SIZE, M_KDTRACE, M_WAITOK|M_ZERO);
}
static void
kdtrace_thread_dtor(void *arg __unused, struct thread *td)
void
kdtrace_thread_dtor(struct thread *td)
{
if (td->td_dtrace != NULL) {
free(td->td_dtrace, M_KDTRACE);
td->td_dtrace = NULL;
}
free(td->td_dtrace, M_KDTRACE);
td->td_dtrace = NULL;
}
/*
* Initialise the kernel DTrace hooks.
*/
static void
init_dtrace(void *dummy __unused)
{
EVENTHANDLER_REGISTER(process_ctor, kdtrace_proc_ctor, NULL,
EVENTHANDLER_PRI_ANY);
EVENTHANDLER_REGISTER(process_dtor, kdtrace_proc_dtor, NULL,
EVENTHANDLER_PRI_ANY);
EVENTHANDLER_REGISTER(thread_ctor, kdtrace_thread_ctor, NULL,
EVENTHANDLER_PRI_ANY);
EVENTHANDLER_REGISTER(thread_dtor, kdtrace_thread_dtor, NULL,
EVENTHANDLER_PRI_ANY);
}
SYSINIT(kdtrace, SI_SUB_KDTRACE, SI_ORDER_FIRST, init_dtrace, NULL);

View File

@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h>
#include <sys/stack.h>
#include <sys/stat.h>
#include <sys/dtrace_bsd.h>
#include <sys/sysctl.h>
#include <sys/filedesc.h>
#include <sys/tty.h>
@ -207,6 +208,9 @@ proc_ctor(void *mem, int size, void *arg, int flags)
struct thread *td;
p = (struct proc *)mem;
#ifdef KDTRACE_HOOKS
kdtrace_proc_ctor(p);
#endif
EVENTHANDLER_DIRECT_INVOKE(process_ctor, p);
td = FIRST_THREAD_IN_PROC(p);
if (td != NULL) {
@ -243,6 +247,9 @@ proc_dtor(void *mem, int size, void *arg)
EVENTHANDLER_DIRECT_INVOKE(thread_dtor, td);
}
EVENTHANDLER_DIRECT_INVOKE(process_dtor, p);
#ifdef KDTRACE_HOOKS
kdtrace_proc_dtor(p);
#endif
if (p->p_ksi != NULL)
KASSERT(! KSI_ONQ(p->p_ksi), ("SIGCHLD queue"));
}

View File

@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sleepqueue.h>
#include <sys/selinfo.h>
#include <sys/syscallsubr.h>
#include <sys/dtrace_bsd.h>
#include <sys/sysent.h>
#include <sys/turnstile.h>
#include <sys/taskqueue.h>
@ -357,6 +358,9 @@ thread_ctor(void *mem, int size, void *arg, int flags)
td->td_lend_user_pri = PRI_MAX;
#ifdef AUDIT
audit_thread_alloc(td);
#endif
#ifdef KDTRACE_HOOKS
kdtrace_thread_ctor(td);
#endif
umtx_thread_alloc(td);
MPASS(td->td_sel == NULL);
@ -395,6 +399,9 @@ thread_dtor(void *mem, int size, void *arg)
#endif
#ifdef AUDIT
audit_thread_free(td);
#endif
#ifdef KDTRACE_HOOKS
kdtrace_thread_dtor(td);
#endif
/* Free all OSD associated to this thread. */
osd_thread_exit(td);

View File

@ -165,6 +165,11 @@ extern dtrace_nfsclient_nfs23_done_probe_func_t
size_t kdtrace_proc_size(void);
size_t kdtrace_thread_size(void);
void kdtrace_proc_ctor(struct proc *p);
void kdtrace_proc_dtor(struct proc *p);
void kdtrace_thread_ctor(struct thread *td);
void kdtrace_thread_dtor(struct thread *td);
/*
* OpenSolaris compatible time functions returning nanoseconds.
* On OpenSolaris these return hrtime_t which we define as uint64_t.