linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fenghua Yu <fenghua.yu@intel.com>
To: "Shuah Khan" <shuah@kernel.org>,
	"Tony Luck" <tony.luck@intel.com>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Babu Moger" <babu.moger@amd.com>
Cc: "linux-kselftest" <linux-kselftest@vger.kernel.org>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	Fenghua Yu <fenghua.yu@intel.com>
Subject: [PATCH v5 09/21] selftests/resctrl: Share show_cache_info() by CAT and CMT tests
Date: Sun,  7 Mar 2021 14:54:50 +0000	[thread overview]
Message-ID: <20210307145502.2916364-10-fenghua.yu@intel.com> (raw)
In-Reply-To: <20210307145502.2916364-1-fenghua.yu@intel.com>

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 <shuah@kernel.org>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
Change Log:
v5:
- Add this patch (Shuah)

 tools/testing/selftests/resctrl/cache.c    | 42 ++++++++++++++++++++++
 tools/testing/selftests/resctrl/cat_test.c | 28 ++-------------
 tools/testing/selftests/resctrl/cmt_test.c | 33 ++---------------
 tools/testing/selftests/resctrl/resctrl.h  |  4 +++
 4 files changed, 52 insertions(+), 55 deletions(-)

diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 2aa1b5c7d9e1..eaf5116b112c 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("%scache miss rate within %d%%\n",
+		       ret ? "fail: " : "", 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;
+}
diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index 0deb38ed971b..109363e9a7d7 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -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)
diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c
index e5af19335115..4adb92cb6ca1 100644
--- a/tools/testing/selftests/resctrl/cmt_test.c
+++ b/tools/testing/selftests/resctrl/cmt_test.c
@@ -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("%scache miss diff within %d, %d\%%\n",
-		       ret ? "fail: " : "not", 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)
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index ebf88217f9de..81f322245ef7 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -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 */
-- 
2.30.1


  parent reply	other threads:[~2021-03-07 14:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-07 14:54 [PATCH v5 00/21] Miscellaneous fixes for resctrl selftests Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 01/21] selftests/resctrl: Enable gcc checks to detect buffer overflows Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 02/21] selftests/resctrl: Fix compilation issues for global variables Fenghua Yu
2021-03-12 19:08   ` Babu Moger
2021-03-12 21:51     ` Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 03/21] selftests/resctrl: Fix compilation issues for other " Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 04/21] selftests/resctrl: Clean up resctrl features check Fenghua Yu
2021-03-12 19:09   ` Babu Moger
2021-03-12 22:01     ` Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 05/21] selftests/resctrl: Ensure sibling CPU is not same as original CPU Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 06/21] selftests/resctrl: Fix missing options "-n" and "-p" Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 07/21] selftests/resctrl: Rename CQM test as CMT test Fenghua Yu
2021-03-12 19:10   ` Babu Moger
2021-03-07 14:54 ` [PATCH v5 08/21] selftests/resctrl: Call kselftest APIs to log test results Fenghua Yu
2021-03-12 19:12   ` Babu Moger
2021-03-12 22:09     ` Fenghua Yu
2021-03-07 14:54 ` Fenghua Yu [this message]
2021-03-07 14:54 ` [PATCH v5 10/21] selftests/resctrl: Fix a printed message Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 11/21] selftests/resctrl: Add config dependencies Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 12/21] selftests/resctrl: Check for resctrl mount point only if resctrl FS is supported Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 13/21] selftests/resctrl: Use resctrl/info for feature detection Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 14/21] selftests/resctrl: Fix MBA/MBM results reporting format Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 15/21] selftests/resctrl: Don't hard code value of "no_of_bits" variable Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 16/21] selftests/resctrl: Modularize resctrl test suite main() function Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 17/21] selftests/resctrl: Skip the test if requested resctrl feature is not supported Fenghua Yu
2021-03-07 14:54 ` [PATCH v5 18/21] selftests/resctrl: Fix unmount resctrl FS Fenghua Yu
2021-03-07 14:55 ` [PATCH v5 19/21] selftests/resctrl: Fix incorrect parsing of iMC counters Fenghua Yu
2021-03-07 14:55 ` [PATCH v5 20/21] selftests/resctrl: Fix checking for < 0 for unsigned values Fenghua Yu
2021-03-07 14:55 ` [PATCH v5 21/21] selftests/resctrl: Create .gitignore to include resctrl_tests Fenghua Yu
2021-03-12 19:08 ` [PATCH v5 00/21] Miscellaneous fixes for resctrl selftests Babu Moger
2021-03-12 22:11   ` Fenghua Yu
2021-04-02 18:10     ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210307145502.2916364-10-fenghua.yu@intel.com \
    --to=fenghua.yu@intel.com \
    --cc=babu.moger@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).