Skip to content

Commit 8b308f9

Browse files
committed
Merge tag 'linux_kselftest-next-7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: "Several fixes and improvements to resctrl tests and a change to kselftest document to clarify the use of FORCE_TARGETS build variable" * tag 'linux_kselftest-next-7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kselftest: fix doc for ksft_test_result_report() selftests/resctrl: Reduce L2 impact on CAT test selftests/resctrl: Simplify perf usage in CAT test selftests/resctrl: Remove requirement on cache miss rate selftests/resctrl: Raise threshold at which MBM and PMU values are compared selftests/resctrl: Increase size of buffer used in MBM and MBA tests selftests/resctrl: Support multiple events associated with iMC selftests/resctrl: Prepare for parsing multiple events per iMC selftests/resctrl: Do not store iMC counter value in counter config structure selftests/resctrl: Reduce interference from L2 occupancy during cache occupancy test selftests/resctrl: Improve accuracy of cache occupancy test docs: kselftest: Document the FORCE_TARGETS build variable
2 parents 42eb3a5 + 5f49742 commit 8b308f9

10 files changed

Lines changed: 193 additions & 101 deletions

File tree

Documentation/dev-tools/kselftest.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ dedicated skiplist::
126126
See the top-level tools/testing/selftests/Makefile for the list of all
127127
possible targets.
128128

129+
Requiring all targets to build successfully
130+
===========================================
131+
132+
By default, the build succeeds as long as at least one target builds
133+
without error. Set ``FORCE_TARGETS=1`` to instead require every target to
134+
build successfully; make will abort as soon as any target fails::
135+
136+
$ make -C tools/testing/selftests FORCE_TARGETS=1
137+
138+
This applies to both the ``all`` and ``install`` targets and is useful in
139+
CI environments where a silent partial build would be misleading.
140+
129141
Running the full range hotplug selftests
130142
========================================
131143

tools/testing/selftests/kselftest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ void ksft_test_result_code(int exit_code, const char *test_name,
346346
}
347347

348348
/**
349-
* ksft_test_result() - Report test success based on truth of condition
349+
* ksft_test_result_report() - Report test result based on a kselftest exit code
350350
*
351-
* @condition: if true, report test success, otherwise failure.
351+
* @result: a kselftest exit code
352352
*/
353353
#define ksft_test_result_report(result, fmt, ...) do { \
354354
switch (result) { \

tools/testing/selftests/resctrl/cache.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config)
1010
memset(pea, 0, sizeof(*pea));
1111
pea->type = PERF_TYPE_HARDWARE;
1212
pea->size = sizeof(*pea);
13-
pea->read_format = PERF_FORMAT_GROUP;
1413
pea->exclude_kernel = 1;
1514
pea->exclude_hv = 1;
1615
pea->exclude_idle = 1;
@@ -37,19 +36,13 @@ int perf_event_reset_enable(int pe_fd)
3736
return 0;
3837
}
3938

40-
void perf_event_initialize_read_format(struct perf_event_read *pe_read)
41-
{
42-
memset(pe_read, 0, sizeof(*pe_read));
43-
pe_read->nr = 1;
44-
}
45-
4639
int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no)
4740
{
4841
int pe_fd;
4942

5043
pe_fd = perf_event_open(pea, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
5144
if (pe_fd == -1) {
52-
ksft_perror("Error opening leader");
45+
ksft_perror("Unable to set up performance monitoring");
5346
return -1;
5447
}
5548

@@ -132,23 +125,23 @@ static int print_results_cache(const char *filename, pid_t bm_pid, __u64 llc_val
132125
*
133126
* Return: =0 on success. <0 on failure.
134127
*/
135-
int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
136-
const char *filename, pid_t bm_pid)
128+
int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid)
137129
{
130+
__u64 value;
138131
int ret;
139132

140133
/* Stop counters after one span to get miss rate */
141134
ret = ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);
142135
if (ret < 0)
143136
return ret;
144137

145-
ret = read(pe_fd, pe_read, sizeof(*pe_read));
138+
ret = read(pe_fd, &value, sizeof(value));
146139
if (ret == -1) {
147140
ksft_perror("Could not get perf value");
148141
return -1;
149142
}
150143

151-
return print_results_cache(filename, bm_pid, pe_read->values[0].value);
144+
return print_results_cache(filename, bm_pid, value);
152145
}
153146

