[libvirt] [PATCH 0/2] Fix cpuMhz of virNodeGetInfo() don't returns maximum cpu frequency

cpuMhz of virNodeGetInfo() should return maximum cpu frequency. (See. http://fossplanet.com/f13/%5Blibvirt%5D-%5Brfd%5D-add-modify-some-api-functi...) virNodeGetInfo() gets it from "cpu MHz" of /proc/cpuinfo, but this value is scaled by cpu power saving feature. This patch gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, if exist. And if this file doesn't exist, it gets from /proc/cpuinfo. -- Minoru Usui <usui@mxm.nes.nec.co.jp>

virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first. Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp> --- src/nodeinfo.c | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 22d53e5..f4e6e1e 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -60,7 +60,7 @@ # define CPU_SYS_PATH "/sys/devices/system/cpu" /* NB, this is not static as we need to call it from the testsuite */ -int linuxNodeInfoCPUPopulate(FILE *cpuinfo, +int linuxNodeInfoCPUPopulate(FILE *cpuinfo, int cpu_mhz, virNodeInfoPtr nodeinfo, bool need_hyperthreads); @@ -167,7 +167,7 @@ static int parse_socket(unsigned int cpu) return get_cpu_value(cpu, "topology/physical_package_id", false); } -int linuxNodeInfoCPUPopulate(FILE *cpuinfo, +int linuxNodeInfoCPUPopulate(FILE *cpuinfo, int cpu_mhz, virNodeInfoPtr nodeinfo, bool need_hyperthreads) { @@ -182,7 +182,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, int online; nodeinfo->cpus = 0; - nodeinfo->mhz = 0; + nodeinfo->mhz = cpu_mhz; nodeinfo->cores = 1; nodeinfo->nodes = 1; @@ -207,7 +207,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, return -1; } nodeinfo->cpus++; - } else if (STRPREFIX(buf, "cpu MHz")) { + } else if (!cpu_mhz && (STRPREFIX(buf, "cpu MHz"))) { char *p; unsigned int ui; buf += 9; @@ -336,14 +336,29 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) { #ifdef __linux__ { - int ret; - FILE *cpuinfo = fopen(CPUINFO_PATH, "r"); + int ret, cpu_mhz = 0; + FILE *cpuinfo; + + /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000; + } + + cpuinfo = fopen(CPUINFO_PATH, "r"); if (!cpuinfo) { virReportSystemError(errno, _("cannot open %s"), CPUINFO_PATH); return -1; } - ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo, true); + ret = linuxNodeInfoCPUPopulate(cpuinfo, cpu_mhz, nodeinfo, true); VIR_FORCE_FCLOSE(cpuinfo); if (ret < 0) return -1; -- 1.7.1 -- Minoru Usui <usui@mxm.nes.nec.co.jp>

On 01/27/2011 02:51 AM, Minoru Usui wrote:
virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
I haven't looked closely at this series yet...
+ /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000;
But which units is this converting between, and should it truncate or round up? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Hi, Eric On Mon, 31 Jan 2011 15:46:39 -0700 Eric Blake <eblake@redhat.com> wrote:
On 01/27/2011 02:51 AM, Minoru Usui wrote:
virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
I haven't looked closely at this series yet...
+ /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000;
But which units is this converting between, and should it truncate or round up?
I think it divide by 1000 is collect, because my machine returns below values. ----------------------------------------------------------------- # cat /sys/devices/system/cpu/cpu?/cpufreq/cpuinfo_max_freq 2333331 2333331 2333331 2333331 2333331 2333331 2333331 2333331 # grep 'cpu MHz' /proc/cpuinfo cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 ----------------------------------------------------------------- On the other hand, I don't have clear opinion about truncate or round up. Present implementation of linuxNodeInfoCPUPopulate() selects truncate, so I implement to truncate logic. -- Minoru Usui <usui@mxm.nes.nec.co.jp>

Hi, Eric On Tue, 1 Feb 2011 10:26:36 +0900 Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
Hi, Eric
On Mon, 31 Jan 2011 15:46:39 -0700 Eric Blake <eblake@redhat.com> wrote:
On 01/27/2011 02:51 AM, Minoru Usui wrote:
virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
I haven't looked closely at this series yet...
+ /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000;
But which units is this converting between, and should it truncate or round up?
I think it divide by 1000 is collect, because my machine returns below values.
----------------------------------------------------------------- # cat /sys/devices/system/cpu/cpu?/cpufreq/cpuinfo_max_freq 2333331 2333331 2333331 2333331 2333331 2333331 2333331 2333331
# grep 'cpu MHz' /proc/cpuinfo cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 -----------------------------------------------------------------
On the other hand, I don't have clear opinion about truncate or round up. Present implementation of linuxNodeInfoCPUPopulate() selects truncate, so I implement to truncate logic.
Are my explanations enough? If not or I'm misunderstanding something, please let me know. -- Minoru Usui <usui@mxm.nes.nec.co.jp>

2011/2/10 Minoru Usui <usui@mxm.nes.nec.co.jp>:
Hi, Eric
On Tue, 1 Feb 2011 10:26:36 +0900 Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
Hi, Eric
On Mon, 31 Jan 2011 15:46:39 -0700 Eric Blake <eblake@redhat.com> wrote:
On 01/27/2011 02:51 AM, Minoru Usui wrote:
virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
I haven't looked closely at this series yet...
+ /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000;
But which units is this converting between, and should it truncate or round up?
I think it divide by 1000 is collect, because my machine returns below values.
----------------------------------------------------------------- # cat /sys/devices/system/cpu/cpu?/cpufreq/cpuinfo_max_freq 2333331 2333331 2333331 2333331 2333331 2333331 2333331 2333331
# grep 'cpu MHz' /proc/cpuinfo cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 -----------------------------------------------------------------
On the other hand, I don't have clear opinion about truncate or round up. Present implementation of linuxNodeInfoCPUPopulate() selects truncate, so I implement to truncate logic.
Are my explanations enough? If not or I'm misunderstanding something, please let me know.
I think we should round up in case we request something, because then we get at least what we requested. If we truncate a request we might get less than we requested, this might result in a bad situation. Recently we switched from truncation to rounding up for memory and storage request because of this. But here we are reporting something. In that case we should truncate, because if we would round up we could report more than there actually is, this might result in a bad situation too. So with rounding up request and truncating reports we are on the safe side in both cases. Matthias

Hi, Matthias Thank you for your help. On Thu, 10 Feb 2011 19:12:46 +0100 Matthias Bolte <matthias.bolte@googlemail.com> wrote:
2011/2/10 Minoru Usui <usui@mxm.nes.nec.co.jp>:
Hi, Eric
On Tue, 1 Feb 2011 10:26:36 +0900 Minoru Usui <usui@mxm.nes.nec.co.jp> wrote:
Hi, Eric
On Mon, 31 Jan 2011 15:46:39 -0700 Eric Blake <eblake@redhat.com> wrote:
On 01/27/2011 02:51 AM, Minoru Usui wrote:
virNodeGetInfo() gets from /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, first.
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
I haven't looked closely at this series yet...
+ /* + * nodeinfo->mhz should return maximum frequency, + * but "cpu MHz" of /proc/cpuinfo is scaled by power saving feature. + * So it gets cpufreq/cpuinfo_max_freq, if possible. + */ + ret = get_cpu_value(0, "cpufreq/cpuinfo_max_freq", true); + if (ret < 0) + return -1; + else if (ret != 1) { + /* convert unit */ + cpu_mhz = ret / 1000;
But which units is this converting between, and should it truncate or round up?
I think it divide by 1000 is collect, because my machine returns below values.
----------------------------------------------------------------- # cat /sys/devices/system/cpu/cpu?/cpufreq/cpuinfo_max_freq 2333331 2333331 2333331 2333331 2333331 2333331 2333331 2333331
# grep 'cpu MHz' /proc/cpuinfo cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 cpu MHz : 2333.331 -----------------------------------------------------------------
On the other hand, I don't have clear opinion about truncate or round up. Present implementation of linuxNodeInfoCPUPopulate() selects truncate, so I implement to truncate logic.
Are my explanations enough? If not or I'm misunderstanding something, please let me know.
I think we should round up in case we request something, because then we get at least what we requested. If we truncate a request we might get less than we requested, this might result in a bad situation. Recently we switched from truncation to rounding up for memory and storage request because of this.
But here we are reporting something. In that case we should truncate, because if we would round up we could report more than there actually is, this might result in a bad situation too.
So with rounding up request and truncating reports we are on the safe side in both cases.
Matthias
I agree with you. In this case we are reporting cpu MHz, so we should truncate it. Eric, what do you think? -- Minoru Usui <usui@mxm.nes.nec.co.jp>

On 02/13/2011 06:08 PM, Minoru Usui wrote:
So with rounding up request and truncating reports we are on the safe side in both cases.
Matthias
I agree with you. In this case we are reporting cpu MHz, so we should truncate it.
Eric, what do you think?
Truncation works for me. I think these patches have missed the cutoff for 0.8.8, though, so I haven't looked closely at them yet. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Add test for nodeinfo-7 of nodeinfotest for cpu power saving environment. Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp> --- tests/nodeinfodata/linux-nodeinfo-7.cpuinfo | 200 ++++++++++++++++++++ .../nodeinfodata/linux-nodeinfo-7.cpuinfo_max_freq | 1 + tests/nodeinfodata/linux-nodeinfo-7.meminfo | 42 ++++ tests/nodeinfodata/linux-nodeinfo-7.txt | 1 + tests/nodeinfotest.c | 27 +++- 5 files changed, 267 insertions(+), 4 deletions(-) create mode 100644 tests/nodeinfodata/linux-nodeinfo-7.cpuinfo create mode 100644 tests/nodeinfodata/linux-nodeinfo-7.cpuinfo_max_freq create mode 100644 tests/nodeinfodata/linux-nodeinfo-7.meminfo create mode 100644 tests/nodeinfodata/linux-nodeinfo-7.txt diff --git a/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo b/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo new file mode 100644 index 0000000..9cd93cd --- /dev/null +++ b/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo @@ -0,0 +1,200 @@ +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 0 +siblings : 4 +core id : 0 +cpu cores : 4 +apicid : 0 +initial apicid : 0 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4655.76 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 1 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 1 +siblings : 4 +core id : 0 +cpu cores : 4 +apicid : 4 +initial apicid : 4 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4655.87 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 2 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 0 +siblings : 4 +core id : 1 +cpu cores : 4 +apicid : 1 +initial apicid : 1 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.37 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 3 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 583.332 +cache size : 4096 KB +physical id : 1 +siblings : 4 +core id : 1 +cpu cores : 4 +apicid : 5 +initial apicid : 5 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.37 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 4 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 0 +siblings : 4 +core id : 2 +cpu cores : 4 +apicid : 2 +initial apicid : 2 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.35 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 5 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 1 +siblings : 4 +core id : 2 +cpu cores : 4 +apicid : 6 +initial apicid : 6 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.37 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 6 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 0 +siblings : 4 +core id : 3 +cpu cores : 4 +apicid : 3 +initial apicid : 3 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.35 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + +processor : 7 +vendor_id : GenuineIntel +cpu family : 6 +model : 15 +model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz +stepping : 7 +cpu MHz : 291.666 +cache size : 4096 KB +physical id : 1 +siblings : 4 +core id : 3 +cpu cores : 4 +apicid : 7 +initial apicid : 7 +fpu : yes +fpu_exception : yes +cpuid level : 10 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca lahf_lm tpr_shadow +bogomips : 4654.37 +clflush size : 64 +cache_alignment : 64 +address sizes : 36 bits physical, 48 bits virtual +power management: + diff --git a/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo_max_freq b/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo_max_freq new file mode 100644 index 0000000..7fb6fab --- /dev/null +++ b/tests/nodeinfodata/linux-nodeinfo-7.cpuinfo_max_freq @@ -0,0 +1 @@ +2333331 diff --git a/tests/nodeinfodata/linux-nodeinfo-7.meminfo b/tests/nodeinfodata/linux-nodeinfo-7.meminfo new file mode 100644 index 0000000..fa505f5 --- /dev/null +++ b/tests/nodeinfodata/linux-nodeinfo-7.meminfo @@ -0,0 +1,42 @@ +MemTotal: 8058876 kB +MemFree: 3721460 kB +Buffers: 437572 kB +Cached: 2834588 kB +SwapCached: 0 kB +Active: 1478220 kB +Inactive: 2493592 kB +Active(anon): 672096 kB +Inactive(anon): 27776 kB +Active(file): 806124 kB +Inactive(file): 2465816 kB +Unevictable: 0 kB +Mlocked: 0 kB +SwapTotal: 987988 kB +SwapFree: 987988 kB +Dirty: 52 kB +Writeback: 444 kB +AnonPages: 699672 kB +Mapped: 21736 kB +Shmem: 292 kB +Slab: 299148 kB +SReclaimable: 132716 kB +SUnreclaim: 166432 kB +KernelStack: 2328 kB +PageTables: 9592 kB +NFS_Unstable: 1044 kB +Bounce: 0 kB +WritebackTmp: 0 kB +CommitLimit: 5017424 kB +Committed_AS: 2541104 kB +VmallocTotal: 34359738367 kB +VmallocUsed: 68912 kB +VmallocChunk: 34359654804 kB +HardwareCorrupted: 0 kB +AnonHugePages: 624640 kB +HugePages_Total: 0 +HugePages_Free: 0 +HugePages_Rsvd: 0 +HugePages_Surp: 0 +Hugepagesize: 2048 kB +DirectMap4k: 7040 kB +DirectMap2M: 8380416 kB diff --git a/tests/nodeinfodata/linux-nodeinfo-7.txt b/tests/nodeinfodata/linux-nodeinfo-7.txt new file mode 100644 index 0000000..f98ed27 --- /dev/null +++ b/tests/nodeinfodata/linux-nodeinfo-7.txt @@ -0,0 +1 @@ +CPUs: 8, MHz: 2333, Nodes: 1, Cores: 4 diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index c690403..12e4926 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -26,10 +26,13 @@ static char *abs_srcdir; # define MAX_FILE 4096 -extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo, +extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, int cpu_mhz, + virNodeInfoPtr nodeinfo, bool need_hyperthreads); -static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { +static int linuxTestCompareFiles(const char *cpuinfofile, + const int cpu_mhz, + const char *outputfile) { char actualData[MAX_FILE]; char expectData[MAX_FILE]; char *expect = &expectData[0]; @@ -44,7 +47,7 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile return -1; memset(&nodeinfo, 0, sizeof(nodeinfo)); - if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) { + if (linuxNodeInfoCPUPopulate(cpuinfo, cpu_mhz, &nodeinfo, false) < 0) { if (virTestGetDebug()) { virErrorPtr error = virSaveLastError(); if (error && error->code != VIR_ERR_OK) @@ -79,12 +82,27 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile static int linuxTestNodeInfo(const void *data) { char cpuinfo[PATH_MAX]; + char cpuinfo_max_freq[PATH_MAX]; char output[PATH_MAX]; + char maxfreqData[MAX_FILE]; + char *maxfreq = &maxfreqData[0]; + int cpu_mhz = 0; + snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo", abs_srcdir, (const char*)data); + snprintf(cpuinfo_max_freq, PATH_MAX, + "%s/nodeinfodata/linux-%s.cpuinfo_max_freq", + abs_srcdir, (const char*)data); snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt", abs_srcdir, (const char*)data); - return linuxTestCompareFiles(cpuinfo, output); + + if (access(cpuinfo_max_freq, R_OK) == 0) { + if (virtTestLoadFile(cpuinfo_max_freq, &maxfreq, MAX_FILE) < 0) + return -1; + cpu_mhz = atoi(maxfreq) / 1000; + } + + return linuxTestCompareFiles(cpuinfo, cpu_mhz, output); } @@ -100,6 +118,7 @@ mymain(int argc, char **argv) "nodeinfo-4", "nodeinfo-5", "nodeinfo-6", + "nodeinfo-7", }; char cwd[PATH_MAX]; -- 1.7.1 -- Minoru Usui <usui@mxm.nes.nec.co.jp>
participants (3)
-
Eric Blake
-
Matthias Bolte
-
Minoru Usui