Blame SOURCES/powerpc-utils-01c9cbcf.patch

956c23
commit 01c9cbcf4face809cb6953bc3cd2a30cd075ed16
956c23
Author: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
956c23
Date:   Thu Dec 6 17:30:38 2018 -0600
956c23
956c23
    lparstat: correct calculation of physc to use tbr
956c23
    
956c23
    Currently phsyc is calculated using the sampled PURR values from lparcfg and
956c23
    a derived timebase that lparstat itself calculates. However, both the Timer
956c23
    Facilities section in Book III of the ISA and PAPR outline that this resource
956c23
    calcuation is done by computing the ratio of the PURR delta and the Timebase
956c23
    Register delta for the sampled period.
956c23
    
956c23
    I've sent a patch upstream to the kernel list to also export the Timebase
956c23
    Register (tbr) in /proc/ppc64/lparcfg [1]. Use this value for calculating
956c23
    physc value when running on a kernel that exposes tbr.
956c23
    
956c23
    [1] https://patchwork.ozlabs.org/patch/1009906/
956c23
    
956c23
    Signed-off-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
956c23
956c23
diff --git a/src/lparstat.c b/src/lparstat.c
956c23
index 23e45f7..ec57c1a 100644
956c23
--- a/src/lparstat.c
956c23
+++ b/src/lparstat.c
956c23
@@ -155,17 +155,27 @@ void get_cpu_physc(struct sysentry *unused_se, char *buf)
956c23
 	float elapsed;
956c23
 	float new_purr, old_purr;
956c23
 	float timebase, physc;
956c23
-
956c23
-	elapsed = elapsed_time() / 1000000.0;
956c23
-
956c23
-	se = get_sysentry("timebase");
956c23
-	timebase = atoi(se->value);
956c23
+	float new_tb, old_tb;
956c23
 
956c23
 	se = get_sysentry("purr");
956c23
 	new_purr = strtoll(se->value, NULL, 0);
956c23
 	old_purr = strtoll(se->old_value, NULL, 0);
956c23
 
956c23
-	physc = (new_purr - old_purr)/timebase/elapsed;
956c23
+	se = get_sysentry("tbr");
956c23
+	if (se->value[0] != '\0') {
956c23
+		new_tb = strtoll(se->value, NULL, 0);
956c23
+		old_tb = strtoll(se->old_value, NULL, 0);
956c23
+
956c23
+		physc = (new_purr - old_purr) / (new_tb - old_tb);
956c23
+	} else {
956c23
+		elapsed = elapsed_time() / 1000000.0;
956c23
+
956c23
+		se = get_sysentry("timebase");
956c23
+		timebase = atoi(se->value);
956c23
+
956c23
+		physc = (new_purr - old_purr)/timebase/elapsed;
956c23
+	}
956c23
+
956c23
 	sprintf(buf, "%.6f", physc);
956c23
 }
956c23
 
956c23
diff --git a/src/lparstat.h b/src/lparstat.h
956c23
index c447692..3aee192 100644
956c23
--- a/src/lparstat.h
956c23
+++ b/src/lparstat.h
956c23
@@ -129,6 +129,8 @@ struct sysentry system_data[] = {
956c23
 	 .descr = "Virtual Processor Dispersions"},
956c23
 	{.name = "purr",
956c23
 	 .descr = "Processor Utilization Resource Register"},
956c23
+	{.name = "tbr",
956c23
+	 .descr = "Timebase Register"},
956c23
 	{.name = "partition_active_processors",
956c23
 	 .descr = "Online Virtual CPUs"},
956c23
 	{.name = "partition_potential_processors",