Merge commit 'mdkent/SIGAR-178'

This commit is contained in:
Doug MacEachern 2009-08-13 15:34:37 -07:00
commit 326d6085a2
5 changed files with 84 additions and 17 deletions

View File

@ -462,34 +462,44 @@ 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 => 'CPU speed', desc => 'Current CPU speed',
plat => 'AFHLSW' plat => '*'
},
{
name => 'mhz_max', type => 'Int',
desc => 'Maximum CPU speed',
plat => 'DL'
},
{
name => 'mhz_min', type => 'Int',
desc => 'Maximum CPU speed',
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',
desc => 'Total CPU cores (logical)', desc => 'Total CPU cores (logical)',
}, },
{ {
name => 'total_sockets', type => 'Int', name => 'total_sockets', type => 'Int',
desc => 'Total CPU sockets (physical)', desc => 'Total CPU sockets (physical)',
}, },
{ {
name => 'cores_per_socket', type => 'Int', name => 'cores_per_socket', type => 'Int',
desc => 'Number of CPU cores per CPU socket', desc => 'Number of CPU cores per CPU socket',
}, },
], ],
Uptime => [ Uptime => [
@ -2065,8 +2075,8 @@ EOF
my $member = $field->{member} || $name; my $member = $field->{member} || $name;
my $desc = $field->{desc} || $name; my $desc = $field->{desc} || $name;
(my $jname = $name) =~ s/_(\w)/\u$1/g; (my $jname = $name) =~ s/_(\w)/\u$1/g;
my $getter = "get\u$jname"; my $getter = "get\u$jname";
$jname = jname($jname); $jname = jname($jname);
my $sig = qq("$field_types{$type}"); my $sig = qq("$field_types{$type}");
my $set = "JENV->Set${type}Field"; my $set = "JENV->Set${type}Field";
my $get = "JENV->Get${type}Field"; my $get = "JENV->Get${type}Field";

View File

@ -11,6 +11,8 @@ puts num.to_s + " total CPUs.."
infos.each do |info| infos.each do |info|
puts "Vendor........" + info.vendor puts "Vendor........" + info.vendor
puts "Model........." + info.model puts "Model........." + info.model
puts "Mhz..........." + info.mhz.to_s puts "Current Mhz..." + info.mhz.to_s
puts "Maximum Mhz..." + info.mhz_max.to_s
puts "Minimum Mhz..." + info.mhz_min.to_s
puts "Cache size...." + info.cache_size.to_s puts "Cache size...." + info.cache_size.to_s
end end

View File

@ -188,6 +188,8 @@ typedef struct {
char vendor[128]; char vendor[128];
char model[128]; char model[128];
int mhz; int mhz;
int mhz_max;
int mhz_min;
sigar_uint64_t cache_size; sigar_uint64_t cache_size;
int total_sockets; int total_sockets;
int total_cores; int total_cores;

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;

View File

@ -1598,7 +1598,23 @@ static void get_cpuinfo_max_freq(sigar_cpu_info_t *cpu_info, int num)
sigar_file2str(max_freq, max_freq, sizeof(max_freq)-1); sigar_file2str(max_freq, max_freq, sizeof(max_freq)-1);
if (status == SIGAR_OK) { if (status == SIGAR_OK) {
cpu_info->mhz = atoi(max_freq) / 1000; cpu_info->mhz_max = atoi(max_freq) / 1000;
}
}
static void get_cpuinfo_min_freq(sigar_cpu_info_t *cpu_info, int num)
{
int status;
char min_freq[PATH_MAX];
snprintf(min_freq, sizeof(min_freq),
"/sys/devices/system/cpu/cpu%d"
"/cpufreq/cpuinfo_min_freq", num);
status =
sigar_file2str(min_freq, min_freq, sizeof(min_freq)-1);
if (status == SIGAR_OK) {
cpu_info->mhz_min = atoi(min_freq) / 1000;
} }
} }
@ -1624,6 +1640,7 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
info = &cpu_infos->data[cpu_infos->number]; info = &cpu_infos->data[cpu_infos->number];
get_cpuinfo_max_freq(info, cpu_infos->number); get_cpuinfo_max_freq(info, cpu_infos->number);
get_cpuinfo_min_freq(info, cpu_infos->number);
info->total_cores = sigar->ncpu; info->total_cores = sigar->ncpu;
info->cores_per_socket = sigar->lcpu; info->cores_per_socket = sigar->lcpu;