powerpc-utils/SOURCES/0004-lparstat-Capture-nomin...

95 lines
2.4 KiB
Diff

From e8f0f534bab72cecdaf6b5822324d71884cb9133 Mon Sep 17 00:00:00 2001
Message-Id: <e8f0f534bab72cecdaf6b5822324d71884cb9133.1587532692.git.kamalesh@linux.vnet.ibm.com>
In-Reply-To: <cover.1587532692.git.kamalesh@linux.vnet.ibm.com>
References: <cover.1587532692.git.kamalesh@linux.vnet.ibm.com>
From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Date: Tue, 21 Apr 2020 07:55:28 -0500
Subject: [PATCH V4 04/14] lparstat: Capture nominal frequency
To: powerpc-utils-devel@googlegroups.com
Cc: Tyrel Datwyler <tyreld@linux.ibm.com>,
Nathan Lynch <nathanl@linux.ibm.com>,
Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>,
Gautham R . Shenoy <ego@linux.vnet.ibm.com>,
Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Capture the nominal frequency/clock from the /proc/cpuinfo. This value
will be used later to calculate the effective/current frequency at which
the processor is running.
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
---
src/lparstat.c | 36 ++++++++++++++++++++++++++++++++++++
src/lparstat.h | 2 ++
2 files changed, 38 insertions(+)
diff --git a/src/lparstat.c b/src/lparstat.c
index 1d0b3a7..24c48ad 100644
--- a/src/lparstat.c
+++ b/src/lparstat.c
@@ -171,6 +171,38 @@ void get_sys_uptime(struct sysentry *unused_se, char *uptime)
fclose(f);
}
+int get_nominal_frequency(void)
+{
+ FILE *f;
+ char buf[80];
+ struct sysentry *se;
+ char *nfreq = NULL;
+
+ f = fopen("/proc/cpuinfo", "r");
+ if (!f) {
+ fprintf(stderr, "Could not open /proc/cpuinfo\n");
+ return -1;
+ }
+
+ while ((fgets(buf, 80, f)) != NULL) {
+ if (!strncmp(buf, "clock", 5)) {
+ nfreq = strchr(buf, ':') + 2;
+ break;
+ }
+ }
+
+ fclose(f);
+
+ if (!nfreq) {
+ fprintf(stderr, "Failed to read Nominal frequency\n");
+ return -1;
+ }
+
+ se = get_sysentry("nominal_freq");
+ snprintf(se->value, sizeof(se->value), "%s", nfreq);
+
+ return 0;
+}
void get_cpu_physc(struct sysentry *unused_se, char *buf)
{
@@ -623,6 +655,10 @@ void init_sysinfo(void)
}
get_online_cores();
+
+ rc = get_nominal_frequency();
+ if (rc)
+ exit(rc);
}
void init_sysdata(void)
diff --git a/src/lparstat.h b/src/lparstat.h
index 6b65b48..c1bac28 100644
--- a/src/lparstat.h
+++ b/src/lparstat.h
@@ -242,6 +242,8 @@ struct sysentry system_data[] = {
/* /proc/cpuinfo */
{.name = "timebase",
.descr = "Timebase"},
+ {.name = "nominal_freq",
+ .descr = "Nominal Frequency"},
/* /proc/interrupts */
{.name = "phint",
--
2.25.3