git: 326a8d3e085d - main - hwpmc: Skip GLOBAL_CTRL updates on stop_pmc().

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Thu, 02 Jun 2022 22:35:59 UTC
The branch main has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=326a8d3e085dda2b82c99cf1eb2997cb4dc99a71

commit 326a8d3e085dda2b82c99cf1eb2997cb4dc99a71
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-06-02 22:20:33 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-06-02 22:35:55 +0000

    hwpmc: Skip GLOBAL_CTRL updates on stop_pmc().
    
    After we wipe PMC configuration, including its local enable bit(s),
    we don't really care about its global enable bit.  Global enable bits
    now may only be cleared by interrupt handler in case of error (sample
    buffer overflow).  Being set is actually a reset default for them.
    
    This saves one WRMSR per process-scope PMC per context switch, that
    is clearly visible in profiles.
    
    MFC after:      1 month
---
 sys/dev/hwpmc/hwpmc_core.c   | 8 ++------
 sys/dev/hwpmc/hwpmc_uncore.c | 6 ++----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c
index a2607ca1d9e3..5d6ca02ea792 100644
--- a/sys/dev/hwpmc/hwpmc_core.c
+++ b/sys/dev/hwpmc/hwpmc_core.c
@@ -472,8 +472,7 @@ iaf_stop_pmc(int cpu, int ri)
 	cc->pc_iafctrl &= ~(IAF_MASK << (ri * 4));
 	wrmsr(IAF_CTRL, cc->pc_iafctrl);
 
-	cc->pc_globalctrl &= ~(1ULL << (ri + IAF_OFFSET));
-	wrmsr(IA_GLOBAL_CTRL, cc->pc_globalctrl);
+	/* Don't need to write IA_GLOBAL_CTRL, one disable is enough. */
 
 	PMCDBG4(MDP,STO,1,"iafctrl=%x(%x) globalctrl=%jx(%jx)",
 	    cc->pc_iafctrl, (uint32_t) rdmsr(IAF_CTRL),
@@ -975,10 +974,7 @@ iap_stop_pmc(int cpu, int ri)
 
 	wrmsr(IAP_EVSEL0 + ri, 0);
 
-	if (core_version >= 2) {
-		cc->pc_globalctrl &= ~(1ULL << ri);
-		wrmsr(IA_GLOBAL_CTRL, cc->pc_globalctrl);
-	}
+	/* Don't need to write IA_GLOBAL_CTRL, one disable is enough. */
 
 	return (0);
 }
diff --git a/sys/dev/hwpmc/hwpmc_uncore.c b/sys/dev/hwpmc/hwpmc_uncore.c
index f69b21e173d5..0d9085564c2a 100644
--- a/sys/dev/hwpmc/hwpmc_uncore.c
+++ b/sys/dev/hwpmc/hwpmc_uncore.c
@@ -366,8 +366,7 @@ ucf_stop_pmc(int cpu, int ri)
 	PMCDBG1(MDP,STO,1,"ucf-stop ucfctrl=%x", ucfc->pc_ucfctrl);
 	wrmsr(UCF_CTRL, ucfc->pc_ucfctrl);
 
-	ucfc->pc_globalctrl &= ~(1ULL << (ri + SELECTOFF(uncore_cputype)));
-	wrmsr(UC_GLOBAL_CTRL, ucfc->pc_globalctrl);
+	/* Don't need to write UC_GLOBAL_CTRL, one disable is enough. */
 
 	PMCDBG4(MDP,STO,1,"ucfctrl=%x(%x) globalctrl=%jx(%jx)",
 	    ucfc->pc_ucfctrl, (uint32_t) rdmsr(UCF_CTRL),
@@ -724,8 +723,7 @@ ucp_stop_pmc(int cpu, int ri)
 	/* stop hw. */
 	wrmsr(SELECTSEL(uncore_cputype) + ri, 0);
 
-	cc->pc_globalctrl &= ~(1ULL << ri);
-	wrmsr(UC_GLOBAL_CTRL, cc->pc_globalctrl);
+	/* Don't need to write UC_GLOBAL_CTRL, one disable is enough. */
 
 	return (0);
 }