[master] 46dd961 Move the stat-summing from WRK to Pool where it mostly happens.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 20 10:44:27 CEST 2014


commit 46dd9617c7d031aa82ca420af95e6579e84d62ad
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 20 08:44:05 2014 +0000

    Move the stat-summing from WRK to Pool where it mostly happens.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 75a64ac..cab075b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1107,6 +1107,8 @@ void Pool_Init(void);
 void Pool_Accept(void);
 void Pool_Work_Thread(void *priv, struct worker *w);
 int Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how);
+void Pool_Sumstat(struct worker *w);
+void Pool_PurgeStat(unsigned nobj);
 
 #define WRW_IsReleased(w)	((w)->wrw == NULL)
 int WRW_Error(const struct worker *w);
@@ -1216,10 +1218,6 @@ void WAIT_Write_Session(struct sess *sp, int fd);
 
 /* cache_wrk.c */
 
-void WRK_Init(void);
-int WRK_TrySumStat(struct worker *w);
-void WRK_SumStat(struct worker *w);
-void WRK_PurgeStat(unsigned nobj);
 void *WRK_thread(void *priv);
 typedef void *bgthread_t(struct worker *, void *priv);
 void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index b5ecfbe..a893ecc 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -404,7 +404,7 @@ EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru)
 	}
 	Lck_Unlock(&lru->mtx);
 
-	WRK_SumStat(wrk);
+	Pool_Sumstat(wrk);
 }
 
 #endif
@@ -589,7 +589,7 @@ exp_thread(struct worker *wrk, void *priv)
 			tnext = 0;
 		} else if (tnext > t) {
 			VSL_Flush(&ep->vsl, 0);
-			WRK_SumStat(wrk);
+			Pool_Sumstat(wrk);
 			(void)Lck_CondWait(&ep->condvar, &ep->mtx, tnext);
 		}
 		Lck_Unlock(&ep->mtx);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index cd48671..73acf01 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -603,7 +603,7 @@ double keep)
 		(void)HSH_DerefObj(&wrk->stats, &o);
 	}
 	WS_Release(wrk->aws, 0);
-	WRK_PurgeStat(nobj);
+	Pool_PurgeStat(nobj);
 }
 
 
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index c6a2599..31d167d 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -217,7 +217,6 @@ child_main(void)
 	VBO_Init();
 	VBE_InitCfg();
 	VBP_Init();
-	WRK_Init();
 	Pool_Init();
 	Pipe_Init();
 
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index fd5a43c..f438b26 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -78,6 +78,59 @@ static struct lock		pool_mtx;
 static pthread_t		thr_pool_herder;
 static unsigned			pool_accepting = 0;
 
+static struct lock		wstat_mtx;
+
+/*--------------------------------------------------------------------*/
+
+static void
+wrk_sumstat(const struct dstat *ds)
+{
+
+	Lck_AssertHeld(&wstat_mtx);
+#define L0(n)
+#define L1(n) (VSC_C_main->n += ds->n)
+#define VSC_F(n, t, l, f, v, d, e) L##l(n);
+#include "tbl/vsc_f_main.h"
+#undef VSC_F
+#undef L0
+#undef L1
+}
+
+void
+Pool_Sumstat(struct worker *w)
+{
+
+	Lck_Lock(&wstat_mtx);
+	wrk_sumstat(&w->stats);
+	Lck_Unlock(&wstat_mtx);
+	memset(&w->stats, 0, sizeof w->stats);
+}
+
+static int
+Pool_TrySumstat(struct worker *w)
+{
+	if (Lck_Trylock(&wstat_mtx))
+		return (0);
+	wrk_sumstat(&w->stats);
+	Lck_Unlock(&wstat_mtx);
+	memset(&w->stats, 0, sizeof w->stats);
+	return (1);
+}
+
+/*--------------------------------------------------------------------
+ * Helper function to update stats for purges under lock
+ */
+
+void
+Pool_PurgeStat(unsigned nobj)
+{
+	Lck_Lock(&wstat_mtx);
+	VSC_C_main->n_purges++;
+	VSC_C_main->n_obj_purged += nobj;
+	Lck_Unlock(&wstat_mtx);
+}
+
+
 /*--------------------------------------------------------------------
  */
 
@@ -148,7 +201,7 @@ pool_accept(struct worker *wrk, void *arg)
 		if (VCA_Accept(ps->lsock, wa) < 0) {
 			wrk->stats.sess_fail++;
 			/* We're going to pace in vca anyway... */
-			(void)WRK_TrySumStat(wrk);
+			(void)Pool_TrySumstat(wrk);
 			continue;
 		}
 
