From e8f0f534bab72cecdaf6b5822324d71884cb9133 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Kamalesh Babulal 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 , Nathan Lynch , Naveen N . Rao , Gautham R . Shenoy , Vasant Hegde 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 --- 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