Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/resctrl: Use correct type for pids

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>

authored by

Ilpo Järvinen and committed by
Shuah Khan
8245a70e 9224db51

+12 -12
+5 -5
tools/testing/selftests/resctrl/cache.c
··· 101 101 * 102 102 * Return: 0 on success, < 0 on error. 103 103 */ 104 - static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value) 104 + static int print_results_cache(const char *filename, pid_t bm_pid, __u64 llc_value) 105 105 { 106 106 FILE *fp; 107 107 108 108 if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) { 109 - printf("Pid: %d \t LLC_value: %llu\n", bm_pid, llc_value); 109 + printf("Pid: %d \t LLC_value: %llu\n", (int)bm_pid, llc_value); 110 110 } else { 111 111 fp = fopen(filename, "a"); 112 112 if (!fp) { ··· 114 114 115 115 return -1; 116 116 } 117 - fprintf(fp, "Pid: %d \t llc_value: %llu\n", bm_pid, llc_value); 117 + fprintf(fp, "Pid: %d \t llc_value: %llu\n", (int)bm_pid, llc_value); 118 118 fclose(fp); 119 119 } 120 120 ··· 133 133 * Return: =0 on success. <0 on failure. 134 134 */ 135 135 int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, 136 - const char *filename, int bm_pid) 136 + const char *filename, pid_t bm_pid) 137 137 { 138 138 int ret; 139 139 ··· 161 161 * 162 162 * Return: =0 on success. <0 on failure. 163 163 */ 164 - int measure_llc_resctrl(const char *filename, int bm_pid) 164 + int measure_llc_resctrl(const char *filename, pid_t bm_pid) 165 165 { 166 166 unsigned long llc_occu_resc = 0; 167 167 int ret;
+2 -2
tools/testing/selftests/resctrl/resctrl.h
··· 174 174 int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no); 175 175 int perf_event_reset_enable(int pe_fd); 176 176 int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, 177 - const char *filename, int bm_pid); 178 - int measure_llc_resctrl(const char *filename, int bm_pid); 177 + const char *filename, pid_t bm_pid); 178 + int measure_llc_resctrl(const char *filename, pid_t bm_pid); 179 179 void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines); 180 180 181 181 /*
+4 -4
tools/testing/selftests/resctrl/resctrl_val.c
··· 566 566 * 567 567 * Return: 0 on success, < 0 on error. 568 568 */ 569 - static int print_results_bw(char *filename, int bm_pid, float bw_imc, 569 + static int print_results_bw(char *filename, pid_t bm_pid, float bw_imc, 570 570 unsigned long bw_resc) 571 571 { 572 572 unsigned long diff = fabs(bw_imc - bw_resc); 573 573 FILE *fp; 574 574 575 575 if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) { 576 - printf("Pid: %d \t Mem_BW_iMC: %f \t ", bm_pid, bw_imc); 576 + printf("Pid: %d \t Mem_BW_iMC: %f \t ", (int)bm_pid, bw_imc); 577 577 printf("Mem_BW_resc: %lu \t Difference: %lu\n", bw_resc, diff); 578 578 } else { 579 579 fp = fopen(filename, "a"); ··· 583 583 return -1; 584 584 } 585 585 if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n", 586 - bm_pid, bw_imc, bw_resc, diff) <= 0) { 586 + (int)bm_pid, bw_imc, bw_resc, diff) <= 0) { 587 587 ksft_print_msg("Could not log results\n"); 588 588 fclose(fp); 589 589 ··· 828 828 PARENT_EXIT(); 829 829 } 830 830 831 - ksft_print_msg("Benchmark PID: %d\n", bm_pid); 831 + ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid); 832 832 833 833 /* 834 834 * The cast removes constness but nothing mutates benchmark_cmd within
+1 -1
tools/testing/selftests/resctrl/resctrlfs.c
··· 508 508 509 509 return -1; 510 510 } 511 - if (fprintf(fp, "%d\n", pid) < 0) { 511 + if (fprintf(fp, "%d\n", (int)pid) < 0) { 512 512 ksft_print_msg("Failed to write pid to tasks file\n"); 513 513 fclose(fp); 514 514