Skip to content

Commit 326baed

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf()
run_fill_buf()'s malloc_and_init_memory parameter is always 1. There's also duplicated memory init code for malloc_and_init_memory == 0 case in fill_buf() which is unused. Remove the malloc_and_init_memory parameter and the duplicated mem init code. While at it, fix also a typo in run_fill_buf() prototype's argument. 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 1b9537b commit 326baed

File tree

5 files changed

+19
-43
lines changed

5 files changed

+19
-43
lines changed

tools/testing/selftests/resctrl/cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
210210
*/
211211
int cat_val(struct resctrl_val_param *param)
212212
{
213-
int malloc_and_init_memory = 1, memflush = 1, operation = 0, ret = 0;
213+
int memflush = 1, operation = 0, ret = 0;
214214
char *resctrl_val = param->resctrl_val;
215215
pid_t bm_pid;
216216

@@ -247,8 +247,8 @@ int cat_val(struct resctrl_val_param *param)
247247
if (ret)
248248
break;
249249

250-
if (run_fill_buf(param->span, malloc_and_init_memory,
251-
memflush, operation, resctrl_val)) {
250+
if (run_fill_buf(param->span, memflush, operation,
251+
resctrl_val)) {
252252
fprintf(stderr, "Error-running fill buffer\n");
253253
ret = -1;
254254
goto pe_close;

tools/testing/selftests/resctrl/fill_buf.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,18 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,
138138
return 0;
139139
}
140140

141-
static int
142-
fill_cache(size_t buf_size, int malloc_and_init, int memflush,
143-
int op, char *resctrl_val)
141+
static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl_val)
144142
{
145143
unsigned char *start_ptr, *end_ptr;
146-
unsigned long long i;
147144
int ret;
148145

149-
if (malloc_and_init)
150-
start_ptr = malloc_and_init_memory(buf_size);
151-
else
152-
start_ptr = malloc(buf_size);
153-
146+
start_ptr = malloc_and_init_memory(buf_size);
154147
if (!start_ptr)
155148
return -1;
156149

157150
startptr = start_ptr;
158151
end_ptr = start_ptr + buf_size;
159152

160-
/*
161-
* It's better to touch the memory once to avoid any compiler
162-
* optimizations
163-
*/
164-
if (!malloc_and_init) {
165-
for (i = 0; i < buf_size; i++)
166-
*start_ptr++ = (unsigned char)rand();
167-
}
168-
169-
start_ptr = startptr;
170-
171153
/* Flush the memory before using to avoid "cache hot pages" effect */
172154
if (memflush)
173155
mem_flush(start_ptr, buf_size);
@@ -188,14 +170,12 @@ fill_cache(size_t buf_size, int malloc_and_init, int memflush,
188170
return 0;
189171
}
190172

191-
int run_fill_buf(size_t span, int malloc_and_init_memory, int memflush, int op,
192-
char *resctrl_val)
173+
int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val)
193174
{
194175
size_t cache_size = span;
195176
int ret;
196177

197-
ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op,
198-
resctrl_val);
178+
ret = fill_cache(cache_size, memflush, op, resctrl_val);
199179
if (ret) {
200180
printf("\n Error in fill cache\n");
201181
return -1;

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +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 malloc_and_init_memory, int memflush, int op,
101-
char *resctrl_va);
100+
int run_fill_buf(size_t span, int memflush, int op, char *resctrl_val);
102101
int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
103102
int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd);
104103
void tests_cleanup(void);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span,
8989
}
9090

9191
if (!has_ben)
92-
sprintf(benchmark_cmd[5], "%s", MBA_STR);
92+
sprintf(benchmark_cmd[4], "%s", MBA_STR);
9393
res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd);
9494
ksft_test_result(!res, "MBM: bw change\n");
9595
if ((get_vendor() == ARCH_INTEL) && res)
@@ -141,7 +141,7 @@ static void run_cmt_test(bool has_ben, char **benchmark_cmd, int cpu_no)
141141
}
142142

143143
if (!has_ben)
144-
sprintf(benchmark_cmd[5], "%s", CMT_STR);
144+
sprintf(benchmark_cmd[4], "%s", CMT_STR);
145145
res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd);
146146
ksft_test_result(!res, "CMT: test\n");
147147
if ((get_vendor() == ARCH_INTEL) && res)
@@ -267,16 +267,15 @@ int main(int argc, char **argv)
267267
benchmark_cmd[ben_count] = NULL;
268268
} else {
269269
/* If no benchmark is given by "-b" argument, use fill_buf. */
270-
for (i = 0; i < 6; i++)
270+
for (i = 0; i < 5; i++)
271271
benchmark_cmd[i] = benchmark_cmd_area[i];
272272

273273
strcpy(benchmark_cmd[0], "fill_buf");
274274
sprintf(benchmark_cmd[1], "%zu", span);
275275
strcpy(benchmark_cmd[2], "1");
276-
strcpy(benchmark_cmd[3], "1");
277-
strcpy(benchmark_cmd[4], "0");
278-
strcpy(benchmark_cmd[5], "");
279-
benchmark_cmd[6] = NULL;
276+
strcpy(benchmark_cmd[3], "0");
277+
strcpy(benchmark_cmd[4], "");
278+
benchmark_cmd[5] = NULL;
280279
}
281280

282281
sprintf(bw_report, "reads");

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)
302302
*/
303303
void run_benchmark(int signum, siginfo_t *info, void *ucontext)
304304
{
305-
int operation, ret, malloc_and_init_memory, memflush;
305+
int operation, ret, memflush;
306306
char **benchmark_cmd;
307307
char resctrl_val[64];
308308
size_t span;
@@ -321,13 +321,11 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext)
321321
if (strcmp(benchmark_cmd[0], "fill_buf") == 0) {
322322
/* Execute default fill_buf benchmark */
323323
span = strtoul(benchmark_cmd[1], NULL, 10);
324-
malloc_and_init_memory = atoi(benchmark_cmd[2]);
325-
memflush = atoi(benchmark_cmd[3]);
326-
operation = atoi(benchmark_cmd[4]);
327-
sprintf(resctrl_val, "%s", benchmark_cmd[5]);
324+
memflush = atoi(benchmark_cmd[2]);
325+
operation = atoi(benchmark_cmd[3]);
326+
sprintf(resctrl_val, "%s", benchmark_cmd[4]);
328327

329-
if (run_fill_buf(span, malloc_and_init_memory, memflush,
330-
operation, resctrl_val))
328+
if (run_fill_buf(span, memflush, operation, resctrl_val))
331329
fprintf(stderr, "Error in running fill buffer\n");
332330
} else {
333331
/* Execute specified benchmark */

0 commit comments

Comments
 (0)