r5213 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Wed Sep 15 11:04:54 CEST 2010


Author: phk
Date: 2010-09-15 11:04:54 +0200 (Wed, 15 Sep 2010)
New Revision: 5213

Added:
   trunk/varnish-cache/bin/varnishd/locks.h
Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
   trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
   trunk/varnish-cache/bin/varnishd/cache_ban.c
   trunk/varnish-cache/bin/varnishd/cache_cli.c
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_lck.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
   trunk/varnish-cache/bin/varnishd/cache_vcl.c
   trunk/varnish-cache/bin/varnishd/flint.lnt
   trunk/varnish-cache/bin/varnishd/hash_classic.c
   trunk/varnish-cache/bin/varnishd/hash_critbit.c
   trunk/varnish-cache/bin/varnishd/hash_simple_list.c
   trunk/varnish-cache/bin/varnishd/storage_file.c
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/bin/varnishd/storage_synth.c
Log:
Classify our locks into kinds, and collect stats for each kind.

This allows us to collect lock collision information without
incurring the overhead of VSL, which should give more relevant
and precise information.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-09-15 09:04:54 UTC (rev 5213)
@@ -89,6 +89,7 @@
 struct cli_proto;
 struct ban;
 struct SHA256Context;
+struct vsc_lck;
 
 struct smp_object;
 struct smp_seg;
@@ -598,7 +599,7 @@
 void Lck__Lock(struct lock *lck, const char *p, const char *f, int l);
 void Lck__Unlock(struct lock *lck, const char *p, const char *f, int l);
 int Lck__Trylock(struct lock *lck, const char *p, const char *f, int l);
-void Lck__New(struct lock *lck, const char *w);
+void Lck__New(struct lock *lck, struct vsc_lck *, const char *);
 void Lck__Assert(const struct lock *lck, int held);
 
 /* public interface: */
@@ -606,13 +607,17 @@
 void Lck_Delete(struct lock *lck);
 void Lck_CondWait(pthread_cond_t *cond, struct lock *lck);
 
-#define Lck_New(a) Lck__New(a, #a);
+#define Lck_New(a, b) Lck__New(a, b, #b)
 #define Lck_Lock(a) Lck__Lock(a, __func__, __FILE__, __LINE__)
 #define Lck_Unlock(a) Lck__Unlock(a, __func__, __FILE__, __LINE__)
 #define Lck_Trylock(a) Lck__Trylock(a, __func__, __FILE__, __LINE__)
 #define Lck_AssertHeld(a) Lck__Assert(a, 1)
 #define Lck_AssertNotHeld(a) Lck__Assert(a, 0)
 
+#define LOCK(nam) extern struct vsc_lck *lck_##nam;
+#include "locks.h"
+#undef LOCK
+
 /* cache_panic.c */
 void PAN_Init(void);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -199,7 +199,7 @@
 	/* Create new backend */
 	ALLOC_OBJ(b, BACKEND_MAGIC);
 	XXXAN(b);
-	Lck_New(&b->mtx);
+	Lck_New(&b->mtx, lck_backend);
 	b->refcount = 1;
 
 	bprintf(buf, "%s(%s,%s,%s)",
@@ -304,6 +304,6 @@
 VBE_Init(void)
 {
 
-	Lck_New(&VBE_mtx);
+	Lck_New(&VBE_mtx, lck_vbe);
 	CLI_AddFuncs(debug_cmds);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -579,6 +579,6 @@
 VBP_Init(void)
 {
 
-	Lck_New(&vbp_mtx);
+	Lck_New(&vbp_mtx, lck_vbp);
 	CLI_AddFuncs(debug_cmds);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -794,7 +794,7 @@
 BAN_Init(void)
 {
 
-	Lck_New(&ban_mtx);
+	Lck_New(&ban_mtx, lck_ban);
 	CLI_AddFuncs(ban_cmds);
 
 	ban_magic = BAN_New();

Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -178,7 +178,7 @@
 CLI_Init(void)
 {
 
-	Lck_New(&cli_mtx);
+	Lck_New(&cli_mtx, lck_cli);
 	cli_thread = pthread_self();
 
 	cls = CLS_New(cli_cb_before, cli_cb_after, params->cli_buffer);

Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -393,7 +393,7 @@
 EXP_Init(void)
 {
 
-	Lck_New(&exp_mtx);
+	Lck_New(&exp_mtx, lck_exp);
 	exp_heap = binheap_new(NULL, object_cmp, object_update);
 	XXXAN(exp_heap);
 	WRK_BgThread(&exp_thread, "cache-timeout", exp_timer, NULL);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -122,7 +122,7 @@
 		oh->refcnt = 1;
 		VTAILQ_INIT(&oh->objcs);
 		VTAILQ_INIT(&oh->waitinglist);
-		Lck_New(&oh->mtx);
+		Lck_New(&oh->mtx, lck_objhdr);
 		w->nobjhead = oh;
 		w->stats.n_objecthead++;
 	}

Modified: trunk/varnish-cache/bin/varnishd/cache_lck.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_lck.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_lck.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -59,6 +59,7 @@
 	pthread_t		owner;
 	VTAILQ_ENTRY(ilck)	list;
 	const char		*w;
+	struct vsc_lck		*stat;
 };
 
 static VTAILQ_HEAD(, ilck)	ilck_head =
@@ -76,6 +77,7 @@
 	if (!(params->diag_bitmap & 0x18)) {
 		AZ(pthread_mutex_lock(&ilck->mtx));
 		AZ(ilck->held);
+		ilck->stat->locks++;
 		ilck->owner = pthread_self();
 		ilck->held = 1;
 		return;
@@ -83,12 +85,16 @@
 	r = pthread_mutex_trylock(&ilck->mtx);
 	assert(r == 0 || r == EBUSY);
 	if (r) {
-		VSL(SLT_Debug, 0, "MTX_CONTEST(%s,%s,%d,%s)", p, f, l, ilck->w);
+		ilck->stat->colls++;
+		if (params->diag_bitmap & 0x8)
+			VSL(SLT_Debug, 0, "MTX_CONTEST(%s,%s,%d,%s)",
+			    p, f, l, ilck->w);
 		AZ(pthread_mutex_lock(&ilck->mtx));
 	} else if (params->diag_bitmap & 0x8) {
 		VSL(SLT_Debug, 0, "MTX_LOCK(%s,%s,%d,%s)", p, f, l, ilck->w);
 	}
 	AZ(ilck->held);
+	ilck->stat->locks++;
 	ilck->owner = pthread_self();
 	ilck->held = 1;
 }
@@ -157,7 +163,7 @@
 }
 
 void
-Lck__New(struct lock *lck, const char *w)
+Lck__New(struct lock *lck, struct vsc_lck *st, const char *w)
 {
 	struct ilck *ilck;
 
@@ -165,6 +171,8 @@
 	ALLOC_OBJ(ilck, ILCK_MAGIC);
 	AN(ilck);
 	ilck->w = w;
+	ilck->stat = st;
+	ilck->stat->creat++;
 	AZ(pthread_mutex_init(&ilck->mtx, NULL));
 	AZ(pthread_mutex_lock(&lck_mtx));
 	VTAILQ_INSERT_TAIL(&ilck_head, ilck, list);
@@ -178,6 +186,7 @@
 	struct ilck *ilck;
 
 	CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
+	ilck->stat->destroy++;
 	lck->priv = NULL;
 	AZ(pthread_mutex_lock(&lck_mtx));
 	VTAILQ_REMOVE(&ilck_head, ilck, list);
@@ -186,12 +195,20 @@
 	FREE_OBJ(ilck);
 }
 
+#define LOCK(nam) struct vsc_lck *lck_##nam;
+#include "locks.h"
+#undef LOCK
 
 void
 LCK_Init(void)
 {
 
 	AZ(pthread_mutex_init(&lck_mtx, NULL));
+#define LOCK(nam) 						\
+	lck_##nam = VSM_Alloc(sizeof(struct vsc_lck), 		\
+	   VSC_CLASS, VSC_TYPE_LCK, #nam);
+#include "locks.h"
+#undef LOCK
 }
 
 /*lint -restore */

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -347,7 +347,7 @@
 		wq[u] = calloc(sizeof *wq[0], 1);
 		XXXAN(wq[u]);
 		wq[u]->magic = WQ_MAGIC;
-		Lck_New(&wq[u]->mtx);
+		Lck_New(&wq[u]->mtx, lck_wq);
 		VTAILQ_INIT(&wq[u]->overflow);
 		VTAILQ_INIT(&wq[u]->idle);
 	}
@@ -597,8 +597,8 @@
 	pthread_t tp;
 
 	AZ(pthread_cond_init(&herder_cond, NULL));
-	Lck_New(&herder_mtx);
-	Lck_New(&wstat_mtx);
+	Lck_New(&herder_mtx, lck_herder);
+	Lck_New(&wstat_mtx, lck_wstat);
 
 	wrk_addpools(params->wthread_pools);
 	AZ(pthread_create(&tp, NULL, wrk_herdtimer_thread, NULL));

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -295,6 +295,6 @@
 SES_Init()
 {
 
-	Lck_New(&stat_mtx);
-	Lck_New(&ses_mem_mtx);
+	Lck_New(&stat_mtx, lck_stat);
+	Lck_New(&ses_mem_mtx, lck_sessmem);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -344,5 +344,5 @@
 {
 
 	CLI_AddFuncs(vcl_cmds);
-	Lck_New(&vcl_mtx);
+	Lck_New(&vcl_mtx, lck_vcl);
 }

Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt	2010-09-15 09:04:54 UTC (rev 5213)
@@ -68,6 +68,7 @@
 -efile(451, "sys/\*.h")	// No include guard
 -efile(451, "machine/\*.h")	// No include guard
 -efile(451, "vcl_returns.h")	// No include guard
+-efile(451, "locks.h")	// No include guard
 -efile(451, "cache_backend_poll.h")	// No include guard
 -efile(451, "steps.h")	// No include guard
 -efile(451, "http_headers.h")	// No include guard

Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_classic.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/hash_classic.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -100,7 +100,7 @@
 
 	for (u = 0; u < hcl_nhash; u++) {
 		VTAILQ_INIT(&hcl_head[u].head);
-		Lck_New(&hcl_head[u].mtx);
+		Lck_New(&hcl_head[u].mtx, lck_hcl);
 		hcl_head[u].magic = HCL_HEAD_MAGIC;
 	}
 }

Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_critbit.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/hash_critbit.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -387,7 +387,7 @@
 
 	(void)oh;
 	CLI_AddFuncs(hcb_cmds);
-	Lck_New(&hcb_mtx);
+	Lck_New(&hcb_mtx, lck_hcb);
 	AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL));
 	memset(&hcb_root, 0, sizeof hcb_root);
 	hcb_build_bittbl();

Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_simple_list.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -55,7 +55,7 @@
 hsl_start(void)
 {
 
-	Lck_New(&hsl_mtx);
+	Lck_New(&hsl_mtx, lck_hsl);
 }
 
 /*--------------------------------------------------------------------

Added: trunk/varnish-cache/bin/varnishd/locks.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/locks.h	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/locks.h	2010-09-15 09:04:54 UTC (rev 5213)
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2010 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+/*lint -save -e525 -e539 */
+LOCK(sms)
+LOCK(smp)
+LOCK(sma)
+LOCK(smf)
+LOCK(hsl)
+LOCK(hcb)
+LOCK(hcl)
+LOCK(vcl)
+LOCK(stat)
+LOCK(sessmem)
+LOCK(wstat)
+LOCK(herder)
+LOCK(wq)
+LOCK(objhdr)
+LOCK(exp)
+LOCK(cli)
+LOCK(ban)
+LOCK(vbp)
+LOCK(vbe)
+LOCK(backend)
+/*lint -restore */

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -439,7 +439,7 @@
 
 	sc = st->priv;
 
