Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-next-5.13-rc1' of git://git.kernel.org/pub…
Browse files Browse the repository at this point in the history
…/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
  ...
  • Loading branch information
Linus Torvalds committed Apr 28, 2021
2 parents 55e6be6 + e750747 commit 2a68c26
Show file tree
Hide file tree
Showing 16 changed files with 412 additions and 299 deletions.
4 changes: 2 additions & 2 deletions Documentation/dev-tools/kselftest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ using a shell script test runner. ``kselftest/module.sh`` is designed
to facilitate this process. There is also a header file provided to
assist writing kernel modules that are for use with kselftest:

- ``tools/testing/kselftest/kselftest_module.h``
- ``tools/testing/kselftest/kselftest/module.sh``
- ``tools/testing/selftests/kselftest_module.h``
- ``tools/testing/selftests/kselftest/module.sh``

How to use
----------
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ifdef building_out_of_srctree
rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
fi
@if [ "X$(TEST_PROGS)" != "X" ]; then \
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) ; \
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
$(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
else \
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \
fi
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/resctrl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: GPL-2.0-only
resctrl_tests
2 changes: 1 addition & 1 deletion tools/testing/selftests/resctrl/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = $(CROSS_COMPILE)gcc
CFLAGS = -g -Wall
CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
SRCS=$(wildcard *.c)
OBJS=$(SRCS:.c=.o)

Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/resctrl/README
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ ARGUMENTS
Parameter '-h' shows usage information.

usage: resctrl_tests [-h] [-b "benchmark_cmd [options]"] [-t test list] [-n no_of_bits]
-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CQM default benchmark is builtin fill_buf
-t test list: run tests specified in the test list, e.g. -t mbm, mba, cqm, cat
-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CMT default benchmark is builtin fill_buf
-t test list: run tests specified in the test list, e.g. -t mbm, mba, cmt, cat
-n no_of_bits: run cache tests using specified no of bits in cache bit mask
-p cpu_no: specify CPU number to run the test. 1 is default
-h: help
52 changes: 47 additions & 5 deletions tools/testing/selftests/resctrl/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static int get_llc_perf(unsigned long *llc_perf_miss)

/*
* Get LLC Occupancy as reported by RESCTRL FS
* For CQM,
* For CMT,
* 1. If con_mon grp and mon grp given, then read from mon grp in
* con_mon grp
* 2. If only con_mon grp given, then read from con_mon grp
Expand Down Expand Up @@ -182,7 +182,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
/*
* Measure cache miss from perf.
*/
if (!strcmp(param->resctrl_val, "cat")) {
if (!strncmp(param->resctrl_val, CAT_STR, sizeof(CAT_STR))) {
ret = get_llc_perf(&llc_perf_miss);
if (ret < 0)
return ret;
Expand All @@ -192,7 +192,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
/*
* Measure llc occupancy from resctrl.
*/
if (!strcmp(param->resctrl_val, "cqm")) {
if (!strncmp(param->resctrl_val, CMT_STR, sizeof(CMT_STR))) {
ret = get_llc_occu_resctrl(&llc_occu_resc);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -234,15 +234,15 @@ int cat_val(struct resctrl_val_param *param)
if (ret)
return ret;

if ((strcmp(resctrl_val, "cat") == 0)) {
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
ret = initialize_llc_perf();
if (ret)
return ret;
}

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

return ret;
}

/*
* show_cache_info: show cache test result information
* @sum_llc_val: sum of LLC cache result data
* @no_of_bits: number of bits
* @cache_span: cache span in bytes for CMT or in lines for CAT
* @max_diff: max difference
* @max_diff_percent: max difference percentage
* @num_of_runs: number of runs
* @platform: show test information on this platform
* @cmt: CMT test or CAT test
*
* Return: 0 on success. non-zero on failure.
*/
int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
unsigned long cache_span, unsigned long max_diff,
unsigned long max_diff_percent, unsigned long num_of_runs,
bool platform, bool cmt)
{
unsigned long avg_llc_val = 0;
float diff_percent;
long avg_diff = 0;
int ret;

avg_llc_val = sum_llc_val / (num_of_runs - 1);
avg_diff = (long)abs(cache_span - avg_llc_val);
diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100;

ret = platform && abs((int)diff_percent) > max_diff_percent &&
(cmt ? (abs(avg_diff) > max_diff) : true);

ksft_print_msg("%s Check cache miss rate within %d%%\n",
ret ? "Fail:" : "Pass:", max_diff_percent);

ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
ksft_print_msg("Number of bits: %d\n", no_of_bits);
ksft_print_msg("Average LLC val: %lu\n", avg_llc_val);
ksft_print_msg("Cache span (%s): %lu\n", cmt ? "bytes" : "lines",
cache_span);

return ret;
}
57 changes: 18 additions & 39 deletions tools/testing/selftests/resctrl/cat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#define MAX_DIFF_PERCENT 4
#define MAX_DIFF 1000000

int count_of_bits;
char cbm_mask[256];
unsigned long long_mask;
unsigned long cache_size;
static int count_of_bits;
static char cbm_mask[256];
static unsigned long long_mask;
static unsigned long cache_size;

/*
* Change schemata. Write schemata to specified
Expand Down Expand Up @@ -52,35 +52,14 @@ static int cat_setup(int num, ...)
return ret;
}

static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
unsigned long span)
{
unsigned long allocated_cache_lines = span / 64;
unsigned long avg_llc_perf_miss = 0;
float diff_percent;

avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1);
diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) /
allocated_cache_lines * 100;

printf("%sok CAT: cache miss rate within %d%%\n",
!is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT ?
"not " : "", MAX_DIFF_PERCENT);
tests_run++;
printf("# Percent diff=%d\n", abs((int)diff_percent));
printf("# Number of bits: %d\n", no_of_bits);
printf("# Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
printf("# Allocated cache lines: %lu\n", allocated_cache_lines);
}

static int check_results(struct resctrl_val_param *param)
{
char *token_array[8], temp[512];
unsigned long sum_llc_perf_miss = 0;
int runs = 0, no_of_bits = 0;
FILE *fp;

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

show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);

return 0;
return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64,
MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS,
!is_amd, false);
}

void cat_test_cleanup(void)
Expand All @@ -132,11 +111,8 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
if (ret)
return ret;

if (!validate_resctrl_feature_request("cat"))
return -1;

/* Get default cbm mask for L3/L2 cache */
ret = get_cbm_mask(cache_type);
ret = get_cbm_mask(cache_type, cbm_mask);
if (ret)
return ret;

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

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

if (n < 1 || n > count_of_bits - 1) {
printf("Invalid input value for no_of_bits n!\n");
printf("Please Enter value in range 1 to %d\n",
count_of_bits - 1);
if (!n)
n = count_of_bits / 2;

if (n > count_of_bits - 1) {
ksft_print_msg("Invalid input value for no_of_bits n!\n");
ksft_print_msg("Please enter value in range 1 to %d\n",
count_of_bits - 1);
return -1;
}

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

struct resctrl_val_param param = {
.resctrl_val = "cat",
.resctrl_val = CAT_STR,
.cpu_no = cpu_no,
.mum_resctrlfs = 0,
.setup = cat_setup,
Expand Down
Loading

0 comments on commit 2a68c26

Please sign in to comment.