Skip to content

Commit 2a68c26

Browse files
committed
Merge tag 'linux-kselftest-next-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest updates from Shuah Khan: - fixes and updates to resctrl test from Fenghua Yu and Reinette Chatre - fixes to Kselftest documentation, framework - minor spelling correction in timers test * tag 'linux-kselftest-next-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (25 commits) selftests/resctrl: Change a few printed messages Documentation: kselftest: fix path to test module files selftests/resctrl: Create .gitignore to include resctrl_tests selftests/resctrl: Fix checking for < 0 for unsigned values selftests/resctrl: Fix incorrect parsing of iMC counters selftests/resctrl: Fix unmount resctrl FS selftests/resctrl: Skip the test if requested resctrl feature is not supported selftests/resctrl: Modularize resctrl test suite main() function selftests/resctrl: Don't hard code value of "no_of_bits" variable selftests/resctrl: Fix MBA/MBM results reporting format selftests/resctrl: Use resctrl/info for feature detection selftests/resctrl: Check for resctrl mount point only if resctrl FS is supported selftests/resctrl: Add config dependencies selftests/resctrl: Fix a printed message selftests/resctrl: Share show_cache_info() by CAT and CMT tests selftests/resctrl: Call kselftest APIs to log test results selftests/resctrl: Rename CQM test as CMT test selftests/resctrl: Fix missing options "-n" and "-p" selftests/resctrl: Ensure sibling CPU is not same as original CPU selftests/resctrl: Clean up resctrl features check ...
2 parents 55e6be6 + e750747 commit 2a68c26

File tree

16 files changed

+412
-299
lines changed

16 files changed

+412
-299
lines changed

Documentation/dev-tools/kselftest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ using a shell script test runner. ``kselftest/module.sh`` is designed
239239
to facilitate this process. There is also a header file provided to
240240
assist writing kernel modules that are for use with kselftest:
241241

242-
- ``tools/testing/kselftest/kselftest_module.h``
243-
- ``tools/testing/kselftest/kselftest/module.sh``
242+
- ``tools/testing/selftests/kselftest_module.h``
243+
- ``tools/testing/selftests/kselftest/module.sh``
244244

245245
How to use
246246
----------

tools/testing/selftests/lib.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ ifdef building_out_of_srctree
7474
rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
7575
fi
7676
@if [ "X$(TEST_PROGS)" != "X" ]; then \
77-
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) ; \
77+
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
78+
$(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
7879
else \
7980
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \
8081
fi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
resctrl_tests

tools/testing/selftests/resctrl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CC = $(CROSS_COMPILE)gcc
2-
CFLAGS = -g -Wall
2+
CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
33
SRCS=$(wildcard *.c)
44
OBJS=$(SRCS:.c=.o)
55

tools/testing/selftests/resctrl/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ ARGUMENTS
4646
Parameter '-h' shows usage information.
4747

4848
usage: resctrl_tests [-h] [-b "benchmark_cmd [options]"] [-t test list] [-n no_of_bits]
49-
-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM default benchmark is builtin fill_buf
50-
-t test list: run tests specified in the test list, e.g. -t mbm, mba, cqm, cat
49+
-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CMT default benchmark is builtin fill_buf
50+
-t test list: run tests specified in the test list, e.g. -t mbm, mba, cmt, cat
5151
-n no_of_bits: run cache tests using specified no of bits in cache bit mask
5252
-p cpu_no: specify CPU number to run the test. 1 is default
5353
-h: help

tools/testing/selftests/resctrl/cache.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int get_llc_perf(unsigned long *llc_perf_miss)
111111

112112
/*
113113
* Get LLC Occupancy as reported by RESCTRL FS
114-
* For CQM,
114+
* For CMT,
115115
* 1. If con_mon grp and mon grp given, then read from mon grp in
116116
* con_mon grp
117117
* 2. If only con_mon grp given, then read from con_mon grp
@@ -182,7 +182,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
182182
/*
183183
* Measure cache miss from perf.
184184
*/
185-
if (!strcmp(param->resctrl_val, "cat")) {
185+
if (!strncmp(param->resctrl_val, CAT_STR, sizeof(CAT_STR))) {
186186
ret = get_llc_perf(&llc_perf_miss);
187187
if (ret < 0)
188188
return ret;
@@ -192,7 +192,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
192192
/*
193193
* Measure llc occupancy from resctrl.
194194
*/
195-
if (!strcmp(param->resctrl_val, "cqm")) {
195+
if (!strncmp(param->resctrl_val, CMT_STR, sizeof(CMT_STR))) {
196196
ret = get_llc_occu_resctrl(&llc_occu_resc);
197197
if (ret < 0)
198198
return ret;
@@ -234,15 +234,15 @@ int cat_val(struct resctrl_val_param *param)
234234
if (ret)
235235
return ret;
236236

237-
if ((strcmp(resctrl_val, "cat") == 0)) {
237+
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
238238
ret = initialize_llc_perf();
239239
if (ret)
240240
return ret;
241241
}
242242

243243
/* Test runs until the callback setup() tells the test to stop. */
244244
while (1) {
245-
if (strcmp(resctrl_val, "cat") == 0) {
245+
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
246246
ret = param->setup(1, param);
247247
if (ret) {
248248
ret = 0;
@@ -270,3 +270,45 @@ int cat_val(struct resctrl_val_param *param)
270270

271271
return ret;
272272
}
273+
274+
/*
275+
* show_cache_info: show cache test result information
276+
* @sum_llc_val: sum of LLC cache result data
277+
* @no_of_bits: number of bits
278+
* @cache_span: cache span in bytes for CMT or in lines for CAT
279+
* @max_diff: max difference
280+
* @max_diff_percent: max difference percentage
281+
* @num_of_runs: number of runs
282+
* @platform: show test information on this platform
283+
* @cmt: CMT test or CAT test
284+
*
285+
* Return: 0 on success. non-zero on failure.
286+
*/
287+
int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
288+
unsigned long cache_span, unsigned long max_diff,
289+
unsigned long max_diff_percent, unsigned long num_of_runs,
290+
bool platform, bool cmt)
291+
{
292+
unsigned long avg_llc_val = 0;
293+
float diff_percent;
294+
long avg_diff = 0;
295+
int ret;
296+
297+
avg_llc_val = sum_llc_val / (num_of_runs - 1);
298+
avg_diff = (long)abs(cache_span - avg_llc_val);
299+
diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100;
300+
301+
ret = platform && abs((int)diff_percent) > max_diff_percent &&
302+
(cmt ? (abs(avg_diff) > max_diff) : true);
303+
304+
ksft_print_msg("%s Check cache miss rate within %d%%\n",
305+
ret ? "Fail:" : "Pass:", max_diff_percent);
306+
307+
ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
308+
ksft_print_msg("Number of bits: %d\n", no_of_bits);
309+
ksft_print_msg("Average LLC val: %lu\n", avg_llc_val);
310+
ksft_print_msg("Cache span (%s): %lu\n", cmt ? "bytes" : "lines",
311+
cache_span);
312+
313+
return ret;
314+
}

tools/testing/selftests/resctrl/cat_test.c

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#define MAX_DIFF_PERCENT 4
1818
#define MAX_DIFF 1000000
1919

20-
int count_of_bits;
21-
char cbm_mask[256];
22-
unsigned long long_mask;
23-
unsigned long cache_size;
20+
static int count_of_bits;
21+
static char cbm_mask[256];
22+
static unsigned long long_mask;
23+
static unsigned long cache_size;
2424

2525
/*
2626
* Change schemata. Write schemata to specified
@@ -52,35 +52,14 @@ static int cat_setup(int num, ...)
5252
return ret;
5353
}
5454

55-
static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
56-
unsigned long span)
57-
{
58-
unsigned long allocated_cache_lines = span / 64;
59-
unsigned long avg_llc_perf_miss = 0;
60-
float diff_percent;
61-
62-
avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1);
63-
diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) /
64-
allocated_cache_lines * 100;
65-
66-
printf("%sok CAT: cache miss rate within %d%%\n",
67-
!is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT ?
68-
"not " : "", MAX_DIFF_PERCENT);
69-
tests_run++;
70-
printf("# Percent diff=%d\n", abs((int)diff_percent));
71-
printf("# Number of bits: %d\n", no_of_bits);
72-
printf("# Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
73-
printf("# Allocated cache lines: %lu\n", allocated_cache_lines);
74-
}
75-
7655
static int check_results(struct resctrl_val_param *param)
7756
{
7857
char *token_array[8], temp[512];
7958
unsigned long sum_llc_perf_miss = 0;
8059
int runs = 0, no_of_bits = 0;
8160
FILE *fp;
8261

83-
printf("# Checking for pass/fail\n");
62+
ksft_print_msg("Checking for pass/fail\n");
8463
fp = fopen(param->filename, "r");
8564
if (!fp) {
8665
perror("# Cannot open file");
@@ -108,9 +87,9 @@ static int check_results(struct resctrl_val_param *param)
10887
fclose(fp);
10988
no_of_bits = count_bits(param->mask);
11089

111-
show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);
112-
113-
return 0;
90+
return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64,
91+
MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS,
92+
!is_amd, false);
11493
}
11594

11695
void cat_test_cleanup(void)
@@ -132,11 +111,8 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
132111
if (ret)
133112
return ret;
134113

135-
if (!validate_resctrl_feature_request("cat"))
136-
return -1;
137-
138114
/* Get default cbm mask for L3/L2 cache */
139-
ret = get_cbm_mask(cache_type);
115+
ret = get_cbm_mask(cache_type, cbm_mask);
140116
if (ret)
141117
return ret;
142118

@@ -146,15 +122,18 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
146122
ret = get_cache_size(cpu_no, cache_type, &cache_size);
147123
if (ret)
148124
return ret;
149-
printf("cache size :%lu\n", cache_size);
125+
ksft_print_msg("Cache size :%lu\n", cache_size);
150126

151127
/* Get max number of bits from default-cabm mask */
152128
count_of_bits = count_bits(long_mask);
153129

154-
if (n < 1 || n > count_of_bits - 1) {
155-
printf("Invalid input value for no_of_bits n!\n");
156-
printf("Please Enter value in range 1 to %d\n",
157-
count_of_bits - 1);
130+
if (!n)
131+
n = count_of_bits / 2;
132+
133+
if (n > count_of_bits - 1) {
134+
ksft_print_msg("Invalid input value for no_of_bits n!\n");
135+
ksft_print_msg("Please enter value in range 1 to %d\n",
136+
count_of_bits - 1);
158137
return -1;
159138
}
160139

@@ -164,7 +143,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
164143
return -1;
165144

166145
struct resctrl_val_param param = {
167-
.resctrl_val = "cat",
146+
.resctrl_val = CAT_STR,
168147
.cpu_no = cpu_no,
169148
.mum_resctrlfs = 0,
170149
.setup = cat_setup,

0 commit comments

Comments
 (0)