Permalink
Browse files

add debug bit to count contended locks

Thank you to phk for the improvement over the initial suggestion
  • Loading branch information...
nigoroll committed Feb 11, 2019
1 parent 5ec2db9 commit 0942fd55bd51faeab8dd9765aac14db129ddf502
Showing with 35 additions and 2 deletions.
  1. +22 −0 bin/varnishd/VSC_lck.vsc
  2. +12 −2 bin/varnishd/cache/cache_lck.c
  3. +1 −0 include/tbl/debug_bits.h
@@ -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 */

0 comments on commit 0942fd5

Please sign in to comment.