From e8eaf6d544270dfb42bbea77597a6b50c309bca0 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 11 Dec 2007 09:03:51 +0000 Subject: [PATCH] Attempt to name threads if possible. On FreeBSD this means that for instance "top -H" will show the varnish threads as "cache-foo" for various values of foo, hopefully giving us another debugging hint. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2293 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 +++ varnish-cache/bin/varnishd/cache_acceptor.c | 1 + .../bin/varnishd/cache_acceptor_epoll.c | 1 + .../bin/varnishd/cache_acceptor_kqueue.c | 1 + .../bin/varnishd/cache_acceptor_poll.c | 1 + varnish-cache/bin/varnishd/cache_expire.c | 2 ++ varnish-cache/bin/varnishd/cache_main.c | 23 +++++++++++++++++++ varnish-cache/bin/varnishd/cache_pool.c | 1 + 8 files changed, 33 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 46a95809..8ff828d8 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -506,6 +506,9 @@ int HTC_Complete(struct http_conn *htc); #include "http_headers.h" #undef HTTPH +/* cache_main.c */ +void THR_Name(const char *name); + /* cache_pipe.c */ void PipeSession(struct sess *sp); diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 9a82bc07..1e014e97 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -154,6 +154,7 @@ vca_acct(void *arg) unsigned u; double now; + THR_Name("cache-acceptor"); (void)arg; /* Set up the poll argument */ diff --git a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c index 34c1c9bf..21e62a8c 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c @@ -73,6 +73,7 @@ vca_main(void *arg) struct sess *sp, *sp2; int i; + THR_Name("cache-epoll"); (void)arg; epfd = epoll_create(16); diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index 128e7948..943ac37f 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -233,6 +233,7 @@ vca_kqueue_main(void *arg) double deadline; struct sess *sp; + THR_Name("cache-kqueue"); (void)arg; kq = kqueue(); diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index f0f82ddd..b74f89a2 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -112,6 +112,7 @@ vca_main(void *arg) double deadline; int i, fd; + THR_Name("cache-poll"); (void)arg; vca_poll(vca_pipes[0]); diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 5595fe70..3f8318a5 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -114,6 +114,7 @@ exp_hangman(void *arg) struct object *o; double t; + THR_Name("cache-hangman"); (void)arg; t = TIM_real(); @@ -167,6 +168,7 @@ exp_prefetch(void *arg) struct object *o2; unsigned char log[1024]; /* XXX size ? */ + THR_Name("cache-timeout"); (void)arg; sp = SES_New(NULL, 0); diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index 4882d2b1..7b41eb60 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -39,6 +39,27 @@ #include "heritage.h" #include "stevedore.h" +/*-------------------------------------------------------------------- + * Name threads if our pthreads implementation supports it. + */ + +#ifdef HAVE_PTHREAD_NP_H +#include +#endif + +void +THR_Name(const char *name) +{ +#ifdef HAVE_PTHREAD_SET_NAME_NP + pthread_set_name_np(pthread_self(), name); +#else + /* + * XXX: we could stash it somewhere else (TLS ?) + */ + (void)name; +#endif +} + /*-------------------------------------------------------------------- * XXX: Think more about which order we start things */ @@ -51,6 +72,8 @@ child_main(void) setbuf(stderr, NULL); printf("Child starts\n"); + THR_Name("cache-main"); + #define SZOF(foo) printf("sizeof(%s) = %zd\n", #foo, sizeof(foo)); SZOF(struct ws); SZOF(struct http); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 96c6bb30..dba99507 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -205,6 +205,7 @@ wrk_thread(void *priv) char c; unsigned char wlog[8192]; /* XXX: size */ + THR_Name("cache-worker"); w = &ww; qp = priv; memset(w, 0, sizeof *w); -- 2.39.5