From: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
To: cpufreq@vger.kernel.org, linux@brodo.de,
sergey.dryabzhinsky@gmail.com, linux@dominikbrodowski.net
Cc: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Subject: [PATCH] cpufrequtils: Report offline cpus in cpufreq-info
Date: Mon, 28 Nov 2016 14:12:30 +0530 [thread overview]
Message-ID: <1480322550-13655-1-git-send-email-akshay.adiga@linux.vnet.ibm.com> (raw)
cpufrequtils did not check if the cpu is online and reported the
frequency anyways, which could be misleading to the user.
Added support to detect if the requested cpu is offline and
report that its offline.
When cpu 3 is offline the output would look as follows :
$./cpufreq-info -c 3
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
CPU 3 is Offline
Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
---
lib/sysfs.c | 28 ++++++++++++++++++++++++++--
utils/info.c | 7 ++++++-
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 24dd563..9448499 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -28,7 +28,6 @@ unsigned int sysfs_read_file(unsigned int cpu, const char *fname, char *buf, siz
char path[SYSFS_PATH_MAX];
int fd;
size_t numread;
-
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpufreq/%s",
cpu, fname);
@@ -192,14 +191,39 @@ static int sysfs_write_one_value(unsigned int cpu, unsigned int which,
int sysfs_cpu_exists(unsigned int cpu)
{
- char file[SYSFS_PATH_MAX];
+ char online[2], file[SYSFS_PATH_MAX];
struct stat statbuf;
+ int len, fd;
snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/", cpu);
if ( stat(file, &statbuf) != 0 )
return -ENOSYS;
+ snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/online", cpu);
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ /*
+ * cpuX directory exists but cpuX/online does not. This
+ * could because of cpu is not hotpluggable, which means
+ * its online.
+ */
+ return 0;
+ }
+
+ len = read(fd, online, 2);
+ if (len < 1) {
+ printf("Could not read cpu%u/online file\n", cpu);
+ close(fd);
+ return len;
+ }
+ /* Returning 1 if its offline */
+ if (online[0] == '0') {
+ close(fd);
+ return 1;
+ }
+ close(fd);
+
return S_ISDIR(statbuf.st_mode) ? 0 : -ENOSYS;
}
diff --git a/utils/info.c b/utils/info.c
index 155e604..3b8fee6 100644
--- a/utils/info.c
+++ b/utils/info.c
@@ -159,10 +159,15 @@ static void debug_output_one(unsigned int cpu)
struct cpufreq_policy *policy;
struct cpufreq_available_governors * governors;
struct cpufreq_stats *stats;
+ int offline;
- if (cpufreq_cpu_exists(cpu)) {
+ offline = cpufreq_cpu_exists(cpu);
+ if (offline < 0) {
printf(gettext ("couldn't analyze CPU %d as it doesn't seem to be present\n"), cpu);
return;
+ } else if (offline == 1) {
+ printf(gettext("CPU %d is Offline\n"), cpu);
+ return;
}
printf(gettext ("analyzing CPU %d:\n"), cpu);
--
2.5.5
reply other threads:[~2016-11-28 8:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1480322550-13655-1-git-send-email-akshay.adiga@linux.vnet.ibm.com \
--to=akshay.adiga@linux.vnet.ibm.com \
--cc=cpufreq@vger.kernel.org \
--cc=linux@brodo.de \
--cc=linux@dominikbrodowski.net \
--cc=sergey.dryabzhinsky@gmail.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).