Fix incorrect max cpu frequency

This commit is contained in:
Vitezslav Crhonek 2013-06-06 16:08:05 +02:00
parent f79262bde9
commit 4dd24b2fc1
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,64 @@
diff --git a/OSBase_Processor.c b/OSBase_Processor.c
index 9556a77..bae0e32 100644
--- a/OSBase_Processor.c
+++ b/OSBase_Processor.c
@@ -36,8 +36,9 @@ static int _processor_data( int, struct cim_processor ** );
static unsigned short _processor_family( int );
static unsigned short _processor_load_perc( int );
char * CPUINFO = "/proc/cpuinfo";
+char * CPUMAXFREQ = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
//char * CPUINFO = "/home/heidineu/local/sblim/cmpi-base-cpuinfo/x86_ibm_xSeries_2x";
//char * CPUINFO = "/home/heidineu/local/sblim/cmpi-base-cpuinfo/x86_ibm_xSeries_4x";
//char * CPUINFO = "/home/heidineu/local/sblim/cmpi-base-cpuinfo/x86_64_AMD";
@@ -246,8 +247,11 @@ static int _processor_data( int id, struct cim_processor ** sptr ) {
char * ptr = NULL;
int count = 0;
int lines = 0;
int rc = 0;
+ char * maxcpufreq = NULL;
+ unsigned long maxMHz = 0;
+ FILE *fp;
_OSBASE_TRACE(4,("--- _processor_data() called"));
count = id;
@@ -345,8 +349,20 @@ static int _processor_data( int id, struct cim_processor ** sptr ) {
cmd = (char *)malloc((strlen(CPUINFO)+64));
strcpy(cmd, "cat ");
strcat(cmd, CPUINFO);
#if defined (INTEL) || defined (X86_64) || defined (IA64)
+ /* if /sys/devices/system/cpu/cpu(id]/cpufreq/cpuinfo_max_freq exists */
+ /* then calculate MaxClockSpeed from there, otherwise the cpufreq module */
+ /* is not loaded, and /proc/cpuinfo always shows maximum speed */
+ maxcpufreq = malloc((strlen(CPUMAXFREQ)+5));
+ sprintf(maxcpufreq, "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", id);
+ if ((fp = fopen(maxcpufreq, "r")) > 0) {
+ if (1 == fscanf(fp, "%lu", &maxMHz)) {
+ maxMHz = maxMHz / 1000;
+ _OSBASE_TRACE(3,("--- _processor_data() maxMHz = %lu", maxMHz));
+ }
+ fclose(fp);
+ }
strcat(cmd, " | grep 'cpu MHz'");
rc = runcommand( cmd, NULL, &hdout, NULL );
#elif defined (S390) || defined (MIPS)
rc = 0; /* clock speed cannot be determined on zSeries or mips */
@@ -379,11 +395,15 @@ static int _processor_data( int id, struct cim_processor ** sptr ) {
ptr = strchr( hdout[id], ':');
#endif
ptr = ptr+1;
(*sptr)->curClockSpeed = atol(ptr);
- (*sptr)->maxClockSpeed = atol(ptr);
+ if (maxMHz > 0)
+ (*sptr)->maxClockSpeed = maxMHz;
+ else
+ (*sptr)->maxClockSpeed = atol(ptr);
}
freeresultbuf(hdout);
+ if (maxcpufreq) free(maxcpufreq);
if(cmd) free(cmd);
_OSBASE_TRACE(4,("--- _processor_data() exited"));
return 0;

View File

@ -1,6 +1,6 @@
Name: sblim-cmpi-base
Version: 1.6.2
Release: 2%{?dist}
Release: 3%{?dist}
Summary: SBLIM CMPI Base Providers
Group: Applications/System
@ -11,6 +11,8 @@ Patch0: sblim-cmpi-base-1.6.0-missing-fclose.patch
Patch1: sblim-cmpi-base-1.6.0-methods-enable.patch
Patch2: sblim-cmpi-base-1.6.0-provider-register-sfcb-init.patch
Patch3: sblim-cmpi-base-1.6.1-double-fclose.patch
# Patch4: already upstream, http://sourceforge.net/p/sblim/bugs/2634/
Patch4: sblim-cmpi-base-1.6.2-max-cpu-frequency.patch
Requires: cim-server sblim-indication_helper
BuildRequires: sblim-cmpi-devel sblim-indication_helper-devel
@ -47,6 +49,7 @@ Testcase Files for the SBLIM Testsuite.
%patch1 -p0 -b .methods-enable
%patch2 -p1 -b .provider-register-sfcb-init
%patch3 -p1 -b .double-fclose
%patch4 -p1 -b .cpu-freq
%build
%configure TESTSUITEDIR=%{_datadir}/sblim-testsuite --disable-static
@ -176,6 +179,9 @@ fi
%postun -p /sbin/ldconfig
%changelog
* Thu Jun 06 2013 Vitezslav Crhonek <vcrhonek@redhat.com> - 1.6.2-3
- Fix incorrect max cpu frequency
* Thu Feb 14 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.6.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild