Skip to content

Commit 0e25181

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Add ->measure() callback to resctrl_val_param
The measurement done in resctrl_val() varies depending on test type. The decision for how to measure is decided based on the string compare to test name which is quite inflexible. Add ->measure() callback into the struct resctrl_val_param to allow each test to provide necessary code as a function which simplifies what resctrl_val() has to do. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Babu Moger <babu.moger@amd.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 711d27b commit 0e25181

5 files changed

Lines changed: 35 additions & 15 deletions

File tree

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ static int cmt_setup(const struct resctrl_test *test,
2929
return 0;
3030
}
3131

32+
static int cmt_measure(const struct user_params *uparams,
33+
struct resctrl_val_param *param, pid_t bm_pid)
34+
{
35+
sleep(1);
36+
return measure_llc_resctrl(param->filename, bm_pid);
37+
}
38+
3239
static int show_results_info(unsigned long sum_llc_val, int no_of_bits,
3340
unsigned long cache_span, unsigned long max_diff,
3441
unsigned long max_diff_percent, unsigned long num_of_runs,
@@ -133,6 +140,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
133140
.mask = ~(long_mask << n) & long_mask,
134141
.num_of_runs = 0,
135142
.setup = cmt_setup,
143+
.measure = cmt_measure,
136144
};
137145

138146
span = cache_portion_size(cache_total_size, param.mask, long_mask);

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static int mba_setup(const struct resctrl_test *test,
5151
return 0;
5252
}
5353

54+
static int mba_measure(const struct user_params *uparams,
55+
struct resctrl_val_param *param, pid_t bm_pid)
56+
{
57+
return measure_mem_bw(uparams, param, bm_pid);
58+
}
59+
5460
static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
5561
{
5662
int allocation, runs;
@@ -150,7 +156,8 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
150156
.mongrp = "m1",
151157
.filename = RESULT_FILE_NAME,
152158
.bw_report = "reads",
153-
.setup = mba_setup
159+
.setup = mba_setup,
160+
.measure = mba_measure,
154161
};
155162
int ret;
156163

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ static int mbm_setup(const struct resctrl_test *test,
105105
return ret;
106106
}
107107

108+
static int mbm_measure(const struct user_params *uparams,
109+
struct resctrl_val_param *param, pid_t bm_pid)
110+
{
111+
return measure_mem_bw(uparams, param, bm_pid);
112+
}
113+
108114
static void mbm_test_cleanup(void)
109115
{
110116
remove(RESULT_FILE_NAME);
@@ -117,7 +123,8 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
117123
.ctrlgrp = "c1",
118124
.filename = RESULT_FILE_NAME,
119125
.bw_report = "reads",
120-
.setup = mbm_setup
126+
.setup = mbm_setup,
127+
.measure = mbm_measure,
121128
};
122129
int ret;
123130

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct resctrl_test {
8787
* @filename: Name of file to which the o/p should be written
8888
* @bw_report: Bandwidth report type (reads vs writes)
8989
* @setup: Call back function to setup test environment
90+
* @measure: Callback that performs the measurement (a single test)
9091
*/
9192
struct resctrl_val_param {
9293
char *resctrl_val;
@@ -99,6 +100,9 @@ struct resctrl_val_param {
99100
int (*setup)(const struct resctrl_test *test,
100101
const struct user_params *uparams,
101102
struct resctrl_val_param *param);
103+
int (*measure)(const struct user_params *uparams,
104+
struct resctrl_val_param *param,
105+
pid_t bm_pid);
102106
};
103107

104108
struct perf_event_read {
@@ -145,6 +149,8 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);
145149
void mem_flush(unsigned char *buf, size_t buf_size);
146150
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
147151
int run_fill_buf(size_t buf_size, int memflush, int op, bool once);
152+
int measure_mem_bw(const struct user_params *uparams,
153+
struct resctrl_val_param *param, pid_t bm_pid);
148154
int resctrl_val(const struct resctrl_test *test,
149155
const struct user_params *uparams,
150156
const char * const *benchmark_cmd,

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,
606606
* available. Compare the two values to validate resctrl value. It takes
607607
* 1 sec to measure the data.
608608
*/
609-
static int measure_mem_bw(const struct user_params *uparams,
610-
struct resctrl_val_param *param, pid_t bm_pid)
609+
int measure_mem_bw(const struct user_params *uparams,
610+
struct resctrl_val_param *param, pid_t bm_pid)
611611
{
612612
unsigned long bw_resc, bw_resc_start, bw_resc_end;
613613
FILE *mem_bw_fp;
@@ -868,17 +868,9 @@ int resctrl_val(const struct resctrl_test *test,
868868
if (ret < 0)
869869
break;
870870

871-
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
872-
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
873-
ret = measure_mem_bw(uparams, param, bm_pid);
874-
if (ret)
875-
break;
876-
} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) {
877-
sleep(1);
878-
ret = measure_llc_resctrl(param->filename, bm_pid);
879-
if (ret)
880-
break;
881-
}
871+
ret = param->measure(uparams, param, bm_pid);
872+
if (ret)
873+
break;
882874
}
883875

884876
out:

0 commit comments

Comments
 (0)