Commit 0942fd55 authored by Nils Goroll's avatar Nils Goroll

add debug bit to count contended locks

Thank you to phk for the improvement over the initial suggestion
parent 5ec2db92
......@@ -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
......@@ -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);
}
......
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment