All of lore.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>,
	"Shaopeng Tan" <tan.shaopeng@jp.fujitsu.com>,
	"Maciej Wieczór-Retman" <maciej.wieczor-retman@intel.com>,
	"Fenghua Yu" <fenghua.yu@intel.com>
Cc: linux-kernel@vger.kernel.org,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 19/24] selftests/resctrl: Pass write_schemata() resource instead of test name
Date: Tue, 24 Oct 2023 12:26:29 +0300	[thread overview]
Message-ID: <20231024092634.7122-20-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20231024092634.7122-1-ilpo.jarvinen@linux.intel.com>

write_schemata() currently takes the test name as an argument and
determines the relevant resource based on the test name. L2 CAT test
needs to set schemata for both L3 and L2 CAT which would get
complicated using the current approach.

Pass a resource instead of test name to write_schemata() to allow more
than one resource be set per test name.

While touching the sprintf(), move the unnecessary %c that is always
'=' directly into the format string.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 tools/testing/selftests/resctrl/cat_test.c  |  9 +++++----
 tools/testing/selftests/resctrl/cmt_test.c  |  1 +
 tools/testing/selftests/resctrl/mba_test.c  |  4 ++--
 tools/testing/selftests/resctrl/mbm_test.c  |  4 ++--
 tools/testing/selftests/resctrl/resctrl.h   |  5 +++--
 tools/testing/selftests/resctrl/resctrlfs.c | 22 +++++----------------
 6 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index aa16fb36d0d4..1ef047cadf4c 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -142,7 +142,8 @@ void cat_test_cleanup(void)
  *
  * Return:		0 on success. non-zero on failure.
  */
-static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long current_mask)
+static int cat_test(struct resctrl_val_param *param, const char *resource,
+		    size_t span, unsigned long current_mask)
 {
 	char *resctrl_val = param->resctrl_val;
 	static struct perf_event_read pe_read;
@@ -177,11 +178,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long
 
 	while (current_mask) {
 		snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask);
-		ret = write_schemata("", schemata, param->cpu_no, param->resctrl_val);
+		ret = write_schemata("", schemata, param->cpu_no, resource);
 		if (ret)
 			goto free_buf;
 		snprintf(schemata, sizeof(schemata), "%lx", current_mask);
-		ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val);
+		ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, resource);
 		if (ret)
 			goto free_buf;
 
@@ -268,7 +269,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
 
 	remove(param.filename);
 
-	ret = cat_test(&param, span, start_mask);
+	ret = cat_test(&param, test->resource, span, start_mask);
 	if (ret)
 		goto out;
 
diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c
index 353c4bae2cfe..b0825d654dcf 100644
--- a/tools/testing/selftests/resctrl/cmt_test.c
+++ b/tools/testing/selftests/resctrl/cmt_test.c
@@ -125,6 +125,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
 
 	struct resctrl_val_param param = {
 		.resctrl_val	= CMT_STR,
+		.resource	= "L3",
 		.ctrlgrp	= "c1",
 		.mongrp		= "m1",
 		.cpu_no		= uparams->cpu,
diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c
index 722f94013cb9..a14b7f4466e5 100644
--- a/tools/testing/selftests/resctrl/mba_test.c
+++ b/tools/testing/selftests/resctrl/mba_test.c
@@ -40,8 +40,7 @@ static int mba_setup(struct resctrl_val_param *p)
 
 	sprintf(allocation_str, "%d", allocation);
 
-	ret = write_schemata(p->ctrlgrp, allocation_str, p->cpu_no,
-			     p->resctrl_val);
+	ret = write_schemata(p->ctrlgrp, allocation_str, p->cpu_no, p->resource);
 	if (ret < 0)
 		return ret;
 
@@ -145,6 +144,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
 {
 	struct resctrl_val_param param = {
 		.resctrl_val	= MBA_STR,
+		.resource	= "MB",
 		.ctrlgrp	= "c1",
 		.mongrp		= "m1",
 		.cpu_no		= uparams->cpu,
diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c
index 943f4f14a499..1ad2c1a7fddb 100644
--- a/tools/testing/selftests/resctrl/mbm_test.c
+++ b/tools/testing/selftests/resctrl/mbm_test.c
@@ -96,8 +96,7 @@ static int mbm_setup(struct resctrl_val_param *p)
 
 	/* Set up shemata with 100% allocation on the first run. */
 	if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL))
-		ret = write_schemata(p->ctrlgrp, "100", p->cpu_no,
-				     p->resctrl_val);
+		ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, p->resource);
 
 	p->num_of_runs++;
 
