]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/resctrl: Use cache size to determine "fill_buf" buffer size
authorReinette Chatre <reinette.chatre@intel.com>
Thu, 24 Oct 2024 21:18:49 +0000 (14:18 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 5 Nov 2024 00:02:03 +0000 (17:02 -0700)
By default the MBM and MBA tests use the "fill_buf" benchmark to
read from a buffer with the goal to measure the memory bandwidth
generated by this buffer access.

Care should be taken when sizing the buffer used by the "fill_buf"
benchmark. If the buffer is small enough to fit in the cache then
it cannot be expected that the benchmark will generate much memory
bandwidth. For example, on a system with 320MB L3 cache the existing
hardcoded default of 250MB is insufficient.

Use the measured cache size to determine a buffer size that can be
expected to trigger memory access while keeping the existing default
as minimum, now renamed to MINIMUM_SPAN, that has been appropriate for
testing so far.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/fill_buf.c
tools/testing/selftests/resctrl/mba_test.c
tools/testing/selftests/resctrl/mbm_test.c
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_tests.c

index 380cc35f10c63c3fb35a5deacfe94e8c6ec5c99d..19a01a52dc1a3c281f35d69e8d09f1868e48640b 100644 (file)
@@ -129,3 +129,16 @@ unsigned char *alloc_buffer(size_t buf_size, bool memflush)
 
        return buf;
 }
+
+ssize_t get_fill_buf_size(int cpu_no, const char *cache_type)
+{
+       unsigned long cache_total_size = 0;
+       int ret;
+
+       ret = get_cache_size(cpu_no, cache_type, &cache_total_size);
+       if (ret)
+               return ret;
+
+       return cache_total_size * 2 > MINIMUM_SPAN ?
+                       cache_total_size * 2 : MINIMUM_SPAN;
+}
index 74d95c460bd0fb8ddeceb19fe555a3be0e0af9c4..bf37f35556607644687661ffac3010d392fc10e8 100644 (file)
@@ -182,7 +182,12 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
                fill_buf.memflush = uparams->fill_buf->memflush;
                param.fill_buf = &fill_buf;
        } else if (!uparams->benchmark_cmd[0]) {
-               fill_buf.buf_size = DEFAULT_SPAN;
+               ssize_t buf_size;
+
+               buf_size = get_fill_buf_size(uparams->cpu, "L3");
+               if (buf_size < 0)
+                       return buf_size;
+               fill_buf.buf_size = buf_size;
                fill_buf.memflush = true;
                param.fill_buf = &fill_buf;
        }
index 72261413c868a6aebaa3f9ba812e84e35802c8f4..4224f8ce353854802b4a81870776d49a6fd10f1b 100644 (file)
@@ -149,7 +149,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
                fill_buf.memflush = uparams->fill_buf->memflush;
                param.fill_buf = &fill_buf;
        } else if (!uparams->benchmark_cmd[0]) {
-               fill_buf.buf_size = DEFAULT_SPAN;
+               ssize_t buf_size;
+
+               buf_size = get_fill_buf_size(uparams->cpu, "L3");
+               if (buf_size < 0)
+                       return buf_size;
+               fill_buf.buf_size = buf_size;
                fill_buf.memflush = true;
                param.fill_buf = &fill_buf;
        }
index 032cd9ebd7614e0c5c1c9bb52ccaff2f8e278fde..a553fe975938e67f1c36c031748b907843440a60 100644 (file)
@@ -41,7 +41,7 @@
 
 #define BENCHMARK_ARGS         64
 
-#define DEFAULT_SPAN           (250 * MB)
+#define MINIMUM_SPAN           (250 * MB)
 
 /*
  * fill_buf_param:     "fill_buf" benchmark parameters
@@ -169,6 +169,7 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
 unsigned char *alloc_buffer(size_t buf_size, bool memflush);
 void mem_flush(unsigned char *buf, size_t buf_size);
 void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
+ssize_t get_fill_buf_size(int cpu_no, const char *cache_type);
 int initialize_read_mem_bw_imc(void);
 int measure_read_mem_bw(const struct user_params *uparams,
                        struct resctrl_val_param *param, pid_t bm_pid);
index 24daf76b403956490fdf846152c066dc0df46a7c..3335af815b210767794ecf789860fec2d510f1c4 100644 (file)
@@ -189,7 +189,7 @@ static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
                        ksft_exit_skip("Unable to parse benchmark buffer size.\n");
                }
        } else {
-               fill_param->buf_size = DEFAULT_SPAN;
+               fill_param->buf_size = MINIMUM_SPAN;
        }
 
        if (uparams->benchmark_cmd[2] && *uparams->benchmark_cmd[2] != '\0') {