154147
/*
@@ -173,6 +166,19 @@ int measure_llc_resctrl(const char *filename, pid_t bm_pid)
173166
return print_results_cache(filename, bm_pid, llc_occu_resc);
174167
}
175168

169+
/*
170+
* Reduce L2 allocation to minimum when testing L3 cache allocation.
171+
*/
172+
int minimize_l2_occupancy(const struct resctrl_test *test,
173+
const struct user_params *uparams,
174+
const struct resctrl_val_param *param)
175+
{
176+
if (!strcmp(test->resource, "L3") && resctrl_resource_exists("L2"))
177+
return write_schemata(param->ctrlgrp, "0x1", uparams->cpu, "L2");
178+
179+
return 0;
180+
}
181+
176182
/*
177183
* show_cache_info - Show generic cache test information
178184
* @no_of_bits: Number of bits

tools/testing/selftests/resctrl/cat_test.c

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,20 @@
1414
#define RESULT_FILE_NAME "result_cat"
1515
#define NUM_OF_RUNS 5
1616

17-
/*
18-
* Minimum difference in LLC misses between a test with n+1 bits CBM to the
19-
* test with n bits is MIN_DIFF_PERCENT_PER_BIT * (n - 1). With e.g. 5 vs 4
20-
* bits in the CBM mask, the minimum difference must be at least
21-
* MIN_DIFF_PERCENT_PER_BIT * (4 - 1) = 3 percent.
22-
*
23-
* The relationship between number of used CBM bits and difference in LLC
24-
* misses is not expected to be linear. With a small number of bits, the
25-
* margin is smaller than with larger number of bits. For selftest purposes,
26-
* however, linear approach is enough because ultimately only pass/fail
27-
* decision has to be made and distinction between strong and stronger
28-
* signal is irrelevant.
29-
*/
30-
#define MIN_DIFF_PERCENT_PER_BIT 1UL
31-
3217
static int show_results_info(__u64 sum_llc_val, int no_of_bits,
3318
unsigned long cache_span,
34-
unsigned long min_diff_percent,
3519
unsigned long num_of_runs, bool platform,
3620
__s64 *prev_avg_llc_val)
3721
{
3822
__u64 avg_llc_val = 0;
39-
float avg_diff;
4023
int ret = 0;
4124

4225
avg_llc_val = sum_llc_val / num_of_runs;
4326
if (*prev_avg_llc_val) {
44-
float delta = (__s64)(avg_llc_val - *prev_avg_llc_val);
45-
46-
avg_diff = delta / *prev_avg_llc_val;
47-
ret = platform && (avg_diff * 100) < (float)min_diff_percent;
27+
ret = platform && (avg_llc_val < *prev_avg_llc_val);
4828

49-
ksft_print_msg("%s Check cache miss rate changed more than %.1f%%\n",
50-
ret ? "Fail:" : "Pass:", (float)min_diff_percent);
51-
52-
ksft_print_msg("Percent diff=%.1f\n", avg_diff * 100);
29+
ksft_print_msg("%s Check cache miss rate increased\n",
30+
ret ? "Fail:" : "Pass:");
5331
}
5432
*prev_avg_llc_val = avg_llc_val;
5533

@@ -58,10 +36,10 @@ static int show_results_info(__u64 sum_llc_val, int no_of_bits,
5836
return ret;
5937
}
6038

61-
/* Remove the highest bit from CBM */
39+
/* Remove the highest bits from CBM */
6240
static unsigned long next_mask(unsigned long current_mask)
6341
{
64-
return current_mask & (current_mask >> 1);
42+
return current_mask & (current_mask >> 2);
6543
}
6644

6745
static int check_results(struct resctrl_val_param *param, const char *cache_type,
@@ -112,7 +90,6 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type
11290

11391
ret = show_results_info(sum_llc_perf_miss, bits,
11492
alloc_size / 64,
115-
MIN_DIFF_PERCENT_PER_BIT * (bits - 1),
11693
runs, get_vendor() == ARCH_INTEL,
11794
&prev_avg_llc_val);
11895
if (ret)
@@ -158,7 +135,6 @@ static int cat_test(const struct resctrl_test *test,
158135
struct resctrl_val_param *param,
159136
size_t span, unsigned long current_mask)
160137
{
161-
struct perf_event_read pe_read;
162138
struct perf_event_attr pea;
163139
cpu_set_t old_affinity;
164140
unsigned char *buf;
@@ -181,8 +157,11 @@ static int cat_test(const struct resctrl_test *test,
181157
if (ret)
182158
goto reset_affinity;
183159

160+
ret = minimize_l2_occupancy(test, uparams, param);
161+
if (ret)
162+
goto reset_affinity;
163+
184164
perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES);
185-
perf_event_initialize_read_format(&pe_read);
186165
pe_fd = perf_open(&pea, bm_pid, uparams->cpu);
187166
if (pe_fd < 0) {
188167
ret = -1;
@@ -215,7 +194,7 @@ static int cat_test(const struct resctrl_test *test,
215194

216195
fill_cache_read(buf, span, true);
217196

218-
ret = perf_event_measure(pe_fd, &pe_read, param->filename, bm_pid);
197+
ret = perf_event_measure(pe_fd, param->filename, bm_pid);
219198
if (ret)
220199
goto free_buf;
221200
}

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,40 @@
1919
#define CON_MON_LCC_OCCUP_PATH \
2020
"%s/%s/mon_data/mon_L3_%02d/llc_occupancy"
2121

22-
static int cmt_init(const struct resctrl_val_param *param, int domain_id)
22+
/*
23+
* Initialize capacity bitmasks (CBMs) of:
24+
* - control group being tested per test parameters,
25+
* - default resource group as inverse of control group being tested to prevent
26+
* other tasks from interfering with test,
27+
* - L2 resource of control group being tested to minimize allocations into
28+
* L2 if possible to better predict L3 occupancy.
29+
*/
30+
static int cmt_init(const struct resctrl_test *test,
31+
const struct user_params *uparams,
32+
const struct resctrl_val_param *param, int domain_id)
2333
{
34+
unsigned long full_mask;
35+
char schemata[64];
36+
int ret;
37+
2438
sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH,
2539
param->ctrlgrp, domain_id);
2640

27-
return 0;
41+
ret = get_full_cbm(test->resource, &full_mask);
42+
if (ret)
43+
return ret;
44+
45+
snprintf(schemata, sizeof(schemata), "%lx", ~param->mask & full_mask);
46+
ret = write_schemata("", schemata, uparams->cpu, test->resource);
47+
if (ret)
48+
return ret;
49+
50+
snprintf(schemata, sizeof(schemata), "%lx", param->mask);
51+
ret = write_schemata(param->ctrlgrp, schemata, uparams->cpu, test->resource);
52+
if (ret)
53+
return ret;
54+
55+
return minimize_l2_occupancy(test, uparams, param);
2856
}
2957

3058
static int cmt_setup(const struct resctrl_test *test,
@@ -153,11 +181,11 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
153181
span = cache_portion_size(cache_total_size, param.mask, long_mask);
154182

155183
if (uparams->fill_buf) {
156-
fill_buf.buf_size = span;
184+
fill_buf.buf_size = span * 2;
157185
fill_buf.memflush = uparams->fill_buf->memflush;
158186
param.fill_buf = &fill_buf;
159187
} else if (!uparams->benchmark_cmd[0]) {
160-
fill_buf.buf_size = span;
188+
fill_buf.buf_size = span * 2;
161189
fill_buf.memflush = true;
162190
param.fill_buf = &fill_buf;
163191
}

tools/testing/selftests/resctrl/fill_buf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ ssize_t get_fill_buf_size(int cpu_no, const char *cache_type)
139139
if (ret)
140140
return ret;
141141

142-
return cache_total_size * 2 > MINIMUM_SPAN ?
143-
cache_total_size * 2 : MINIMUM_SPAN;
142+
return cache_total_size * 4 > MINIMUM_SPAN ?
143+
cache_total_size * 4 : MINIMUM_SPAN;
144144
}

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
#define RESULT_FILE_NAME "result_mba"
1414
#define NUM_OF_RUNS 5
15-
#define MAX_DIFF_PERCENT 8
15+
#define MAX_DIFF_PERCENT 15
1616
#define ALLOCATION_MAX 100
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)
20+
static int mba_init(const struct resctrl_test *test,
21+
const struct user_params *uparams,
22+
const struct resctrl_val_param *param, int domain_id)
2123
{
2224
int ret;
2325

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "resctrl.h"
1212

1313
#define RESULT_FILE_NAME "result_mbm"
14-
#define MAX_DIFF_PERCENT 8
14+
#define MAX_DIFF_PERCENT 15
1515
#define NUM_OF_RUNS 5
1616

1717
static int
@@ -83,7 +83,9 @@ static int check_results(size_t span)
8383
return ret;
8484
}
8585

86-
static int mbm_init(const struct resctrl_val_param *param, int domain_id)
86+
static int mbm_init(const struct resctrl_test *test,
87+
const struct user_params *uparams,
88+
const struct resctrl_val_param *param, int domain_id)
8789
{
8890
int ret;
8991

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* and MBM respectively, for instance generating "overhead" traffic which
5656
* is not counted against any specific RMID.
5757
*/
58-
#define THROTTLE_THRESHOLD 750
58+
#define THROTTLE_THRESHOLD 2500
5959

6060
/*
6161
* fill_buf_param: "fill_buf" benchmark parameters
@@ -135,7 +135,9 @@ struct resctrl_val_param {
135135
char filename[64];
136136
unsigned long mask;
137137
int num_of_runs;
138-
int (*init)(const struct resctrl_val_param *param,
138+
int (*init)(const struct resctrl_test *test,
139+
const struct user_params *uparams,
140+
const struct resctrl_val_param *param,
139141
int domain_id);
140142
int (*setup)(const struct resctrl_test *test,
141143
const struct user_params *uparams,
@@ -146,13 +148,6 @@ struct resctrl_val_param {
146148
struct fill_buf_param *fill_buf;
147149
};
148150

149-
struct perf_event_read {
150-
__u64 nr; /* The number of events */
151-
struct {
152-
__u64 value; /* The value of the event */
153-
} values[2];
154-
};
155-
156151
/*
157152
* Memory location that consumes values compiler must not optimize away.
158153
* Volatile ensures writes to this location cannot be optimized away by
@@ -208,12 +203,13 @@ unsigned int count_bits(unsigned long n);
208203
int snc_kernel_support(void);
209204

210205
void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
211-
void perf_event_initialize_read_format(struct perf_event_read *pe_read);
212206
int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no);
213207
int perf_event_reset_enable(int pe_fd);
214-
int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
215-
const char *filename, pid_t bm_pid);
208+
int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid);
216209
int measure_llc_resctrl(const char *filename, pid_t bm_pid);
210+
int minimize_l2_occupancy(const struct resctrl_test *test,
211+
const struct user_params *uparams,
212+
const struct resctrl_val_param *param);
217213
void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines);
218214

219215
/*

0 commit comments

Comments
 (0)