From: VMware, Inc <> Date: Mon, 21 Nov 2011 23:20:56 +0000 (-0800) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2011.11.20-535097~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4023b5086bbb390aec9909077c04ccdb374f87e4;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index 49b01d1f1..3a81092a6 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -2418,17 +2418,37 @@ Hostinfo_GetRatedCpuMhz(int32 cpuNumber, // IN: return FALSE; # endif #else - float fMhz = 0; - char *readVal = HostinfoGetCpuInfo(cpuNumber, "cpu MHz"); +#if defined(VMX86_SERVER) + if (HostType_OSIsVMK()) { + uint32 tscKhzEstimate; + VMK_ReturnStatus status = VMKernel_GetTSCkhzEstimate(&tscKhzEstimate); - if (readVal == NULL) { - return FALSE; + /* + * The TSC frequency matches the CPU frequency in all modern CPUs. + * Regardless, the TSC frequency is a much better estimate of + * reality than failing or returning zero. + */ + + *mHz = tscKhzEstimate / 1000; + + return (status == VMK_OK); } +#endif + + { + float fMhz = 0; + char *readVal = HostinfoGetCpuInfo(cpuNumber, "cpu MHz"); + + if (readVal == NULL) { + return FALSE; + } + + if (sscanf(readVal, "%f", &fMhz) == 1) { + *mHz = (unsigned int)(fMhz + 0.5); + } - if (sscanf(readVal, "%f", &fMhz) == 1) { - *mHz = (unsigned int)(fMhz + 0.5); + free(readVal); } - free(readVal); return TRUE; #endif