diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -45,6 +45,7 @@ #include "opt_clock.h" #include "opt_cpu.h" #include "opt_hwpmc_hooks.h" +#include "opt_hwt_hooks.h" #include "opt_isa.h" #include "opt_kdb.h" @@ -74,6 +75,10 @@ PMC_SOFT_DEFINE( , , page_fault, write); #endif +#ifdef HWT_HOOKS +#include +#endif + #include #include #include @@ -202,6 +207,34 @@ }, }; +static __inline bool +nmi_handle_pcint(struct trapframe *frame) +{ + bool handled = false; + +#ifdef HWT_HOOKS + /* + * Handle Intel PT interrupt if hwt is active. + */ + if (hwt_intr != NULL && + (*hwt_intr)(frame) != 0) + handled = true; +#endif +#ifdef HWPMC_HOOKS + /* + * CPU PMCs interrupt using an NMI. If the PMC module is + * active, pass the 'rip' value to the PMC module's interrupt + * handler. A non-zero return value means that + * the NMI was consumed by the handler. + */ + if (pmc_intr != NULL && + (*pmc_intr)(frame) != 0) + handled = true; +#endif + + return (handled); +} + /* * Exception, fault, and trap interface to the FreeBSD kernel. * This common code is called from assembly language IDT gate entry @@ -249,17 +282,8 @@ } if (type == T_NMI) { -#ifdef HWPMC_HOOKS - /* - * CPU PMCs interrupt using an NMI. If the PMC module is - * active, pass the 'rip' value to the PMC module's interrupt - * handler. A non-zero return value from the handler means that - * the NMI was consumed by it and we can return immediately. - */ - if (pmc_intr != NULL && - (*pmc_intr)(frame) != 0) + if (nmi_handle_pcint(frame)) return; -#endif } if ((frame->tf_rflags & PSL_I) == 0) {