[experimental-ims] c9d9539 Further Pool/Wrk separation.

Geoff Simmons geoff at varnish-cache.org
Mon Jan 9 21:51:49 CET 2012


commit c9d9539defa9769e688a5af0864fadcdf63ae7e9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Sep 17 09:54:05 2011 +0000

    Further Pool/Wrk separation.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 5b4b575..a6b1786 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -840,10 +840,8 @@ void PipeSession(struct sess *sp);
 
 /* cache_pool.c */
 void Pool_Init(void);
-int WRK_QueueSession(struct sess *sp);
-void WRK_SumStat(struct worker *w);
-int WRK_TrySumStat(struct worker *w);
-void WRK_thread_real(void *priv, struct worker *w);
+int Pool_QueueSession(struct sess *sp);
+void Pool_Work_Thread(void *priv, struct worker *w);
 
 #define WRW_IsReleased(w)	((w)->wrw.wfd == NULL)
 int WRW_Error(const struct worker *w);
@@ -858,9 +856,6 @@ unsigned WRW_WriteH(struct worker *w, const txt *hh, const char *suf);
 void WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len);
 #endif  /* SENDFILE_WORKS */
 
-typedef void *bgthread_t(struct sess *, void *priv);
-void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
-    void *priv);
 
 /* cache_session.c [SES] */
 void SES_Init(void);
@@ -937,7 +932,12 @@ void VMOD_Init(void);
 /* cache_wrk.c */
 
 void WRK_Init(void);
+int WRK_TrySumStat(struct worker *w);
+void WRK_SumStat(struct worker *w);
 void *WRK_thread(void *priv);
+typedef void *bgthread_t(struct sess *, void *priv);
+void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
+    void *priv);
 
 /* cache_ws.c */
 
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 2b3f87e..0692d46 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -319,7 +319,7 @@ vca_acct(void *arg)
 			sp->sockaddrlen = l;
 
 			sp->step = STP_FIRST;
