[master] fff848208 optimize vbp_thread wakeup

Nils Goroll nils.goroll at uplex.de
Wed Apr 17 11:41:06 UTC 2019


commit fff848208dc2efd495f4e6aead6a898c2fca3f18
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Apr 17 13:31:25 2019 +0200

    optimize vbp_thread wakeup
    
    We only need to wake up vbp_thread if the probe we insert on the binheap
    has become the next due. As a binheap_root() call is cheap and saves
    posting many signals, this optimization should be worth some extra
    lines.
    
    Also we add a function for the two places where we insert into the heap.
    
    Ref #2976

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index c99b0abea..c87c73465 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -409,6 +409,17 @@ vbp_poke(struct vbp_target *vt)
 		vt->happy |= 1;
 }
 
+/*--------------------------------------------------------------------
+ */
+static void
+vbp_heap_insert(struct vbp_target *vt)
+{
+	// Lck_AssertHeld(&vbp_mtx);
+	binheap_insert(vbp_heap, vt);
+	if (binheap_root(vbp_heap) == vt)
+		AZ(pthread_cond_signal(&vbp_cond));
+}
+
 /*--------------------------------------------------------------------
  */
 
@@ -438,8 +449,7 @@ vbp_task(struct worker *wrk, void *priv)
 		if (vt->heap_idx != BINHEAP_NOIDX) {
 			vt->due = VTIM_real() + vt->interval;
 			binheap_delete(vbp_heap, vt->heap_idx);
-			binheap_insert(vbp_heap, vt);
-			AZ(pthread_cond_signal(&vbp_cond));
+			vbp_heap_insert(vt);
 		}
 	}
 	Lck_Unlock(&vbp_mtx);
@@ -638,8 +648,7 @@ VBP_Control(const struct backend *be, int enable)
 	if (enable) {
 		assert(vt->heap_idx == BINHEAP_NOIDX);
 		vt->due = VTIM_real();
-		binheap_insert(vbp_heap, vt);
-		AZ(pthread_cond_signal(&vbp_cond));
+		vbp_heap_insert(vt);
 	} else {
 		assert(vt->heap_idx != BINHEAP_NOIDX);
 		binheap_delete(vbp_heap, vt->heap_idx);


More information about the varnish-commit mailing list