[PATCH v3 03/10] selftests/resctrl: Do not store iMC counter value in counter config structure

Reinette Chatre
2026-03-13T20:32:56Z

The MBM and MBA tests compare MBM memory bandwidth measurements against
the memory bandwidth event values obtained from each memory controller's
PMU. The memory bandwidth event settings are discovered from the memory
controller details found in /sys/bus/event_source/devices/uncore_imc_N and
stored in struct imc_counter_config.

In addition to event settings struct imc_counter_config contains
imc_counter_config::return_value in which the associated event value is
stored on every read.

The event value is consumed and immediately recorded at regular intervals.
The stored value is never consumed afterwards, making its storage as part
of event configuration unnecessary.

Remove the return_value member from struct imc_counter_config. Instead
just use a more aptly named "measurement" local variable for use during
event reading.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Chen Yu <yu.c.chen@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
Changes since v2:
- Rename "return_value" -> "measurement". (Ilpo)
- Add Ilpo's Rb tag.
- Add Chen Yu's tag.
---
tools/testing/selftests/resctrl/resctrl_val.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
index a5a8badb83d4..71d6f88cc1f7 100644
--- a/tools/testing/selftests/resctrl/resctrl_val.c
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -32,7 +32,6 @@ struct imc_counter_config {
__u64 event;
__u64 umask;
struct perf_event_attr pe;
- struct membw_read_format return_value;
int fd;
};

@@ -312,23 +311,23 @@ static int get_read_mem_bw_imc(float *bw_imc)
* Take overflow into consideration before calculating total bandwidth.
*/
for (imc = 0; imc < imcs; imc++) {
+ struct membw_read_format measurement;
struct imc_counter_config *r =
&imc_counters_config[imc];

- if (read(r->fd, &r->return_value,
- sizeof(struct membw_read_format)) == -1) {
+ if (read(r->fd, &measurement, sizeof(measurement)) == -1) {
ksft_perror("Couldn't get read bandwidth through iMC");
return -1;
}

- __u64 r_time_enabled = r->return_value.time_enabled;
- __u64 r_time_running = r->return_value.time_running;
+ __u64 r_time_enabled = measurement.time_enabled;
+ __u64 r_time_running = measurement.time_running;

if (r_time_enabled != r_time_running)
of_mul_read = (float)r_time_enabled /
(float)r_time_running;

- reads += r->return_value.value * of_mul_read * SCALE;
+ reads += measurement.value * of_mul_read * SCALE;
}

*bw_imc = reads;
--
2.50.1