Skip to contentSkip to conversation

perf/amd/ibs: Fix sample period computations

PATCH Superseded Ravi Bangoria 2 participants 19 messages Dec 6, 2024

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover perf/amd/ibs: Fix sample period computations

IBS Fetch and IBS Op pmus have constraints on supported sample period values. The IBS hw behavior could be undefined if they are not followed. Currently, IBS driver does not honor them correctly and thus a malicious event could cause issues to the system. Fortunately, the IBS hw is very resilient so far and IBS pmus are restricted to root only, so the attack vector is minimal. In any case, these are genuine bugs and must be fixed.

Patches are rebased to peterz/queue/perf/core (f7372965c41d).

v1: https://lore.kernel.org/r/[email protected]
v1->v2:
- Patch #1 to #8: No code changes. Include Acked-by from Namhyung.
- Patch #9 and #10: Add perf test to test IBS pmus with various valid and invalid sample periods.

Ravi Bangoria (10):
perf/amd/ibs: Remove IBS_{FETCH|OP}_CONFIG_MASK macros perf/amd/ibs: Remove pointless sample period check perf/amd/ibs: Fix ->config to sample period calculation for OP pmu perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt perf/amd/ibs: Don't allow freq mode event creation through ->config
interface
perf/amd/ibs: Add pmu specific minimum period perf/amd/ibs: Add ->check_period() callback
perf/core: Introduce pmu->adjust_period() callback
perf test: Introduce DEFINE_SUITE_EXCLUSIVE()
perf test amd ibs: Add sample period unit test

 arch/x86/events/amd/ibs.c                  |  97 ++-
 arch/x86/include/asm/perf_event.h          |   1 +
 include/linux/perf_event.h                 |   5 +
 kernel/events/core.c                       |  12 +-
 tools/perf/arch/x86/include/arch-tests.h   |   1 +
 tools/perf/arch/x86/tests/Build            |   1 +
 tools/perf/arch/x86/tests/amd-ibs-period.c | 953 +++++++++++++++++++++
 tools/perf/arch/x86/tests/arch-tests.c     |   2 +
 tools/perf/tests/tests.h                   |  10 +
 9 files changed, 1055 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/arch/x86/tests/amd-ibs-period.c
Signature · 1 line
2.47.0
#1 lore raw

PATCH v2 1/10 perf/amd/ibs: Remove IBS_{FETCH|OP}_CONFIG_MASK macros

Definition of these macros are very simple and they are used at only one place. Get rid of unnecessary redirection.

---
 arch/x86/events/amd/ibs.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/events/amd/ibs.c +2 -6
index f02939655b2a..26dd5e5874f9 100644
@@ -28,10 +28,6 @@ static u32 ibs_caps;
 #include <asm/nmi.h>
 #include <asm/amd-ibs.h>
 
-#define IBS_FETCH_CONFIG_MASK	(IBS_FETCH_RAND_EN | IBS_FETCH_MAX_CNT)
-#define IBS_OP_CONFIG_MASK	IBS_OP_MAX_CNT
-
-
 /*
  * IBS states:
  *
@@ -670,7 +666,7 @@ static struct perf_ibs perf_ibs_fetch = {
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSFETCHCTL,
-	.config_mask		= IBS_FETCH_CONFIG_MASK,
+	.config_mask		= IBS_FETCH_MAX_CNT | IBS_FETCH_RAND_EN,
 	.cnt_mask		= IBS_FETCH_MAX_CNT,
 	.enable_mask		= IBS_FETCH_ENABLE,
 	.valid_mask		= IBS_FETCH_VAL,
@@ -694,7 +690,7 @@ static struct perf_ibs perf_ibs_op = {
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSOPCTL,
-	.config_mask		= IBS_OP_CONFIG_MASK,
+	.config_mask		= IBS_OP_MAX_CNT,
 	.cnt_mask		= IBS_OP_MAX_CNT | IBS_OP_CUR_CNT |
 				  IBS_OP_CUR_CNT_RAND,
 	.enable_mask		= IBS_OP_ENABLE,
Signature · 1 line
2.47.0
#2 lore raw

PATCH v2 2/10 perf/amd/ibs: Remove pointless sample period check

In reply to Ravi Bangoria

Valid perf event sample period value for IBS PMUs (Fetch and Op both) is limited to multiple of 0x10. perf_ibs_init() has this check:

  if (!event->attr.sample_freq && hwc->sample_period & 0x0f)
          return -EINVAL;

But it's broken since hwc->sample_period will always be 0 when event->attr.sample_freq is 0 (irrespective of event->attr.freq value.)

One option to fix this is to change the condition:

- if (!event->attr.sample_freq && hwc->sample_period & 0x0f)
+ if (!event->attr.freq && hwc->sample_period & 0x0f)

However, that will break all userspace tools which have been using IBS event with sample_period not multiple of 0x10.

Another option is to remove the condition altogether and mask lower nibble _silently_, same as what current code is inadvertently doing. I'm preferring this approach as it keeps the existing behavior.

---
 arch/x86/events/amd/ibs.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
arch/x86/events/amd/ibs.c +2 -7
index 26dd5e5874f9..484606a9bf6b 100644
@@ -294,13 +294,8 @@ static int perf_ibs_init(struct perf_event *event)
 		if (config & perf_ibs->cnt_mask)
 			/* raw max_cnt may not be set */
 			return -EINVAL;
-		if (!event->attr.sample_freq && hwc->sample_period & 0x0f)
-			/*
-			 * lower 4 bits can not be set in ibs max cnt,
-			 * but allowing it in case we adjust the
-			 * sample period to set a frequency.
-			 */
-			return -EINVAL;
+
+		/* Silently mask off lower nibble. IBS hw mandates it. */
 		hwc->sample_period &= ~0x0FULL;
 		if (!hwc->sample_period)
 			hwc->sample_period = 0x10;
Signature · 1 line
2.47.0
#3 lore raw

PATCH v2 3/10 perf/amd/ibs: Fix ->config to sample period calculation for OP pmu

In reply to Ravi Bangoria

Instead of using standard perf_event_attr->freq=0 and ->sample_period fields, IBS event in 'sample period mode' can also be opened by setting period value directly in perf_event_attr->config in a MaxCnt bit-field format.

IBS OP MaxCnt bits are defined as:

(high bits) IbsOpCtl[26:20] = IbsOpMaxCnt[26:20] (low bits) IbsOpCtl[15:0] = IbsOpMaxCnt[19:4]

Perf event sample period can be derived from MaxCnt bits as:

  sample_period = (high bits) | ((low_bits) << 4);

However, current code just masks MaxCnt bits and shifts all of them, including high bits, which is incorrect. Fix it.

---
 arch/x86/events/amd/ibs.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
arch/x86/events/amd/ibs.c +13 -4
index 484606a9bf6b..63e1c1c11727 100644
@@ -268,7 +268,7 @@ static int perf_ibs_init(struct perf_event *event)
 {
 	struct hw_perf_event *hwc = &event->hw;
 	struct perf_ibs *perf_ibs;
-	u64 max_cnt, config;
+	u64 config;
 	int ret;
 
 	perf_ibs = get_ibs_pmu(event->attr.type);
@@ -300,10 +300,19 @@ static int perf_ibs_init(struct perf_event *event)
 		if (!hwc->sample_period)
 			hwc->sample_period = 0x10;
 	} else {
-		max_cnt = config & perf_ibs->cnt_mask;
+		u64 period = 0;
+
+		if (perf_ibs == &perf_ibs_op) {
+			period = (config & IBS_OP_MAX_CNT) << 4;
+			if (ibs_caps & IBS_CAPS_OPCNTEXT)
+				period |= config & IBS_OP_MAX_CNT_EXT_MASK;
+		} else {
+			period = (config & IBS_FETCH_MAX_CNT) << 4;
+		}
+
 		config &= ~perf_ibs->cnt_mask;
-		event->attr.sample_period = max_cnt << 4;
-		hwc->sample_period = event->attr.sample_period;
+		event->attr.sample_period = period;
+		hwc->sample_period = period;
 	}
 
 	if (!hwc->sample_period)
Signature · 1 line
2.47.0
#4 lore raw

PATCH v2 4/10 perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt

In reply to Ravi Bangoria

IBS Op uses two counters: MaxCnt and CurCnt. MaxCnt is programmed with the desired sample period. IBS hw generates sample when CurCnt reaches to MaxCnt. The size of these counter used to be 20 bits but later they were extended to 27 bits. The 7 bit extension is indicated by CPUID Fn8000_001B_EAX[6 / OpCntExt].

perf_ibs->cnt_mask variable contains bit masks for MaxCnt and CurCnt. But IBS driver does not set upper 7 bits of CurCnt in cnt_mask even when OpCntExt CPUID bit is set. Fix this.

IBS driver uses cnt_mask[CurCnt] bits only while disabling an event. Fortunately, CurCnt bits are not read from MSR while re-enabling the event, instead MaxCnt is programmed with desired period and CurCnt is set to 0. Hence, we did not see any issues so far.

---
 arch/x86/events/amd/ibs.c         | 3 ++-
 arch/x86/include/asm/perf_event.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/events/amd/ibs.c +2 -1
index 63e1c1c11727..11123c174a3b 100644
@@ -1221,7 +1221,8 @@ static __init int perf_ibs_op_init(void)
 	if (ibs_caps & IBS_CAPS_OPCNTEXT) {
 		perf_ibs_op.max_period  |= IBS_OP_MAX_CNT_EXT_MASK;
 		perf_ibs_op.config_mask	|= IBS_OP_MAX_CNT_EXT_MASK;
-		perf_ibs_op.cnt_mask    |= IBS_OP_MAX_CNT_EXT_MASK;
+		perf_ibs_op.cnt_mask    |= (IBS_OP_MAX_CNT_EXT_MASK |
+					    IBS_OP_CUR_CNT_EXT_MASK);
 	}
 
 	if (ibs_caps & IBS_CAPS_ZEN4)
arch/x86/include/asm/perf_event.h +1 -0
index cb9c4679f45c..aff9fc693b11 100644
@@ -510,6 +510,7 @@ struct pebs_xmm {
  */
 #define IBS_OP_CUR_CNT		(0xFFF80ULL<<32)
 #define IBS_OP_CUR_CNT_RAND	(0x0007FULL<<32)
+#define IBS_OP_CUR_CNT_EXT_MASK	(0x7FULL<<52)
 #define IBS_OP_CNT_CTL		(1ULL<<19)
 #define IBS_OP_VAL		(1ULL<<18)
 #define IBS_OP_ENABLE		(1ULL<<17)
Signature · 1 line
2.47.0
#5 lore raw

PATCH v2 5/10 perf/amd/ibs: Don't allow freq mode event creation through ->config interface

In reply to Ravi Bangoria

Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface.

However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks.

Don't allow freq mode event creation through perf_event_attr->config interface.

---
 arch/x86/events/amd/ibs.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/events/amd/ibs.c +3 -0
index 11123c174a3b..a687ffb09905 100644
@@ -302,6 +302,9 @@ static int perf_ibs_init(struct perf_event *event)
 	} else {
 		u64 period = 0;
 
+		if (event->attr.freq)
+			return -EINVAL;
+
 		if (perf_ibs == &perf_ibs_op) {
 			period = (config & IBS_OP_MAX_CNT) << 4;
 			if (ibs_caps & IBS_CAPS_OPCNTEXT)
Signature · 1 line
2.47.0
#6 lore raw

Re: [PATCH v2 05/10] perf/amd/ibs: Don't allow freq mode event creation through ->config interface

Quoted 6 lines · Ravi Bangoria

Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface.

Quoted 7 lines

However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks.

Then let's fix those rate checks?

AFAICS this patch limits functionality because the IBS driver would have to be fixed/enhanced to support frequency based events?

I'd strongly favor fixing/enhancing the driver instead, as 'perf top -F 1000' is easy to use and it is a useful concept.

Thanks,

Ingo

#7 lore raw

Re: [PATCH v2 05/10] perf/amd/ibs: Don't allow freq mode event creation through ->config interface

Hi Ingo,

Quoted 14 lines
Quoted 6 lines

Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface.

Quoted 7 lines

However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks.

Quoted 7 lines

Then let's fix those rate checks?

AFAICS this patch limits functionality because the IBS driver would have to be fixed/enhanced to support frequency based events?

I'd strongly favor fixing/enhancing the driver instead, as 'perf top -F 1000' is easy to use and it is a useful concept.

No. This patch does not prevent opening an IBS event in freq mode. User can still open freq mode IBS event with usual interface attr->freq=1 and attr->sample_freq=<freq>. i.e. 'perf top -F 1000' with IBS event will work fine with this patch.

Thanks,
Ravi

#8 lore raw

Re: [PATCH v2 05/10] perf/amd/ibs: Don't allow freq mode event creation through ->config interface

Quoted 21 lines · Ravi Bangoria

Hi Ingo,

Quoted 19 lines
Quoted 6 lines

Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface.

Quoted 7 lines

However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks.

Then let's fix those rate checks?

AFAICS this patch limits functionality because the IBS driver would have to be fixed/enhanced to support frequency based events?

Quoted 7 lines
Quoted 2 lines

I'd strongly favor fixing/enhancing the driver instead, as 'perf top -F 1000' is easy to use and it is a useful concept.

No. This patch does not prevent opening an IBS event in freq mode. User can still open freq mode IBS event with usual interface attr->freq=1 and attr->sample_freq=<freq>. i.e. 'perf top -F 1000' with IBS event will work fine with this patch.

Oh, I see - the regular tooling uses perf_event_attr->sample_period, right?

Never mind then.

Thanks,

Ingo

#9 lore raw

Re: [PATCH v2 05/10] perf/amd/ibs: Don't allow freq mode event creation through ->config interface

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 6 lines

Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL MSR. Since the sample period is programmed in these control registers, IBS PMU driver allows opening an IBS event by setting sample period value directly in perf_event_attr->config instead of using explicit perf_event_attr->sample_period interface.

Quoted 7 lines

However, this logic is not applicable for freq mode events since the semantics of control register fields are applicable only to fixed sample period whereas the freq mode event adjusts sample period after each and every sample. Currently, IBS driver (unintentionally) allows creating freq mode event via ->config interface, which is semantically wrong as well as detrimental because it can be misused to bypass perf_event_max_sample_rate checks.

Then let's fix those rate checks?

AFAICS this patch limits functionality because the IBS driver would have to be fixed/enhanced to support frequency based events?

I'd strongly favor fixing/enhancing the driver instead, as 'perf top -F 1000' is easy to use and it is a useful concept.

Quoted 6 lines
Quoted 4 lines

No. This patch does not prevent opening an IBS event in freq mode. User can still open freq mode IBS event with usual interface attr->freq=1 and attr->sample_freq=<freq>. i.e. 'perf top -F 1000' with IBS event will work fine with this patch.

Oh, I see - the regular tooling uses perf_event_attr->sample_period, right?

Correct.

Quoted 1 line

Never mind then.

No worries. Thanks for the review :)

Thanks,
Ravi

#10 lore raw

PATCH v2 6/10 perf/amd/ibs: Add pmu specific minimum period

In reply to Ravi Bangoria

0x10 is the minimum sample period for IBS Fetch and 0x90 for IBS Op. Current IBS pmu driver uses 0x10 for both the pmus, which is incorrect. Fix it by adding pmu specific minimum period values in struct perf_ibs.

Also, bail out opening a 'sample period mode' event if the user requested sample period is less than pmu supported minimum value. For a 'freq mode' event, start calibrating sample period from pmu specific minimum period.

---
 arch/x86/events/amd/ibs.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
arch/x86/events/amd/ibs.c +16 -8
index a687ffb09905..cc58ef4d8de3 100644
@@ -83,6 +83,7 @@ struct perf_ibs {
 	u64				cnt_mask;
 	u64				enable_mask;
 	u64				valid_mask;
+	u16				min_period;
 	u64				max_period;
 	unsigned long			offset_mask[1];
 	int				offset_max;
@@ -295,10 +296,14 @@ static int perf_ibs_init(struct perf_event *event)
 			/* raw max_cnt may not be set */
 			return -EINVAL;
 
-		/* Silently mask off lower nibble. IBS hw mandates it. */
-		hwc->sample_period &= ~0x0FULL;
-		if (!hwc->sample_period)
-			hwc->sample_period = 0x10;
+		if (event->attr.freq) {
+			hwc->sample_period = perf_ibs->min_period;
+		} else {
+			/* Silently mask off lower nibble. IBS hw mandates it. */
+			hwc->sample_period &= ~0x0FULL;
+			if (hwc->sample_period < perf_ibs->min_period)
+				return -EINVAL;
+		}
 	} else {
 		u64 period = 0;
 
@@ -316,10 +321,10 @@ static int perf_ibs_init(struct perf_event *event)
 		config &= ~perf_ibs->cnt_mask;
 		event->attr.sample_period = period;
 		hwc->sample_period = period;
-	}
 
-	if (!hwc->sample_period)
-		return -EINVAL;
+		if (hwc->sample_period < perf_ibs->min_period)
+			return -EINVAL;
+	}
 
 	/*
 	 * If we modify hwc->sample_period, we also need to update
@@ -340,7 +345,8 @@ static int perf_ibs_set_period(struct perf_ibs *perf_ibs,
 	int overflow;
 
 	/* ignore lower 4 bits in min count: */
-	overflow = perf_event_set_period(hwc, 1<<4, perf_ibs->max_period, period);
+	overflow = perf_event_set_period(hwc, perf_ibs->min_period,
+					 perf_ibs->max_period, period);
 	local64_set(&hwc->prev_count, 0);
 
 	return overflow;
