diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index cefe4acc8e6c..a5768ec25765 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include "opt_hwpmc_hooks.h" #include "opt_sched.h" +#include "opt_kdtrace.h" #include #include @@ -61,6 +62,12 @@ __FBSDID("$FreeBSD$"); #include #endif +#ifdef KDTRACE_HOOKS +#include +int dtrace_vtime_active; +dtrace_vtime_switch_func_t dtrace_vtime_switch_func; +#endif + /* * INVERSE_ESTCPU_WEIGHT is only suitable for statclock() frequencies in * the range 100-256 Hz (approximately). @@ -962,6 +969,16 @@ sched_switch(struct thread *td, struct thread *newtd, int flags) #endif /* I feel sleepy */ lock_profile_release_lock(&sched_lock.lock_object); +#ifdef KDTRACE_HOOKS + /* + * If DTrace has set the active vtime enum to anything + * other than INACTIVE (0), then it should have set the + * function to call. + */ + if (dtrace_vtime_active) + (*dtrace_vtime_switch_func)(newtd); +#endif + cpu_switch(td, newtd, td->td_lock); lock_profile_obtain_lock_success(&sched_lock.lock_object, 0, 0, __FILE__, __LINE__); diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 7fe80afa1449..172f41aa58a5 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include "opt_hwpmc_hooks.h" +#include "opt_kdtrace.h" #include "opt_sched.h" #include @@ -69,6 +70,12 @@ __FBSDID("$FreeBSD$"); #include #endif +#ifdef KDTRACE_HOOKS +#include +int dtrace_vtime_active; +dtrace_vtime_switch_func_t dtrace_vtime_switch_func; +#endif + #include #include @@ -1823,6 +1830,17 @@ sched_switch(struct thread *td, struct thread *newtd, int flags) #endif lock_profile_release_lock(&TDQ_LOCKPTR(tdq)->lock_object); TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd; + +#ifdef KDTRACE_HOOKS + /* + * If DTrace has set the active vtime enum to anything + * other than INACTIVE (0), then it should have set the + * function to call. + */ + if (dtrace_vtime_active) + (*dtrace_vtime_switch_func)(newtd); +#endif + cpu_switch(td, newtd, mtx); /* * We may return from cpu_switch on a different cpu. However,