[master] 611815f Tag threads separately with request and session.

Poul-Henning Kamp phk at varnish-cache.org
Tue Jun 19 11:45:48 CEST 2012


commit 611815fad3537b2815bc6fc6028abc40f53f2477
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 19 09:45:09 2012 +0000

    Tag threads separately with request and session.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 5823943..6ee34ec 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -854,7 +854,9 @@ uint32_t VXID_Get(struct vxid *v);
 extern volatile struct params * cache_param;
 void THR_SetName(const char *name);
 const char* THR_GetName(void);
-void THR_SetSession(const struct sess *sp);
+void THR_SetRequest(const struct req *);
+const struct req * THR_GetRequest(void);
+void THR_SetSession(const struct sess *);
 const struct sess * THR_GetSession(void);
 
 /* cache_lck.c */
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index e29593d..9078834 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -198,7 +198,7 @@ VGZ_ObufFull(const struct vgz *vg)
 }
 
 /*--------------------------------------------------------------------
- * Keep the outbuffer supplied with storage 
+ * Keep the outbuffer supplied with storage
  */
 
 int
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index f038c9e..041578b 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -46,6 +46,7 @@ volatile struct params	*cache_param;
  */
 
 static pthread_key_t sp_key;
+static pthread_key_t req_key;
 
 void
 THR_SetSession(const struct sess *sp)
@@ -61,6 +62,20 @@ THR_GetSession(void)
 	return (pthread_getspecific(sp_key));
 }
 
+void
+THR_SetRequest(const struct req *req)
+{
+
+	AZ(pthread_setspecific(req_key, req));
+}
+
+const struct req *
+THR_GetRequest(void)
+{
+
+	return (pthread_getspecific(req_key));
+}
+
 /*--------------------------------------------------------------------
  * Name threads if our pthreads implementation supports it.
  */
@@ -126,6 +141,7 @@ child_main(void)
 	cache_param = heritage.param;
 
 	AZ(pthread_key_create(&sp_key, NULL));
+	AZ(pthread_key_create(&req_key, NULL));
 	AZ(pthread_key_create(&name_key, NULL));
 
 	THR_SetName("cache-main");
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index c5f49de..af8bf6f 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -228,14 +228,52 @@ pan_busyobj(const struct busyobj *bo)
 /*--------------------------------------------------------------------*/
 
 static void
+pan_req(const struct req *req)
+{
+	const char *hand;
+
+	VSB_printf(pan_vsp, "req = %p {\n", req);
+	VSB_printf(pan_vsp, "  sp = %p, xid = %u,\n", req->sp, req->xid);
+	hand = VCL_Return_Name(req->handling);
+	if (hand != NULL)
+		VSB_printf(pan_vsp, "  handling = %s,\n", hand);
+	else
+		VSB_printf(pan_vsp, "  handling = 0x%x,\n", req->handling);
+	if (req->err_code)
+		VSB_printf(pan_vsp,
+		    "  err_code = %d, err_reason = %s,\n", req->err_code,
+		    req->err_reason ? req->err_reason : "(null)");
+
+	VSB_printf(pan_vsp, "  restarts = %d, esi_level = %d\n",
+	    req->restarts, req->esi_level);
+
+	if (req->busyobj != NULL)
+		pan_busyobj(req->busyobj);
+
+	pan_ws(req->ws, 2);
+	pan_http("req", req->http, 2);
+	if (req->resp->ws != NULL)
+		pan_http("resp", req->resp, 4);
+
+	if (VALID_OBJ(req->vcl, VCL_CONF_MAGIC))
+		pan_vcl(req->vcl);
+
+	if (VALID_OBJ(req->obj, OBJECT_MAGIC))
+		pan_object(req->obj);
+
+	VSB_printf(pan_vsp, "},\n");
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
 pan_sess(const struct sess *sp)
 {
-	const char *stp, *hand;
+	const char *stp;
 
 	VSB_printf(pan_vsp, "sp = %p {\n", sp);
-	VSB_printf(pan_vsp,
-	    "  fd = %d, id = %u, xid = %u,\n",
-	    sp->fd, sp->vsl_id & VSL_IDENTMASK, sp->req->xid);
+	VSB_printf(pan_vsp, "  fd = %d, id = %u,\n",
+	    sp->fd, sp->vsl_id & VSL_IDENTMASK);
 	VSB_printf(pan_vsp, "  client = %s %s,\n",
 	    sp->addr ? sp->addr : "?.?.?.?",
 	    sp->port ? sp->port : "?");
@@ -245,40 +283,14 @@ pan_sess(const struct sess *sp)
 #undef STEP
 		default: stp = NULL;
 	}
-	hand = VCL_Return_Name(sp->req->handling);
 	if (stp != NULL)
 		VSB_printf(pan_vsp, "  step = %s,\n", stp);
 	else
 		VSB_printf(pan_vsp, "  step = 0x%x,\n", sp->step);
-	if (hand != NULL)
-		VSB_printf(pan_vsp, "  handling = %s,\n", hand);
-	else
-		VSB_printf(pan_vsp, "  handling = 0x%x,\n", sp->req->handling);
-	if (sp->req->err_code)
-		VSB_printf(pan_vsp,
-		    "  err_code = %d, err_reason = %s,\n", sp->req->err_code,
-		    sp->req->err_reason ? sp->req->err_reason : "(null)");
-
-	VSB_printf(pan_vsp, "  restarts = %d, esi_level = %d\n",
-	    sp->req->restarts, sp->req->esi_level);
-
-	if (sp->req->busyobj != NULL)
-		pan_busyobj(sp->req->busyobj);
-
-	pan_ws(sp->req->ws, 2);
-	pan_http("req", sp->req->http, 2);
-	if (sp->req->resp->ws != NULL)
-		pan_http("resp", sp->req->resp, 4);
 
 	if (sp->wrk != NULL)
 		pan_wrk(sp->wrk);
 
-	if (VALID_OBJ(sp->req->vcl, VCL_CONF_MAGIC))
-		pan_vcl(sp->req->vcl);
-
-	if (VALID_OBJ(sp->req->obj, OBJECT_MAGIC))
-		pan_object(sp->req->obj);
-
 	VSB_printf(pan_vsp, "},\n");
 }
 
@@ -318,6 +330,7 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 {
 	const char *q;
 	const struct sess *sp;
+	const struct req *req;
 
 	AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
 						  we're going to die
@@ -361,6 +374,9 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 		sp = THR_GetSession();
 		if (sp != NULL)
 			pan_sess(sp);
+		req = THR_GetRequest();
+		if (req != NULL)
+			pan_req(req);
 	}
 	VSB_printf(pan_vsp, "\n");
 	VSB_bcat(pan_vsp, "", 1);	/* NUL termination */
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index f236389..df268f1 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -307,6 +307,7 @@ SES_GetReq(struct sess *sp)
 	req->magic = REQ_MAGIC;
 	sp->req = req;
 	req->sp = sp;
+	THR_SetRequest(req);
 
 	e = (char*)req + sz;
 	p = (char*)(req + 1);
@@ -359,6 +360,7 @@ SES_ReleaseReq(struct sess *sp)
 	sp->req->sp = NULL;
 	MPL_Free(pp->mpl_req, sp->req);
 	sp->req = NULL;
+	THR_SetRequest(NULL);
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list