Skip to content

Commit b1a901e

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Simplify span lifetime
struct resctrl_val_param contains span member. resctrl_val(), however, never uses it because the value of span is embedded into the default benchmark command and parsed from it by run_benchmark(). Remove span from resctrl_val_param. Provide DEFAULT_SPAN for the code that needs it. CMT and CAT tests communicate span that is different from the DEFAULT_SPAN between their internal functions which is converted into passing it directly as a parameter. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 47e36f1 commit b1a901e

6 files changed

Lines changed: 26 additions & 25 deletions

File tree

tools/testing/selftests/resctrl/cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
205205
* cache_val: execute benchmark and measure LLC occupancy resctrl
206206
* and perf cache miss for the benchmark
207207
* @param: parameters passed to cache_val()
208+
* @span: buffer size for the benchmark
208209
*
209210
* Return: 0 on success. non-zero on failure.
210211
*/
211-
int cat_val(struct resctrl_val_param *param)
212+
int cat_val(struct resctrl_val_param *param, size_t span)
212213
{
213214
int memflush = 1, operation = 0, ret = 0;
214215
char *resctrl_val = param->resctrl_val;
@@ -245,7 +246,7 @@ int cat_val(struct resctrl_val_param *param)
245246
if (ret)
246247
break;
247248

248-
if (run_fill_buf(param->span, memflush, operation, true)) {
249+
if (run_fill_buf(span, memflush, operation, true)) {
249250
fprintf(stderr, "Error-running fill buffer\n");
250251
ret = -1;
251252
goto pe_close;

tools/testing/selftests/resctrl/cat_test.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int cat_setup(struct resctrl_val_param *p)
4141
return ret;
4242
}
4343

44-
static int check_results(struct resctrl_val_param *param)
44+
static int check_results(struct resctrl_val_param *param, size_t span)
4545
{
4646
char *token_array[8], temp[512];
4747
unsigned long sum_llc_perf_miss = 0;
@@ -76,7 +76,7 @@ static int check_results(struct resctrl_val_param *param)
7676
fclose(fp);
7777
no_of_bits = count_bits(param->mask);
7878

79-
return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64,
79+
return show_cache_info(sum_llc_perf_miss, no_of_bits, span / 64,
8080
MAX_DIFF, MAX_DIFF_PERCENT, runs - 1,
8181
get_vendor() == ARCH_INTEL, false);
8282
}
@@ -96,6 +96,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
9696
char cbm_mask[256];
9797
int count_of_bits;
9898
char pipe_message;
99+
size_t span;
99100

100101
/* Get default cbm mask for L3/L2 cache */
101102
ret = get_cbm_mask(cache_type, cbm_mask);
@@ -140,7 +141,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
140141
/* Set param values for parent thread which will be allocated bitmask
141142
* with (max_bits - n) bits
142143
*/
143-
param.span = cache_size * (count_of_bits - n) / count_of_bits;
144+
span = cache_size * (count_of_bits - n) / count_of_bits;
144145
strcpy(param.ctrlgrp, "c2");
145146
strcpy(param.mongrp, "m2");
146147
strcpy(param.filename, RESULT_FILE_NAME2);
@@ -162,7 +163,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
162163
param.mask = l_mask_1;
163164
strcpy(param.ctrlgrp, "c1");
164165
strcpy(param.mongrp, "m1");
165-
param.span = cache_size * n / count_of_bits;
166+
span = cache_size * n / count_of_bits;
166167
strcpy(param.filename, RESULT_FILE_NAME1);
167168
param.num_of_runs = 0;
168169
param.cpu_no = sibling_cpu_no;
@@ -176,9 +177,9 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
176177

177178
remove(param.filename);
178179

179-
ret = cat_val(&param);
180+
ret = cat_val(&param, span);
180181
if (ret == 0)
181-
ret = check_results(&param);
182+
ret = check_results(&param, span);
182183

183184
if (bm_pid == 0) {
184185
/* Tell parent that child is ready */

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int cmt_setup(struct resctrl_val_param *p)
2727
return 0;
2828
}
2929

30-
static int check_results(struct resctrl_val_param *param, int no_of_bits)
30+
static int check_results(struct resctrl_val_param *param, size_t span, int no_of_bits)
3131
{
3232
char *token_array[8], temp[512];
3333
unsigned long sum_llc_occu_resc = 0;
@@ -58,7 +58,7 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits)
5858
}
5959
fclose(fp);
6060

61-
return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span,
61+
return show_cache_info(sum_llc_occu_resc, no_of_bits, span,
6262
MAX_DIFF, MAX_DIFF_PERCENT, runs - 1,
6363
true, true);
6464
}
@@ -74,6 +74,7 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
7474
unsigned long long_mask;
7575
char cbm_mask[256];
7676
int count_of_bits;
77+
size_t span;
7778
int ret;
7879

7980
if (!validate_resctrl_feature_request(CMT_STR))
@@ -105,21 +106,21 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
105106
.cpu_no = cpu_no,
106107
.filename = RESULT_FILE_NAME,
107108
.mask = ~(long_mask << n) & long_mask,
108-
.span = cache_size * n / count_of_bits,
109109
.num_of_runs = 0,
110110
.setup = cmt_setup,
111111
};
112112

113+
span = cache_size * n / count_of_bits;
113114
if (strcmp(benchmark_cmd[0], "fill_buf") == 0)
114-
sprintf(benchmark_cmd[1], "%zu", param.span);
115+
sprintf(benchmark_cmd[1], "%zu", span);
115116

116117
remove(RESULT_FILE_NAME);
117118

118119
ret = resctrl_val(benchmark_cmd, &param);
119120
if (ret)
120121
goto out;
121122

122-
ret = check_results(&param, n);
123+
ret = check_results(&param, span, n);
123124

124125
out:
125126
cmt_test_cleanup();

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,12 @@ void mbm_test_cleanup(void)
109109
remove(RESULT_FILE_NAME);
110110
}
111111

112-
int mbm_bw_change(size_t span, int cpu_no, char **benchmark_cmd)
112+
int mbm_bw_change(int cpu_no, char **benchmark_cmd)
113113
{
114114
struct resctrl_val_param param = {
115115
.resctrl_val = MBM_STR,
116116
.ctrlgrp = "c1",
117117
.mongrp = "m1",
118-
.span = span,
119118
.cpu_no = cpu_no,
120119
.filename = RESULT_FILE_NAME,
121120
.bw_report = "reads",
@@ -129,7 +128,7 @@ int mbm_bw_change(size_t span, int cpu_no, char **benchmark_cmd)
129128
if (ret)
130129
goto out;
131130

132-
ret = check_results(span);
131+
ret = check_results(DEFAULT_SPAN);
133132

134133
out:
135134
mbm_test_cleanup();

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#define END_OF_TESTS 1
4040

41+
#define DEFAULT_SPAN (250 * MB)
42+
4143
#define PARENT_EXIT(err_msg) \
4244
do { \
4345
perror(err_msg); \
@@ -52,7 +54,6 @@
5254
* @ctrlgrp: Name of the control monitor group (con_mon grp)
5355
* @mongrp: Name of the monitor group (mon grp)
5456
* @cpu_no: CPU number to which the benchmark would be binded
55-
* @span: Memory bytes accessed in each benchmark iteration
5657
* @filename: Name of file to which the o/p should be written
5758
* @bw_report: Bandwidth report type (reads vs writes)
5859
* @setup: Call back function to setup test environment
@@ -62,7 +63,6 @@ struct resctrl_val_param {
6263
char ctrlgrp[64];
6364
char mongrp[64];
6465
int cpu_no;
65-
size_t span;
6666
char filename[64];
6767
char *bw_report;
6868
unsigned long mask;
@@ -98,7 +98,7 @@ int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
9898
int group_fd, unsigned long flags);
9999
int run_fill_buf(size_t span, int memflush, int op, bool once);
100100
int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
101-
int mbm_bw_change(size_t span, int cpu_no, char **benchmark_cmd);
101+
int mbm_bw_change(int cpu_no, char **benchmark_cmd);
102102
void tests_cleanup(void);
103103
void mbm_test_cleanup(void);
104104
int mba_schemata_change(int cpu_no, char **benchmark_cmd);
@@ -108,7 +108,7 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size);
108108
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
109109
int signal_handler_register(void);
110110
void signal_handler_unregister(void);
111-
int cat_val(struct resctrl_val_param *param);
111+
int cat_val(struct resctrl_val_param *param, size_t span);
112112
void cat_test_cleanup(void);
113113
int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
114114
int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd);

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void tests_cleanup(void)
7070
cat_test_cleanup();
7171
}
7272

73-
static void run_mbm_test(char **benchmark_cmd, size_t span, int cpu_no)
73+
static void run_mbm_test(char **benchmark_cmd, int cpu_no)
7474
{
7575
int res;
7676

@@ -87,7 +87,7 @@ static void run_mbm_test(char **benchmark_cmd, size_t span, int cpu_no)
8787
goto umount;
8888
}
8989

90-
res = mbm_bw_change(span, cpu_no, benchmark_cmd);
90+
res = mbm_bw_change(cpu_no, benchmark_cmd);
9191
ksft_test_result(!res, "MBM: bw change\n");
9292
if ((get_vendor() == ARCH_INTEL) && res)
9393
ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
@@ -177,7 +177,6 @@ int main(int argc, char **argv)
177177
int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0;
178178
char *benchmark_cmd[BENCHMARK_ARGS];
179179
int ben_ind, ben_count, tests = 0;
180-
size_t span = 250 * MB;
181180
bool cat_test = true;
182181

183182
for (i = 0; i < argc; i++) {
@@ -271,7 +270,7 @@ int main(int argc, char **argv)
271270
benchmark_cmd[i] = benchmark_cmd_area[i];
272271

273272
strcpy(benchmark_cmd[0], "fill_buf");
274-
sprintf(benchmark_cmd[1], "%zu", span);
273+
sprintf(benchmark_cmd[1], "%u", DEFAULT_SPAN);
275274
strcpy(benchmark_cmd[2], "1");
276275
strcpy(benchmark_cmd[3], "0");
277276
strcpy(benchmark_cmd[4], "false");
@@ -289,7 +288,7 @@ int main(int argc, char **argv)
289288
ksft_set_plan(tests ? : 4);
290289

291290
if (mbm_test)
292-
run_mbm_test(benchmark_cmd, span, cpu_no);
291+
run_mbm_test(benchmark_cmd, cpu_no);
293292

294293
if (mba_test)
295294
run_mba_test(benchmark_cmd, cpu_no);

0 commit comments

Comments
 (0)