]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/resctrl: Use correct type for pids
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 10 Jun 2024 15:14:46 +0000 (18:14 +0300)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 11 Jul 2024 17:23:53 +0000 (11:23 -0600)
A few functions receive PIDs through int arguments. PIDs variables
should be of type pid_t, not int.

Convert pid arguments from int to pid_t.

Before printing PID, match the type to %d by casting to int which is
enough for Linux (standard would allow using a longer integer type but
generalizing for that would complicate the code unnecessarily, the
selftest code does not need to be portable).

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/cache.c
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_val.c
tools/testing/selftests/resctrl/resctrlfs.c

index 1b339d6bbff1c945fdcfac6acafd908ae1bd96c8..1ff1104e657531cf2ec42ba519ac56d98751553a 100644 (file)
@@ -101,12 +101,12 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
  *
  * Return:             0 on success, < 0 on error.
  */
-static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value)
+static int print_results_cache(const char *filename, pid_t bm_pid, __u64 llc_value)
 {
        FILE *fp;
 
        if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) {
-               printf("Pid: %d \t LLC_value: %llu\n", bm_pid, llc_value);
+               printf("Pid: %d \t LLC_value: %llu\n", (int)bm_pid, llc_value);
        } else {
                fp = fopen(filename, "a");
                if (!fp) {
@@ -114,7 +114,7 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value
 
                        return -1;
                }
-               fprintf(fp, "Pid: %d \t llc_value: %llu\n", bm_pid, llc_value);
+               fprintf(fp, "Pid: %d \t llc_value: %llu\n", (int)bm_pid, llc_value);
                fclose(fp);
        }
 
@@ -133,7 +133,7 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value
  * Return: =0 on success. <0 on failure.
  */
 int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
-                      const char *filename, int bm_pid)
+                      const char *filename, pid_t bm_pid)
 {
        int ret;
 
@@ -161,7 +161,7 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
  *
  * Return: =0 on success. <0 on failure.
  */
-int measure_llc_resctrl(const char *filename, int bm_pid)
+int measure_llc_resctrl(const char *filename, pid_t bm_pid)
 {
        unsigned long llc_occu_resc = 0;
        int ret;
index 00d51fa7531cea4d660a6758fe95eaaf9456dacb..e6f221236c79aaa7617dae9cdc9305aacdaf89ee 100644 (file)
@@ -174,8 +174,8 @@ void perf_event_initialize_read_format(struct perf_event_read *pe_read);
 int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no);
 int perf_event_reset_enable(int pe_fd);
 int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
-                      const char *filename, int bm_pid);
-int measure_llc_resctrl(const char *filename, int bm_pid);
+                      const char *filename, pid_t bm_pid);
+int measure_llc_resctrl(const char *filename, pid_t bm_pid);
 void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines);
 
 /*
index cccf6b80f3f351c01796c0076fcca8eaa946364f..5704fa3ba202f6e7af3c3c5f04d3fc7e582e7fd6 100644 (file)
@@ -566,14 +566,14 @@ void signal_handler_unregister(void)
  *
  * Return:             0 on success, < 0 on error.
  */
-static int print_results_bw(char *filename,  int bm_pid, float bw_imc,
+static int print_results_bw(char *filename, pid_t bm_pid, float bw_imc,
                            unsigned long bw_resc)
 {
        unsigned long diff = fabs(bw_imc - bw_resc);
        FILE *fp;
 
        if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) {
-               printf("Pid: %d \t Mem_BW_iMC: %f \t ", bm_pid, bw_imc);
+               printf("Pid: %d \t Mem_BW_iMC: %f \t ", (int)bm_pid, bw_imc);
                printf("Mem_BW_resc: %lu \t Difference: %lu\n", bw_resc, diff);
        } else {
                fp = fopen(filename, "a");
@@ -583,7 +583,7 @@ static int print_results_bw(char *filename,  int bm_pid, float bw_imc,
                        return -1;
                }
                if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n",
-                           bm_pid, bw_imc, bw_resc, diff) <= 0) {
+                           (int)bm_pid, bw_imc, bw_resc, diff) <= 0) {
                        ksft_print_msg("Could not log results\n");
                        fclose(fp);
 
@@ -828,7 +828,7 @@ int resctrl_val(const struct resctrl_test *test,
                PARENT_EXIT();
        }
 
-       ksft_print_msg("Benchmark PID: %d\n", bm_pid);
+       ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid);
 
        /*
         * The cast removes constness but nothing mutates benchmark_cmd within
index 9b86f826a40c8046b020e8fe13aeb86a45097f6a..917d677adbba4ab0b61494edc0bc618af7f3a2f1 100644 (file)
@@ -508,7 +508,7 @@ static int write_pid_to_tasks(char *tasks, pid_t pid)
 
                return -1;
        }
-       if (fprintf(fp, "%d\n", pid) < 0) {
+       if (fprintf(fp, "%d\n", (int)pid) < 0) {
                ksft_print_msg("Failed to write pid to tasks file\n");
                fclose(fp);