[master] 0942fd55b add debug bit to count contended locks
Nils Goroll
nils.goroll at uplex.de
Mon Feb 11 10:18:03 UTC 2019
commit 0942fd55bd51faeab8dd9765aac14db129ddf502
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Feb 11 11:16:40 2019 +0100
add debug bit to count contended locks
Thank you to phk for the improvement over the initial suggestion
diff --git a/bin/varnishd/VSC_lck.vsc b/bin/varnishd/VSC_lck.vsc
index 1a6b6ee8b..0470964a5 100644
--- a/bin/varnishd/VSC_lck.vsc
+++ b/bin/varnishd/VSC_lck.vsc
@@ -30,5 +30,27 @@
:oneliner: Lock Operations
+.. varnish_vsc:: dbg_busy
+ :type: counter
+ :level: debug
+ :oneliner: Contended lock operations
+
+ If the ``lck`` debug bit is set: Lock operations which
+ returned EBUSY on the first locking attempt.
+
+ If the ``lck`` debug bit is unset, this counter will never be
+ incremented even if lock operations are contended.
+
+.. varnish_vsc:: dbg_try_fail
+ :type: counter
+ :level: debug
+ :oneliner: Contended trylock operations
+
+ If the ``lck`` debug bit is set: Trylock operations which
+ returned EBUSY.
+
+ If the ``lck`` debug bit is unset, this counter will never be
+ incremented even if lock operations are contended.
+
.. varnish_vsc_end:: lck
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 30cbbab4a..af21c7ba4 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -107,11 +107,20 @@ void v_matchproto_()
Lck__Lock(struct lock *lck, const char *p, int l)
{
struct ilck *ilck;
+ int r = EINVAL;
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
if (DO_DEBUG(DBG_WITNESS))
Lck_Witness_Lock(ilck, p, l, "");
- AZ(pthread_mutex_lock(&ilck->mtx));
+ else if (DO_DEBUG(DBG_LCK)) {
+ r = pthread_mutex_trylock(&ilck->mtx);
+ if (r == EBUSY)
+ ilck->stat->dbg_busy++;
+ else
+ AZ(r);
+ }
+ if (r)
+ AZ(pthread_mutex_lock(&ilck->mtx));
AZ(ilck->held);
ilck->stat->locks++;
ilck->owner = pthread_self();
@@ -162,7 +171,8 @@ Lck__Trylock(struct lock *lck, const char *p, int l)
ilck->held = 1;
ilck->stat->locks++;
ilck->owner = pthread_self();
- }
+ } else if (DO_DEBUG(DBG_LCK))
+ ilck->stat->dbg_try_fail++;
return (r);
}
diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h
index 8bf099d5d..83206e80d 100644
--- a/include/tbl/debug_bits.h
+++ b/include/tbl/debug_bits.h
@@ -51,6 +51,7 @@ DEBUG_BIT(VMOD_SO_KEEP, vmod_so_keep, "Keep copied VMOD libraries")
DEBUG_BIT(PROCESSORS, processors, "Fetch/Deliver processors")
DEBUG_BIT(PROTOCOL, protocol, "Protocol debugging")
DEBUG_BIT(VCL_KEEP, vcl_keep, "Keep VCL C and so files")
+DEBUG_BIT(LCK, lck, "Additional lock statistics")
#undef DEBUG_BIT
/*lint -restore */
More information about the varnish-commit
mailing list