Skip to content

Commit 8245a70

Browse files
ij-intelshuahkh
authored andcommitted
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>
1 parent 9224db5 commit 8245a70

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

tools/testing/selftests/resctrl/cache.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,20 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
101101
*
102102
* Return: 0 on success, < 0 on error.
103103
*/
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)
105105
{
106106
FILE *fp;
107107

108108
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);
110110
} else {
111111
fp = fopen(filename, "a");
112112
if (!fp) {
113113
ksft_perror("Cannot open results file");
114114

115115
return -1;
116116
}
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);
118118
fclose(fp);
119119
}
120120

@@ -133,7 +133,7 @@ static int print_results_cache(const char *filename, int bm_pid, __u64 llc_value
133133
* Return: =0 on success. <0 on failure.
134134
*/
135135
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)
137137
{
138138
int ret;
139139

@@ -161,7 +161,7 @@ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read,
161161
*
162162
* Return: =0 on success. <0 on failure.
163163
*/
164-
int measure_llc_resctrl(const char *filename, int bm_pid)
164+
int measure_llc_resctrl(const char *filename, pid_t bm_pid)
165165
{
166166
unsigned long llc_occu_resc = 0;
167167
int ret;

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ void perf_event_initialize_read_format(struct perf_event_read *pe_read);
174174
int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no);
175175
int perf_event_reset_enable(int pe_fd);
176176
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);
179179
void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines);
180180

181181
/*

tools/testing/selftests/resctrl/resctrl_val.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,14 @@ void signal_handler_unregister(void)
566566
*
567567
* Return: 0 on success, < 0 on error.
568568
*/
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,
570570
unsigned long bw_resc)
571571
{
572572
unsigned long diff = fabs(bw_imc - bw_resc);
573573
FILE *fp;
574574

575575
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);
577577
printf("Mem_BW_resc: %lu \t Difference: %lu\n", bw_resc, diff);
578578
} else {
579579
fp = fopen(filename, "a");
@@ -583,7 +583,7 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc,
583583
return -1;
584584
}
585585
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) {
587587
ksft_print_msg("Could not log results\n");
588588
fclose(fp);
589589

@@ -828,7 +828,7 @@ int resctrl_val(const struct resctrl_test *test,
828828
PARENT_EXIT();
829829
}
830830

831-
ksft_print_msg("Benchmark PID: %d\n", bm_pid);
831+
ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid);
832832

833833
/*
834834
* The cast removes constness but nothing mutates benchmark_cmd within

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static int write_pid_to_tasks(char *tasks, pid_t pid)
508508

509509
return -1;
510510
}
511-
if (fprintf(fp, "%d\n", pid) < 0) {
511+
if (fprintf(fp, "%d\n", (int)pid) < 0) {
512512
ksft_print_msg("Failed to write pid to tasks file\n");
513513
fclose(fp);
514514

0 commit comments

Comments
 (0)