git: 2bd4b5475fc5 - stable/13 - hwpmc: Skip GLOBAL_CTRL updates on stop_pmc().

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Mon, 04 Jul 2022 18:09:29 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=2bd4b5475fc57ba72c8b06c8bcdec4da47f2bb85

commit 2bd4b5475fc57ba72c8b06c8bcdec4da47f2bb85
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-06-02 22:20:33 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-07-04 17:48:10 +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
    
    (cherry picked from commit 326a8d3e085dda2b82c99cf1eb2997cb4dc99a71)
---
 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 56efc72aed80..22e6adbd778d 100644
--- a/sys/dev/hwpmc/hwpmc_core.c
+++ b/sys/dev/hwpmc/hwpmc_core.c
@@ -474,8 +474,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),
@@ -979,10 +978,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 1a1d3c744351..f87b36616d18 100644
--- a/sys/dev/hwpmc/hwpmc_uncore.c
+++ b/sys/dev/hwpmc/hwpmc_uncore.c
@@ -369,8 +369,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),
@@ -730,8 +729,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);
 }