selftests/resctrl: Convert span to size_t
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 17 Jul 2023 13:14:57 +0000 (16:14 +0300)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 25 Jul 2023 14:53:13 +0000 (08:53 -0600)
Span is defined either as unsigned long or int.

Consistently use size_t everywhere for span as it refers to size of the
memory block.

Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/cache.c
tools/testing/selftests/resctrl/cmt_test.c
tools/testing/selftests/resctrl/fill_buf.c
tools/testing/selftests/resctrl/mbm_test.c
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_tests.c
tools/testing/selftests/resctrl/resctrlfs.c

index 289b619..53df668 100644 (file)
@@ -286,7 +286,7 @@ pe_close:
  * Return:             0 on success. non-zero on failure.
  */
 int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
-                   unsigned long cache_span, unsigned long max_diff,
+                   size_t cache_span, unsigned long max_diff,
                    unsigned long max_diff_percent, unsigned long num_of_runs,
                    bool platform, bool cmt)
 {
@@ -308,7 +308,7 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
        ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
        ksft_print_msg("Number of bits: %d\n", no_of_bits);
        ksft_print_msg("Average LLC val: %lu\n", avg_llc_val);
-       ksft_print_msg("Cache span (%s): %lu\n", cmt ? "bytes" : "lines",
+       ksft_print_msg("Cache span (%s): %zu\n", cmt ? "bytes" : "lines",
                       cache_span);
 
        return ret;
index d31e284..beb0f06 100644 (file)
@@ -121,7 +121,7 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
        };
 
        if (strcmp(benchmark_cmd[0], "fill_buf") == 0)
-               sprintf(benchmark_cmd[1], "%lu", param.span);
+               sprintf(benchmark_cmd[1], "%zu", param.span);
 
        remove(RESULT_FILE_NAME);
 
index 3b328c8..785cbd8 100644 (file)
@@ -139,7 +139,7 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,
 }
 
 static int
-fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush,
+fill_cache(size_t buf_size, int malloc_and_init, int memflush,
           int op, char *resctrl_val)
 {
        unsigned char *start_ptr, *end_ptr;
@@ -188,10 +188,10 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush,
        return 0;
 }
 
-int run_fill_buf(unsigned long span, int malloc_and_init_memory,
-                int memflush, int op, char *resctrl_val)
+int run_fill_buf(size_t span, int malloc_and_init_memory, int memflush, int op,
+                char *resctrl_val)
 {
-       unsigned long long cache_size = span;
+       size_t cache_size = span;
        int ret;
 
        ret = fill_cache(cache_size, malloc_and_init_memory, memflush, op,
index 24326cb..fd11615 100644 (file)
@@ -15,7 +15,7 @@
 #define NUM_OF_RUNS            5
 
 static int
-show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
+show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span)
 {
        unsigned long avg_bw_imc = 0, avg_bw_resc = 0;
        unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
@@ -40,14 +40,14 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
        ksft_print_msg("%s Check MBM diff within %d%%\n",
                       ret ? "Fail:" : "Pass:", MAX_DIFF_PERCENT);
        ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
-       ksft_print_msg("Span (MB): %d\n", span);
+       ksft_print_msg("Span (MB): %zu\n", span);
        ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);
        ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc);
 
        return ret;
 }
 
-static int check_results(int span)
+static int check_results(size_t span)
 {
        unsigned long bw_imc[NUM_OF_RUNS], bw_resc[NUM_OF_RUNS];
        char temp[1024], *token_array[8];
@@ -115,7 +115,7 @@ void mbm_test_cleanup(void)
        remove(RESULT_FILE_NAME);
 }
 
-int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd)
+int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd)
 {
        struct resctrl_val_param param = {
                .resctrl_val    = MBM_STR,
index 99678d6..52068ce 100644 (file)
@@ -63,7 +63,7 @@ struct resctrl_val_param {
        char            ctrlgrp[64];
        char            mongrp[64];
        int             cpu_no;
-       unsigned long   span;
+       size_t          span;
        char            filename[64];
        char            *bw_report;
        unsigned long   mask;
@@ -97,10 +97,10 @@ 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,
                    int group_fd, unsigned long flags);
-int run_fill_buf(unsigned long span, int malloc_and_init_memory, int memflush,
-                int op, char *resctrl_va);
+int run_fill_buf(size_t span, int malloc_and_init_memory, int memflush, int op,
+                char *resctrl_va);
 int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param);
-int mbm_bw_change(int span, int cpu_no, char *bw_report, char **benchmark_cmd);
+int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd);
 void tests_cleanup(void);
 void mbm_test_cleanup(void);
 int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd);
@@ -119,7 +119,7 @@ void cmt_test_cleanup(void);
 int get_core_sibling(int cpu_no);
 int measure_cache_vals(struct resctrl_val_param *param, int bm_pid);
 int show_cache_info(unsigned long sum_llc_val, int no_of_bits,
-                   unsigned long cache_span, unsigned long max_diff,
+                   size_t cache_span, unsigned long max_diff,
                    unsigned long max_diff_percent, unsigned long num_of_runs,
                    bool platform, bool cmt);
 
index 0363c4b..bae8f20 100644 (file)
@@ -70,7 +70,7 @@ void tests_cleanup(void)
        cat_test_cleanup();
 }
 
-static void run_mbm_test(bool has_ben, char **benchmark_cmd, int span,
+static void run_mbm_test(bool has_ben, char **benchmark_cmd, size_t span,
                         int cpu_no, char *bw_report)
 {
        int res;
@@ -99,7 +99,7 @@ umount:
        umount_resctrlfs();
 }
 
-static void run_mba_test(bool has_ben, char **benchmark_cmd, int span,
+static void run_mba_test(bool has_ben, char **benchmark_cmd, size_t span,
                         int cpu_no, char *bw_report)
 {
        int res;
@@ -118,7 +118,7 @@ static void run_mba_test(bool has_ben, char **benchmark_cmd, int span,
        }
 
        if (!has_ben)
-               sprintf(benchmark_cmd[1], "%d", span);
+               sprintf(benchmark_cmd[1], "%zu", span);
        res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd);
        ksft_test_result(!res, "MBA: schemata change\n");
 
@@ -181,11 +181,12 @@ umount:
 int main(int argc, char **argv)
 {
        bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true;
-       int c, cpu_no = 1, span = 250, argc_new = argc, i, no_of_bits = 0;
        char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64];
        char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE];
+       int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0;
        int ben_ind, ben_count, tests = 0;
        bool cat_test = true;
+       size_t span = 250;
 
        for (i = 0; i < argc; i++) {
                if (strcmp(argv[i], "-b") == 0) {
@@ -273,7 +274,7 @@ int main(int argc, char **argv)
                        benchmark_cmd[i] = benchmark_cmd_area[i];
 
                strcpy(benchmark_cmd[0], "fill_buf");
-               sprintf(benchmark_cmd[1], "%d", span);
+               sprintf(benchmark_cmd[1], "%zu", span);
                strcpy(benchmark_cmd[2], "1");
                strcpy(benchmark_cmd[3], "1");
                strcpy(benchmark_cmd[4], "0");
index c456669..14fb85a 100644 (file)
@@ -303,7 +303,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no)
 void run_benchmark(int signum, siginfo_t *info, void *ucontext)
 {
        int operation, ret, malloc_and_init_memory, memflush;
-       unsigned long span, buffer_span;
+       size_t span, buffer_span;
        char **benchmark_cmd;
        char resctrl_val[64];
        FILE *fp;