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>
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;
}
/*