Skip to content

Commit f77b967

Browse files
rchatreshuahkh
authored andcommitted
selftests/resctrl: Use cache size to determine "fill_buf" buffer size
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 <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 3cb3f0b commit f77b967

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

tools/testing/selftests/resctrl/fill_buf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,16 @@ unsigned char *alloc_buffer(size_t buf_size, bool memflush)
129129

130130
return buf;
131131
}
132+
133+
ssize_t get_fill_buf_size(int cpu_no, const char *cache_type)
134+
{
135+
unsigned long cache_total_size = 0;
136+
int ret;
137+
138+
ret = get_cache_size(cpu_no, cache_type, &cache_total_size);
139+
if (ret)
140+
return ret;
141+
142+
return cache_total_size * 2 > MINIMUM_SPAN ?
143+
cache_total_size * 2 : MINIMUM_SPAN;
144+
}

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
182182
fill_buf.memflush = uparams->fill_buf->memflush;
183183
param.fill_buf = &fill_buf;
184184
} else if (!uparams->benchmark_cmd[0]) {
185-
fill_buf.buf_size = DEFAULT_SPAN;
185+
ssize_t buf_size;
186+
187+
buf_size = get_fill_buf_size(uparams->cpu, "L3");
188+
if (buf_size < 0)
189+
return buf_size;
190+
fill_buf.buf_size = buf_size;
186191
fill_buf.memflush = true;
187192
param.fill_buf = &fill_buf;
188193
}

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
149149
fill_buf.memflush = uparams->fill_buf->memflush;
150150
param.fill_buf = &fill_buf;
151151
} else if (!uparams->benchmark_cmd[0]) {
152-
fill_buf.buf_size = DEFAULT_SPAN;
152+
ssize_t buf_size;
153+
154+
buf_size = get_fill_buf_size(uparams->cpu, "L3");
155+
if (buf_size < 0)
156+
return buf_size;
157+
fill_buf.buf_size = buf_size;
153158
fill_buf.memflush = true;
154159
param.fill_buf = &fill_buf;
155160
}

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
#define BENCHMARK_ARGS 64
4343

44-
#define DEFAULT_SPAN (250 * MB)
44+
#define MINIMUM_SPAN (250 * MB)
4545

4646
/*
4747
* 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,
169169
unsigned char *alloc_buffer(size_t buf_size, bool memflush);
170170
void mem_flush(unsigned char *buf, size_t buf_size);
171171
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
172+
ssize_t get_fill_buf_size(int cpu_no, const char *cache_type);
172173
int initialize_read_mem_bw_imc(void);
173174
int measure_read_mem_bw(const struct user_params *uparams,
174175
struct resctrl_val_param *param, pid_t bm_pid);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
189189
ksft_exit_skip("Unable to parse benchmark buffer size.\n");
190190
}
191191
} else {
192-
fill_param->buf_size = DEFAULT_SPAN;
192+
fill_param->buf_size = MINIMUM_SPAN;
193193
}
194194

195195
if (uparams->benchmark_cmd[2] && *uparams->benchmark_cmd[2] != '\0') {

0 commit comments

Comments
 (0)