diff --git a/sys/dev/hwpmc/hwpmc_x86.c b/sys/dev/hwpmc/hwpmc_x86.c --- a/sys/dev/hwpmc/hwpmc_x86.c +++ b/sys/dev/hwpmc/hwpmc_x86.c @@ -241,14 +241,17 @@ else return (NULL); - /* disallow sampling if we do not have an LAPIC */ - if (md != NULL && !lapic_enable_pcint()) - for (i = 0; i < md->pmd_nclass; i++) { - if (i == PMC_CLASS_INDEX_SOFT) - continue; - md->pmd_classdep[i].pcd_caps &= ~PMC_CAP_INTERRUPT; - } - nmi_register_handler(md->pmd_intr); + if (md != NULL) { + nmi_register_handler(md->pmd_intr); + /* disallow sampling if we do not have an LAPIC */ + if (!lapic_enable_pcint()) + for (i = 0; i < md->pmd_nclass; i++) { + if (i == PMC_CLASS_INDEX_SOFT) + continue; + md->pmd_classdep[i].pcd_caps &= + ~PMC_CAP_INTERRUPT; + } + } return (md); } @@ -256,9 +259,10 @@ void pmc_md_finalize(struct pmc_mdep *md) { - - lapic_disable_pcint(); - nmi_remove_handler(md->pmd_intr); + if (md != NULL) { + lapic_disable_pcint(); + nmi_remove_handler(md->pmd_intr); + } if (cpu_vendor_id == CPU_VENDOR_AMD || cpu_vendor_id == CPU_VENDOR_HYGON) pmc_amd_finalize(md);