aboutsummaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2018-09-14 01:30:05 +0000
committerMatt Macy <mmacy@FreeBSD.org>2018-09-14 01:30:05 +0000
commit0204d85a62dd18966eae15cc71e9be117b2433c2 (patch)
tree1313fd2905e2b04f7684e2eb90d1927ce0962cb5 /sys/dev
parent3b9156971f7ec928aa3e03ac8dc5eea87ffe8cb7 (diff)
downloadsrc-0204d85a62dd18966eae15cc71e9be117b2433c2.tar.gz
src-0204d85a62dd18966eae15cc71e9be117b2433c2.zip
hwpmc: set default rate if event description lacks one / filter rate against misuse
Not all event descriptions have a sample rate (such as inst_retired.any) this will restore the legacy behavior of using 65536 in that case. It also prevents accidental API misuse that could lead to panic. PR: 230985 Reported by: markj Reviewed by: markj Approved by: re (gjb) Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D16958
Notes
Notes: svn path=/head/; revision=338677
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/hwpmc/hwpmc_mod.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 4d7a4535d27b..20df37d24bd6 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
+#include <sys/syslog.h>
#include <sys/systm.h>
#include <sys/vnode.h>
@@ -3942,9 +3943,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
pmc->pm_flags = pa.pm_flags;
/* XXX set lower bound on sampling for process counters */
- if (PMC_IS_SAMPLING_MODE(mode))
- pmc->pm_sc.pm_reloadcount = pa.pm_count;
- else
+ if (PMC_IS_SAMPLING_MODE(mode)) {
+ /*
+ * Don't permit requested sample rate to be less than 1000
+ */
+ 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);
+ } else
pmc->pm_sc.pm_initial = pa.pm_count;
/* switch thread to CPU 'cpu' */
@@ -4460,9 +4468,16 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
break;
}
- if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)))
- pm->pm_sc.pm_reloadcount = sc.pm_count;
- else
+ if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) {
+ /*
+ * Don't permit requested sample rate to be less than 1000
+ */
+ 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);
+ } else
pm->pm_sc.pm_initial = sc.pm_count;
}
break;