@@ -113,6 +112,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
 {
 	struct resctrl_val_param param = {
 		.resctrl_val	= MBM_STR,
+		.resource	= "MB",
 		.ctrlgrp	= "c1",
 		.mongrp		= "m1",
 		.cpu_no		= uparams->cpu,
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index e017adf1390d..99fbce4794bc 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -81,6 +81,7 @@ struct resctrl_test {
 /*
  * resctrl_val_param:	resctrl test parameters
  * @resctrl_val:	Resctrl feature (Eg: mbm, mba.. etc)
+ * @resource:		Resource to test (e.g., MB, L3, L2, etc.)
  * @ctrlgrp:		Name of the control monitor group (con_mon grp)
  * @mongrp:		Name of the monitor group (mon grp)
  * @cpu_no:		CPU number to which the benchmark would be binded
@@ -90,6 +91,7 @@ struct resctrl_test {
  */
 struct resctrl_val_param {
 	char		*resctrl_val;
+	char		*resource;
 	char		ctrlgrp[64];
 	char		mongrp[64];
 	int		cpu_no;
@@ -127,8 +129,7 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature)
 bool test_resource_feature_check(const struct resctrl_test *test);
 char *fgrep(FILE *inf, const char *str);
 int taskset_benchmark(pid_t bm_pid, int cpu_no);
-int write_schemata(char *ctrlgrp, char *schemata, int cpu_no,
-		   char *resctrl_val);
+int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource);
 int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
 			    char *resctrl_val);
 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu,
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c
index 2851ffe64b56..7d72bea3ed58 100644
--- a/tools/testing/selftests/resctrl/resctrlfs.c
+++ b/tools/testing/selftests/resctrl/resctrlfs.c
@@ -496,23 +496,17 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
  * @ctrlgrp:		Name of the con_mon grp
  * @schemata:		Schemata that should be updated to
  * @cpu_no:		CPU number that the benchmark PID is binded to
- * @resctrl_val:	Resctrl feature (Eg: mbm, mba.. etc)
+ * @resource:		Resctrl resource (Eg: MB, L3, L2, etc.)
  *
  * Update schemata of a con_mon grp *only* if requested resctrl feature is
  * allocation type
  *
  * Return: 0 on success, non-zero on failure
  */
-int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)
+int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource)
 {
 	char controlgroup[1024], reason[128], schema[1024] = {};
-	int resource_id, fd, schema_len = -1, ret = 0;
-
-	if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) &&
-	    strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) &&
-	    strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) &&
-	    strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))
-		return -ENOENT;
+	int resource_id, fd, schema_len, ret = 0;
 
 	if (!schemata) {
 		ksft_print_msg("Skipping empty schemata update\n");
@@ -532,14 +526,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)
 	else
 		sprintf(controlgroup, "%s/schemata", RESCTRL_PATH);
 
-	if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) ||
-	    !strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))
-		schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n",
-				      "L3:", resource_id, '=', schemata);
-	if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) ||
-	    !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)))
-		schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n",
-				      "MB:", resource_id, '=', schemata);
+	schema_len = snprintf(schema, sizeof(schema), "%s:%d=%s\n",
+			      resource, resource_id, schemata);
 	if (schema_len < 0 || schema_len >= sizeof(schema)) {
 		snprintf(reason, sizeof(reason),
 			 "snprintf() failed with return value : %d", schema_len);
-- 
2.30.2


  parent reply	other threads:[~2023-10-24  9:31 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-24  9:26 [PATCH 00/24] selftests/resctrl: CAT test improvements & generalized test framework Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 01/24] selftests/resctrl: Split fill_buf to allow tests finer-grained control Ilpo Järvinen
2023-10-27 11:24   ` Maciej Wieczór-Retman
2023-11-02 17:46   ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 02/24] selftests/resctrl: Refactor fill_buf functions Ilpo Järvinen
2023-10-27 11:32   ` Maciej Wieczór-Retman
2023-10-27 11:41     ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 03/24] selftests/resctrl: Refactor get_cbm_mask() Ilpo Järvinen
2023-10-27 11:39   ` Maciej Wieczór-Retman
2023-11-02 17:47   ` Reinette Chatre
2023-11-03 12:09     ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 04/24] selftests/resctrl: Mark get_cache_size() cache_type const Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 05/24] selftests/resctrl: Create cache_size() helper Ilpo Järvinen
2023-11-02 17:47   ` Reinette Chatre
2023-11-03  8:53     ` Ilpo Järvinen
2023-11-03 22:49       ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 06/24] selftests/resctrl: Exclude shareable bits from schemata in CAT test Ilpo Järvinen
2023-11-02 17:48   ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 07/24] selftests/resctrl: Split measure_cache_vals() function Ilpo Järvinen
2023-11-02 17:48   ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 08/24] selftests/resctrl: Split show_cache_info() to test specific and generic parts Ilpo Järvinen
2023-11-02 17:48   ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 09/24] selftests/resctrl: Remove unnecessary __u64 -> unsigned long conversion Ilpo Järvinen
2023-11-02 17:48   ` Reinette Chatre
2023-11-03  9:19     ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 10/24] selftests/resctrl: Remove nested calls in perf event handling Ilpo Järvinen
2023-11-02 17:49   ` Reinette Chatre
2023-11-03  9:45     ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 11/24] selftests/resctrl: Consolidate naming of perf event related things Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 12/24] selftests/resctrl: Improve perf init Ilpo Järvinen
2023-10-27 11:45   ` Maciej Wieczór-Retman
2023-10-24  9:26 ` [PATCH 13/24] selftests/resctrl: Convert perf related globals to locals Ilpo Järvinen
2023-10-27 11:47   ` Maciej Wieczór-Retman
2023-10-24  9:26 ` [PATCH 14/24] selftests/resctrl: Move cat_val() to cat_test.c and rename to cat_test() Ilpo Järvinen
2023-10-27 11:51   ` Maciej Wieczór-Retman
2023-10-27 12:18     ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 15/24] selftests/resctrl: Read in less obvious order to defeat prefetch optimizations Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 16/24] selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test Ilpo Järvinen
2023-10-27 12:05   ` Maciej Wieczór-Retman
     [not found]     ` <fb5e1a50-ba7-1ee8-8bf2-bb8b64b27b1@linux.intel.com>
2023-10-31  7:24       ` Maciej Wieczór-Retman
2023-11-02 17:51   ` Reinette Chatre
2023-11-03 10:57     ` Ilpo Järvinen
2023-11-03 22:50       ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 17/24] selftests/resctrl: Create struct for input parameter Ilpo Järvinen
2023-10-27 12:07   ` Maciej Wieczór-Retman
2023-11-02 17:51   ` Reinette Chatre
2023-11-03 11:24     ` Ilpo Järvinen
2023-11-03 22:50       ` Reinette Chatre
2023-11-06  9:06         ` Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 18/24] selftests/resctrl: Introduce generalized test framework Ilpo Järvinen
2023-11-02 17:52   ` Reinette Chatre
2023-11-03  9:54     ` Ilpo Järvinen
2023-11-03 22:50       ` Reinette Chatre
2023-10-24  9:26 ` Ilpo Järvinen [this message]
2023-10-24  9:26 ` [PATCH 20/24] selftests/resctrl: Add helper to convert L2/3 to integer Ilpo Järvinen
2023-10-27 12:09   ` Maciej Wieczór-Retman
2023-10-24  9:26 ` [PATCH 21/24] selftests/resctrl: Get resource id from cache id Ilpo Järvinen
     [not found]   ` <cb2ctfignowlom7lb2t5zhdgtm4s2jlzlvtumlnvxecwwtjk34@ysgepmgkv6bb>
     [not found]     ` <ab4c6aa5-ea49-363a-ff7b-2215665f185d@linux.intel.com>
2023-10-31  7:58       ` Maciej Wieczór-Retman
2023-10-24  9:26 ` [PATCH 22/24] selftests/resctrl: Add test groups and name L3 CAT test L3_CAT Ilpo Järvinen
2023-10-24  9:26 ` [PATCH 23/24] selftests/resctrl: Add L2 CAT test Ilpo Järvinen
2023-11-02 17:57   ` Reinette Chatre
2023-11-03 10:39     ` Ilpo Järvinen
2023-11-03 22:53       ` Reinette Chatre
2023-11-06  9:53         ` Ilpo Järvinen
2023-11-06 17:03           ` Reinette Chatre
2023-11-06 21:22             ` Reinette Chatre
2023-11-07  9:33               ` Ilpo Järvinen
2023-11-08 16:31                 ` Reinette Chatre
2023-10-24  9:26 ` [PATCH 24/24] selftests/resctrl: Ignore failures from L2 CAT test with <= 2 bits Ilpo Järvinen
2023-11-02 17:57   ` Reinette Chatre
2023-11-03 10:24     ` Ilpo Järvinen
2023-11-03 22:53       ` 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=20231024092634.7122-20-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.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=tan.shaopeng@jp.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.