mirror of https://github.com/xzeldon/htop.git
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.
This commit is contained in:
parent
3834f2a68f
commit
2844429f15
|
@ -39,14 +39,17 @@ static long fscale;
|
||||||
static int pageSize;
|
static int pageSize;
|
||||||
static int pageSizeKB;
|
static int pageSizeKB;
|
||||||
|
|
||||||
static char const *freqSysctls[] = {
|
static const struct {
|
||||||
"machdep.est.frequency.current",
|
const char* name;
|
||||||
"machdep.powernow.frequency.current",
|
long int scale;
|
||||||
"machdep.intrepid.frequency.current",
|
} freqSysctls[] = {
|
||||||
"machdep.loongson.frequency.current",
|
{ "machdep.est.frequency.current", 1 },
|
||||||
"machdep.cpu.frequency.current",
|
{ "machdep.powernow.frequency.current", 1 },
|
||||||
"machdep.frequency.current",
|
{ "machdep.intrepid.frequency.current", 1 },
|
||||||
NULL
|
{ "machdep.loongson.frequency.current", 1 },
|
||||||
|
{ "machdep.cpu.frequency.current", 1 },
|
||||||
|
{ "machdep.frequency.current", 1 },
|
||||||
|
{ "machdep.tsc_freq", 1000000 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void NetBSDProcessList_updateCPUcount(ProcessList* super) {
|
static void NetBSDProcessList_updateCPUcount(ProcessList* super) {
|
||||||
|
@ -428,7 +431,7 @@ static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
|
||||||
unsigned int cpus = this->super.existingCPUs;
|
unsigned int cpus = this->super.existingCPUs;
|
||||||
bool match = false;
|
bool match = false;
|
||||||
char name[64];
|
char name[64];
|
||||||
int freq = 0;
|
long int freq = 0;
|
||||||
size_t freqSize;
|
size_t freqSize;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < cpus; i++) {
|
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);
|
xSnprintf(name, sizeof(name), "machdep.cpufreq.cpu%u.current", i);
|
||||||
freqSize = sizeof(freq);
|
freqSize = sizeof(freq);
|
||||||
if (sysctlbyname(name, &freq, &freqSize, NULL, 0) != -1) {
|
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;
|
match = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,9 +456,10 @@ static void NetBSDProcessList_scanCPUFrequency(NetBSDProcessList* this) {
|
||||||
* Iterate through legacy sysctl nodes for single-core frequency until
|
* Iterate through legacy sysctl nodes for single-core frequency until
|
||||||
* we find a match...
|
* we find a match...
|
||||||
*/
|
*/
|
||||||
for (const char** s = freqSysctls; *s != NULL; ++s) {
|
for (size_t i = 0; i < ARRAYSIZE(freqSysctls); i++) {
|
||||||
freqSize = sizeof(freq);
|
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;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue