From 6bc0d4f1e181c2254b7e35f9b3f77128f663a525 Mon Sep 17 00:00:00 2001 Message-Id: <6bc0d4f1e181c2254b7e35f9b3f77128f663a525.1587532692.git.kamalesh@linux.vnet.ibm.com> In-Reply-To: References: From: Kamalesh Babulal Date: Tue, 21 Apr 2020 08:00:49 -0500 Subject: [PATCH V4 06/14] lparstat: Read SPURR, Idle_{PURR, SPURR} values To: powerpc-utils-devel@googlegroups.com Cc: Tyrel Datwyler , Nathan Lynch , Naveen N . Rao , Gautham R . Shenoy , Vasant Hegde Parse per-cpu /sys/devices/system/cpu/cpu/{spurr, idle_purr, idle_spurr} files to accumulate system wide SPURR, Idle PURR, Idle SPURR values like PURR value captured in /proc/powerpc/lparcfg. Calculating scaled utilization metrics, need them. Signed-off-by: Kamalesh Babulal --- src/lparstat.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lparstat.h | 11 +++++++++ 2 files changed, 71 insertions(+) diff --git a/src/lparstat.c b/src/lparstat.c index f5c0ce5..7c55a8c 100644 --- a/src/lparstat.c +++ b/src/lparstat.c @@ -165,6 +165,61 @@ error: return -1; } +int parse_sysfs_values(void) +{ + unsigned long long spurr, idle_spurr, idle_purr, value; + char line[SYSDATA_VALUE_SZ]; + struct sysentry *se; + int i, rc; + + spurr = idle_spurr = idle_purr = 0UL; + + for (i = 0; cpu_sysfs_fds[i].spurr > 0; i++) { + rc = pread(cpu_sysfs_fds[i].spurr, (void *)line, sizeof(line), 0); + if (rc == -1) { + fprintf(stderr, "Failed to /sys/devices/system/cpu/cpu%d/spurr\n", + cpu_sysfs_fds[i].cpu); + goto error; + } + + value = strtoll(line, NULL, 16); + spurr += value; + + rc = pread(cpu_sysfs_fds[i].idle_purr, (void *)line, sizeof(line), 0); + if (rc == -1) { + fprintf(stderr, "Failed to /sys/devices/system/cpu/cpu%d/idle_purr\n", + cpu_sysfs_fds[i].cpu); + goto error; + } + + value = strtoll(line, NULL, 16); + idle_purr += value; + + rc = pread(cpu_sysfs_fds[i].idle_spurr, (void *)line, sizeof(line), 0); + if (rc == -1) { + fprintf(stderr, "Failed to /sys/devices/system/cpu/cpu%d/idle_spurr\n", + cpu_sysfs_fds[i].cpu); + goto error; + } + + value = strtoll(line, NULL, 16); + idle_spurr += value; + } + + se = get_sysentry("spurr"); + sprintf(se->value, "%llu", spurr); + se = get_sysentry("idle_purr"); + sprintf(se->value, "%llu", idle_purr); + se = get_sysentry("idle_spurr"); + sprintf(se->value, "%llu", idle_spurr); + + return 0; + +error: + close_cpu_sysfs_fds(threads_in_system); + return -1; +} + static void sig_int_handler(int signal) { close_cpu_sysfs_fds(threads_in_system); @@ -750,11 +805,16 @@ void init_sysinfo(void) void init_sysdata(void) { + int rc = 0; + get_time(); parse_lparcfg(); parse_proc_stat(); parse_proc_ints(); get_time_base(); + rc = parse_sysfs_values(); + if (rc) + exit(rc); } void update_sysdata(void) diff --git a/src/lparstat.h b/src/lparstat.h index 617737b..eec59d6 100644 --- a/src/lparstat.h +++ b/src/lparstat.h @@ -266,6 +266,17 @@ struct sysentry system_data[] = { .descr = "System Uptime", .get = &get_sys_uptime}, + /* /sys/devices/system/cpu/cpu/ */ + /* Sum of per CPU SPURR registers */ + {.name = "spurr", + .descr = "Scaled Processor Utilization Resource Register"}, + /* Sum of per CPU Idle PURR Values */ + {.name = "idle_purr", + .descr = "Processor Utilization Resource Idle Values"}, + /* Sum of per CPU Idle SPURR Values */ + {.name = "idle_spurr", + .descr = "Scaled Processor Utilization Resource Idle Values"}, + {.name[0] = '\0'}, }; -- 2.25.3