summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/resctrl/cache.c
diff options
context:
space:
mode:
authorFenghua Yu <fenghua.yu@intel.com>2021-03-17 05:22:43 +0300
committerShuah Khan <skhan@linuxfoundation.org>2021-04-02 22:54:14 +0300
commit03216ed7bb4de8ce707eb4de23a08516a542770f (patch)
treeba3c7b98f16e13c26b41181422b27820e07d34a3 /tools/testing/selftests/resctrl/cache.c
parentca2f4214f9671dfc08b6c5723188e03574203dc5 (diff)
downloadlinux-03216ed7bb4de8ce707eb4de23a08516a542770f.tar.xz
selftests/resctrl: Share show_cache_info() by CAT and CMT tests
show_cache_info() functions are defined separately in CAT and CMT tests. But the functions are same for the tests and unnecessary to be defined separately. Share the function by the tests. Suggested-by: Shuah Khan <skhan@linuxfoundation.org> Tested-by: Babu Moger <babu.moger@amd.com> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/resctrl/cache.c')
-rw-r--r--tools/testing/selftests/resctrl/cache.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 2aa1b5c7d9e1..362e3a418caa 100644
--- a/tools/testing/selftests/resctrl/cache.c
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -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 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;
+}