From: VMware, Inc <> Date: Mon, 26 Jul 2010 19:05:45 +0000 (-0700) Subject: lib/lock: Detect contention in multiple ways X-Git-Tag: 2010.07.25-280253~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6a1434770ab2efb29600cd432ead8b110772cd22;p=thirdparty%2Fopen-vm-tools.git lib/lock: Detect contention in multiple ways 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 --- diff --git a/open-vm-tools/lib/lock/ulStats.c b/open-vm-tools/lib/lock/ulStats.c index 8315cd5b9..0f62194f4 100644 --- a/open-vm-tools/lib/lock/ulStats.c +++ b/open-vm-tools/lib/lock/ulStats.c @@ -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; } /*