]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Mon, 21 Nov 2011 23:20:56 +0000 (15:20 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 21 Nov 2011 23:20:56 +0000 (15:20 -0800)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/misc/hostinfoPosix.c

index 49b01d1f1c2ac3aefe1ac033617faf505dc1ab58..3a81092a601aa4472c8bed75e278cadbfa9cad72 100644 (file)
@@ -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