diff mbox series

[v3,20/21] selftests/resctrl: Fix unnecessary usage of global variables

Message ID 20201020235126.1871815-21-fenghua.yu@intel.com
State New
Headers show
Series Miscellaneous fixes for resctrl selftests | expand

Commit Message

Fenghua Yu Oct. 20, 2020, 11:51 p.m. UTC
Reinette reported following compilation issue on Fedora 32, gcc version
10.1.1

/usr/bin/ld: cmt_test.o:<src_dir>/cmt_test.c:22: multiple definition of
`cache_size'; cat_test.o:<src_dir>/cat_test.c:23: first defined here

The same issue is reported for long_mask and count_of_bits variables as
well. Compiler isn't happy because these variables are defined globally in
two .c files namely cmt_test.c and cat_test.c and the compiler during
compilation finds that the variable is already defined (multiple definition
error).

Taking a closer look at the usage of these variables reveals that these
variables are used only locally to cmt_resctrl_val() (defined in
cmt_test.c) and cat_perf_miss_val() (defined in cat_test.c) functions.
These variables are not shared between the two functions. So, there is no
need for these variables to be global. Hence, fix this issue by making
them local variables to the functions where they are used.

Fixes: 78941183d1b15 ("selftests/resctrl: Add Cache QoS Monitoring (CQM) selftest")
Fixes: 790bf585b0eee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest")
Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
 tools/testing/selftests/resctrl/cat_test.c | 7 ++-----
 tools/testing/selftests/resctrl/cmt_test.c | 6 ++----
 2 files changed, 4 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index a18a37ce626c..e518f8f7b4d8 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -17,10 +17,7 @@ 
 #define MAX_DIFF_PERCENT	4
 #define MAX_DIFF		1000000
 
-int count_of_bits;
 char cbm_mask[256];
-unsigned long long_mask;
-unsigned long cache_size;
 
 /*
  * Change schemata. Write schemata to specified
@@ -121,8 +118,8 @@  void cat_test_cleanup(void)
 
 int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
 {
-	unsigned long l_mask, l_mask_1;
-	int ret, pipefd[2], sibling_cpu_no;
+	unsigned long l_mask, l_mask_1, long_mask, cache_size;
+	int ret, pipefd[2], sibling_cpu_no, count_of_bits;
 	char pipe_message;
 	pid_t bm_pid;
 
diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c
index 119ae65abec7..f0cb441cca9f 100644
--- a/tools/testing/selftests/resctrl/cmt_test.c
+++ b/tools/testing/selftests/resctrl/cmt_test.c
@@ -16,10 +16,7 @@ 
 #define MAX_DIFF		2000000
 #define MAX_DIFF_PERCENT	15
 
-int count_of_bits;
 char cbm_mask[256];
-unsigned long long_mask;
-unsigned long cache_size;
 
 static int cmt_setup(int num, ...)
 {
@@ -113,7 +110,8 @@  void cmt_test_cleanup(void)
 
 int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
 {
-	int ret, mum_resctrlfs;
+	int ret, mum_resctrlfs, count_of_bits;
+	unsigned long long_mask, cache_size;
 
 	cache_size = 0;
 	mum_resctrlfs = 1;