-			if (WRK_QueueSession(sp)) {
+			if (Pool_QueueSession(sp)) {
 				VSC_C_main->client_drop++;
 				pace += params->acceptor_sleep_incr;
 			} else {
@@ -347,7 +347,7 @@ vca_handover(struct sess *sp, int status)
 		break;
 	case 1:
 		sp->step = STP_START;
-		if (WRK_QueueSession(sp))
+		if (Pool_QueueSession(sp))
 			VSC_C_main->client_drop_late++;
 		break;
 	default:
diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c
index 328964a..16e5cf0 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -504,7 +504,7 @@ hsh_rush(struct objhead *oh)
 		AZ(sp->wrk);
 		VTAILQ_REMOVE(&wl->list, sp, list);
 		DSL(0x20, SLT_Debug, sp->id, "off waiting list");
-		if (WRK_QueueSession(sp)) {
+		if (Pool_QueueSession(sp)) {
 			/*
 			 * We could not schedule the session, leave the
 			 * rest on the busy list.
diff --git a/bin/varnishd/cache_pool.c b/bin/varnishd/cache_pool.c
index b7f1f41..a80cd9b 100644
--- a/bin/varnishd/cache_pool.c
+++ b/bin/varnishd/cache_pool.c
@@ -56,7 +56,6 @@
 #include "cache.h"
 #include "stevedore.h"
 #include "hash_slinger.h"
-#include "vsha256.h"
 
 VTAILQ_HEAD(workerhead, worker);
 
@@ -86,7 +85,7 @@ static struct lock		herder_mtx;
 /*--------------------------------------------------------------------*/
 
 void
-WRK_thread_real(void *priv, struct worker *w)
+Pool_Work_Thread(void *priv, struct worker *w)
 {
 	struct wq *qp;
 	int stats_clean;
@@ -217,7 +216,7 @@ wrk_do_cnt_sess(struct worker *w, void *priv)
 /*--------------------------------------------------------------------*/
 
 int
-WRK_QueueSession(struct sess *sp)
+Pool_QueueSession(struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AZ(sp->wrk);
@@ -456,58 +455,6 @@ wrk_herder_thread(void *priv)
 	NEEDLESS_RETURN(NULL);
 }
 
-/*--------------------------------------------------------------------
- * Create and starte a back-ground thread which as its own worker and
- * session data structures;
- */
-
-struct bgthread {
-	unsigned	magic;
-#define BGTHREAD_MAGIC	0x23b5152b
-	const char	*name;
-	bgthread_t	*func;
-	void		*priv;
-};
-
-static void *
-wrk_bgthread(void *arg)
-{
-	struct bgthread *bt;
-	struct worker ww;
-	struct sess *sp;
-	uint32_t logbuf[1024];	/* XXX:  size ? */
-
-	CAST_OBJ_NOTNULL(bt, arg, BGTHREAD_MAGIC);
-	THR_SetName(bt->name);
-	sp = SES_Alloc();
-	XXXAN(sp);
-	memset(&ww, 0, sizeof ww);
-	sp->wrk = &ww;
-	ww.magic = WORKER_MAGIC;
-	ww.wlp = ww.wlb = logbuf;
-	ww.wle = logbuf + (sizeof logbuf) / 4;
-
-	(void)bt->func(sp, bt->priv);
-
-	WRONG("BgThread terminated");
-
-	NEEDLESS_RETURN(NULL);
-}
-
-void
-WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func, void *priv)
-{
-	struct bgthread *bt;
-
-	ALLOC_OBJ(bt, BGTHREAD_MAGIC);
-	AN(bt);
-
-	bt->name = name;
-	bt->func = func;
-	bt->priv = priv;
-	AZ(pthread_create(thr, NULL, wrk_bgthread, bt));
-}
-
 /*--------------------------------------------------------------------*/
 
 void
diff --git a/bin/varnishd/cache_wrk.c b/bin/varnishd/cache_wrk.c
index 9b3bc2b..66ba04b 100644
--- a/bin/varnishd/cache_wrk.c
+++ b/bin/varnishd/cache_wrk.c
@@ -43,7 +43,6 @@
 #include "vcl.h"
 #include "cli_priv.h"
 #include "cache.h"
-#include "stevedore.h"
 #include "hash_slinger.h"
 #include "vsha256.h"
 
@@ -87,6 +86,58 @@ WRK_TrySumStat(struct worker *w)
 	return (1);
 }
 
+/*--------------------------------------------------------------------
+ * Create and starte a back-ground thread which as its own worker and
+ * session data structures;
+ */
+
+struct bgthread {
+	unsigned	magic;
+#define BGTHREAD_MAGIC	0x23b5152b
+	const char	*name;
+	bgthread_t	*func;
+	void		*priv;
+};
+
+static void *
+wrk_bgthread(void *arg)
+{
+	struct bgthread *bt;
+	struct worker ww;
+	struct sess *sp;
+	uint32_t logbuf[1024];	/* XXX:  size ? */
+
+	CAST_OBJ_NOTNULL(bt, arg, BGTHREAD_MAGIC);
+	THR_SetName(bt->name);
+	sp = SES_Alloc();
+	XXXAN(sp);
+	memset(&ww, 0, sizeof ww);
+	sp->wrk = &ww;
+	ww.magic = WORKER_MAGIC;
+	ww.wlp = ww.wlb = logbuf;
+	ww.wle = logbuf + (sizeof logbuf) / 4;
+
+	(void)bt->func(sp, bt->priv);
+
+	WRONG("BgThread terminated");
+
+	NEEDLESS_RETURN(NULL);
+}
+
+void
+WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func, void *priv)
+{
+	struct bgthread *bt;
+
+	ALLOC_OBJ(bt, BGTHREAD_MAGIC);
+	AN(bt);
+
+	bt->name = name;
+	bt->func = func;
+	bt->priv = priv;
+	AZ(pthread_create(thr, NULL, wrk_bgthread, bt));
+}
+
 /*--------------------------------------------------------------------*/
 
 static void *
@@ -123,7 +174,7 @@ wrk_thread_real(void *priv, unsigned shm_workspace, unsigned sess_workspace,
 
 	VSL(SLT_WorkThread, 0, "%p start", w);
 
-	WRK_thread_real(priv, w);
+	Pool_Work_Thread(priv, w);
 
 	VSL(SLT_WorkThread, 0, "%p end", w);
 	if (w->vcl != NULL)



More information about the varnish-commit mailing list