powerpc-utils/SOURCES/0003-lparstat-Read-the-onli...

100 lines
2.7 KiB
Diff

From 9263de80d08451beacc29e4eb83492234d648796 Mon Sep 17 00:00:00 2001
Message-Id: <9263de80d08451beacc29e4eb83492234d648796.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:54:01 -0500
Subject: [PATCH V4 03/14] lparstat: Read the online cores
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>
The accumulation of PURR/SPURR values are total of all online CPU in
the system, hence the timebase also needs to be scaled to the number
of cores. Add a helper to read the online cores.
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
---
src/lparstat.c | 32 ++++++++++++++++++++++++++++++++
src/lparstat.h | 4 ++++
2 files changed, 36 insertions(+)
diff --git a/src/lparstat.c b/src/lparstat.c
index b7cb2d2..1d0b3a7 100644
--- a/src/lparstat.c
+++ b/src/lparstat.c
@@ -88,6 +88,11 @@ static int parse_smt_state(void)
return __do_smt(false, cpus_in_system, threads_per_cpu, false);
}
+static int get_one_smt_state(int core)
+{
+ return __get_one_smt_state(core, threads_per_cpu);
+}
+
void get_time()
{
struct timeval t;
@@ -556,6 +561,31 @@ void get_smt_mode(struct sysentry *se, char *buf)
sprintf(buf, "%d", smt_state);
}
+void get_online_cores(void)
+{
+ struct sysentry *se;
+ int *core_state;
+ int online_cores = 0;
+ int i;
+
+ core_state = calloc(cpus_in_system, sizeof(int));
+ if (!core_state) {
+ fprintf(stderr, "Failed to read online cores\n");
+ return;
+ }
+
+ for (i = 0; i < cpus_in_system; i++) {
+ core_state[i] = (get_one_smt_state(i) > 0);
+ if (core_state[i])
+ online_cores++;
+ }
+
+ se = get_sysentry("online_cores");
+ sprintf(se->value, "%d", online_cores);
+
+ free(core_state);
+}
+
long long get_cpu_time_diff()
{
long long old_total = 0, new_total = 0;
@@ -591,6 +621,8 @@ void init_sysinfo(void)
fprintf(stderr, "Failed to capture system CPUs information\n");
exit(rc);
}
+
+ get_online_cores();
}
void init_sysdata(void)
diff --git a/src/lparstat.h b/src/lparstat.h
index ae84caf..6b65b48 100644
--- a/src/lparstat.h
+++ b/src/lparstat.h
@@ -189,6 +189,10 @@ struct sysentry system_data[] = {
.descr = "SMT",
.get = &get_smt_mode},
+ /* online cores, cpu_info_helpers::get_one_smt_state() */
+ {.name = "online_cores",
+ .descr = "Online Cores"},
+
/* /proc/stat */
{.name = "cpu_total",
.descr = "CPU Total Time"},
--
2.25.3