Untested stab at cpu mhz min/max support for Darwin.

This commit is contained in:
Matthew Kent 2009-08-12 23:41:06 -07:00
parent 09f3418c1a
commit dcddb5f642
2 changed files with 52 additions and 16 deletions

View File

@ -462,32 +462,32 @@ use vars qw(%classes %cmds);
{ {
name => 'vendor', type => 'String', name => 'vendor', type => 'String',
desc => 'CPU vendor id', desc => 'CPU vendor id',
plat => 'AFLHSW' plat => '*'
}, },
{ {
name => 'model', type => 'String', name => 'model', type => 'String',
desc => 'CPU model', desc => 'CPU model',
plat => 'AFLHSW' plat => '*'
}, },
{ {
name => 'mhz', type => 'Int', name => 'mhz', type => 'Int',
desc => 'Current CPU speed', desc => 'Current CPU speed',
plat => 'AFHLSW' plat => '*'
}, },
{ {
name => 'mhz_max', type => 'Int', name => 'mhz_max', type => 'Int',
desc => 'Maximum CPU speed', desc => 'Maximum CPU speed',
plat => 'L' plat => 'DL'
}, },
{ {
name => 'mhz_min', type => 'Int', name => 'mhz_min', type => 'Int',
desc => 'Maximum CPU speed', desc => 'Maximum CPU speed',
plat => 'L' plat => 'DL'
}, },
{ {
name => 'cache_size', type => 'Long', name => 'cache_size', type => 'Long',
desc => 'CPU cache size', desc => 'CPU cache size',
plat => 'AL' plat => 'ADL'
}, },
{ {
name => 'total_cores', type => 'Int', name => 'total_cores', type => 'Int',

View File

@ -2237,6 +2237,8 @@ int sigar_file_system_usage_get(sigar_t *sigar,
#ifdef DARWIN #ifdef DARWIN
#define CTL_HW_FREQ "hw.cpufrequency" #define CTL_HW_FREQ "hw.cpufrequency"
#define CTL_HW_FREQ_MAX "hw.cpufrequency_max"
#define CTL_HW_FREQ_MIN "hw.cpufrequency_min"
#else #else
/* XXX FreeBSD 5.x+ only? */ /* XXX FreeBSD 5.x+ only? */
#define CTL_HW_FREQ "machdep.tsc_freq" #define CTL_HW_FREQ "machdep.tsc_freq"
@ -2246,7 +2248,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_info_list_t *cpu_infos) sigar_cpu_info_list_t *cpu_infos)
{ {
int i; int i;
unsigned int mhz; unsigned int mhz, mhz_min, mhz_max;
int cache_size=SIGAR_FIELD_NOTIMPL; int cache_size=SIGAR_FIELD_NOTIMPL;
size_t size; size_t size;
char model[128], vendor[128], *ptr; char model[128], vendor[128], *ptr;
@ -2257,24 +2259,48 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
#if defined(DARWIN) #if defined(DARWIN)
{ {
int mib[] = { CTL_HW, HW_CPU_FREQ }; int mib[2];
mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
size = sizeof(mhz); size = sizeof(mhz);
if (sysctl(mib, NMIB(mib), &mhz, &size, NULL, 0) < 0) { if (sysctl(mib, NMIB(mib), &mhz, &size, NULL, 0) < 0) {
mhz = SIGAR_FIELD_NOTIMPL; mhz = SIGAR_FIELD_NOTIMPL;
} }
mib[1] = HW_CPU_FREQ_MAX;
size = sizeof(mhz_max);
if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) {
mhz_max = SIGAR_FIELD_NOTIMPL;
}
mib[1] = HW_CPU_FREQ_MIN;
size = sizeof(mhz_min);
if (sysctl(mib, NMIB(mib), &mhz_max, &size, NULL, 0) < 0) {
mhz_min = SIGAR_FIELD_NOTIMPL;
}
} }
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
if (sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0) < 0) { if (sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0) < 0) {
mhz = SIGAR_FIELD_NOTIMPL; mhz = SIGAR_FIELD_NOTIMPL;
} }
/* TODO */
mhz_max = SIGAR_FIELD_NOTIMPL;
mhz_min = SIGAR_FIELD_NOTIMPL;
#else #else
/*XXX OpenBSD*/ /*XXX OpenBSD*/
mhz = SIGAR_FIELD_NOTIMPL; mhz = SIGAR_FIELD_NOTIMPL;
mhz_max = SIGAR_FIELD_NOTIMPL;
mhz_min = SIGAR_FIELD_NOTIMPL;
#endif #endif
if (mhz != SIGAR_FIELD_NOTIMPL) { if (mhz != SIGAR_FIELD_NOTIMPL) {
mhz /= 1000000; mhz /= 1000000;
} }
if (mhz_max != SIGAR_FIELD_NOTIMPL) {
mhz_max /= 1000000;
}
if (mhz_min != SIGAR_FIELD_NOTIMPL) {
mhz_min /= 1000000;
}
size = sizeof(model); size = sizeof(model);
#ifdef __OpenBSD__ #ifdef __OpenBSD__
@ -2297,6 +2323,14 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
/* freebsd4 */ /* freebsd4 */
mhz = sigar_cpu_mhz_from_model(model); mhz = sigar_cpu_mhz_from_model(model);
} }
/* XXX not sure */
if (mhz_max == SIGAR_FIELD_NOTIMPL) {
mhz_max = 0;
}
if (mhz_min == SIGAR_FIELD_NOTIMPL) {
mhz_min = 0;
}
#ifdef DARWIN #ifdef DARWIN
size = sizeof(vendor); size = sizeof(vendor);
@ -2351,6 +2385,8 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
sigar_cpu_model_adjust(sigar, info); sigar_cpu_model_adjust(sigar, info);
info->mhz = mhz; info->mhz = mhz;
info->mhz_max = mhz_max;
info->mhz_min = mhz_min;
info->cache_size = cache_size; info->cache_size = cache_size;
info->total_cores = sigar->ncpu; info->total_cores = sigar->ncpu;
info->cores_per_socket = sigar->lcpu; info->cores_per_socket = sigar->lcpu;