Blob Blame History Raw
From 9f4055e95380a19a824f13cd3e629d2e73be075f Mon Sep 17 00:00:00 2001
Message-Id: <9f4055e95380a19a824f13cd3e629d2e73be075f.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 08:05:45 -0500
Subject: [PATCH V4 08/14] lparstat: Derive effective 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>

Effective/current operating frequency is derived by following:

Effective frequency = (delta SPURR / delta PURR) * nominal frequency

it required to calculate the scaled variants using SPURR, whereas
the currently computed values based on the PURR.
performed.

Effective frequency is derived from PURR/SPURR values, hence call
get_frequency() after function updating sysfs values.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
---
 src/lparstat.c | 23 +++++++++++++++++++++++
 src/lparstat.h |  3 +++
 2 files changed, 26 insertions(+)

diff --git a/src/lparstat.c b/src/lparstat.c
index 152e5fa..0f9dffc 100644
--- a/src/lparstat.c
+++ b/src/lparstat.c
@@ -352,6 +352,28 @@ int get_nominal_frequency(void)
 	return 0;
 }
 
+void get_effective_frequency()
+{
+	struct sysentry *se;
+	double delta_purr, delta_spurr;
+	double nominal_freq, effective_freq;
+
+	se = get_sysentry("nominal_freq");
+	nominal_freq = strtol(se->value, NULL, 10);
+
+	/*
+	 * Calculate the Effective Frequency (EF)
+	 * EF = (delta SPURR / delta PURR) * nominal frequency
+	 */
+	delta_purr = get_delta_value("purr");
+	delta_spurr = get_delta_value("spurr");
+
+	effective_freq = (delta_spurr / delta_purr) * nominal_freq;
+
+	se = get_sysentry("effective_freq");
+	sprintf(se->value, "%f", effective_freq);
+}
+
 void get_cpu_physc(struct sysentry *unused_se, char *buf)
 {
 	struct sysentry *se;
@@ -830,6 +852,7 @@ void init_sysdata(void)
 	rc = parse_sysfs_values();
 	if (rc)
 		exit(rc);
+	get_effective_frequency();
 }
 
 void update_sysdata(void)
diff --git a/src/lparstat.h b/src/lparstat.h
index eec59d6..5e91d67 100644
--- a/src/lparstat.h
+++ b/src/lparstat.h
@@ -256,6 +256,9 @@ struct sysentry system_data[] = {
 	 .descr = "Timebase"},
 	{.name = "nominal_freq",
 	 .descr = "Nominal Frequency"},
+	/* derived from nominal freq */
+	{.name = "effective_freq",
+	 .descr = "Effective Frequency"},
 
 	/* /proc/interrupts */
 	{.name = "phint",
-- 
2.25.3