Commit ca160887 authored by Ilpo Järvinen's avatar Ilpo Järvinen Committed by Shuah Khan

selftests/resctrl: Pass write_schemata() resource instead of test name

write_schemata() takes the test name as an argument and determines the
relevant resource based on the test name. Such mapping from name to
resource does not really belong to resctrlfs.c that should provide
only generic, test-independent functions.

Pass the resource stored in the test information structure to
write_schemata() instead of the test name. The new API is also more
flexible as it enables to use write_schemata() for more than one
resource within a test.

While touching the sprintf(), move the unnecessary %c that is always
'=' directly into the format string.
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent c603ff5b
...@@ -135,6 +135,7 @@ void cat_test_cleanup(void) ...@@ -135,6 +135,7 @@ void cat_test_cleanup(void)
/* /*
* cat_test - Execute CAT benchmark and measure cache misses * cat_test - Execute CAT benchmark and measure cache misses
* @test: Test information structure
* @uparams: User supplied parameters * @uparams: User supplied parameters
* @param: Parameters passed to cat_test() * @param: Parameters passed to cat_test()
* @span: Buffer size for the benchmark * @span: Buffer size for the benchmark
...@@ -152,7 +153,9 @@ void cat_test_cleanup(void) ...@@ -152,7 +153,9 @@ void cat_test_cleanup(void)
* *
* Return: 0 when the test was run, < 0 on error. * Return: 0 when the test was run, < 0 on error.
*/ */
static int cat_test(const struct user_params *uparams, struct resctrl_val_param *param, static int cat_test(const struct resctrl_test *test,
const struct user_params *uparams,
struct resctrl_val_param *param,
size_t span, unsigned long current_mask) size_t span, unsigned long current_mask)
{ {
char *resctrl_val = param->resctrl_val; char *resctrl_val = param->resctrl_val;
...@@ -196,11 +199,11 @@ static int cat_test(const struct user_params *uparams, struct resctrl_val_param ...@@ -196,11 +199,11 @@ static int cat_test(const struct user_params *uparams, struct resctrl_val_param
while (current_mask) { while (current_mask) {
snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask); snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask);
ret = write_schemata("", schemata, uparams->cpu, param->resctrl_val); ret = write_schemata("", schemata, uparams->cpu, test->resource);
if (ret) if (ret)
goto free_buf; goto free_buf;
snprintf(schemata, sizeof(schemata), "%lx", current_mask); snprintf(schemata, sizeof(schemata), "%lx", current_mask);
ret = write_schemata(param->ctrlgrp, schemata, uparams->cpu, param->resctrl_val); ret = write_schemata(param->ctrlgrp, schemata, uparams->cpu, test->resource);
if (ret) if (ret)
goto free_buf; goto free_buf;
...@@ -279,7 +282,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param ...@@ -279,7 +282,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
remove(param.filename); remove(param.filename);
ret = cat_test(uparams, &param, span, start_mask); ret = cat_test(test, uparams, &param, span, start_mask);
if (ret) if (ret)
goto out; goto out;
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#define MAX_DIFF 2000000 #define MAX_DIFF 2000000
#define MAX_DIFF_PERCENT 15 #define MAX_DIFF_PERCENT 15
static int cmt_setup(const struct user_params *uparams, struct resctrl_val_param *p) static int cmt_setup(const struct resctrl_test *test,
const struct user_params *uparams,
struct resctrl_val_param *p)
{ {
/* Run NUM_OF_RUNS times */ /* Run NUM_OF_RUNS times */
if (p->num_of_runs >= NUM_OF_RUNS) if (p->num_of_runs >= NUM_OF_RUNS)
...@@ -150,7 +152,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param ...@@ -150,7 +152,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
remove(RESULT_FILE_NAME); remove(RESULT_FILE_NAME);
ret = resctrl_val(uparams, cmd, &param); ret = resctrl_val(test, uparams, cmd, &param);
if (ret) if (ret)
goto out; goto out;
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
* con_mon grp, mon_grp in resctrl FS. * con_mon grp, mon_grp in resctrl FS.
* For each allocation, run 5 times in order to get average values. * For each allocation, run 5 times in order to get average values.
*/ */
static int mba_setup(const struct user_params *uparams, struct resctrl_val_param *p) static int mba_setup(const struct resctrl_test *test,
const struct user_params *uparams,
struct resctrl_val_param *p)
{ {
static int runs_per_allocation, allocation = 100; static int runs_per_allocation, allocation = 100;
char allocation_str[64]; char allocation_str[64];
...@@ -40,8 +42,7 @@ static int mba_setup(const struct user_params *uparams, struct resctrl_val_param ...@@ -40,8 +42,7 @@ static int mba_setup(const struct user_params *uparams, struct resctrl_val_param
sprintf(allocation_str, "%d", allocation); sprintf(allocation_str, "%d", allocation);
ret = write_schemata(p->ctrlgrp, allocation_str, uparams->cpu, ret = write_schemata(p->ctrlgrp, allocation_str, uparams->cpu, test->resource);
p->resctrl_val);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -155,7 +156,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param ...@@ -155,7 +156,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
remove(RESULT_FILE_NAME); remove(RESULT_FILE_NAME);
ret = resctrl_val(uparams, uparams->benchmark_cmd, &param); ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
if (ret) if (ret)
goto out; goto out;
......
...@@ -86,7 +86,9 @@ static int check_results(size_t span) ...@@ -86,7 +86,9 @@ static int check_results(size_t span)
return ret; return ret;
} }
static int mbm_setup(const struct user_params *uparams, struct resctrl_val_param *p) static int mbm_setup(const struct resctrl_test *test,
const struct user_params *uparams,
struct resctrl_val_param *p)
{ {
int ret = 0; int ret = 0;
...@@ -96,8 +98,7 @@ static int mbm_setup(const struct user_params *uparams, struct resctrl_val_param ...@@ -96,8 +98,7 @@ static int mbm_setup(const struct user_params *uparams, struct resctrl_val_param
/* Set up shemata with 100% allocation on the first run. */ /* Set up shemata with 100% allocation on the first run. */
if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL)) if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL))
ret = write_schemata(p->ctrlgrp, "100", uparams->cpu, ret = write_schemata(p->ctrlgrp, "100", uparams->cpu, test->resource);
p->resctrl_val);
p->num_of_runs++; p->num_of_runs++;
...@@ -123,7 +124,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param ...@@ -123,7 +124,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
remove(RESULT_FILE_NAME); remove(RESULT_FILE_NAME);
ret = resctrl_val(uparams, uparams->benchmark_cmd, &param); ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
if (ret) if (ret)
goto out; goto out;
......
...@@ -98,7 +98,8 @@ struct resctrl_val_param { ...@@ -98,7 +98,8 @@ struct resctrl_val_param {
char *bw_report; char *bw_report;
unsigned long mask; unsigned long mask;
int num_of_runs; int num_of_runs;
int (*setup)(const struct user_params *uparams, int (*setup)(const struct resctrl_test *test,
const struct user_params *uparams,
struct resctrl_val_param *param); struct resctrl_val_param *param);
}; };
...@@ -137,8 +138,7 @@ bool test_resource_feature_check(const struct resctrl_test *test); ...@@ -137,8 +138,7 @@ bool test_resource_feature_check(const struct resctrl_test *test);
char *fgrep(FILE *inf, const char *str); char *fgrep(FILE *inf, const char *str);
int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity); int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity);
int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity); int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity);
int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource);
char *resctrl_val);
int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
char *resctrl_val); char *resctrl_val);
int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
...@@ -147,7 +147,9 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush); ...@@ -147,7 +147,9 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);
void mem_flush(unsigned char *buf, size_t buf_size); void mem_flush(unsigned char *buf, size_t buf_size);
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
int run_fill_buf(size_t buf_size, int memflush, int op, bool once); int run_fill_buf(size_t buf_size, int memflush, int op, bool once);
int resctrl_val(const struct user_params *uparams, const char * const *benchmark_cmd, int resctrl_val(const struct resctrl_test *test,
const struct user_params *uparams,
const char * const *benchmark_cmd,
struct resctrl_val_param *param); struct resctrl_val_param *param);
void tests_cleanup(void); void tests_cleanup(void);
void mbm_test_cleanup(void); void mbm_test_cleanup(void);
......
...@@ -684,13 +684,16 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext) ...@@ -684,13 +684,16 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
/* /*
* resctrl_val: execute benchmark and measure memory bandwidth on * resctrl_val: execute benchmark and measure memory bandwidth on
* the benchmark * the benchmark
* @test: test information structure
* @uparams: user supplied parameters * @uparams: user supplied parameters
* @benchmark_cmd: benchmark command and its arguments * @benchmark_cmd: benchmark command and its arguments
* @param: parameters passed to resctrl_val() * @param: parameters passed to resctrl_val()
* *
* Return: 0 when the test was run, < 0 on error. * Return: 0 when the test was run, < 0 on error.
*/ */
int resctrl_val(const struct user_params *uparams, const char * const *benchmark_cmd, int resctrl_val(const struct resctrl_test *test,
const struct user_params *uparams,
const char * const *benchmark_cmd,
struct resctrl_val_param *param) struct resctrl_val_param *param)
{ {
char *resctrl_val = param->resctrl_val; char *resctrl_val = param->resctrl_val;
...@@ -826,7 +829,7 @@ int resctrl_val(const struct user_params *uparams, const char * const *benchmark ...@@ -826,7 +829,7 @@ int resctrl_val(const struct user_params *uparams, const char * const *benchmark
/* Test runs until the callback setup() tells the test to stop. */ /* Test runs until the callback setup() tells the test to stop. */
while (1) { while (1) {
ret = param->setup(uparams, param); ret = param->setup(test, uparams, param);
if (ret == END_OF_TESTS) { if (ret == END_OF_TESTS) {
ret = 0; ret = 0;
break; break;
......
...@@ -529,23 +529,17 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, ...@@ -529,23 +529,17 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
* @ctrlgrp: Name of the con_mon grp * @ctrlgrp: Name of the con_mon grp
* @schemata: Schemata that should be updated to * @schemata: Schemata that should be updated to
* @cpu_no: CPU number that the benchmark PID is binded to * @cpu_no: CPU number that the benchmark PID is binded to
* @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) * @resource: Resctrl resource (Eg: MB, L3, L2, etc.)
* *
* Update schemata of a con_mon grp *only* if requested resctrl feature is * Update schemata of a con_mon grp *only* if requested resctrl resource is
* allocation type * allocation type
* *
* Return: 0 on success, < 0 on error. * Return: 0 on success, < 0 on error.
*/ */
int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource)
{ {
char controlgroup[1024], reason[128], schema[1024] = {}; char controlgroup[1024], reason[128], schema[1024] = {};
int resource_id, fd, schema_len = -1, ret = 0; int resource_id, fd, schema_len, ret = 0;
if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) &&
strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) &&
strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) &&
strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))
return -ENOENT;
if (!schemata) { if (!schemata) {
ksft_print_msg("Skipping empty schemata update\n"); ksft_print_msg("Skipping empty schemata update\n");
...@@ -565,14 +559,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) ...@@ -565,14 +559,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)
else else
sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); sprintf(controlgroup, "%s/schemata", RESCTRL_PATH);
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) || schema_len = snprintf(schema, sizeof(schema), "%s:%d=%s\n",
!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) resource, resource_id, schemata);
schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n",
"L3:", resource_id, '=', schemata);
if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) ||
!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)))
schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n",
"MB:", resource_id, '=', schemata);
if (schema_len < 0 || schema_len >= sizeof(schema)) { if (schema_len < 0 || schema_len >= sizeof(schema)) {
snprintf(reason, sizeof(reason), snprintf(reason, sizeof(reason),
"snprintf() failed with return value : %d", schema_len); "snprintf() failed with return value : %d", schema_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment