Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jul 2022 16:47:36 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 46b46bb77405 - stable/13 - hwpmc: Permit the minimum sampling count to be set as a sysctl.
Message-ID:  <202207131647.26DGla70052154@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=46b46bb77405c3eaf0dbd0c0c09130f773d88718

commit 46b46bb77405c3eaf0dbd0c0c09130f773d88718
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-06-09 18:05:34 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-07-13 16:19:13 +0000

    hwpmc: Permit the minimum sampling count to be set as a sysctl.
    
    A rarely occurring event (e.g. an event that occurs less than 1000
    times during execution of a program) may require a lower minimum
    threshold than 1000.  Replace the hardcoded 1000 with a sysctl that
    the administrator can use to permit smaller sampling count values.
    
    Reviewed by:    mhorne, mav
    Sponsored by:   University of Cambridge, Google, Inc.
    Differential Revision:  https://reviews.freebsd.org/D35400
    
    (cherry picked from commit ca341f3cf52f8cb036d93cd611d8f3f5b552ea8e)
---
 share/man/man4/hwpmc.4    |  3 +++
 sys/dev/hwpmc/hwpmc_mod.c | 38 ++++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/share/man/man4/hwpmc.4 b/share/man/man4/hwpmc.4
index 063313045137..5b3353ff935d 100644
--- a/share/man/man4/hwpmc.4
+++ b/share/man/man4/hwpmc.4
@@ -423,6 +423,9 @@ The size in kilobytes of each log buffer used by
 .Nm Ns 's
 logging function.
 The default buffer size is 4KB.
+.It Va kern.hwpmc.mincount Pq integer, read-write
+The minimum sampling rate for sampling mode PMCs.
+The default count is 1000 events.
 .It Va kern.hwpmc.mtxpoolsize Pq integer, read-only
 The size of the spin mutex pool used by the PMC driver.
 The default is 32.
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index ac0d542c8a4d..50b4f3bc9d3b 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -363,6 +363,14 @@ SYSCTL_INT(_kern_hwpmc, OID_AUTO, threadfreelist_max, CTLFLAG_RW,
     "maximum number of available thread entries before freeing some");
 
 
+/*
+ * kern.hwpmc.mincount -- minimum sample count
+ */
+static u_int pmc_mincount = 1000;
+SYSCTL_INT(_kern_hwpmc, OID_AUTO, mincount, CTLFLAG_RWTUN,
+    &pmc_mincount, 0,
+    "minimum count for sampling counters");
+
 /*
  * security.bsd.unprivileged_syspmcs -- allow non-root processes to
  * allocate system-wide PMCs.
@@ -3950,13 +3958,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
 		/* XXX set lower bound on sampling for process counters */
 		if (PMC_IS_SAMPLING_MODE(mode)) {
 			/*
-			 * Don't permit requested sample rate to be less than 1000
+			 * Don't permit requested sample rate to be
+			 * less than pmc_mincount.
 			 */
-			if (pa.pm_count < 1000)
-				log(LOG_WARNING,
-					"pmcallocate: passed sample rate %ju - setting to 1000\n",
-					(uintmax_t)pa.pm_count);
-			pmc->pm_sc.pm_reloadcount = MAX(1000, pa.pm_count);
+			if (pa.pm_count < MAX(1, pmc_mincount))
+				log(LOG_WARNING, "pmcallocate: passed sample "
+				    "rate %ju - setting to %u\n",
+				    (uintmax_t)pa.pm_count,
+				    MAX(1, pmc_mincount));
+			pmc->pm_sc.pm_reloadcount = MAX(MAX(1, pmc_mincount),
+			    pa.pm_count);
 		} else
 			pmc->pm_sc.pm_initial = pa.pm_count;
 
@@ -4474,13 +4485,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
 
 		if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) {
 			/*
-			 * Don't permit requested sample rate to be less than 1000
+			 * Don't permit requested sample rate to be
+			 * less than pmc_mincount.
 			 */
-			if (sc.pm_count < 1000)
-				log(LOG_WARNING,
-					"pmcsetcount: passed sample rate %ju - setting to 1000\n",
-					(uintmax_t)sc.pm_count);
-			pm->pm_sc.pm_reloadcount = MAX(1000, sc.pm_count);
+			if (sc.pm_count < MAX(1, pmc_mincount))
+				log(LOG_WARNING, "pmcsetcount: passed sample "
+				    "rate %ju - setting to %u\n",
+				    (uintmax_t)sc.pm_count,
+				    MAX(1, pmc_mincount));
+			pm->pm_sc.pm_reloadcount = MAX(MAX(1, pmc_mincount),
+			    sc.pm_count);
 		} else
 			pm->pm_sc.pm_initial = sc.pm_count;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207131647.26DGla70052154>