Skip to content

Commit aef5efa

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Add ->init() callback into resctrl_val_param
The struct resctrl_val_param is there to customize behavior inside resctrl_val() which is currently not used to full extent and there are number of strcmp()s for test name in resctrl_val done by resctrl_val(). Create ->init() hook into the struct resctrl_val_param to cleanly do per test initialization. Remove also unused branches to setup paths and the related #defines for CMT test. While touching kerneldoc, make the adjacent line consistent with the newly added form (callback vs call back). 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 0e25181 commit aef5efa

5 files changed

Lines changed: 60 additions & 63 deletions

File tree

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
#define MAX_DIFF 2000000
1717
#define MAX_DIFF_PERCENT 15
1818

19+
#define CON_MON_LCC_OCCUP_PATH \
20+
"%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy"
21+
22+
static int cmt_init(const struct resctrl_val_param *param, int domain_id)
23+
{
24+
sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH,
25+
param->ctrlgrp, param->mongrp, domain_id);
26+
27+
return 0;
28+
}
29+
1930
static int cmt_setup(const struct resctrl_test *test,
2031
const struct user_params *uparams,
2132
struct resctrl_val_param *p)
@@ -139,6 +150,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
139150
.filename = RESULT_FILE_NAME,
140151
.mask = ~(long_mask << n) & long_mask,
141152
.num_of_runs = 0,
153+
.init = cmt_init,
142154
.setup = cmt_setup,
143155
.measure = cmt_measure,
144156
};

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#define ALLOCATION_MIN 10
1818
#define ALLOCATION_STEP 10
1919

