mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Swapnil Sapkal <swapnil.sapkal@amd.com>
To: <tony.luck@intel.com>, <reinette.chatre@intel.com>,
	<babu.moger@amd.com>, <fenghua.yu@intel.com>, <shuah@kernel.org>
Cc: <Dave.Martin@arm.com>, <james.morse@arm.com>,
	<peternewman@google.com>, <eranian@google.com>,
	<tan.shaopeng@fujitsu.com>, <linux-kernel@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <x86@kernel.org>,
	<swapnil.sapkal@amd.com>
Subject: [PATCH v6 4/5] selftests/resctrl: Use bandwidth values for AMD MBA schemata
Date: Tue, 1 Dec 2026 08:34:25 +0000	[thread overview]
Message-ID: <20261201083426.26730-5-swapnil.sapkal@amd.com> (raw)
In-Reply-To: <20261201083426.26730-1-swapnil.sapkal@amd.com>

MBA (Memory Bandwidth Allocation) throttles memory bandwidth using a
percentage, so the MBA test sweeps the schemata from 10% to 100% in
steps of 10%. AMD MBA instead uses an absolute memory bandwidth value.

Sweep the AMD MBA schemata from 4 GB/s to 40 GB/s in steps of 4 GB/s.
The hardware represents these in units of 1/8 GB/s, so the test writes
32, 64, ... up to 320. The number of allocations swept (10), and hence
the number of measurements, stays the same for both.

Select the minimum and step of the sweep based on the vendor and walk
the sweep by index so that both mba_setup() and show_mba_info() are
bounded by NUM_OF_ALLOCS.

Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
---

v5->v6:
    - Dropped "Intel" from the description of the percentage based
      interface, which is the generic interface. (Reinette)
    - Walk the sweep by index: mba_setup() now computes
      mba_alloc_min() + mba_alloc_step() * alloc_idx and is bounded by
      NUM_OF_ALLOCS, matching show_mba_info(). This drops the static
      accumulator and its 'allocation == 0' sentinel (0 is a valid minimum)
      and makes mba_alloc_max() unnecessary. (Reinette)
    - Defined NUM_OF_ALLOCS as a plain 10 rather than deriving an
      architecture neutral count from the percentage constants. (Reinette)
    - Dropped ALLOCATION_MAX, AMD_ALLOCATION_MAX and the build time checks
      on them. Now that the sweep is bounded by NUM_OF_ALLOCS it always
      produces exactly NUM_OF_ALLOCS allocations whatever the per vendor
      constants are, so the checks could no longer catch anything and the
      two maximums had no remaining user: a sweep is fully described by its
      minimum, its step and NUM_OF_ALLOCS.
    - Renamed the show_mba_info() loop variable to alloc_idx and compute the
      allocation once; fixed reverse fir order there and in
      check_results(). (Reinette)
    - Dropped the "Got more results than expected" bounds check: it was
      unrelated to AMD enablement and its message implied a failure while
      the test continued. (Reinette)

v4->v5:
    - New patch.

 tools/testing/selftests/resctrl/mba_test.c | 66 +++++++++++++++-------
 1 file changed, 46 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c
index 17ae73d3476c..ca87396671f0 100644
--- a/tools/testing/selftests/resctrl/mba_test.c
+++ b/tools/testing/selftests/resctrl/mba_test.c
@@ -13,10 +13,32 @@
 #define RESULT_FILE_NAME	"result_mba"
 #define NUM_OF_RUNS		5
 #define MAX_DIFF_PERCENT	15
-#define ALLOCATION_MAX		100
+
+/* MBA is specified as a percentage: 10%, 20% ... 100%. */
 #define ALLOCATION_MIN		10
 #define ALLOCATION_STEP		10
 
+/*
+ * AMD MBA is not a percentage but an absolute memory bandwidth value, which
+ * the hardware represents in units of 1/8 GB/s. Sweep the bandwidth from
+ * 4 GB/s in steps of 4 GB/s, i.e. 32, 64 ... up to 320 (40 GB/s).
+ */
+#define AMD_ALLOCATION_MIN	32
+#define AMD_ALLOCATION_STEP	32
+
+/* Number of MBA schemata allocations to sweep (same for both vendors). */
+#define NUM_OF_ALLOCS		10
+
+static unsigned int mba_alloc_min(void)
+{
+	return get_vendor() == ARCH_AMD ? AMD_ALLOCATION_MIN : ALLOCATION_MIN;
+}
+
+static unsigned int mba_alloc_step(void)
+{
+	return get_vendor() == ARCH_AMD ? AMD_ALLOCATION_STEP : ALLOCATION_STEP;
+}
+
 static int mba_init(const struct resctrl_test *test,
 		    const struct user_params *uparams,
 		    const struct resctrl_val_param *param, int domain_id)
