From 09f3418c1a7a77bb8ffb215c0f905587f579cc95 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Wed, 12 Aug 2009 22:51:48 -0700 Subject: [PATCH] Add linux collection of cpu min/max. Make cpu mhz default the current mhz. --- bindings/SigarWrapper.pm | 12 +++++++++++- bindings/ruby/examples/cpu_info.rb | 4 +++- include/sigar.h | 2 ++ src/os/linux/linux_sigar.c | 19 ++++++++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 5801f70e..6f79a5c3 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -471,9 +471,19 @@ use vars qw(%classes %cmds); }, { name => 'mhz', type => 'Int', - desc => 'CPU speed', + desc => 'Current CPU speed', plat => 'AFHLSW' }, + { + name => 'mhz_max', type => 'Int', + desc => 'Maximum CPU speed', + plat => 'L' + }, + { + name => 'mhz_min', type => 'Int', + desc => 'Maximum CPU speed', + plat => 'L' + }, { name => 'cache_size', type => 'Long', desc => 'CPU cache size', diff --git a/bindings/ruby/examples/cpu_info.rb b/bindings/ruby/examples/cpu_info.rb index f68a5a80..a38dec8d 100644 --- a/bindings/ruby/examples/cpu_info.rb +++ b/bindings/ruby/examples/cpu_info.rb @@ -11,6 +11,8 @@ puts num.to_s + " total CPUs.." infos.each do |info| puts "Vendor........" + info.vendor 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 end diff --git a/include/sigar.h b/include/sigar.h index d5f5d6a2..003ede19 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -188,6 +188,8 @@ typedef struct { char vendor[128]; char model[128]; int mhz; + int mhz_max; + int mhz_min; sigar_uint64_t cache_size; int total_sockets; int total_cores; diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 1d3a9e1e..008c9bc3 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -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); 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]; get_cpuinfo_max_freq(info, cpu_infos->number); + get_cpuinfo_min_freq(info, cpu_infos->number); info->total_cores = sigar->ncpu; info->cores_per_socket = sigar->lcpu;