diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c index 7aaf6f2a5b18..583a2d36bc74 100644 --- a/lib/libpmc/libpmc_pmu_util.c +++ b/lib/libpmc/libpmc_pmu_util.c @@ -237,6 +237,7 @@ pmu_parse_event(struct pmu_event_desc *ped, const char *eventin) return (ENOMEM); r = event; bzero(ped, sizeof(*ped)); + ped->ped_period = DEFAULT_SAMPLE_COUNT; ped->ped_umask = -1; while ((kvp = strsep(&event, ",")) != NULL) { key = strsep(&kvp, "="); 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 #include #include +#include #include #include @@ -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;