diff mbox series

[V1,12/13] selftests/resctrl: Dynamically select buffer size for CAT test

Message ID 18ab8b47d1d2b6373d7899bdf8df19fa94afcfaa.1583657204.git.sai.praneeth.prakhya@intel.com (mailing list archive)
State New
Headers show
Series Miscellaneous fixes for resctrl selftests | expand

Commit Message

Prakhya, Sai Praneeth March 7, 2020, 3:40 a.m. UTC
Presently, while running CAT test case, if user hasn't given any input for
'-n' option, the test defaults to 5 bits to determine the buffer size that
is used during test. Instead of statically running always with 5 bits,
change it such that the buffer size is always half of the cache size.

Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
---
 tools/testing/selftests/resctrl/cat_test.c      | 16 +++++++++++-----
 tools/testing/selftests/resctrl/resctrl.h       |  3 ++-
 tools/testing/selftests/resctrl/resctrl_tests.c |  7 ++++---
 3 files changed, 17 insertions(+), 9 deletions(-)

Comments

Reinette Chatre March 10, 2020, 10:19 p.m. UTC | #1
Hi Sai,

On 3/6/2020 7:40 PM, Sai Praneeth Prakhya wrote:
> Presently, while running CAT test case, if user hasn't given any input for
> '-n' option, the test defaults to 5 bits to determine the buffer size that
> is used during test. Instead of statically running always with 5 bits,
> change it such that the buffer size is always half of the cache size.

This seems more appropriate as a preparation patch to not have to make
so many changes on top of the earlier patches included in this series.

Reinette
Prakhya, Sai Praneeth March 11, 2020, 2:52 a.m. UTC | #2
Hi Reinette,

On Tue, 2020-03-10 at 15:19 -0700, Reinette Chatre wrote:
> Hi Sai,
> 
> On 3/6/2020 7:40 PM, Sai Praneeth Prakhya wrote:
> > Presently, while running CAT test case, if user hasn't given any input for
> > '-n' option, the test defaults to 5 bits to determine the buffer size that
> > is used during test. Instead of statically running always with 5 bits,
> > change it such that the buffer size is always half of the cache size.
> 
> This seems more appropriate as a preparation patch to not have to make
> so many changes on top of the earlier patches included in this series.

Ok.. makes sense.

Regards,
Sai
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index f7a67f005fe5..d1c50430ab20 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -109,7 +109,8 @@  void cat_test_cleanup(void)
 	remove(RESULT_FILE_NAME);
 }
 
-static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type)
+static int prepare_masks_for_two_processes(int *no_of_bits, bool user_bits,
+					   char *cache_type)
 {
 	int ret, i;
 	unsigned long long_mask, shareable_mask;
@@ -123,12 +124,15 @@  static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type)
 	long_mask = strtoul(cbm_mask, NULL, 16);
 	count_of_bits = count_bits(long_mask);
 
+	if (!user_bits)
+		*no_of_bits = count_of_bits / 2;
+
 	/*
 	 * Max limit is count_of_bits - 1 because we need exclusive masks for
 	 * the two processes. So, the last saved bit will be used by the other
 	 * process.
 	 */
-	if (no_of_bits < 1 || no_of_bits > count_of_bits - 1) {
+	if (*no_of_bits < 1 || *no_of_bits > count_of_bits - 1) {
 		printf("Invalid input value for no_of_bits 'n'\n");
 		printf("Please Enter value in range 1 to %d\n",
 		       count_of_bits - 1);
@@ -140,7 +144,7 @@  static int prepare_masks_for_two_processes(int no_of_bits, char *cache_type)
 		return ret;
 
 	/* Prepare cbm mask without any shareable bits */
-	for (i = 0; i < no_of_bits; i++) {
+	for (i = 0; i < *no_of_bits; i++) {
 		p1_mask <<= 1;
 		p1_mask |= 1;
 	}
@@ -176,7 +180,8 @@  static int start_noisy_process(pid_t pid, int sibling_cpu_no)
 	return 0;
 }
 
-int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type)
+int cat_perf_miss_val(int cpu_no, int no_of_bits, bool user_bits,
+		      char *cache_type)
 {
 	int ret, sibling_cpu_no;
 	unsigned long buf_size;
@@ -194,7 +199,8 @@  int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type)
 	if (!validate_resctrl_feature_request("cat"))
 		return -1;
 
-	ret = prepare_masks_for_two_processes(no_of_bits, cache_type);
+	ret = prepare_masks_for_two_processes(&no_of_bits, user_bits,
+					      cache_type);
 	if (ret)
 		return ret;
 
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index cb67ad689475..393f2f34ccac 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -102,7 +102,8 @@  void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
 int setup_critical_process(pid_t pid, struct resctrl_val_param *param);
 int run_critical_process(pid_t pid, struct resctrl_val_param *param);
 void cat_test_cleanup(void);
-int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type);
+int cat_perf_miss_val(int cpu_no, int no_of_bits, bool user_bits,
+		      char *cache_type);
 int cqm_schemata_change(int cpu_no, int span, char *cache_type,
 			char **benchmark_cmd);
 unsigned int count_bits(unsigned long n);
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index 3c408c636b6d..4461c3dc8cce 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -57,11 +57,11 @@  void tests_cleanup(void)
 int main(int argc, char **argv)
 {
 	bool has_ben = false, mbm_test = true, mba_test = true, cqm_test = true;
-	int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 5;
+	int res, c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits;
 	char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64];
 	char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE];
 	int ben_ind, ben_count;
-	bool cat_test = true;
+	bool cat_test = true, user_bits = false;
 
 	for (i = 0; i < argc; i++) {
 		if (strcmp(argv[i], "-b") == 0) {
@@ -105,6 +105,7 @@  int main(int argc, char **argv)
 			cpu_no = atoi(optarg);
 			break;
 		case 'n':
+			user_bits = true;
 			no_of_bits = atoi(optarg);
 			break;
 		case 'h':
@@ -192,7 +193,7 @@  int main(int argc, char **argv)
 
 	if (cat_test) {
 		printf("# Starting CAT test ...\n");
-		res = cat_perf_miss_val(cpu_no, no_of_bits, "L3");
+		res = cat_perf_miss_val(cpu_no, no_of_bits, user_bits, "L3");
 		printf("%sok CAT: test\n", res ? "not " : "");
 		cat_test_cleanup();
 		tests_run++;