linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saket Kumar Bhaskar <skb99@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: trenn@suse.com, shuah@kernel.org, ray.huang@amd.com,
	linux-pm@vger.kernel.org,
	Saket Kumar Bhaskar <skb99@linux.vnet.ibm.com>
Subject: [PATCH] tools/cpupower: Choose first online CPU to display details
Date: Mon, 21 Nov 2022 11:05:30 +0530	[thread overview]
Message-ID: <20221121053530.103600-1-skb99@linux.vnet.ibm.com> (raw)

The default output of cpupower info utils shows unexpected output
when CPU 0 is disabled.

Considering a case where CPU 0 is disabled, output of cpupower idle-info:

Before change:
cpupower idle-info
CPUidle driver: pseries_idle
CPUidle governor: menu
analyzing CPU 0:
 *is offline

After change:
./cpupower idle-info
CPUidle driver: pseries_idle
CPUidle governor: menu
analyzing CPU 0:
 *is offline
analyzing CPU 1:

Number of idle states: 2
Available idle states: snooze Shared Cede
snooze:
Flags/Description: snooze
Latency: 0
Usage: 919
Duration: 68227
Shared Cede:
Flags/Description: Shared Cede
Latency: 10
Usage: 99324
Duration: 67871518243

If -c option is not passed, CPU 0 was chosen as the default chosen CPU to
display details. However when CPU 0 is offline, it results in showing
unexpected output. This commit chooses the first online CPU
instead of CPU 0, hence keeping the output more relevant in all cases.

Somewhat similar logic to set all CPUs in default case is present in
cpufreq-set.c, cpuidle-set.c, cpupower-set.c. But here we have added
logic to stop at first online CPU.

Signed-off-by: Saket Kumar Bhaskar <skb99@linux.vnet.ibm.com>
---
 tools/power/cpupower/utils/cpufreq-info.c  | 15 ++++++++++++---
 tools/power/cpupower/utils/cpuidle-info.c  | 15 ++++++++++++---
 tools/power/cpupower/utils/cpupower-info.c | 16 +++++++++++++---
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c
index 0646f615fe2d..4001a5934494 100644
--- a/tools/power/cpupower/utils/cpufreq-info.c
+++ b/tools/power/cpupower/utils/cpufreq-info.c
@@ -508,6 +508,7 @@ int cmd_freq_info(int argc, char **argv)
 	unsigned int cpu = 0;
 	unsigned int human = 0;
 	int output_param = 0;
+	bool is_default = false;
 
 	do {
 		ret = getopt_long(argc, argv, "oefwldpgrasmybnc", info_opts,
@@ -572,9 +573,11 @@ int cmd_freq_info(int argc, char **argv)
 
 	ret = 0;
 
-	/* Default is: show output of CPU 0 only */
-	if (bitmask_isallclear(cpus_chosen))
-		bitmask_setbit(cpus_chosen, 0);
+	/* Default is: set all CPUs */
+	if (bitmask_isallclear(cpus_chosen)) {
+		bitmask_setall(cpus_chosen);
+		is_default = true;
+	}
 
 	switch (output_param) {
 	case -1:
@@ -646,6 +649,12 @@ int cmd_freq_info(int argc, char **argv)
 		}
 		if (ret)
 			return ret;
+
+		if (is_default) {
+			bitmask_clearall(cpus_chosen);
+			bitmask_setbit(cpus_chosen, cpu);
+			break;
+		}
 	}
 	return ret;
 }
diff --git a/tools/power/cpupower/utils/cpuidle-info.c b/tools/power/cpupower/utils/cpuidle-info.c
index f2b202c5552a..a0e2f5b98537 100644
--- a/tools/power/cpupower/utils/cpuidle-info.c
+++ b/tools/power/cpupower/utils/cpuidle-info.c
@@ -139,6 +139,7 @@ int cmd_idle_info(int argc, char **argv)
 	extern int optind, opterr, optopt;
 	int ret = 0, cont = 1, output_param = 0, verbose = 1;
 	unsigned int cpu = 0;
+	bool is_default = false;
 
 	do {
 		ret = getopt_long(argc, argv, "os", info_opts, NULL);
@@ -176,9 +177,11 @@ int cmd_idle_info(int argc, char **argv)
 		cpuidle_exit(EXIT_FAILURE);
 	}
 
-	/* Default is: show output of CPU 0 only */
-	if (bitmask_isallclear(cpus_chosen))
-		bitmask_setbit(cpus_chosen, 0);
+	/* Default is: set all CPUs */
+	if (bitmask_isallclear(cpus_chosen)) {
+		bitmask_setall(cpus_chosen);
+		is_default = true;
+	}
 
 	if (output_param == 0)
 		cpuidle_general_output();
@@ -208,6 +211,12 @@ int cmd_idle_info(int argc, char **argv)
 			break;
 		}
 		printf("\n");
+
+		if (is_default) {
+			bitmask_clearall(cpus_chosen);
+			bitmask_setbit(cpus_chosen, cpu);
+			break;
+		}
 	}
 	return EXIT_SUCCESS;
 }
diff --git a/tools/power/cpupower/utils/cpupower-info.c b/tools/power/cpupower/utils/cpupower-info.c
index 06345b543786..995bc20a8c7d 100644
--- a/tools/power/cpupower/utils/cpupower-info.c
+++ b/tools/power/cpupower/utils/cpupower-info.c
@@ -40,6 +40,7 @@ int cmd_info(int argc, char **argv)
 		int params;
 	} params = {};
 	int ret = 0;
+	bool is_default = false;
 
 	ret = uname(&uts);
 	if (!ret && (!strcmp(uts.machine, "ppc64le") ||
@@ -67,9 +68,12 @@ int cmd_info(int argc, char **argv)
 	if (!params.params)
 		params.params = 0x7;
 
-	/* Default is: show output of CPU 0 only */
-	if (bitmask_isallclear(cpus_chosen))
-		bitmask_setbit(cpus_chosen, 0);
+	/* Default is: set all CPUs */
+	if (bitmask_isallclear(cpus_chosen)) {
+		bitmask_setall(cpus_chosen);
+		is_default = true;
+	}
+
 
 	/* Add more per cpu options here */
 	if (!params.perf_bias)
@@ -109,6 +113,12 @@ int cmd_info(int argc, char **argv)
 			} else
 				printf(_("perf-bias: %d\n"), ret);
 		}
+
+		if (is_default) {
+			bitmask_clearall(cpus_chosen);
+			bitmask_setbit(cpus_chosen, cpu);
+			break;
+		}
 	}
 	return 0;
 }
-- 
2.31.1


             reply	other threads:[~2022-11-21  5:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21  5:35 Saket Kumar Bhaskar [this message]
2022-11-21 20:26 ` [PATCH] tools/cpupower: Choose first online CPU to display details Shuah Khan

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=20221121053530.103600-1-skb99@linux.vnet.ibm.com \
    --to=skb99@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ray.huang@amd.com \
    --cc=shuah@kernel.org \
    --cc=trenn@suse.com \
    /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;
as well as URLs for NNTP newsgroup(s).