@@ -677,6 +683,7 @@ static struct perf_ibs perf_ibs_fetch = {
 	.cnt_mask		= IBS_FETCH_MAX_CNT,
 	.enable_mask		= IBS_FETCH_ENABLE,
 	.valid_mask		= IBS_FETCH_VAL,
+	.min_period		= 0x10,
 	.max_period		= IBS_FETCH_MAX_CNT << 4,
 	.offset_mask		= { MSR_AMD64_IBSFETCH_REG_MASK },
 	.offset_max		= MSR_AMD64_IBSFETCH_REG_COUNT,
@@ -702,6 +709,7 @@ static struct perf_ibs perf_ibs_op = {
 				  IBS_OP_CUR_CNT_RAND,
 	.enable_mask		= IBS_OP_ENABLE,
 	.valid_mask		= IBS_OP_VAL,
+	.min_period		= 0x90,
 	.max_period		= IBS_OP_MAX_CNT << 4,
 	.offset_mask		= { MSR_AMD64_IBSOP_REG_MASK },
 	.offset_max		= MSR_AMD64_IBSOP_REG_COUNT,
Signature · 1 line
2.47.0
#11 lore raw

Re: [PATCH v2 06/10] perf/amd/ibs: Add pmu specific minimum period

Quoted 7 lines · Ravi Bangoria

0x10 is the minimum sample period for IBS Fetch and 0x90 for IBS Op. Current IBS pmu driver uses 0x10 for both the pmus, which is incorrect. Fix it by adding pmu specific minimum period values in struct perf_ibs.

Also, bail out opening a 'sample period mode' event if the user requested sample period is less than pmu supported minimum value. For a 'freq mode' event, start calibrating sample period from pmu specific minimum period.

Could you please capitalize PMU consistently, like the rest of the code does, both in code comments and in changelogs?

It's "PMU" and "PMUs", not "pmu" and "pmus". The only lower case use is when we mention 'struct pmu' - and that should be quoted.

Thanks,

Ingo

#12 lore raw

Re: [PATCH v2 06/10] perf/amd/ibs: Add pmu specific minimum period

Quoted 11 lines · Ingo Molnar
Quoted 7 lines · Ravi Bangoria

0x10 is the minimum sample period for IBS Fetch and 0x90 for IBS Op. Current IBS pmu driver uses 0x10 for both the pmus, which is incorrect. Fix it by adding pmu specific minimum period values in struct perf_ibs.

Also, bail out opening a 'sample period mode' event if the user requested sample period is less than pmu supported minimum value. For a 'freq mode' event, start calibrating sample period from pmu specific minimum period.

Quoted 5 lines

Could you please capitalize PMU consistently, like the rest of the code does, both in code comments and in changelogs?

It's "PMU" and "PMUs", not "pmu" and "pmus". The only lower case use is when we mention 'struct pmu' - and that should be quoted.

Sure. Will fix that in next revision.

Thanks,
Ravi

#13 lore raw

PATCH v2 7/10 perf/amd/ibs: Add ->check_period() callback

In reply to Ravi Bangoria

IBS Fetch and IBS Op pmus have constraints on sample period. The sample period is verified at the time of opening an event but not at the ioctl() interface. Hence, a user can open an event with valid period but change it later with ioctl(). Add a ->check_period() callback to verify the period provided at ioctl() is also valid.

---
 arch/x86/events/amd/ibs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
arch/x86/events/amd/ibs.c +24 -0
index cc58ef4d8de3..54a434722c79 100644
@@ -551,6 +551,28 @@ static void perf_ibs_del(struct perf_event *event, int flags)
 
 static void perf_ibs_read(struct perf_event *event) { }
 
+static int perf_ibs_check_period(struct perf_event *event, u64 value)
+{
+	struct perf_ibs *perf_ibs;
+	u64 low_nibble;
+
+	if (event->attr.freq)
+		return 0;
+
+	perf_ibs = container_of(event->pmu, struct perf_ibs, pmu);
+	low_nibble = value & 0xFULL;
+
+	/*
+	 * This contradicts with perf_ibs_init() which allows sample period
+	 * with lower nibble bits set but silently masks them off. Whereas
+	 * this returns error.
+	 */
+	if (low_nibble || value < perf_ibs->min_period)
+		return -EINVAL;
+
+	return 0;
+}
+
 /*
  * We need to initialize with empty group if all attributes in the
  * group are dynamic.
@@ -676,6 +698,7 @@ static struct perf_ibs perf_ibs_fetch = {
 		.start		= perf_ibs_start,
 		.stop		= perf_ibs_stop,
 		.read		= perf_ibs_read,
+		.check_period	= perf_ibs_check_period,
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSFETCHCTL,
@@ -701,6 +724,7 @@ static struct perf_ibs perf_ibs_op = {
 		.start		= perf_ibs_start,
 		.stop		= perf_ibs_stop,
 		.read		= perf_ibs_read,
+		.check_period	= perf_ibs_check_period,
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSOPCTL,
Signature · 1 line
2.47.0
#14 lore raw

PATCH v2 8/10 perf/core: Introduce pmu->adjust_period() callback

In reply to Ravi Bangoria

Many hardware pmus have constraints about sample period. For ex, minimum supported sample period for IBS Op pmu is 0x90, the sample period must be multiple of 0x10 for IBS Fetch and IBS Op.

Add an optional callback adjust_period() to struct pmu to allow pmu specific drivers to adjust sample period calculated by generic code. This will ensure the sample_period value will always be valid and no additional code is required in PMU specific drivers to re-adjust the period.

---
 arch/x86/events/amd/ibs.c  | 11 +++++++++++
 include/linux/perf_event.h |  5 +++++
 kernel/events/core.c       | 12 ++++++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)
arch/x86/events/amd/ibs.c +11 -0
index 54a434722c79..e41f83989b4e 100644
@@ -573,6 +573,15 @@ static int perf_ibs_check_period(struct perf_event *event, u64 value)
 	return 0;
 }
 
+static u64 perf_ibs_adjust_period(struct perf_event *event, u64 period)
+{
+	struct perf_ibs *perf_ibs = container_of(event->pmu, struct perf_ibs, pmu);
+
+	period &= ~0xFULL;
+
+	return period < perf_ibs->min_period ? perf_ibs->min_period : period;
+}
+
 /*
  * We need to initialize with empty group if all attributes in the
  * group are dynamic.
@@ -699,6 +708,7 @@ static struct perf_ibs perf_ibs_fetch = {
 		.stop		= perf_ibs_stop,
 		.read		= perf_ibs_read,
 		.check_period	= perf_ibs_check_period,
+		.adjust_period	= perf_ibs_adjust_period,
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSFETCHCTL,
@@ -725,6 +735,7 @@ static struct perf_ibs perf_ibs_op = {
 		.stop		= perf_ibs_stop,
 		.read		= perf_ibs_read,
 		.check_period	= perf_ibs_check_period,
+		.adjust_period	= perf_ibs_adjust_period,
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	},
 	.msr			= MSR_AMD64_IBSOPCTL,
include/linux/perf_event.h +5 -0
index bf831b1485ff..d588d3dda492 100644
@@ -582,6 +582,11 @@ struct pmu {
 	 * Check period value for PERF_EVENT_IOC_PERIOD ioctl.
 	 */
 	int (*check_period)		(struct perf_event *event, u64 value); /* optional */
+
+	/*
+	 * Adjust period value according to pmu constraints.
+	 */
+	u64 (*adjust_period)		(struct perf_event *event, u64 period); /* optional */
 };
 
 enum perf_addr_filter_action_t {
kernel/events/core.c +10 -2
index 4c6f6c286b2d..6858f8d9b16c 100644
@@ -4192,9 +4192,9 @@ static void perf_adjust_period(struct perf_event *event, u64 nsec, u64 count, bo
 	if (!sample_period)
 		sample_period = 1;
 
-	hwc->sample_period = sample_period;
+	hwc->sample_period = event->pmu->adjust_period(event, sample_period);
 
-	if (local64_read(&hwc->period_left) > 8*sample_period) {
+	if (local64_read(&hwc->period_left) > 8*hwc->sample_period) {
 		if (disable)
 			event->pmu->stop(event, PERF_EF_UPDATE);
 
@@ -11562,6 +11562,11 @@ static int perf_event_nop_int(struct perf_event *event, u64 value)
 	return 0;
 }
 
+static u64 perf_pmu_nop_adjust_period(struct perf_event *event, u64 period)
+{
+	return period;
+}
+
 static DEFINE_PER_CPU(unsigned int, nop_txn_flags);
 
 static void perf_pmu_start_txn(struct pmu *pmu, unsigned int flags)
@@ -11899,6 +11904,9 @@ int perf_pmu_register(struct pmu *pmu, const char *name, int type)
 	if (!pmu->check_period)
 		pmu->check_period = perf_event_nop_int;
 
+	if (!pmu->adjust_period)
+		pmu->adjust_period = perf_pmu_nop_adjust_period;
+
 	if (!pmu->event_idx)
 		pmu->event_idx = perf_event_idx_default;
 
Signature · 1 line
2.47.0
#15 lore raw

PATCH v2 9/10 perf test: Introduce DEFINE_SUITE_EXCLUSIVE()

In reply to Ravi Bangoria

A variant of DEFINE_SUITE() but sets ->exclusive bit for the test so the test will be executed sequentially.

---
 tools/perf/tests/tests.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/perf/tests/tests.h +10 -0
index cb58b43aa063..8aea344536b8 100644
@@ -81,6 +81,16 @@ struct test_suite {
 		.test_cases = tests__##_name,		\
 	}
 
+#define DEFINE_SUITE_EXCLUSIVE(description, _name)	\
+	struct test_case tests__##_name[] = {           \
+		TEST_CASE_EXCLUSIVE(description, _name),\
+		{	.name = NULL, }			\
+	};						\
+	struct test_suite suite__##_name = {		\
+		.desc = description,			\
+		.test_cases = tests__##_name,		\
+	}
+
 /* Tests */
 DECLARE_SUITE(vmlinux_matches_kallsyms);
 DECLARE_SUITE(openat_syscall_event);
Signature · 1 line
2.47.0
#16 lore raw

PATCH v2 10/10 perf test amd ibs: Add sample period unit test

In reply to Ravi Bangoria

IBS Fetch and IBS Op pmus has various constraints on supported sample periods. Add perf unit tests to test those.

Running it in parallel with other tests causes intermittent failures. Mark it exclusive to force it to run sequentially.

---
 tools/perf/arch/x86/include/arch-tests.h   |   1 +
 tools/perf/arch/x86/tests/Build            |   1 +
 tools/perf/arch/x86/tests/amd-ibs-period.c | 953 +++++++++++++++++++++
 tools/perf/arch/x86/tests/arch-tests.c     |   2 +
 4 files changed, 957 insertions(+)
 create mode 100644 tools/perf/arch/x86/tests/amd-ibs-period.c
tools/perf/arch/x86/include/arch-tests.h +1 -0
index c0421a26b875..4fd425157d7d 100644
@@ -14,6 +14,7 @@ int test__intel_pt_hybrid_compat(struct test_suite *test, int subtest);
 int test__bp_modify(struct test_suite *test, int subtest);
 int test__x86_sample_parsing(struct test_suite *test, int subtest);
 int test__amd_ibs_via_core_pmu(struct test_suite *test, int subtest);
+int test__amd_ibs_period(struct test_suite *test, int subtest);
 int test__hybrid(struct test_suite *test, int subtest);
 
 extern struct test_suite *arch_tests[];
tools/perf/arch/x86/tests/Build +1 -0
index 3227053f3355..db4b7945fc40 100644
@@ -10,6 +10,7 @@ perf-test-$(CONFIG_AUXTRACE) += insn-x86.o
 endif
 perf-test-$(CONFIG_X86_64) += bp-modify.o
 perf-test-y += amd-ibs-via-core-pmu.o
+perf-test-y += amd-ibs-period.o
 
 ifdef SHELLCHECK
   SHELL_TESTS := gen-insn-x86-dat.sh
tools/perf/arch/x86/tests/amd-ibs-period.c new file +953 -0

953 lines not on this page · raw message

tools/perf/arch/x86/tests/arch-tests.c +2 -0
index a216a5d172ed..bfee2432515b 100644
@@ -25,6 +25,7 @@ DEFINE_SUITE("x86 bp modify", bp_modify);
 #endif
 DEFINE_SUITE("x86 Sample parsing", x86_sample_parsing);
 DEFINE_SUITE("AMD IBS via core pmu", amd_ibs_via_core_pmu);
+DEFINE_SUITE_EXCLUSIVE("AMD IBS sample period", amd_ibs_period);
 static struct test_case hybrid_tests[] = {
 	TEST_CASE_REASON("x86 hybrid event parsing", hybrid, "not hybrid"),
 	{ .name = NULL, }
@@ -50,6 +51,7 @@ struct test_suite *arch_tests[] = {
 #endif
 	&suite__x86_sample_parsing,
 	&suite__amd_ibs_via_core_pmu,
+	&suite__amd_ibs_period,
 	&suite__hybrid,
 	NULL,
 };
Signature · 1 line
2.47.0
#17 lore raw

Re: [PATCH v2 10/10] perf test amd ibs: Add sample period unit test

Quoted 5 lines · Ravi Bangoria

IBS Fetch and IBS Op pmus has various constraints on supported sample periods. Add perf unit tests to test those.

Running it in parallel with other tests causes intermittent failures. Mark it exclusive to force it to run sequentially.

The verbose mode of unit test is quite exhaustive so I've not added it in the commit description. Here is the sample output on a Zen5 machine:

Without patches:

  $ sudo ./perf test -vv 112
   75: AMD IBS sample period:
  --- start ---
  test child forked, pid 7368
  Using CPUID AuthenticAMD-26-2-1

IBS config tests:
-----------------
Fetch PMU tests:

  0xffff            : Ok   (nr samples: 1224)
  0x1000            : Ok   (nr samples: 19866)
  0xff              : Ok   (nr samples: 40738)
  0x1               : Ok   (nr samples: 40945)
  0x0               : Ok
  0x10000           : Ok
  Op PMU tests:
  0x0               : Ok
  0x1               : Fail
  0x8               : Fail
  0x9               : Ok   (nr samples: 40543)
  0xf               : Ok   (nr samples: 40543)
  0x1000            : Ok   (nr samples: 20267)
  0xffff            : Ok   (nr samples: 1289)
  0x10000           : Ok
  0x100000          : Fail (nr samples: 17)
  0xf00000          : Fail (nr samples: 1)
  0xf0ffff          : Fail (nr samples: 1)
  0x1f0ffff         : Fail (nr samples: 1)
  0x7f0ffff         : Fail (nr samples: 0)
  0x8f0ffff         : Ok
  0x17f0ffff        : Ok

IBS sample period constraint tests:
-----------------------------------
Fetch PMU test:
freq 0, sample_freq 0: Ok
freq 0, sample_freq 1: Fail

  freq 0, sample_freq      15: Fail
  freq 0, sample_freq      16: Ok   (nr samples: 1604)
  freq 0, sample_freq      17: Ok   (nr samples: 1604)
  freq 0, sample_freq     143: Ok   (nr samples: 1232)
  freq 0, sample_freq     144: Ok   (nr samples: 1274)
  freq 0, sample_freq     145: Ok   (nr samples: 1241)
  freq 0, sample_freq    1234: Ok   (nr samples: 1261)
  freq 0, sample_freq   65520: Ok   (nr samples: 2660)
  freq 0, sample_freq   65535: Ok   (nr samples: 2635)
  freq 0, sample_freq   65552: Ok   (nr samples: 2633)
  freq 0, sample_freq 8388607: Ok   (nr samples: 31)
  freq 1, sample_freq       0: Ok
  freq 1, sample_freq       1: Ok   (nr samples: 4)
  freq 1, sample_freq      15: Ok   (nr samples: 4)
  freq 1, sample_freq      16: Ok   (nr samples: 4)
  freq 1, sample_freq      17: Ok   (nr samples: 4)
  freq 1, sample_freq     143: Ok   (nr samples: 5)
  freq 1, sample_freq     144: Ok   (nr samples: 5)
  freq 1, sample_freq     145: Ok   (nr samples: 5)
  freq 1, sample_freq    1234: Ok   (nr samples: 8)
  freq 1, sample_freq   65520: Ok   (nr samples: 541)
  freq 1, sample_freq   65535: Ok   (nr samples: 622)
  freq 1, sample_freq   65552: Ok   (nr samples: 720)
  freq 1, sample_freq 8388607: Ok
  Op PMU test:
  freq 0, sample_freq       0: Ok
  freq 0, sample_freq       1: Fail
  freq 0, sample_freq      15: Fail
  freq 0, sample_freq      16: Fail
  freq 0, sample_freq      17: Fail
  freq 0, sample_freq     143: Fail
  freq 0, sample_freq     144: Ok   (nr samples: 2005)
  freq 0, sample_freq     145: Ok   (nr samples: 1604)
  freq 0, sample_freq    1234: Ok   (nr samples: 1604)
  freq 0, sample_freq   65520: Ok   (nr samples: 2547)
  freq 0, sample_freq   65535: Ok   (nr samples: 2532)
  freq 0, sample_freq   65552: Ok   (nr samples: 2469)
  freq 0, sample_freq 8388607: Ok   (nr samples: 30)
  freq 1, sample_freq       0: Ok
  freq 1, sample_freq       1: Fail (nr samples: 4)
  freq 1, sample_freq      15: Fail (nr samples: 4)
  freq 1, sample_freq      16: Fail (nr samples: 4)
  freq 1, sample_freq      17: Fail (nr samples: 4)
  freq 1, sample_freq     143: Fail (nr samples: 5)
  freq 1, sample_freq     144: Fail (nr samples: 5)
  freq 1, sample_freq     145: Fail (nr samples: 5)
  freq 1, sample_freq    1234: Fail (nr samples: 6)
  freq 1, sample_freq   65520: Fail (nr samples: 602)
  freq 1, sample_freq   65535: Fail (nr samples: 618)
  freq 1, sample_freq   65552: Fail (nr samples: 622)

freq 1, sample_freq 8388607: Ok

IBS ioctl() tests:
------------------
Fetch PMU tests

  ioctl(period = 0x0      ): Ok
  ioctl(period = 0x1      ): Fail
  ioctl(period = 0xf      ): Fail
  ioctl(period = 0x10     ): Ok
  ioctl(period = 0x11     ): Fail
  ioctl(period = 0x1f     ): Fail
  ioctl(period = 0x20     ): Ok
  ioctl(period = 0x80     ): Ok
  ioctl(period = 0x8f     ): Fail
  ioctl(period = 0x90     ): Ok
  ioctl(period = 0x91     ): Fail
  ioctl(period = 0x100    ): Ok
  ioctl(period = 0xfff0   ): Ok
  ioctl(period = 0xffff   ): Fail
  ioctl(period = 0x10000  ): Ok
  ioctl(period = 0x1fff0  ): Ok
  ioctl(period = 0x1fff5  ): Fail
  ioctl(freq   = 0x0      ): Ok
  ioctl(freq   = 0x1      ): Ok
  ioctl(freq   = 0xf      ): Ok
  ioctl(freq   = 0x10     ): Ok
  ioctl(freq   = 0x11     ): Ok
  ioctl(freq   = 0x1f     ): Ok
  ioctl(freq   = 0x20     ): Ok
  ioctl(freq   = 0x80     ): Ok
  ioctl(freq   = 0x8f     ): Ok
  ioctl(freq   = 0x90     ): Ok
  ioctl(freq   = 0x91     ): Ok
  ioctl(freq   = 0x100    ): Ok
  Op PMU tests
  ioctl(period = 0x0      ): Ok
  ioctl(period = 0x1      ): Fail
  ioctl(period = 0xf      ): Fail
  ioctl(period = 0x10     ): Fail
  ioctl(period = 0x11     ): Fail
  ioctl(period = 0x1f     ): Fail
  ioctl(period = 0x20     ): Fail
  ioctl(period = 0x80     ): Fail
  ioctl(period = 0x8f     ): Fail
  ioctl(period = 0x90     ): Ok
  ioctl(period = 0x91     ): Fail
  ioctl(period = 0x100    ): Ok
  ioctl(period = 0xfff0   ): Ok
  ioctl(period = 0xffff   ): Fail
  ioctl(period = 0x10000  ): Ok
  ioctl(period = 0x1fff0  ): Ok
  ioctl(period = 0x1fff5  ): Fail
  ioctl(freq   = 0x0      ): Ok
  ioctl(freq   = 0x1      ): Ok
  ioctl(freq   = 0xf      ): Ok
  ioctl(freq   = 0x10     ): Ok
  ioctl(freq   = 0x11     ): Ok
  ioctl(freq   = 0x1f     ): Ok
  ioctl(freq   = 0x20     ): Ok
  ioctl(freq   = 0x80     ): Ok
  ioctl(freq   = 0x8f     ): Ok
  ioctl(freq   = 0x90     ): Ok
  ioctl(freq   = 0x91     ): Ok
  ioctl(freq   = 0x100    ): Ok

IBS freq (negative) tests:
--------------------------
freq 1, sample_freq 200000: Fail

IBS L3MissOnly test: (takes a while)
--------------------
Fetch L3MissOnly: Fail (nr_samples: 1159)
Op L3MissOnly: Ok (nr_samples: 1205)
---- end(-1) ----
75: AMD IBS sample period : FAILED!

With patches:

  $ sudo ./perf test -vv 112
  112: AMD IBS sample period:
  --- start ---
  test child forked, pid 44042
  Using CPUID AuthenticAMD-26-2-1

IBS config tests:
-----------------
Fetch PMU tests:

  0xffff            : Ok   (nr samples: 1278)
  0x1000            : Ok   (nr samples: 20129)
  0xff              : Ok   (nr samples: 40529)
  0x1               : Ok   (nr samples: 40443)
  0x0               : Ok
  0x10000           : Ok
  Op PMU tests:
  0x0               : Ok
  0x1               : Ok
  0x8               : Ok
  0x9               : Ok   (nr samples: 40443)
  0xf               : Ok   (nr samples: 40761)
  0x1000            : Ok   (nr samples: 20808)
  0xffff            : Ok   (nr samples: 1261)
  0x10000           : Ok
  0x100000          : Ok   (nr samples: 1276)
  0xf00000          : Ok   (nr samples: 87)
  0xf0ffff          : Ok   (nr samples: 77)
  0x1f0ffff         : Ok   (nr samples: 39)
  0x7f0ffff         : Ok   (nr samples: 8)
  0x8f0ffff         : Ok
  0x17f0ffff        : Ok

IBS sample period constraint tests:
-----------------------------------
Fetch PMU test:
freq 0, sample_freq 0: Ok
freq 0, sample_freq 1: Ok

  freq 0, sample_freq      15: Ok
  freq 0, sample_freq      16: Ok   (nr samples: 1272)
  freq 0, sample_freq      17: Ok   (nr samples: 1272)
  freq 0, sample_freq     143: Ok   (nr samples: 1590)
  freq 0, sample_freq     144: Ok   (nr samples: 1272)
  freq 0, sample_freq     145: Ok   (nr samples: 1272)
  freq 0, sample_freq    1234: Ok   (nr samples: 1272)
  freq 0, sample_freq    4103: Ok   (nr samples: 1272)
  freq 0, sample_freq   65520: Ok   (nr samples: 2530)
  freq 0, sample_freq   65535: Ok   (nr samples: 2339)
  freq 0, sample_freq   65552: Ok   (nr samples: 2546)
  freq 0, sample_freq 8388607: Ok   (nr samples: 30)
  freq 1, sample_freq       0: Ok
  freq 1, sample_freq       1: Ok   (nr samples: 4)
  freq 1, sample_freq      15: Ok   (nr samples: 4)
  freq 1, sample_freq      16: Ok   (nr samples: 4)
  freq 1, sample_freq      17: Ok   (nr samples: 4)
  freq 1, sample_freq     143: Ok   (nr samples: 5)
  freq 1, sample_freq     144: Ok   (nr samples: 5)
  freq 1, sample_freq     145: Ok   (nr samples: 5)
  freq 1, sample_freq    1234: Ok   (nr samples: 9)
  freq 1, sample_freq    4103: Ok   (nr samples: 36)
  freq 1, sample_freq   65520: Ok   (nr samples: 954)
  freq 1, sample_freq   65535: Ok   (nr samples: 1590)
  freq 1, sample_freq   65552: Ok   (nr samples: 1272)
  freq 1, sample_freq 8388607: Ok
  Op PMU test:
  freq 0, sample_freq       0: Ok
  freq 0, sample_freq       1: Ok
  freq 0, sample_freq      15: Ok
  freq 0, sample_freq      16: Ok
  freq 0, sample_freq      17: Ok
  freq 0, sample_freq     143: Ok
  freq 0, sample_freq     144: Ok   (nr samples: 1272)
  freq 0, sample_freq     145: Ok   (nr samples: 1272)
  freq 0, sample_freq    1234: Ok   (nr samples: 1272)
  freq 0, sample_freq    4103: Ok   (nr samples: 1272)
  freq 0, sample_freq   65520: Ok   (nr samples: 2599)
  freq 0, sample_freq   65535: Ok   (nr samples: 2558)
  freq 0, sample_freq   65552: Ok   (nr samples: 2480)
  freq 0, sample_freq 8388607: Ok   (nr samples: 31)
  freq 1, sample_freq       0: Ok
  freq 1, sample_freq       1: Ok   (nr samples: 4)
  freq 1, sample_freq      15: Ok   (nr samples: 4)
  freq 1, sample_freq      16: Ok   (nr samples: 4)
  freq 1, sample_freq      17: Ok   (nr samples: 4)
  freq 1, sample_freq     143: Ok   (nr samples: 5)
  freq 1, sample_freq     144: Ok   (nr samples: 5)
  freq 1, sample_freq     145: Ok   (nr samples: 5)
  freq 1, sample_freq    1234: Ok   (nr samples: 8)
  freq 1, sample_freq    4103: Ok   (nr samples: 30)
  freq 1, sample_freq   65520: Ok   (nr samples: 577)
  freq 1, sample_freq   65535: Ok   (nr samples: 585)
  freq 1, sample_freq   65552: Ok   (nr samples: 577)

freq 1, sample_freq 8388607: Ok

IBS ioctl() tests:
------------------
Fetch PMU tests

  ioctl(period = 0x0      ): Ok
  ioctl(period = 0x1      ): Ok
  ioctl(period = 0xf      ): Ok
  ioctl(period = 0x10     ): Ok
  ioctl(period = 0x11     ): Ok
  ioctl(period = 0x1f     ): Ok
  ioctl(period = 0x20     ): Ok
  ioctl(period = 0x80     ): Ok
  ioctl(period = 0x8f     ): Ok
  ioctl(period = 0x90     ): Ok
  ioctl(period = 0x91     ): Ok
  ioctl(period = 0x100    ): Ok
  ioctl(period = 0xfff0   ): Ok
  ioctl(period = 0xffff   ): Ok
  ioctl(period = 0x10000  ): Ok
  ioctl(period = 0x1fff0  ): Ok
  ioctl(period = 0x1fff5  ): Ok
  ioctl(freq   = 0x0      ): Ok
  ioctl(freq   = 0x1      ): Ok
  ioctl(freq   = 0xf      ): Ok
  ioctl(freq   = 0x10     ): Ok
  ioctl(freq   = 0x11     ): Ok
  ioctl(freq   = 0x1f     ): Ok
  ioctl(freq   = 0x20     ): Ok
  ioctl(freq   = 0x80     ): Ok
  ioctl(freq   = 0x8f     ): Ok
  ioctl(freq   = 0x90     ): Ok
  ioctl(freq   = 0x91     ): Ok
  ioctl(freq   = 0x100    ): Ok
  Op PMU tests
  ioctl(period = 0x0      ): Ok
  ioctl(period = 0x1      ): Ok
  ioctl(period = 0xf      ): Ok
  ioctl(period = 0x10     ): Ok
  ioctl(period = 0x11     ): Ok
  ioctl(period = 0x1f     ): Ok
  ioctl(period = 0x20     ): Ok
  ioctl(period = 0x80     ): Ok
  ioctl(period = 0x8f     ): Ok
  ioctl(period = 0x90     ): Ok
  ioctl(period = 0x91     ): Ok
  ioctl(period = 0x100    ): Ok
  ioctl(period = 0xfff0   ): Ok
  ioctl(period = 0xffff   ): Ok
  ioctl(period = 0x10000  ): Ok
  ioctl(period = 0x1fff0  ): Ok
  ioctl(period = 0x1fff5  ): Ok
  ioctl(freq   = 0x0      ): Ok
  ioctl(freq   = 0x1      ): Ok
  ioctl(freq   = 0xf      ): Ok
  ioctl(freq   = 0x10     ): Ok
  ioctl(freq   = 0x11     ): Ok
  ioctl(freq   = 0x1f     ): Ok
  ioctl(freq   = 0x20     ): Ok
  ioctl(freq   = 0x80     ): Ok
  ioctl(freq   = 0x8f     ): Ok
  ioctl(freq   = 0x90     ): Ok
  ioctl(freq   = 0x91     ): Ok
  ioctl(freq   = 0x100    ): Ok

IBS freq (negative) tests:
--------------------------
freq 1, sample_freq 200000: Ok

IBS L3MissOnly test: (takes a while)
--------------------
Fetch L3MissOnly: Ok (nr_samples: 1408)
Op L3MissOnly: Ok (nr_samples: 1456)
---- end(0) ----
112: AMD IBS sample period : Ok

Thanks,
Ravi

#18 lore raw

Re: [PATCH v2 10/10] perf test amd ibs: Add sample period unit test

Quoted 7 lines · Ravi Bangoria
Quoted 5 lines · Ravi Bangoria

IBS Fetch and IBS Op pmus has various constraints on supported sample periods. Add perf unit tests to test those.

Running it in parallel with other tests causes intermittent failures. Mark it exclusive to force it to run sequentially.

Quoted 6 lines

The verbose mode of unit test is quite exhaustive so I've not added it in the commit description. Here is the sample output on a Zen5 machine:

Without patches:

With patches:

That's not a problem - please include this in the changelog for the next version, it's useful information.

Thanks,

Ingo