summaryrefslogtreecommitdiffstats
path: root/netbsd
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-08-30 19:26:50 +0200
committerBenBE <BenBE@geshi.org>2021-09-03 12:17:45 +0200
commit2844429f15b8bdf790aad064ecce505ad4b0440c (patch)
tree3325dc05b65380c99ff1f8ded8c781397c6eceb6 /netbsd
parent3834f2a68f167044256604d68aab8d4a5d5265d9 (diff)
NetBSD: scale CPU frequencies
Use a value type of 'long int' to avoid ENOMEM failures of sysctl(3). Also check for "machdep.tsc_freq", scaled in MHz.
Diffstat (limited to 'netbsd')
-rw-r--r--netbsd/NetBSDProcessList.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/netbsd/NetBSDProcessList.c b/netbsd/NetBSDProcessList.c
index 4ab62e4f..84520505 100644
--- a/netbsd/NetBSDProcessList.c
+++ b/netbsd/NetBSDProcessList.c
@@ -39,14 +39,17 @@ static long fscale;
static int pageSize;
static int pageSizeKB;
-static char const *freqSysctls[] = {
- "machdep.est.frequency.current",
- "machdep.powernow.frequency.current",
- "machdep.intrepid.frequency.current",
- "machdep.loongson.frequency.current",
- "machdep.cpu.frequency.current",
- "machdep.frequency.current",
- NULL
+static const struct {
+ const char* name;
+ long int scale;
+} freqSysctls[] = {
+ { "machdep.est.frequency.current", 1 },
+ { "machdep.powernow.frequency.current", 1 },
+ { "machdep.intrepid.frequency.current", 1 },
+ { "machdep.loongson.frequency.current", 1 },
+ { "machdep.cpu.frequency.current", 1 },
+ { "machdep.frequency.current", 1 },
+ { "machdep.tsc_freq", 1000000 },
};
static void NetBSDProcessList_updateCPUcount(ProcessList* super) {
@@ -428,7 +431,7 @@ static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
unsigned int cpus = this->super.existingCPUs;
bool match = false;
char name[64];
- int freq = 0;
+ long int freq = 0;
size_t freqSize;
for (unsigned int i = 0; i < cpus; i++) {
@@ -440,7 +443,7 @@ static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
xSnprintf(name, sizeof(name), "machdep.cpufreq.cpu%u.current", i);
freqSize = sizeof(freq);
if (sysctlbyname(name, &freq, &freqSize, NULL, 0) != -1) {
- this->cpuData[i + 1].frequency = freq;
+ this->cpuData[i + 1].frequency = freq; /* already in MHz */
match = true;
}
}
@@ -453,9 +456,10 @@ static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
* Iterate through legacy sysctl nodes for single-core frequency until
* we find a match...
*/
- for (const char** s = freqSysctls; *s != NULL; ++s) {
+ for (size_t i = 0; i < ARRAYSIZE(freqSysctls); i++) {
freqSize = sizeof(freq);
- if (sysctlbyname(*s, &freq, &freqSize, NULL, 0) != -1) {
+ if (sysctlbyname(freqSysctls[i].name, &freq, &freqSize, NULL, 0) != -1) {
+ freq /= freqSysctls[i].scale; /* scale to MHz */
match = true;
break;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy