Skip to content

Commit 7f3c980

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Don't pass test name to fill_buf
Test name is passed to fill_buf functions so that they can loop around buffer only once. This is required for CAT test case. To loop around buffer only once, caller doesn't need to let fill_buf know which test case it is. Instead, pass a boolean argument 'once' which makes fill_buf more generic. As run_benchmark() no longer needs to pass the test name to run_fill_buf(), a few test running functions can be simplified to not write the test name into the default benchmark_cmd. The has_ben argument can also be removed now from those test running functions. Co-developed-by: Fenghua Yu <[email protected]> Signed-off-by: Fenghua Yu <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Tested-by: Babu Moger <[email protected]> Tested-by: Shaopeng Tan (Fujitsu) <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent f412397 commit 7f3c980

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

tools/testing/selftests/resctrl/cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ int cat_val(struct resctrl_val_param *param)
247247
if (ret)
248248
break;
249249

250-
if (run_fill_buf(param->span, memflush, operation,
251-
resctrl_val)) {
250+
if (run_fill_buf(param->span, memflush, operation, true)) {
252251
fprintf(stderr, "Error-running fill buffer\n");
253252
ret = -1;
254253
goto pe_close;

tools/testing/selftests/resctrl/fill_buf.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,14 @@ static void fill_one_span_write(unsigned char *buf, size_t buf_size)
101101
}
102102
}
103103

104-
static int fill_cache_read(unsigned char *buf, size_t buf_size,
105-
char *resctrl_val)
104+
static int fill_cache_read(unsigned char *buf, size_t buf_size, bool once)
106105
{
107106
int ret = 0;
108107
FILE *fp;
109108

110109
while (1) {
111110
ret = fill_one_span_read(buf, buf_size);
112-
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)))
111+
if (once)
113112
break;
114113
}
115114

@@ -125,19 +124,18 @@ static int fill_cache_read(unsigned char *buf, size_t buf_size,
125124
return 0;
126125
}
127126

128-
static int fill_cache_write(unsigned char *buf, size_t buf_size,
129-
char *resctrl_val)
127+
static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once)
130128
{
131129
while (1) {
132130
fill_one_span_write(buf, buf_size);
133-
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)))
131+
if (once)
134132
break;
135133
}
136134

137135
return 0;
138136
}
139137

140-
static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)
138+
static int fill_cache(size_t buf_size, int memflush, int op, bool once)
141139
{
142140
unsigned char *buf;
143141
int ret;
@@ -151,9 +149,9 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)
151149
mem_flush(buf, buf_size);
152150

153151
if (op == 0)
154-
ret = fill_cache_read(buf, buf_size, resctrl_val);
152+
ret = fill_cache_read(buf, buf_size, once);
155153
else
156-
ret = fill_cache_write(buf, buf_size, resctrl_val);
154+
ret = fill_cache_write(buf, buf_size, once);
157155

158156
free(buf);
159157

@@ -166,12 +164,12 @@ static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)
166164
return 0;
167165
}
168166

169-
int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val)
167+
int run_fill_buf(size_t span, int memflush, int op, bool once)
170168
{
171169
size_t cache_size = span;
172170
int ret;
173171

174-
ret = fill_cache(cache_size, memflush, op, resctrl_val);
172+
ret = fill_cache(cache_size, memflush, op, once);
175173
if (ret) {
176174
printf("\n Error in fill cache\n");
177175
return -1;

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
9797
char *resctrl_val);
9898
int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
9999
int group_fd, unsigned long flags);
100-
int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val);
100+
int run_fill_buf(size_t span, int memflush, int op, bool once);
101101
int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
102102
int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd);
103103
void tests_cleanup(void);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void tests_cleanup(void)
7070
cat_test_cleanup();
7171
}
7272

73-
static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span,
73+
static void run_mbm_test(char **benchmark_cmd, size_t span,
7474
int cpu_no, char *bw_report)
7575
{
7676
int res;
@@ -88,8 +88,6 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span,
8888
goto umount;
8989
}
9090

91-
if (!has_ben)
92-
sprintf(benchmark_cmd[4], "%s", MBA_STR);
9391
res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd);
9492
ksft_test_result(!res, "MBM: bw change\n");
9593
if ((get_vendor() == ARCH_INTEL) && res)
@@ -123,7 +121,7 @@ static void run_mba_test(char **benchmark_cmd, int cpu_no, char *bw_report)
123121
umount_resctrlfs();
124122
}
125123

126-
static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no)
124+
static void run_cmt_test(char **benchmark_cmd, int cpu_no)
127125
{
128126
int res;
129127

@@ -140,8 +138,6 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no)
140138
goto umount;
141139
}
142140

143-
if (!has_ben)
144-
sprintf(benchmark_cmd[4], "%s", CMT_STR);
145141
res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd);
146142
ksft_test_result(!res, "CMT: test\n");
147143
if ((get_vendor() == ARCH_INTEL) && res)
@@ -274,7 +270,7 @@ int main(int argc, char **argv)
274270
sprintf(benchmark_cmd[1], "%zu", span);
275271
strcpy(benchmark_cmd[2], "1");
276272
strcpy(benchmark_cmd[3], "0");
277-
strcpy(benchmark_cmd[4], "");
273+
strcpy(benchmark_cmd[4], "false");
278274
benchmark_cmd[5] = NULL;
279275
}
280276

@@ -292,13 +288,13 @@ int main(int argc, char **argv)
292288
ksft_set_plan(tests ? : 4);
293289

294290
if (mbm_test)
295-
run_mbm_test(has_ben, benchmark_cmd, span, cpu_no, bw_report);
291+
run_mbm_test(benchmark_cmd, span, cpu_no, bw_report);
296292

297293
if (mba_test)
298294
run_mba_test(benchmark_cmd, cpu_no, bw_report);
299295

300296
if (cmt_test)
301-
run_cmt_test(has_ben, benchmark_cmd, cpu_no);
297+
run_cmt_test(benchmark_cmd, cpu_no);
302298

303299
if (cat_test)
304300
run_cat_test(cpu_no, no_of_bits);

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext)
304304
{
305305
int operation, ret, memflush;
306306
char **benchmark_cmd;
307-
char resctrl_val[64];
308307
size_t span;
308+
bool once;
309309
FILE *fp;
310310

311311
benchmark_cmd = info->si_ptr;
@@ -323,9 +323,14 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext)
323323
span = strtoul(benchmark_cmd[1], NULL, 10);
324324
memflush = atoi(benchmark_cmd[2]);
325325
operation = atoi(benchmark_cmd[3]);
326-
sprintf(resctrl_val, "%s", benchmark_cmd[4]);
326+
if (!strcmp(benchmark_cmd[4], "true"))
327+
once = true;
328+
else if (!strcmp(benchmark_cmd[4], "false"))
329+
once = false;
330+
else
331+
PARENT_EXIT("Invalid once parameter");
327332

328-
if (run_fill_buf(span, memflush, operation, resctrl_val))
333+
if (run_fill_buf(span, memflush, operation, once))
329334
fprintf(stderr, "Error in running fill buffer\n");
330335
} else {
331336
/* Execute specified benchmark */

0 commit comments

Comments
 (0)