-	Lck_New(&sc->mtx);
+	Lck_New(&sc->mtx, lck_smf);
 	Lck_Lock(&sc->mtx);
 	smf_open_chunk(sc, sc->filesize, 0, &fail, &sum);
 	Lck_Unlock(&sc->mtx);

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -187,7 +187,7 @@
 	struct sma_sc *sma_sc;
 
 	CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
-	Lck_New(&sma_sc->sma_mtx);
+	Lck_New(&sma_sc->sma_mtx, lck_sma);
 	sma_sc->stats = VSM_Alloc(sizeof *sma_sc->stats,
 	    VSC_CLASS, VSC_TYPE_SMA, st->ident);
 	memset(sma_sc->stats, 0, sizeof *sma_sc->stats);

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -1228,7 +1228,7 @@
 
 	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
 
-	Lck_New(&sc->mtx);
+	Lck_New(&sc->mtx, lck_smp);
 	Lck_Lock(&sc->mtx);
 
 	sc->objbuf = malloc(sizeof *sc->objbuf * sc->aim_nobj);

Modified: trunk/varnish-cache/bin/varnishd/storage_synth.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_synth.c	2010-09-15 08:53:25 UTC (rev 5212)
+++ trunk/varnish-cache/bin/varnishd/storage_synth.c	2010-09-15 09:04:54 UTC (rev 5213)
@@ -64,7 +64,7 @@
 SMS_Init(void)
 {
 
-	Lck_New(&sms_mtx);
+	Lck_New(&sms_mtx, lck_sms);
 }
 
 static struct stevedore sms_stevedore = {




More information about the varnish-commit mailing list