Skip to content

Commit

Permalink
selftests/resctrl: Create struct for input parameters
Browse files Browse the repository at this point in the history
resctrl_tests reads a set of parameters and passes them individually
for each tests which causes variations in the call signature between
the tests.

Add struct input_params to hold all input parameters. It can be easily
passed to every test without varying the call signature.

Signed-off-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>
  • Loading branch information
Ilpo Järvinen authored and Shuah Khan committed Feb 13, 2024
1 parent 6c8cb74 commit 15f2988
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 71 deletions.
20 changes: 11 additions & 9 deletions tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void cat_test_cleanup(void)

/*
* cat_test - Execute CAT benchmark and measure cache misses
* @uparams: User supplied parameters
* @param: Parameters passed to cat_test()
* @span: Buffer size for the benchmark
* @current_mask Start mask for the first iteration
Expand All @@ -151,7 +152,8 @@ void cat_test_cleanup(void)
*
* Return: 0 when the test was run, < 0 on error.
*/
static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long current_mask)
static int cat_test(const struct user_params *uparams, struct resctrl_val_param *param,
size_t span, unsigned long current_mask)
{
char *resctrl_val = param->resctrl_val;
struct perf_event_read pe_read;
Expand All @@ -168,7 +170,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
bm_pid = getpid();

/* Taskset benchmark to specified cpu */
ret = taskset_benchmark(bm_pid, param->cpu_no, &old_affinity);
ret = taskset_benchmark(bm_pid, uparams->cpu, &old_affinity);
if (ret)
return ret;

Expand All @@ -180,7 +182,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long

perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES);
perf_event_initialize_read_format(&pe_read);
pe_fd = perf_open(&pea, bm_pid, param->cpu_no);
pe_fd = perf_open(&pea, bm_pid, uparams->cpu);
if (pe_fd < 0) {
ret = -1;
goto reset_affinity;
Expand All @@ -194,11 +196,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long

while (current_mask) {
snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask);
ret = write_schemata("", schemata, param->cpu_no, param->resctrl_val);
ret = write_schemata("", schemata, uparams->cpu, param->resctrl_val);
if (ret)
goto free_buf;
snprintf(schemata, sizeof(schemata), "%lx", current_mask);
ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val);
ret = write_schemata(param->ctrlgrp, schemata, uparams->cpu, param->resctrl_val);
if (ret)
goto free_buf;

Expand Down Expand Up @@ -229,10 +231,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
return ret;
}

int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
int cat_perf_miss_val(const struct user_params *uparams, char *cache_type)
{
unsigned long long_mask, start_mask, full_cache_mask;
unsigned long cache_total_size = 0;
int n = uparams->bits;
unsigned int start;
int count_of_bits;
size_t span;
Expand All @@ -247,7 +250,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
return ret;

/* Get L3/L2 cache size */
ret = get_cache_size(cpu_no, cache_type, &cache_total_size);
ret = get_cache_size(uparams->cpu, cache_type, &cache_total_size);
if (ret)
return ret;
ksft_print_msg("Cache size :%lu\n", cache_total_size);
Expand All @@ -267,7 +270,6 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)

struct resctrl_val_param param = {
.resctrl_val = CAT_STR,
.cpu_no = cpu_no,
.ctrlgrp = "c1",
.filename = RESULT_FILE_NAME,
.num_of_runs = 0,
Expand All @@ -277,7 +279,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)

remove(param.filename);

ret = cat_test(&param, span, start_mask);
ret = cat_test(uparams, &param, span, start_mask);
if (ret)
goto out;

Expand Down
16 changes: 8 additions & 8 deletions tools/testing/selftests/resctrl/cmt_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define MAX_DIFF 2000000
#define MAX_DIFF_PERCENT 15

static int cmt_setup(struct resctrl_val_param *p)
static int cmt_setup(const struct user_params *uparams, struct resctrl_val_param *p)
{
/* Run NUM_OF_RUNS times */
if (p->num_of_runs >= NUM_OF_RUNS)
Expand Down Expand Up @@ -94,11 +94,12 @@ void cmt_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
int cmt_resctrl_val(const struct user_params *uparams)
{
const char * const *cmd = benchmark_cmd;
const char * const *cmd = uparams->benchmark_cmd;
const char *new_cmd[BENCHMARK_ARGS];
unsigned long cache_total_size = 0;
int n = uparams->bits ? : 5;
unsigned long long_mask;
char *span_str = NULL;
int count_of_bits;
Expand All @@ -109,7 +110,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
if (ret)
return ret;

ret = get_cache_size(cpu_no, "L3", &cache_total_size);
ret = get_cache_size(uparams->cpu, "L3", &cache_total_size);
if (ret)
return ret;
ksft_print_msg("Cache size :%lu\n", cache_total_size);
Expand All @@ -126,7 +127,6 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)
.resctrl_val = CMT_STR,
.ctrlgrp = "c1",
.mongrp = "m1",
.cpu_no = cpu_no,
.filename = RESULT_FILE_NAME,
.mask = ~(long_mask << n) & long_mask,
.num_of_runs = 0,
Expand All @@ -137,8 +137,8 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)

if (strcmp(cmd[0], "fill_buf") == 0) {
/* Duplicate the command to be able to replace span in it */
for (i = 0; benchmark_cmd[i]; i++)
new_cmd[i] = benchmark_cmd[i];
for (i = 0; uparams->benchmark_cmd[i]; i++)
new_cmd[i] = uparams->benchmark_cmd[i];
new_cmd[i] = NULL;

ret = asprintf(&span_str, "%zu", span);
Expand All @@ -150,7 +150,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd)

