Skip to content

Commit 14d28ec

Browse files
johnhubbardshuahkh
authored andcommitted
selftests/resctrl: fix clang build warnings related to abs(), labs() calls
When building with clang, via: make LLVM=1 -C tools/testing/selftests ...two types of warnings occur: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value warning: taking the absolute value of unsigned type 'unsigned long' has no effect Fix these by: a) using labs() in place of abs(), when long integers are involved, and b) Change to use signed integer data types, in places where subtraction is used (and could end up with negative values). c) Remove a duplicate abs() call in cmt_test.c. Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent b07b7e2 commit 14d28ec

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tools/testing/selftests/resctrl/cmt_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ static int show_results_info(unsigned long sum_llc_val, int no_of_bits,
4040
int ret;
4141

4242
avg_llc_val = sum_llc_val / num_of_runs;
43-
avg_diff = (long)abs(cache_span - avg_llc_val);
43+
avg_diff = (long)(cache_span - avg_llc_val);
4444
diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100;
4545

4646
ret = platform && abs((int)diff_percent) > max_diff_percent &&
47-
abs(avg_diff) > max_diff;
47+
labs(avg_diff) > max_diff;
4848

4949
ksft_print_msg("%s Check cache miss rate within %lu%%\n",
5050
ret ? "Fail:" : "Pass:", max_diff_percent);

tools/testing/selftests/resctrl/mba_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
6060
/* Memory bandwidth from 100% down to 10% */
6161
for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP;
6262
allocation++) {
63-
unsigned long avg_bw_imc, avg_bw_resc;
6463
unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
64+
long avg_bw_imc, avg_bw_resc;
6565
int avg_diff_per;
6666
float avg_diff;
6767

tools/testing/selftests/resctrl/mbm_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
static int
1818
show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span)
1919
{
20-
unsigned long avg_bw_imc = 0, avg_bw_resc = 0;
2120
unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
21+
long avg_bw_imc = 0, avg_bw_resc = 0;
2222
int runs, ret, avg_diff_per;
2323
float avg_diff = 0;
2424

0 commit comments

Comments
 (0)