@@ -33,17 +55,20 @@ static int mba_init(const struct resctrl_test *test,
 }
 
 /*
- * Change schemata percentage from 100 to 10%. Write schemata to specified
- * con_mon grp, mon_grp in resctrl FS.
+ * Sweep the MBA schemata over NUM_OF_ALLOCS allocations, from the minimum
+ * allocation upwards in steps. The allocation is a percentage (10% .. 100%)
+ * or, on AMD, an absolute memory bandwidth value (4 GB/s .. 40 GB/s). Write
+ * schemata to the specified con_mon grp, mon_grp in resctrl FS.
  * For each allocation, run 5 times in order to get average values.
  */
 static int mba_setup(const struct resctrl_test *test,
 		     const struct user_params *uparams,
 		     struct resctrl_val_param *p)
 {
-	static unsigned int allocation = ALLOCATION_MIN;
 	static int runs_per_allocation;
+	static unsigned int alloc_idx;
 	char allocation_str[64];
+	unsigned int allocation;
 	int ret;
 
 	if (runs_per_allocation >= NUM_OF_RUNS)
@@ -53,17 +78,18 @@ static int mba_setup(const struct resctrl_test *test,
 	if (runs_per_allocation++ != 0)
 		return 0;
 
-	if (allocation > ALLOCATION_MAX)
+	if (alloc_idx >= NUM_OF_ALLOCS)
 		return END_OF_TESTS;
 
-	sprintf(allocation_str, "%d", allocation);
+	allocation = mba_alloc_min() + mba_alloc_step() * alloc_idx;
+	alloc_idx++;
+
+	sprintf(allocation_str, "%u", allocation);
 
 	ret = write_schemata(p->ctrlgrp, allocation_str, uparams->cpu, test->resource);
 	if (ret < 0)
 		return ret;
 
-	allocation += ALLOCATION_STEP;
-
 	return 0;
 }
 
@@ -75,21 +101,23 @@ static int mba_measure(const struct user_params *uparams,
 
 static bool show_mba_info(unsigned long *bw_mc, unsigned long *bw_resc)
 {
-	unsigned int allocation;
+	unsigned int alloc_step = mba_alloc_step();
+	unsigned int alloc_min = mba_alloc_min();
+	unsigned int alloc_idx;
 	bool ret = false;
 	int runs;
 
 	ksft_print_msg("Results are displayed in (MB)\n");
-	/* Memory bandwidth from 100% down to 10% */
-	for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP;
-	     allocation++) {
+	/* Memory bandwidth for each of the swept MBA allocations */
+	for (alloc_idx = 0; alloc_idx < NUM_OF_ALLOCS; alloc_idx++) {
+		unsigned int allocation = alloc_min + alloc_step * alloc_idx;
 		unsigned long sum_bw_mc = 0, sum_bw_resc = 0;
 		long avg_bw_mc, avg_bw_resc;
 		int avg_diff_per;
 		float avg_diff;
 
-		for (runs = NUM_OF_RUNS * allocation;
-		     runs < NUM_OF_RUNS * allocation + NUM_OF_RUNS ; runs++) {
+		for (runs = NUM_OF_RUNS * alloc_idx;
+		     runs < NUM_OF_RUNS * alloc_idx + NUM_OF_RUNS ; runs++) {
 			sum_bw_mc += bw_mc[runs];
 			sum_bw_resc += bw_resc[runs];
 		}
@@ -98,8 +126,7 @@ static bool show_mba_info(unsigned long *bw_mc, unsigned long *bw_resc)
 		avg_bw_resc = sum_bw_resc / NUM_OF_RUNS;
 		if (avg_bw_mc < THROTTLE_THRESHOLD || avg_bw_resc < THROTTLE_THRESHOLD) {
 			ksft_print_msg("Bandwidth below threshold (%d MiB). Dropping results from MBA schemata %u.\n",
-				       THROTTLE_THRESHOLD,
-				       ALLOCATION_MIN + ALLOCATION_STEP * allocation);
+				       THROTTLE_THRESHOLD, allocation);
 			continue;
 		}
 
@@ -109,8 +136,7 @@ static bool show_mba_info(unsigned long *bw_mc, unsigned long *bw_resc)
 		ksft_print_msg("%s Check MBA diff within %d%% for schemata %u\n",
 			       avg_diff_per > MAX_DIFF_PERCENT ?
 			       "Fail:" : "Pass:",
-			       MAX_DIFF_PERCENT,
-			       ALLOCATION_MIN + ALLOCATION_STEP * allocation);
+			       MAX_DIFF_PERCENT, allocation);
 
 		ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
 		ksft_print_msg("avg_bw_mc: %lu\n", avg_bw_mc);
@@ -129,9 +155,9 @@ static bool show_mba_info(unsigned long *bw_mc, unsigned long *bw_resc)
 
 static int check_results(void)
 {
-	unsigned long bw_resc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP];
-	unsigned long bw_mc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP];
 	char *token_array[8], output[] = RESULT_FILE_NAME, temp[512];
+	unsigned long bw_resc[NUM_OF_RUNS * NUM_OF_ALLOCS];
+	unsigned long bw_mc[NUM_OF_RUNS * NUM_OF_ALLOCS];
 	int runs;
 	FILE *fp;
 
-- 
2.43.0


  parent reply	other threads:[~2026-12-01  8:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:34 [PATCH v6 0/5] selftests/resctrl: Add MBM and MBA test support for AMD Swapnil Sapkal
2026-12-01  8:34 ` [PATCH v6 1/5] selftests/resctrl: Rename variables and functions to generic names Swapnil Sapkal
2026-12-01  8:34 ` [PATCH v6 2/5] selftests/resctrl: Detect vendor to select memory controller sysfs name Swapnil Sapkal
2026-12-01  8:34 ` [PATCH v6 3/5] selftests/resctrl: Add support for MBM and MBA tests on AMD Swapnil Sapkal
2026-12-01  8:34 ` Swapnil Sapkal [this message]
2026-12-01  8:34 ` [PATCH v6 5/5] selftests/resctrl: Enable " Swapnil Sapkal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201083426.26730-5-swapnil.sapkal@amd.com \
    --to=swapnil.sapkal@amd.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=eranian@google.com \
    --cc=fenghua.yu@intel.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=peternewman@google.com \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®