[master] 197bc2a Cache the next idle value rather than frob the waited list.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jan 15 13:20:07 CET 2015


commit 197bc2a25c4b59dcd002743db91e67c01f0ab624
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jan 15 12:19:51 2015 +0000

    Cache the next idle value rather than frob the waited list.

diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 6d88566..8390b72 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -54,7 +54,6 @@ static void *
 wait_poker_thread(void *arg)
 {
 	struct waiter *w;
-	struct waited *wp;
 	double now;
 
 	(void)arg;
@@ -71,14 +70,7 @@ wait_poker_thread(void *arg)
 		VTAILQ_INSERT_TAIL(&waiters, w, list);
 		assert(w->pipes[1] >= 0);
 
-		wp = VTAILQ_FIRST(&w->waithead);
-		CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
-		if (wp == w->pipe_w) {
-			VTAILQ_REMOVE(&w->waithead, wp, list);
-			VTAILQ_INSERT_TAIL(&w->waithead, wp, list);
-			wp = VTAILQ_FIRST(&w->waithead);
-		}
-		if (wp->idle + *w->tmo < now)
+		if (w->next_idle + *w->tmo < now)
 			(void)write(w->pipes[1], &w->pipe_w, sizeof w->pipe_w);
 		Lck_Unlock(&wait_mtx);
 	}
@@ -166,6 +158,22 @@ Wait_Enter(const struct waiter *w, struct waited *wp)
 	return (0);
 }
 
+static void
+wait_updidle(struct waiter *w)
+{
+	struct waited *wp;
+
+	wp = VTAILQ_FIRST(&w->waithead);
+	if (wp == NULL)
+		return;
+	if (wp == w->pipe_w) {
+		VTAILQ_REMOVE(&w->waithead, wp, list);
+		VTAILQ_INSERT_TAIL(&w->waithead, wp, list);
+		wp = VTAILQ_FIRST(&w->waithead);
+	}
+	w->next_idle = wp->idle;
+}
+
 void
 Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 {
@@ -181,6 +189,7 @@ Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 
 		VTAILQ_REMOVE(&w->waithead, wp, list);
 		w->func(wp, ev, now);
+		wait_updidle(w);
 		return;
 	}
 
@@ -213,6 +222,7 @@ Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 		VTAILQ_REMOVE(&w->waithead, wp, list);
 		w->func(wp, WAITER_TIMEOUT, now);
 	}
+	wait_updidle(w);
 }
 
 void
diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h
index ba0d0e5..14b5e6f 100644
--- a/bin/varnishd/waiter/waiter_priv.h
+++ b/bin/varnishd/waiter/waiter_priv.h
@@ -41,6 +41,7 @@ struct waiter {
 
 	int				pipes[2];
 	struct waited			*pipe_w;
+	double				next_idle;
 
 	volatile double			*tmo;
 	VTAILQ_HEAD(,waited)		waithead;



More information about the varnish-commit mailing list