selftests/resctrl: Share show_cache_info() by CAT and CMT tests
authorFenghua Yu <fenghua.yu@intel.com>
Wed, 17 Mar 2021 02:22:43 +0000 (02:22 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 2 Apr 2021 19:54:14 +0000 (13:54 -0600)
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>
tools/testing/selftests/resctrl/cache.c
tools/testing/selftests/resctrl/cat_test.c
tools/testing/selftests/resctrl/cmt_test.c
tools/testing/selftests/resctrl/resctrl.h

index 2aa1b5c7d9e1d74e7b0e1179adee3d5117ebb2f1..362e3a418caad491cec176d0d62cccd3337be06b 100644 (file)
@@ -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;
+}
index 1daf911076c7863725d4828392b1e36e0d4d055b..090d3afc7a78007abe4938f5d718fdfa8c5ee1c6 100644 (file)
@@ -52,30 +52,6 @@ static int cat_setup(int num, ...)
        return ret;
 }
 
-static int 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;
-       int ret;
-
-       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;
-
-       ret = !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT;
-       ksft_print_msg("Cache miss rate %swithin %d%%\n",
-                      ret ? "not " : "", 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("Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
-       ksft_print_msg("Allocated cache lines: %lu\n", allocated_cache_lines);
-
-       return ret;
-}
-
 static int check_results(struct resctrl_val_param *param)
 {
        char *token_array[8], temp[512];
@@ -111,7 +87,9 @@ static int check_results(struct resctrl_val_param *param)
        fclose(fp);
        no_of_bits = count_bits(param->mask);
 
-       return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);
+       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)
index b1ab1bd1f74daea9904356115fd591619111c3f1..8968e36db99d79cca16e99321e4f79e72bad4e24 100644 (file)
@@ -39,35 +39,6 @@ static int cmt_setup(int num, ...)
        return 0;
 }
 
-static int show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits,
-                          unsigned long span)
-{
-       unsigned long avg_llc_occu_resc = 0;
-       float diff_percent;
-       long avg_diff = 0;
-       int ret;
-
-       avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1);
-       avg_diff = (long)abs(span - avg_llc_occu_resc);
-
-       diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100;
-
-       ret = (abs((int)diff_percent) > MAX_DIFF_PERCENT) &&
-             (abs(avg_diff) > MAX_DIFF);
-
-       ksft_print_msg("%s cache miss diff within %d, %d\%%\n",
-                      ret ? "Fail:" : "Pass:", MAX_DIFF, (int)MAX_DIFF_PERCENT);
-
-       ksft_print_msg("Diff: %ld\n", avg_diff);
-       ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
-       ksft_print_msg("Results are displayed in (Bytes)\n");
-       ksft_print_msg("Number of bits: %d\n", no_of_bits);
-       ksft_print_msg("Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc);
-       ksft_print_msg("llc_occu_exp (span): %lu\n", span);
-
-       return ret;
-}
-
 static int check_results(struct resctrl_val_param *param, int no_of_bits)
 {
        char *token_array[8], temp[512];
@@ -99,7 +70,9 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits)
        }
        fclose(fp);
 
-       return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span);
+       return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span,
+                              MAX_DIFF, MAX_DIFF_PERCENT, NUM_OF_RUNS,
+                              true, true);
 }
 
 void cmt_test_cleanup(void)
index ebf88217f9deb2b6bbb41ff1cea3e424a776da97..81f322245ef7c8bd0c63016380f6d3f98a27fd97 100644 (file)
@@ -108,5 +108,9 @@ unsigned int count_bits(unsigned long n);
 void cmt_test_cleanup(void);
 int get_core_sibling(int cpu_no);
 int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
+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);
 
 #endif /* RESCTRL_H */