Skip to content

Commit 1384241

Browse files
rchatreshuahkh
authored andcommitted
selftests/resctrl: Only support measured read operation
The CMT, MBM, and MBA tests rely on a benchmark to generate memory traffic. By default this is the "fill_buf" benchmark that can be replaced via the "-b" command line argument. The original intent of the "-b" command line parameter was to replace the default "fill_buf" benchmark, but the implementation also exposes an alternative use case where the "fill_buf" parameters itself can be modified. One of the parameters to "fill_buf" is the "operation" that can be either "read" or "write" and indicates whether the "fill_buf" should use "read" or "write" operations on the allocated buffer. While replacing "fill_buf" default parameters is technically possible, replacing the default "read" parameter with "write" is not supported because the MBA and MBM tests only measure "read" operations. The "read" operation is also most appropriate for the CMT test that aims to use the benchmark to allocate into the cache. Avoid any potential inconsistencies between test and measurement by removing code for unsupported "write" operations to the buffer. Ignore any attempt from user space to enable this unsupported test configuration, instead always use read operations. Keep the initialization of the, now unused, "fill_buf" parameters to reserve these parameter positions since it has been exposed as an API. Future parameter additions cannot use these parameter positions. Signed-off-by: Reinette Chatre <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent f306913 commit 1384241

File tree

4 files changed

+9
-31
lines changed

4 files changed

+9
-31
lines changed

tools/testing/selftests/resctrl/fill_buf.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,6 @@ static int fill_one_span_read(unsigned char *buf, size_t buf_size)
8888
return sum;
8989
}
9090

91-
static void fill_one_span_write(unsigned char *buf, size_t buf_size)
92-
{
93-
unsigned char *end_ptr = buf + buf_size;
94-
unsigned char *p;
95-
96-
p = buf;
97-
while (p < end_ptr) {
98-
*p = '1';
99-
p += (CL_SIZE / 2);
100-
}
101-
}
102-
10391
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once)
10492
{
10593
int ret = 0;
@@ -114,15 +102,6 @@ void fill_cache_read(unsigned char *buf, size_t buf_size, bool once)
114102
*value_sink = ret;
115103
}
116104

117-
static void fill_cache_write(unsigned char *buf, size_t buf_size, bool once)
118-
{
119-
while (1) {
120-
fill_one_span_write(buf, buf_size);
121-
if (once)
122-
break;
123-
}
124-
}
125-
126105
unsigned char *alloc_buffer(size_t buf_size, int memflush)
127106
{
128107
void *buf = NULL;
@@ -151,18 +130,15 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush)
151130
return buf;
152131
}
153132

154-
int run_fill_buf(size_t buf_size, int memflush, int op)
133+
int run_fill_buf(size_t buf_size, int memflush)
155134
{
156135
unsigned char *buf;
157136

158137
buf = alloc_buffer(buf_size, memflush);
159138
if (!buf)
160139
return -1;
161140

162-
if (op == 0)
163-
fill_cache_read(buf, buf_size, false);
164-
else
165-
fill_cache_write(buf, buf_size, false);
141+
fill_cache_read(buf, buf_size, false);
166142

167143
free(buf);
168144

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
142142
unsigned char *alloc_buffer(size_t buf_size, int memflush);
143143
void mem_flush(unsigned char *buf, size_t buf_size);
144144
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
145-
int run_fill_buf(size_t buf_size, int memflush, int op);
145+
int run_fill_buf(size_t buf_size, int memflush);
146146
int initialize_mem_bw_imc(void);
147147
int measure_mem_bw(const struct user_params *uparams,
148148
struct resctrl_val_param *param, pid_t bm_pid,

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,16 @@ int main(int argc, char **argv)
265265
ksft_exit_fail_msg("Out of memory!\n");
266266
uparams.benchmark_cmd[1] = span_str;
267267
uparams.benchmark_cmd[2] = "1";
268-
uparams.benchmark_cmd[3] = "0";
269268
/*
269+
* Third parameter was previously used for "operation"
270+
* (read/write) of which only (now default) "read"/"0"
271+
* works.
270272
* Fourth parameter was previously used to indicate
271273
* how long "fill_buf" should run for, with "false"
272274
* ("fill_buf" will keep running until terminated)
273275
* the only option that works.
274276
*/
277+
uparams.benchmark_cmd[3] = NULL;
275278
uparams.benchmark_cmd[4] = NULL;
276279
}
277280

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ int measure_mem_bw(const struct user_params *uparams,
622622
*/
623623
static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
624624
{
625-
int operation, ret, memflush;
626625
char **benchmark_cmd;
626+
int ret, memflush;
627627
size_t span;
628628
FILE *fp;
629629

@@ -643,9 +643,8 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
643643
/* Execute default fill_buf benchmark */
644644
span = strtoul(benchmark_cmd[1], NULL, 10);
645645
memflush = atoi(benchmark_cmd[2]);
646-
operation = atoi(benchmark_cmd[3]);
647646

648-
if (run_fill_buf(span, memflush, operation))
647+
if (run_fill_buf(span, memflush))
649648
fprintf(stderr, "Error in running fill buffer\n");
650649
} else {
651650
/* Execute specified benchmark */

0 commit comments

Comments
 (0)