20+
static int mba_init(const struct resctrl_val_param *param, int domain_id)
21+
{
22+
int ret;
23+
24+
ret = initialize_mem_bw_imc();
25+
if (ret)
26+
return ret;
27+
28+
initialize_mem_bw_resctrl(param, domain_id);
29+
30+
return 0;
31+
}
32+
2033
/*
2134
* Change schemata percentage from 100 to 10%. Write schemata to specified
2235
* con_mon grp, mon_grp in resctrl FS.
@@ -156,6 +169,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
156169
.mongrp = "m1",
157170
.filename = RESULT_FILE_NAME,
158171
.bw_report = "reads",
172+
.init = mba_init,
159173
.setup = mba_setup,
160174
.measure = mba_measure,
161175
};

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ static int check_results(size_t span)
8686
return ret;
8787
}
8888

89+
static int mbm_init(const struct resctrl_val_param *param, int domain_id)
90+
{
91+
int ret;
92+
93+
ret = initialize_mem_bw_imc();
94+
if (ret)
95+
return ret;
96+
97+
initialize_mem_bw_resctrl(param, domain_id);
98+
99+
return 0;
100+
}
101+
89102
static int mbm_setup(const struct resctrl_test *test,
90103
const struct user_params *uparams,
91104
struct resctrl_val_param *p)
@@ -123,6 +136,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
123136
.ctrlgrp = "c1",
124137
.filename = RESULT_FILE_NAME,
125138
.bw_report = "reads",
139+
.init = mbm_init,
126140
.setup = mbm_setup,
127141
.measure = mbm_measure,
128142
};

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ struct resctrl_test {
8686
* @mongrp: Name of the monitor group (mon grp)
8787
* @filename: Name of file to which the o/p should be written
8888
* @bw_report: Bandwidth report type (reads vs writes)
89-
* @setup: Call back function to setup test environment
89+
* @init: Callback function to initialize test environment
90+
* @setup: Callback function to setup per test run environment
9091
* @measure: Callback that performs the measurement (a single test)
9192
*/
9293
struct resctrl_val_param {
@@ -97,6 +98,8 @@ struct resctrl_val_param {
9798
char *bw_report;
9899
unsigned long mask;
99100
int num_of_runs;
101+
int (*init)(const struct resctrl_val_param *param,
102+
int domain_id);
100103
int (*setup)(const struct resctrl_test *test,
101104
const struct user_params *uparams,
102105
struct resctrl_val_param *param);
@@ -149,8 +152,11 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);
149152
void mem_flush(unsigned char *buf, size_t buf_size);
150153
void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
151154
int run_fill_buf(size_t buf_size, int memflush, int op, bool once);
155+
int initialize_mem_bw_imc(void);
152156
int measure_mem_bw(const struct user_params *uparams,
153157
struct resctrl_val_param *param, pid_t bm_pid);
158+
void initialize_mem_bw_resctrl(const struct resctrl_val_param *param,
159+
int domain_id);
154160
int resctrl_val(const struct resctrl_test *test,
155161
const struct user_params *uparams,
156162
const char * const *benchmark_cmd,

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@
2323
#define CON_MBM_LOCAL_BYTES_PATH \
2424
"%s/%s/mon_data/mon_L3_%02d/mbm_local_bytes"
2525

26-
#define CON_MON_LCC_OCCUP_PATH \
27-
"%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy"
28-
29-
#define CON_LCC_OCCUP_PATH \
30-
"%s/%s/mon_data/mon_L3_%02d/llc_occupancy"
31-
32-
#define MON_LCC_OCCUP_PATH \
33-
"%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy"
34-
35-
#define LCC_OCCUP_PATH \
36-
"%s/mon_data/mon_L3_%02d/llc_occupancy"
37-
3826
struct membw_read_format {
3927
__u64 value; /* The value of the event */
4028
__u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */
@@ -268,7 +256,7 @@ static int num_of_imcs(void)
268256
return count;
269257
}
270258

271-
static int initialize_mem_bw_imc(void)
259+
int initialize_mem_bw_imc(void)
272260
{
273261
int imc, j;
274262

@@ -424,24 +412,18 @@ static int get_mem_bw_imc(char *bw_report, float *bw_imc)
424412

425413
/*
426414
* initialize_mem_bw_resctrl: Appropriately populate "mbm_total_path"
427-
* @ctrlgrp: Name of the control monitor group (con_mon grp)
428-
* @domain_id: Domain ID (cache ID; for MB, L3 cache ID)
415+
* @param: Parameters passed to resctrl_val()
416+
* @domain_id: Domain ID (cache ID; for MB, L3 cache ID)
429417
*/
430-
static void initialize_mem_bw_resctrl(const char *ctrlgrp, int domain_id)
418+
void initialize_mem_bw_resctrl(const struct resctrl_val_param *param,
419+
int domain_id)
431420
{
432421
sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH,
433-
ctrlgrp, domain_id);
422+
param->ctrlgrp, domain_id);
434423
}
435424

436425
/*
437-
* Get MBM Local bytes as reported by resctrl FS
438-
* For MBM,
439-
* 1. If con_mon grp and mon grp are given, then read from con_mon grp's mon grp
440-
* 2. If only con_mon grp is given, then read from con_mon grp
441-
* 3. If both are not given, then read from root con_mon grp
442-
* For MBA,
443-
* 1. If con_mon grp is given, then read from it
444-
* 2. If con_mon grp is not given, then read from root con_mon grp
426+
* Open file to read MBM local bytes from resctrl FS
445427
*/
446428
static FILE *open_mem_bw_resctrl(const char *mbm_bw_file)
447429
{
@@ -454,6 +436,9 @@ static FILE *open_mem_bw_resctrl(const char *mbm_bw_file)
454436
return fp;
455437
}
456438

439+
/*
440+
* Get MBM Local bytes as reported by resctrl FS
441+
*/
457442
static int get_mem_bw_resctrl(FILE *fp, unsigned long *mbm_total)
458443
{
459444
if (fscanf(fp, "%lu\n", mbm_total) <= 0) {
@@ -566,35 +551,6 @@ static int print_results_bw(char *filename, pid_t bm_pid, float bw_imc,
566551
return 0;
567552
}
568553

569-
static void set_cmt_path(const char *ctrlgrp, const char *mongrp, char sock_num)
570-
{
571-
if (strlen(ctrlgrp) && strlen(mongrp))
572-
sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH,
573-
ctrlgrp, mongrp, sock_num);
574-
else if (!strlen(ctrlgrp) && strlen(mongrp))
575-
sprintf(llc_occup_path, MON_LCC_OCCUP_PATH, RESCTRL_PATH,
576-
mongrp, sock_num);
577-
else if (strlen(ctrlgrp) && !strlen(mongrp))
578-
sprintf(llc_occup_path, CON_LCC_OCCUP_PATH, RESCTRL_PATH,
579-
ctrlgrp, sock_num);
580-
else if (!strlen(ctrlgrp) && !strlen(mongrp))
581-
sprintf(llc_occup_path, LCC_OCCUP_PATH, RESCTRL_PATH, sock_num);
582-
}
583-
584-
/*
585-
* initialize_llc_occu_resctrl: Appropriately populate "llc_occup_path"
586-
* @ctrlgrp: Name of the control monitor group (con_mon grp)
587-
* @mongrp: Name of the monitor group (mon grp)
588-
* @domain_id: Domain ID (cache ID; for MB, L3 cache ID)
589-
* @resctrl_val: Resctrl feature (Eg: cat, cmt.. etc)
590-
*/
591-
static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,
592-
int domain_id, char *resctrl_val)
593-
{
594-
if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))
595-
set_cmt_path(ctrlgrp, mongrp, domain_id);
596-
}
597-
598554
/*
599555
* measure_mem_bw - Measures memory bandwidth numbers while benchmark runs
600556
* @uparams: User supplied parameters
@@ -825,16 +781,11 @@ int resctrl_val(const struct resctrl_test *test,
825781
if (ret)
826782
goto out;
827783

828-
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
829-
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
830-
ret = initialize_mem_bw_imc();
784+
if (param->init) {
785+
ret = param->init(param, domain_id);
831786
if (ret)
832787
goto out;
833-
834-
initialize_mem_bw_resctrl(param->ctrlgrp, domain_id);
835-
} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))
836-
initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp,
837-
domain_id, resctrl_val);
788+
}
838789

839790
/* Parent waits for child to be ready. */
840791
close(pipefd[1]);

0 commit comments

Comments
 (0)