]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/lock: Detect contention in multiple ways
authorVMware, Inc <>
Mon, 26 Jul 2010 19:05:45 +0000 (12:05 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 26 Jul 2010 19:05:45 +0000 (12:05 -0700)
The locking code can detect contention in two ways:

a) The number of failed acquisitions divided by the
total number of acquisitions.

b) Detected contention while successfully acquiring.

Use the larger of these two to report the contention ratio
for statistics. This provides a more flexible way to detect
any contention, regardless of how/what is reported.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/lock/ulStats.c

index 8315cd5b9a2f19a9f1432e62f0ff5f394fca0ccd..0f62194f426fe16a7db2297cf865433e0c48d853 100644 (file)
@@ -653,9 +653,23 @@ MXUserKitchen(MXUserAcquisitionStats *stats,  // IN:
    if (stats->numAttempts == 0) {
       *contentionRatio = 0.0;
    } else {
-      uint64 failures = stats->numAttempts - stats->numSuccesses;
+      double basic;
+      double acquisition;
 
-      *contentionRatio = ((double) failures) / ((double) stats->numAttempts);
+      /*
+       * Contention shows up in two ways - failed attempts to acquire
+       * and detected contention while acquiring. Determine which is
+       * the largest and use that as the contention ratio for the
+       * specified statistics.
+       */
+
+      basic = ((double) stats->numAttempts - stats->numSuccesses) /
+               ((double) stats->numAttempts);
+
+      acquisition = ((double) stats->numSuccessesContended) /
+                     ((double) stats->numSuccesses);
+
+      *contentionRatio = (basic < acquisition) ? acquisition : basic;
    }
 
    /*