public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-kselftest@vger.kernel.org,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Babu Moger" <babu.moger@amd.com>,
	"Maciej Wieczór-Retman" <maciej.wieczor-retman@intel.com>
Cc: linux-kernel@vger.kernel.org, "Fenghua Yu" <fenghua.yu@intel.com>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH v4 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param
Date: Mon, 20 May 2024 15:30:13 +0300	[thread overview]
Message-ID: <20240520123020.18938-10-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20240520123020.18938-1-ilpo.jarvinen@linux.intel.com>

The measurement done in resctrl_val() varies depending on test type.
The decision for how to measure is decided based on the string compare
to test name which is quite inflexible.

Add ->measure() callback into the struct resctrl_val_param to allow
each test to provide necessary code as a function which simplifies what
resctrl_val() has to do.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---

v2:
- spaces -> tabs
---
 tools/testing/selftests/resctrl/cmt_test.c    |  8 ++++++++
 tools/testing/selftests/resctrl/mba_test.c    |  9 ++++++++-
 tools/testing/selftests/resctrl/mbm_test.c    |  9 ++++++++-
 tools/testing/selftests/resctrl/resctrl.h     |  6 ++++++
 tools/testing/selftests/resctrl/resctrl_val.c | 18 +++++-------------
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c
index a44e6fcd37b7..d8521386cd18 100644
--- a/tools/testing/selftests/resctrl/cmt_test.c
+++ b/tools/testing/selftests/resctrl/cmt_test.c
@@ -29,6 +29,13 @@ static int cmt_setup(const struct resctrl_test *test,
 	return 0;
 }
 
+static int cmt_measure(const struct user_params *uparams,
+		       struct resctrl_val_param *param, pid_t bm_pid)
+{
+	sleep(1);
+	return measure_llc_resctrl(param->filename, bm_pid);
+}
+
 static int show_results_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,
@@ -133,6 +140,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
 		.mask		= ~(long_mask << n) & long_mask,
 		.num_of_runs	= 0,
 		.setup		= cmt_setup,
+		.measure	= cmt_measure,
 	};
 
 	span = cache_portion_size(cache_total_size, param.mask, long_mask);
diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c
index 5d6af9e8afed..de6e29faf214 100644
--- a/tools/testing/selftests/resctrl/mba_test.c
+++ b/tools/testing/selftests/resctrl/mba_test.c
@@ -51,6 +51,12 @@ static int mba_setup(const struct resctrl_test *test,
 	return 0;
 }
 
+static int mba_measure(const struct user_params *uparams,
+		       struct resctrl_val_param *param, pid_t bm_pid)
+{
+	return measure_mem_bw(uparams, param, bm_pid);
+}
+
 static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
 {
 	int allocation, runs;
@@ -150,7 +156,8 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
 		.mongrp		= "m1",
 		.filename	= RESULT_FILE_NAME,
 		.bw_report	= "reads",
-		.setup		= mba_setup
+		.setup		= mba_setup,
+		.measure	= mba_measure,
 	};
 	int ret;
 
diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c
index 96d279b06377..59e26adf60bb 100644
--- a/tools/testing/selftests/resctrl/mbm_test.c
+++ b/tools/testing/selftests/resctrl/mbm_test.c
@@ -105,6 +105,12 @@ static int mbm_setup(const struct resctrl_test *test,
 	return ret;
 }
 
+static int mbm_measure(const struct user_params *uparams,
+		       struct resctrl_val_param *param, pid_t bm_pid)
+{
+	return measure_mem_bw(uparams, param, bm_pid);
+}
+
 static void mbm_test_cleanup(void)
 {
 	remove(RESULT_FILE_NAME);
@@ -117,7 +123,8 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
 		.ctrlgrp	= "c1",
 		.filename	= RESULT_FILE_NAME,
 		.bw_report	= "reads",
-		.setup		= mbm_setup
+		.setup		= mbm_setup,
+		.measure	= mbm_measure,
 	};
 	int ret;
 
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index e4b6dc672ecc..5dc3def70669 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -87,6 +87,7 @@ struct resctrl_test {
  * @filename:		Name of file to which the o/p should be written
  * @bw_report:		Bandwidth report type (reads vs writes)
  * @setup:		Call back function to setup test environment
+ * @measure:		Callback that performs the measurement (a single test)
  */
 struct resctrl_val_param {
 	char		*resctrl_val;
@@ -99,6 +100,9 @@ struct resctrl_val_param {
 	int		(*setup)(const struct resctrl_test *test,
 				 const struct user_params *uparams,
 				 struct resctrl_val_param *param);
+	int		(*measure)(const struct user_params *uparams,
+				   struct resctrl_val_param *param,
+				   pid_t bm_pid);
 };
 
 struct perf_event_read {
@@ -145,6 +149,8 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush);
 void mem_flush(unsigned char *buf, size_t buf_size);
 void fill_cache_read(unsigned char *buf, size_t buf_size, bool once);
 int run_fill_buf(size_t buf_size, int memflush, int op, bool once);
+int measure_mem_bw(const struct user_params *uparams,
+		   struct resctrl_val_param *param, pid_t bm_pid);
 int resctrl_val(const struct resctrl_test *test,
 		const struct user_params *uparams,
 		const char * const *benchmark_cmd,
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
index a3cf3c5ed17f..76ae89e1aea3 100644
--- a/tools/testing/selftests/resctrl/resctrl_val.c
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -607,8 +607,8 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,
  * @param:		parameters passed to resctrl_val()
  * @bm_pid:		PID that runs the benchmark
  */
-static int measure_mem_bw(const struct user_params *uparams,
-			  struct resctrl_val_param *param, pid_t bm_pid)
+int measure_mem_bw(const struct user_params *uparams,
+		   struct resctrl_val_param *param, pid_t bm_pid)
 {
 	unsigned long bw_resc, bw_resc_start, bw_resc_end;
 	FILE *mem_bw_fp, *mem_bw_fp2;
@@ -879,17 +879,9 @@ int resctrl_val(const struct resctrl_test *test,
 		if (ret < 0)
 			break;
 
-		if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
-		    !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
-			ret = measure_mem_bw(uparams, param, bm_pid);
-			if (ret)
-				break;
-		} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) {
-			sleep(1);
-			ret = measure_llc_resctrl(param->filename, bm_pid);
-			if (ret)
-				break;
-		}
+		ret = param->measure(uparams, param, bm_pid);
+		if (ret)
+			break;
 	}
 
 out:
-- 
2.39.2


  parent reply	other threads:[~2024-05-20 12:31 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 12:30 [PATCH v4 00/16] selftests/resctrl: resctrl_val() related cleanups & improvements Ilpo Järvinen
2024-05-20 12:30 ` [PATCH v4 01/16] selftests/resctrl: Fix closing IMC fds on error and open-code R+W instead of loops Ilpo Järvinen
2024-05-29 17:42   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 02/16] selftests/resctrl: Calculate resctrl FS derived mem bw over sleep(1) only Ilpo Järvinen
2024-05-24  0:10   ` Reinette Chatre
2024-05-24  7:57     ` Ilpo Järvinen
2024-05-24 15:14       ` Reinette Chatre
2024-05-24 15:26         ` Ilpo Järvinen
2024-05-28 10:19           ` Ilpo Järvinen
2024-05-28 15:15             ` Reinette Chatre
2024-05-30 11:11               ` Ilpo Järvinen
2024-05-30 15:08                 ` Reinette Chatre
2024-05-31 12:51                   ` Ilpo Järvinen
2024-05-20 12:30 ` [PATCH v4 03/16] selftests/resctrl: Make "bandwidth" consistent in comments & prints Ilpo Järvinen
2024-05-29 17:43   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 04/16] selftests/resctrl: Consolidate get_domain_id() into resctrl_val() Ilpo Järvinen
2024-05-29 17:43   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 05/16] selftests/resctrl: Use correct type for pids Ilpo Järvinen
2024-05-29 17:44   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 06/16] selftests/resctrl: Cleanup bm_pid and ppid usage & limit scope Ilpo Järvinen
2024-05-29 17:44   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 07/16] selftests/resctrl: Rename measure_vals() to measure_mem_bw_vals() & document Ilpo Järvinen
2024-05-29 17:44   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 08/16] selftests/resctrl: Simplify mem bandwidth file code for MBA & MBM tests Ilpo Järvinen
2024-05-29 17:45   ` Reinette Chatre
2024-05-20 12:30 ` Ilpo Järvinen [this message]
2024-05-29 17:46   ` [PATCH v4 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 10/16] selftests/resctrl: Add ->init() callback into resctrl_val_param Ilpo Järvinen
2024-05-29 17:48   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 11/16] selftests/resctrl: Simplify bandwidth report type handling Ilpo Järvinen
2024-05-29 17:46   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 12/16] selftests/resctrl: Make some strings passed to resctrlfs functions const Ilpo Järvinen
2024-05-29 17:47   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 13/16] selftests/resctrl: Convert ctrlgrp & mongrp to pointers Ilpo Järvinen
2024-05-29 17:48   ` Reinette Chatre
2024-05-30 11:44     ` Ilpo Järvinen
2024-05-20 12:30 ` [PATCH v4 14/16] selftests/resctrl: Remove mongrp from MBA test Ilpo Järvinen
2024-05-29 17:49   ` Reinette Chatre
2024-05-30 11:56     ` Ilpo Järvinen
2024-05-30 15:09       ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 15/16] selftests/resctrl: Remove mongrp from CMT test Ilpo Järvinen
2024-05-29 17:49   ` Reinette Chatre
2024-05-20 12:30 ` [PATCH v4 16/16] selftests/resctrl: Remove test name comparing from write_bm_pid_to_resctrl() Ilpo Järvinen
2024-05-29 17:52   ` Reinette Chatre

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=20240520123020.18938-10-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=babu.moger@amd.com \
    --cc=fenghua.yu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /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