Skip to content

Commit 508934b

Browse files
maciejwieczorretmanshuahkh
authored andcommitted
selftests/resctrl: Move run_benchmark() to a more fitting file
resctrlfs.c contains mostly functions that interact in some way with resctrl FS entries while functions inside resctrl_val.c deal with measurements and benchmarking. run_benchmark() is located in resctrlfs.c even though it's purpose is not interacting with the resctrl FS but to execute cache checking logic. Move run_benchmark() to resctrl_val.c just before resctrl_val() that makes use of run_benchmark(). Make run_benchmark() static since it's not used between multiple files anymore. Remove return comment from kernel-doc since the function is type void. Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 20d96b2 commit 508934b

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ int validate_bw_report_request(char *bw_report);
8686
bool validate_resctrl_feature_request(const char *resource, const char *feature);
8787
char *fgrep(FILE *inf, const char *str);
8888
int taskset_benchmark(pid_t bm_pid, int cpu_no);
89-
void run_benchmark(int signum, siginfo_t *info, void *ucontext);
9089
int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
9190
char *resctrl_val);
9291
int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,56 @@ measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start)
625625
return 0;
626626
}
627627

628+
/*
629+
* run_benchmark - Run a specified benchmark or fill_buf (default benchmark)
630+
* in specified signal. Direct benchmark stdio to /dev/null.
631+
* @signum: signal number
632+
* @info: signal info
633+
* @ucontext: user context in signal handling
634+
*/
635+
static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
636+
{
637+
int operation, ret, memflush;
638+
char **benchmark_cmd;
639+
size_t span;
640+
bool once;
641+
FILE *fp;
642+
643+
benchmark_cmd = info->si_ptr;
644+
645+
/*
646+
* Direct stdio of child to /dev/null, so that only parent writes to
647+
* stdio (console)
648+
*/
649+
fp = freopen("/dev/null", "w", stdout);
650+
if (!fp)
651+
PARENT_EXIT("Unable to direct benchmark status to /dev/null");
652+
653+
if (strcmp(benchmark_cmd[0], "fill_buf") == 0) {
654+
/* Execute default fill_buf benchmark */
655+
span = strtoul(benchmark_cmd[1], NULL, 10);
656+
memflush = atoi(benchmark_cmd[2]);
657+
operation = atoi(benchmark_cmd[3]);
658+
if (!strcmp(benchmark_cmd[4], "true"))
659+
once = true;
660+
else if (!strcmp(benchmark_cmd[4], "false"))
661+
once = false;
662+
else
663+
PARENT_EXIT("Invalid once parameter");
664+
665+
if (run_fill_buf(span, memflush, operation, once))
666+
fprintf(stderr, "Error in running fill buffer\n");
667+
} else {
668+
/* Execute specified benchmark */
669+
ret = execvp(benchmark_cmd[0], benchmark_cmd);
670+
if (ret)
671+
perror("wrong\n");
672+
}
673+
674+
fclose(stdout);
675+
PARENT_EXIT("Unable to run specified benchmark");
676+
}
677+
628678
/*
629679
* resctrl_val: execute benchmark and measure memory bandwidth on
630680
* the benchmark

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -294,58 +294,6 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)
294294
return 0;
295295
}
296296

297-
/*
298-
* run_benchmark - Run a specified benchmark or fill_buf (default benchmark)
299-
* in specified signal. Direct benchmark stdio to /dev/null.
300-
* @signum: signal number
301-
* @info: signal info
302-
* @ucontext: user context in signal handling
303-
*
304-
* Return: void
305-
*/
306-
void run_benchmark(int signum, siginfo_t *info, void *ucontext)
307-
{
308-
int operation, ret, memflush;
309-
char **benchmark_cmd;
310-
size_t span;
311-
bool once;
312-
FILE *fp;
313-
314-
benchmark_cmd = info->si_ptr;
315-
316-
/*
317-
* Direct stdio of child to /dev/null, so that only parent writes to
318-
* stdio (console)
319-
*/
320-
fp = freopen("/dev/null", "w", stdout);
321-
if (!fp)
322-
PARENT_EXIT("Unable to direct benchmark status to /dev/null");
323-
324-
if (strcmp(benchmark_cmd[0], "fill_buf") == 0) {
325-
/* Execute default fill_buf benchmark */
326-
span = strtoul(benchmark_cmd[1], NULL, 10);
327-
memflush = atoi(benchmark_cmd[2]);
328-
operation = atoi(benchmark_cmd[3]);
329-
if (!strcmp(benchmark_cmd[4], "true"))
330-
once = true;
331-
else if (!strcmp(benchmark_cmd[4], "false"))
332-
once = false;
333-
else
334-
PARENT_EXIT("Invalid once parameter");
335-
336-
if (run_fill_buf(span, memflush, operation, once))
337-
fprintf(stderr, "Error in running fill buffer\n");
338-
} else {
339-
/* Execute specified benchmark */
340-
ret = execvp(benchmark_cmd[0], benchmark_cmd);
341-
if (ret)
342-
perror("wrong\n");
343-
}
344-
345-
fclose(stdout);
346-
PARENT_EXIT("Unable to run specified benchmark");
347-
}
348-
349297
/*
350298
* create_grp - Create a group only if one doesn't exist
351299
* @grp_name: Name of the group

0 commit comments

Comments
 (0)