@@ -287,7 +340,7 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
 			wrk->task.priv = wrk;
 			VTAILQ_INSERT_HEAD(&pp->idle_queue, &wrk->task, list);
 			if (stats_dirty) {
-				WRK_SumStat(wrk);
+				Pool_Sumstat(wrk);
 				stats_dirty = 0;
 			}
 			do {
@@ -307,9 +360,9 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
 		tp->func(wrk, tp->priv);
 
 		if (++stats_dirty >= cache_param->wthread_stats_rate) {
-			WRK_SumStat(wrk);
+			Pool_Sumstat(wrk);
 			stats_dirty = 0;
-		} else if (WRK_TrySumStat(wrk))
+		} else if (Pool_TrySumstat(wrk))
 			stats_dirty = 0;
 	}
 	wrk->pool = NULL;
@@ -531,6 +584,7 @@ void
 Pool_Init(void)
 {
 
+	Lck_New(&wstat_mtx, lck_wstat);
 	Lck_New(&pool_mtx, lck_wq);
 	AZ(pthread_create(&thr_pool_herder, NULL, pool_poolherder, NULL));
 }
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 2c266ce..38a662b 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -37,59 +37,6 @@
 #include "cache.h"
 
 #include "hash/hash_slinger.h"
-
-static struct lock		wstat_mtx;
-
-/*--------------------------------------------------------------------*/
-
-static void
-wrk_sumstat(const struct dstat *ds)
-{
-
-	Lck_AssertHeld(&wstat_mtx);
-#define L0(n)
-#define L1(n) (VSC_C_main->n += ds->n)
-#define VSC_F(n, t, l, f, v, d, e) L##l(n);
-#include "tbl/vsc_f_main.h"
-#undef VSC_F
-#undef L0
-#undef L1
-}
-
-void
-WRK_SumStat(struct worker *w)
-{
-
-	Lck_Lock(&wstat_mtx);
-	wrk_sumstat(&w->stats);
-	Lck_Unlock(&wstat_mtx);
-	memset(&w->stats, 0, sizeof w->stats);
-}
-
-int
-WRK_TrySumStat(struct worker *w)
-{
-	if (Lck_Trylock(&wstat_mtx))
-		return (0);
-	wrk_sumstat(&w->stats);
-	Lck_Unlock(&wstat_mtx);
-	memset(&w->stats, 0, sizeof w->stats);
-	return (1);
-}
-
-/*--------------------------------------------------------------------
- * Helper function to update stats for purges under lock
- */
-
-void
-WRK_PurgeStat(unsigned nobj)
-{
-	Lck_Lock(&wstat_mtx);
-	VSC_C_main->n_purges++;
-	VSC_C_main->n_obj_purged += nobj;
-	Lck_Unlock(&wstat_mtx);
-}
-
 /*--------------------------------------------------------------------
  * Create and starte a back-ground thread which as its own worker and
  * session data structures;
@@ -164,7 +111,7 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
 	if (w->nbo != NULL)
 		VBO_Free(&w->nbo);
 	HSH_Cleanup(w);
-	WRK_SumStat(w);
+	Pool_Sumstat(w);
 	return (NULL);
 }
 
@@ -174,9 +121,3 @@ WRK_thread(void *priv)
 
 	return (wrk_thread_real(priv, cache_param->workspace_thread));
 }
-
-void
-WRK_Init(void)
-{
-	Lck_New(&wstat_mtx, lck_wstat);
-}
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index 4e14bdd..4c7e4b5 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -369,7 +369,7 @@ hcb_cleaner(struct worker *wrk, void *priv)
 		VSTAILQ_CONCAT(&dead_y, &cool_y);
 		VTAILQ_CONCAT(&dead_h, &cool_h, hoh_list);
 		Lck_Unlock(&hcb_mtx);
-		WRK_SumStat(wrk);
+		Pool_Sumstat(wrk);
 		VTIM_sleep(cache_param->critbit_cooloff);
 	}
 	NEEDLESS_RETURN(NULL);
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index f27ccd9..f66cd52 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -161,7 +161,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
 		EXP_Inject(oc, sg->lru, so->ttl);
 		sg->nobj++;
 	}
-	WRK_SumStat(wrk);
+	Pool_Sumstat(wrk);
 	sg->flags |= SMP_SEG_LOADED;
 }
 



More information about the varnish-commit mailing list