public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-kselftest@vger.kernel.org, "Shuah Khan" <shuah@kernel.org>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Babu Moger" <babu.moger@amd.com>,
	"Maciej Wieczór-Retman" <maciej.wieczor-retman@intel.com>
Cc: "Fenghua Yu" <fenghua.yu@intel.com>,
	linux-kernel@vger.kernel.org,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH v7 05/16] selftests/resctrl: Use correct type for pids
Date: Mon, 10 Jun 2024 18:14:46 +0300	[thread overview]
Message-ID: <20240610151457.7305-6-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com>

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>
---

v5:
- Cast to int before printing to match with %d.
---
 tools/testing/selftests/resctrl/cache.c       | 10 +++++-----
 tools/testing/selftests/resctrl/resctrl.h     |  4 ++--
 tools/testing/selftests/resctrl/resctrl_val.c |  8 ++++----
 tools/testing/selftests/resctrl/resctrlfs.c   |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 1b339d6bbff1..1ff1104e6575 100644
--- a/tools/testing/selftests/resctrl/cache.c
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -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;
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 00d51fa7531c..e6f221236c79 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -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);
 
 /*
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
index cccf6b80f3f3..5704fa3ba202 100644
--- a/tools/testing/selftests/resctrl/resctrl_val.c
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -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
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c
index 9b86f826a40c..917d677adbba 100644
--- a/tools/testing/selftests/resctrl/resctrlfs.c
+++ b/tools/testing/selftests/resctrl/resctrlfs.c
@@ -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);
 
-- 
2.39.2


  parent reply	other threads:[~2024-06-10 15:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-10 15:14 [PATCH v7 00/16] selftests/resctrl: resctrl_val() related cleanups & improvements Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 01/16] selftests/resctrl: Fix closing IMC fds on error and open-code R+W instead of loops Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 02/16] selftests/resctrl: Calculate resctrl FS derived mem bw over sleep(1) only Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 03/16] selftests/resctrl: Make "bandwidth" consistent in comments & prints Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 04/16] selftests/resctrl: Consolidate get_domain_id() into resctrl_val() Ilpo Järvinen
2024-06-10 15:14 ` Ilpo Järvinen [this message]
2024-06-10 15:14 ` [PATCH v7 06/16] selftests/resctrl: Cleanup bm_pid and ppid usage & limit scope Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 07/16] selftests/resctrl: Rename measure_vals() to measure_mem_bw_vals() & document Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 08/16] selftests/resctrl: Simplify mem bandwidth file code for MBA & MBM tests Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 10/16] selftests/resctrl: Add ->init() callback into resctrl_val_param Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 11/16] selftests/resctrl: Simplify bandwidth report type handling Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 12/16] selftests/resctrl: Make some strings passed to resctrlfs functions const Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 13/16] selftests/resctrl: Convert ctrlgrp & mongrp to pointers Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 14/16] selftests/resctrl: Remove mongrp from MBA test Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 15/16] selftests/resctrl: Remove mongrp from CMT test Ilpo Järvinen
2024-06-10 15:14 ` [PATCH v7 16/16] selftests/resctrl: Remove test name comparing from write_bm_pid_to_resctrl() Ilpo Järvinen
2024-06-10 21:58 ` [PATCH v7 00/16] selftests/resctrl: resctrl_val() related cleanups & improvements Reinette Chatre
2024-06-18 23:44 ` Shuah Khan
2024-06-21 20:49   ` Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240610151457.7305-6-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=babu.moger@amd.com \
    --cc=fenghua.yu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox