[master] 3fc784782 wrk: Track workers to dump them during a panic

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Aug 17 06:57:05 UTC 2021


commit 3fc7847828963d0870b2eb4f4880512209304bfb
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jul 12 07:31:05 2021 +0200

    wrk: Track workers to dump them during a panic
    
    In the most common case of a VCL transaction panicking this should only
    result in an extra "Already dumped, see above" message, but it may give
    more insights for other kinds of tasks.

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index a60e8a584..4b98a8a0f 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -76,6 +76,7 @@ cache_vrnd_unlock(void)
 
 static pthread_key_t req_key;
 static pthread_key_t bo_key;
+static pthread_key_t wrk_key;
 pthread_key_t witness_key;
 
 void
@@ -106,6 +107,20 @@ THR_GetRequest(void)
 	return (pthread_getspecific(req_key));
 }
 
+void
+THR_SetWorker(const struct worker *wrk)
+{
+
+	AZ(pthread_setspecific(wrk_key, wrk));
+}
+
+struct worker *
+THR_GetWorker(void)
+{
+
+	return (pthread_getspecific(wrk_key));
+}
+
 /*--------------------------------------------------------------------
  * Name threads if our pthreads implementation supports it.
  */
@@ -351,6 +366,7 @@ child_main(int sigmagic, size_t altstksz)
 
 	AZ(pthread_key_create(&req_key, NULL));
 	AZ(pthread_key_create(&bo_key, NULL));
+	AZ(pthread_key_create(&wrk_key, NULL));
 	AZ(pthread_key_create(&witness_key, free));
 	AZ(pthread_key_create(&name_key, NULL));
 
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 68309705f..533c9e906 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -712,6 +712,7 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	const char *q;
 	struct req *req;
 	struct busyobj *bo;
+	struct worker *wrk;
 	struct sigaction sa;
 	int err = errno;
 
@@ -794,6 +795,9 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 		pan_busyobj(pan_vsb, bo);
 		if (bo != NULL)
 			VSL_Flush(bo->vsl, 0);
+		wrk = THR_GetWorker();
+		VSB_cat(pan_vsb, "thr.");
+		pan_wrk(pan_vsb, wrk);
 		VMOD_Panic(pan_vsb);
 		pan_pool(pan_vsb);
 	} else {
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 96db999b1..3f5d929f3 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -309,6 +309,8 @@ void THR_SetBusyobj(const struct busyobj *);
 struct busyobj * THR_GetBusyobj(void);
 void THR_SetRequest(const struct req *);
 struct req * THR_GetRequest(void);
+void THR_SetWorker(const struct worker *);
+struct worker * THR_GetWorker(void);
 void THR_Init(void);
 
 /* cache_lck.c */
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 32b53024d..db4139a98 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -145,6 +145,7 @@ WRK_Thread(struct pool *qp, size_t stacksize, unsigned thread_workspace)
 	w->lastused = NAN;
 	memset(&ds, 0, sizeof ds);
 	w->stats = &ds;
+	THR_SetWorker(w);
 	AZ(pthread_cond_init(&w->cond, NULL));
 
 	WS_Init(w->aws, "wrk", ws, thread_workspace);


More information about the varnish-commit mailing list