remove(RESULT_FILE_NAME);

ret = resctrl_val(cmd, &param);
ret = resctrl_val(uparams, cmd, &param);
if (ret)
goto out;

Expand Down
9 changes: 4 additions & 5 deletions tools/testing/selftests/resctrl/mba_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* con_mon grp, mon_grp in resctrl FS.
* For each allocation, run 5 times in order to get average values.
*/
static int mba_setup(struct resctrl_val_param *p)
static int mba_setup(const struct user_params *uparams, struct resctrl_val_param *p)
{
static int runs_per_allocation, allocation = 100;
char allocation_str[64];
Expand All @@ -40,7 +40,7 @@ static int mba_setup(struct resctrl_val_param *p)

sprintf(allocation_str, "%d", allocation);

ret = write_schemata(p->ctrlgrp, allocation_str, p->cpu_no,
ret = write_schemata(p->ctrlgrp, allocation_str, uparams->cpu,
p->resctrl_val);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -141,13 +141,12 @@ void mba_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd)
int mba_schemata_change(const struct user_params *uparams)
{
struct resctrl_val_param param = {
.resctrl_val = MBA_STR,
.ctrlgrp = "c1",
.mongrp = "m1",
.cpu_no = cpu_no,
.filename = RESULT_FILE_NAME,
.bw_report = "reads",
.setup = mba_setup
Expand All @@ -156,7 +155,7 @@ int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd)

remove(RESULT_FILE_NAME);

ret = resctrl_val(benchmark_cmd, &param);
ret = resctrl_val(uparams, uparams->benchmark_cmd, &param);
if (ret)
goto out;

Expand Down
9 changes: 4 additions & 5 deletions tools/testing/selftests/resctrl/mbm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int check_results(size_t span)
return ret;
}

static int mbm_setup(struct resctrl_val_param *p)
static int mbm_setup(const struct user_params *uparams, struct resctrl_val_param *p)
{
int ret = 0;

Expand All @@ -96,7 +96,7 @@ static int mbm_setup(struct resctrl_val_param *p)

/* Set up shemata with 100% allocation on the first run. */
if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL))
ret = write_schemata(p->ctrlgrp, "100", p->cpu_no,
ret = write_schemata(p->ctrlgrp, "100", uparams->cpu,
p->resctrl_val);

p->num_of_runs++;
Expand All @@ -109,13 +109,12 @@ void mbm_test_cleanup(void)
remove(RESULT_FILE_NAME);
}

int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd)
int mbm_bw_change(const struct user_params *uparams)
{
struct resctrl_val_param param = {
.resctrl_val = MBM_STR,
.ctrlgrp = "c1",
.mongrp = "m1",
.cpu_no = cpu_no,
.filename = RESULT_FILE_NAME,
.bw_report = "reads",
.setup = mbm_setup
Expand All @@ -124,7 +123,7 @@ int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd)

remove(RESULT_FILE_NAME);

ret = resctrl_val(benchmark_cmd, &param);
ret = resctrl_val(uparams, uparams->benchmark_cmd, &param);
if (ret)
goto out;

Expand Down
28 changes: 20 additions & 8 deletions tools/testing/selftests/resctrl/resctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@
exit(EXIT_FAILURE); \
} while (0)

/*
* user_params: User supplied parameters
* @cpu: CPU number to which the benchmark will be bound to
* @bits: Number of bits used for cache allocation size
* @benchmark_cmd: Benchmark command to run during (some of the) tests
*/
struct user_params {
int cpu;
int bits;
const char *benchmark_cmd[BENCHMARK_ARGS];
};

/*
* resctrl_val_param: resctrl test parameters
* @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc)
* @ctrlgrp: Name of the control monitor group (con_mon grp)
* @mongrp: Name of the monitor group (mon grp)
* @cpu_no: CPU number to which the benchmark would be binded
* @filename: Name of file to which the o/p should be written
* @bw_report: Bandwidth report type (reads vs writes)
* @setup: Call back function to setup test environment
Expand All @@ -58,12 +69,12 @@ struct resctrl_val_param {
char *resctrl_val;
char ctrlgrp[64];
char mongrp[64];
int cpu_no;
char filename[64];
char *bw_report;
unsigned long mask;
int num_of_runs;
int (*setup)(struct resctrl_val_param *param);
int (*setup)(const struct user_params *uparams,
struct resctrl_val_param *param);
};

struct perf_event_read {
Expand Down Expand Up @@ -110,11 +121,12 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);
void mem_flush(unsigned char *buf, size_t buf_size);
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 resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param);
int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd);
int resctrl_val(const struct user_params *uparams, const char * const *benchmark_cmd,
struct resctrl_val_param *param);
int mbm_bw_change(const struct user_params *uparams);
void tests_cleanup(void);
void mbm_test_cleanup(void);
int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd);
int mba_schemata_change(const struct user_params *uparams);
void mba_test_cleanup(void);
unsigned long create_bit_mask(unsigned int start, unsigned int len);
unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
Expand All @@ -125,8 +137,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
int signal_handler_register(void);
void signal_handler_unregister(void);
void cat_test_cleanup(void);
int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd);
int cat_perf_miss_val(const struct user_params *uparams, char *cache_type);
int cmt_resctrl_val(const struct user_params *uparams);
unsigned int count_bits(unsigned long n);
void cmt_test_cleanup(void);

Expand Down
Loading

0 comments on commit 15f2988

Please sign in to comment.