Page MenuHomeFreeBSD

D61367.1795626724.diff
No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None

D61367.1795626724.diff

diff --git a/share/man/man4/hwpmc.4 b/share/man/man4/hwpmc.4
--- a/share/man/man4/hwpmc.4
+++ b/share/man/man4/hwpmc.4
@@ -441,6 +441,17 @@
The number of rows in the hash tables used to keep track of owner and
target processes.
The default is 16.
+.It Va kern.hwpmc.ibs_fetch_min_period Pq integer, read-write
+The smallest sample period that the kernel accepts for an AMD IBS fetch
+PMC.
+A small period causes an interrupt rate that the system cannot sustain.
+The default is 65536.
+The kernel never accepts a period below 16, the hardware minimum.
+.It Va kern.hwpmc.ibs_op_min_period Pq integer, read-write
+The smallest sample period that the kernel accepts for an AMD IBS op
+PMC.
+The default is 65536.
+The kernel never accepts a period below 144, the hardware minimum.
.It Va kern.hwpmc.logbuffersize Pq integer, read-only
The size in kilobytes of each log buffer used by
.Nm Ns 's
diff --git a/sys/dev/hwpmc/hwpmc_ibs.h b/sys/dev/hwpmc/hwpmc_ibs.h
--- a/sys/dev/hwpmc/hwpmc_ibs.h
+++ b/sys/dev/hwpmc/hwpmc_ibs.h
@@ -88,6 +88,10 @@
#define IBS_OP_MAX_RATE 134217712
#define IBS_OP_MAX_RATE_PREEXT 1048560
+/* Hardware minimum periods. */
+#define IBS_FETCH_HW_MIN_PERIOD 0x10
+#define IBS_OP_HW_MIN_PERIOD 0x90
+
/* IBS Fetch Control */
#define IBS_FETCH_CTL 0xC0011030 /* IBS Fetch Control */
#define IBS_FETCH_CTL_L3MISS (1ULL << 61) /* L3 Cache Miss */
diff --git a/sys/dev/hwpmc/hwpmc_ibs.c b/sys/dev/hwpmc/hwpmc_ibs.c
--- a/sys/dev/hwpmc/hwpmc_ibs.c
+++ b/sys/dev/hwpmc/hwpmc_ibs.c
@@ -89,6 +89,17 @@
&ibs_op_ctl2_extra_mask, 0,
"Extra allowed bits in the IBS op control 2 MSR (override; default 0)");
+/* IBS minimum periods match libpmc. */
+static u_int ibs_fetch_min_period = IBS_FETCH_MIN_RATE;
+SYSCTL_UINT(_kern_hwpmc, OID_AUTO, ibs_fetch_min_period, CTLFLAG_RWTUN,
+ &ibs_fetch_min_period, 0,
+ "Minimum IBS fetch sample period");
+
+static u_int ibs_op_min_period = IBS_OP_MIN_RATE;
+SYSCTL_UINT(_kern_hwpmc, OID_AUTO, ibs_op_min_period, CTLFLAG_RWTUN,
+ &ibs_op_min_period, 0,
+ "Minimum IBS op sample period");
+
/* Count fetch and op stops. */
struct ibs_cpu {
int pc_stopping;
@@ -144,6 +155,7 @@
ibs_validate_fetch_config(uint64_t config)
{
uint64_t allowed_mask;
+ u_int minp;
allowed_mask = ibs_fetch_allowed_mask | ibs_fetch_extra_mask;
if ((config & ~allowed_mask) != 0) {
@@ -152,6 +164,12 @@
" 0x%jx", (uintmax_t)config, (uintmax_t)allowed_mask));
}
+ minp = MAX(ibs_fetch_min_period, IBS_FETCH_HW_MIN_PERIOD);
+ if (IBS_FETCH_CTL_TO_INTERVAL(config) < minp)
+ return (EXTERROR(EINVAL,
+ "IBS fetch period %ju is below the minimum %u",
+ (uintmax_t)IBS_FETCH_CTL_TO_INTERVAL(config), minp));
+
return (0);
}
@@ -159,6 +177,7 @@
ibs_validate_op_config(uint64_t config)
{
uint64_t allowed_mask;
+ u_int minp;
allowed_mask = ibs_op_allowed_mask;
@@ -186,6 +205,12 @@
" 0x%jx", (uintmax_t)config, (uintmax_t)allowed_mask));
}
+ minp = MAX(ibs_op_min_period, IBS_OP_HW_MIN_PERIOD);
+ if (IBS_OP_CTL_TO_INTERVAL(config) < minp)
+ return (EXTERROR(EINVAL,
+ "IBS op period %ju is below the minimum %u",
+ (uintmax_t)IBS_OP_CTL_TO_INTERVAL(config), minp));
+
return (0);
}
diff --git a/tests/sys/pmc/pmc_exterr_test.c b/tests/sys/pmc/pmc_exterr_test.c
--- a/tests/sys/pmc/pmc_exterr_test.c
+++ b/tests/sys/pmc/pmc_exterr_test.c
@@ -407,6 +407,50 @@
require_exterr("IBS op ctl config");
}
+ATF_TC_WITHOUT_HEAD(ibs_op_period_below_minimum);
+ATF_TC_BODY(ibs_op_period_below_minimum, tc)
+{
+ struct pmc_op_pmcallocate pa;
+
+ ATF_REQUIRE_FEATURE("exterr_strings");
+ require_hwpmc();
+ require_class(PMC_CLASS_IBS, "IBS");
+ clear_exterr();
+
+ memset(&pa, 0, sizeof(pa));
+ pa.pm_caps = PMC_CAP_SYSTEM;
+ pa.pm_class = PMC_CLASS_IBS;
+ pa.pm_mode = PMC_MODE_SS;
+ pa.pm_cpu = 0;
+ pa.pm_md.pm_ibs.ibs_type = IBS_PMC_OP;
+ pa.pm_md.pm_ibs.ibs_ctl = IBS_OP_INTERVAL_TO_CTL(16);
+
+ ATF_REQUIRE_ERRNO(EINVAL, hwpmc_call(PMC_OP_PMCALLOCATE, &pa) == -1);
+ require_exterr("IBS op period 16 is below the minimum");
+}
+
+ATF_TC_WITHOUT_HEAD(ibs_fetch_period_below_minimum);
+ATF_TC_BODY(ibs_fetch_period_below_minimum, tc)
+{
+ struct pmc_op_pmcallocate pa;
+
+ ATF_REQUIRE_FEATURE("exterr_strings");
+ require_hwpmc();
+ require_class(PMC_CLASS_IBS, "IBS");
+ clear_exterr();
+
+ memset(&pa, 0, sizeof(pa));
+ pa.pm_caps = PMC_CAP_SYSTEM;
+ pa.pm_class = PMC_CLASS_IBS;
+ pa.pm_mode = PMC_MODE_SS;
+ pa.pm_cpu = 0;
+ pa.pm_md.pm_ibs.ibs_type = IBS_PMC_FETCH;
+ pa.pm_md.pm_ibs.ibs_ctl = IBS_FETCH_INTERVAL_TO_CTL(16);
+
+ ATF_REQUIRE_ERRNO(EINVAL, hwpmc_call(PMC_OP_PMCALLOCATE, &pa) == -1);
+ require_exterr("IBS fetch period 16 is below the minimum");
+}
+
ATF_TC_WITHOUT_HEAD(ibs_nonsampling_mode);
ATF_TC_BODY(ibs_nonsampling_mode, tc)
{
@@ -438,6 +482,8 @@
ATF_TP_ADD_TC(tp, pmcrw_no_flags);
ATF_TP_ADD_TC(tp, pmcrw_write_running);
ATF_TP_ADD_TC(tp, amd_invalid_subclass);
+ ATF_TP_ADD_TC(tp, ibs_op_period_below_minimum);
+ ATF_TP_ADD_TC(tp, ibs_fetch_period_below_minimum);
ATF_TP_ADD_TC(tp, amd_invalid_config_bits);
ATF_TP_ADD_TC(tp, amd_invalid_df_config_bits);
ATF_TP_ADD_TC(tp, ibs_missing_system_capability);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 25, 5:12 PM (1 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41917527
Default Alt Text
D61367.1795626724.diff (5 KB)

Event Timeline