Commit 39185851 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Don't use a thread from the pool, backend polling is far too long-lived for

that to make sense.

We do not need a mutex for our list, all manipulation is from CLI thread.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3096 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 6b11eec1
...@@ -54,15 +54,12 @@ ...@@ -54,15 +54,12 @@
#include "vrt.h" #include "vrt.h"
#include "cache_backend.h" #include "cache_backend.h"
static MTX vbp_mtx;
struct vbp_target { struct vbp_target {
unsigned magic; unsigned magic;
#define VBP_TARGET_MAGIC 0x6b7cb656 #define VBP_TARGET_MAGIC 0x6b7cb656
struct backend *backend; struct backend *backend;
struct vrt_backend_probe probe; struct vrt_backend_probe probe;
struct workreq wrq;
int stop; int stop;
int req_len; int req_len;
...@@ -72,6 +69,7 @@ struct vbp_target { ...@@ -72,6 +69,7 @@ struct vbp_target {
#undef BITMAP #undef BITMAP
VTAILQ_ENTRY(vbp_target) list; VTAILQ_ENTRY(vbp_target) list;
pthread_t thread;
}; };
static VTAILQ_HEAD(, vbp_target) vbp_list = static VTAILQ_HEAD(, vbp_target) vbp_list =
...@@ -85,7 +83,7 @@ static char default_request[] = ...@@ -85,7 +83,7 @@ static char default_request[] =
static void static void
dsleep(double t) dsleep(double t)
{ {
if (t > 10.0) if (t > 100.0)
(void)sleep((int)round(t)); (void)sleep((int)round(t));
else else
(void)usleep((int)round(t * 1e6)); (void)usleep((int)round(t * 1e6));
...@@ -212,20 +210,15 @@ vbp_poke(struct vbp_target *vt) ...@@ -212,20 +210,15 @@ vbp_poke(struct vbp_target *vt)
* One thread per backend to be poked. * One thread per backend to be poked.
*/ */
static void static void *
vbp_wrk_poll_backend(struct worker *w, void *priv) vbp_wrk_poll_backend(void *priv)
{ {
struct vbp_target *vt; struct vbp_target *vt;
(void)w;
THR_SetName("backend poll"); THR_SetName("backend poll");
CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC); CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC);
LOCK(&vbp_mtx);
VTAILQ_INSERT_TAIL(&vbp_list, vt, list);
UNLOCK(&vbp_mtx);
/* Establish defaults (XXX: Should they go in VCC instead ?) */ /* Establish defaults (XXX: Should they go in VCC instead ?) */
if (vt->probe.request == NULL) if (vt->probe.request == NULL)
vt->probe.request = default_request; vt->probe.request = default_request;
...@@ -247,14 +240,10 @@ vbp_wrk_poll_backend(struct worker *w, void *priv) ...@@ -247,14 +240,10 @@ vbp_wrk_poll_backend(struct worker *w, void *priv)
#include "cache_backend_poll.h" #include "cache_backend_poll.h"
#undef BITMAP #undef BITMAP
vbp_poke(vt); vbp_poke(vt);
dsleep(vt->probe.interval); if (!vt->stop)
dsleep(vt->probe.interval);
} }
LOCK(&vbp_mtx); return (NULL);
VTAILQ_REMOVE(&vbp_list, vt, list);
UNLOCK(&vbp_mtx);
vt->backend->probe = NULL;
FREE_OBJ(vt);
THR_SetName("cache-worker");
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -280,7 +269,7 @@ vbp_bitmap(struct cli *cli, const char *s, uint64_t map, const char *lbl) ...@@ -280,7 +269,7 @@ vbp_bitmap(struct cli *cli, const char *s, uint64_t map, const char *lbl)
/*lint -e{506} constant value boolean */ /*lint -e{506} constant value boolean */
/*lint -e{774} constant value boolean */ /*lint -e{774} constant value boolean */
static void static void
vbp_health_one(struct cli *cli, struct vbp_target *vt) vbp_health_one(struct cli *cli, const struct vbp_target *vt)
{ {
cli_out(cli, "Health stats for backend %s\n", cli_out(cli, "Health stats for backend %s\n",
...@@ -301,6 +290,7 @@ vbp_health(struct cli *cli, const char * const *av, void *priv) ...@@ -301,6 +290,7 @@ vbp_health(struct cli *cli, const char * const *av, void *priv)
{ {
struct vbp_target *vt; struct vbp_target *vt;
ASSERT_CLI();
(void)av; (void)av;
(void)priv; (void)priv;
...@@ -336,21 +326,32 @@ VBP_Start(struct backend *b, struct vrt_backend_probe const *p) ...@@ -336,21 +326,32 @@ VBP_Start(struct backend *b, struct vrt_backend_probe const *p)
vt->probe = *p; vt->probe = *p;
b->probe = vt; b->probe = vt;
vt->wrq.func = vbp_wrk_poll_backend; VTAILQ_INSERT_TAIL(&vbp_list, vt, list);
vt->wrq.priv = vt;
if (WRK_Queue(&vt->wrq) == 0) AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt));
return;
assert(0 == __LINE__);
b->probe = NULL;
FREE_OBJ(vt);
} }
void void
VBP_Stop(struct backend *b) VBP_Stop(struct backend *b)
{ {
struct vbp_target *vt;
void *ret;
CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
ASSERT_CLI();
if (b->probe == NULL) if (b->probe == NULL)
return; return;
b->probe->stop = 1; CHECK_OBJ_NOTNULL(b->probe, VBP_TARGET_MAGIC);
vt = b->probe;
vt->stop = 1;
AZ(pthread_cancel(vt->thread));
AZ(pthread_join(vt->thread, &ret));
VTAILQ_REMOVE(&vbp_list, vt, list);
b->probe = NULL;
FREE_OBJ(vt);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -361,7 +362,5 @@ void ...@@ -361,7 +362,5 @@ void
VBP_Init(void) VBP_Init(void)
{ {
MTX_INIT(&vbp_mtx);
CLI_AddFuncs(DEBUG_CLI, debug_cmds); CLI_AddFuncs(DEBUG_CLI, debug_cmds);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment