[master] 7532c3a7e Eliminate a level of structure on vrt_privs, the extra 'magic' does not buy us anything because the compiler can see at all times what goes on.

Poul-Henning Kamp phk at FreeBSD.org
Fri Nov 8 08:53:06 UTC 2019


commit 7532c3a7ed6c12635af1a2278e024fe61a351568
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Nov 8 08:52:00 2019 +0000

    Eliminate a level of structure on vrt_privs, the extra 'magic' does
    not buy us anything because the compiler can see at all times what
    goes on.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 40f1f9185..3c3f1ba94 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -199,13 +199,7 @@ struct vxid_pool {
 
 /*--------------------------------------------------------------------*/
 
-VRBT_HEAD(vrt_priv_tree,vrt_priv);
-
-struct vrt_privs {
-	unsigned		magic;
-#define VRT_PRIVS_MAGIC		0x03ba7502
-	struct vrt_priv_tree	privs;
-};
+VRBT_HEAD(vrt_privs, vrt_priv);
 
 /* Worker pool stuff -------------------------------------------------*/
 
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 6eac91434..98b7f9a74 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -153,8 +153,6 @@ VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **pbo)
 	AZ(bo->htc);
 	AZ(bo->stale_oc);
 
-	AZ(bo->privs->magic);
-
 	VSLb(bo->vsl, SLT_BereqAcct, "%ju %ju %ju %ju %ju %ju",
 	    (uintmax_t)bo->acct.bereq_hdrbytes,
 	    (uintmax_t)bo->acct.bereq_bodybytes,
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 8fb6ec7f2..767903682 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -212,8 +212,6 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 	req->director_hint = NULL;
 	req->restarts = 0;
 
-	AZ(req->privs->magic);
-
 	if (req->vcl != NULL)
 		VCL_Recache(wrk, &req->vcl);
 
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 650ce3a6c..4fb23dd92 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -1082,7 +1082,6 @@ CNT_Request(struct req *req)
 
 	AN(req->vsl->wid & VSL_CLIENTMARKER);
 	AN(req->vcl);
-	CHECK_OBJ(req->privs, VRT_PRIVS_MAGIC);
 
 	for (nxt = REQ_FSM_MORE; nxt == REQ_FSM_MORE; ) {
 		/*
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 76152cbf3..c2c46d4a9 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -50,7 +50,8 @@ struct vrt_privs cli_task_privs[1];
 
 static inline int vrt_priv_dyncmp(const struct vrt_priv *,
     const struct vrt_priv *);
-VRBT_PROTOTYPE_STATIC(vrt_priv_tree, vrt_priv, entry, vrt_priv_dyncmp)
+
+VRBT_PROTOTYPE_STATIC(vrt_privs, vrt_priv, entry, vrt_priv_dyncmp)
 
 /*--------------------------------------------------------------------
  */
@@ -64,9 +65,8 @@ pan_privs(struct vsb *vsb, const struct vrt_privs *privs)
 	if (PAN_already(vsb, privs))
 		return;
 	VSB_indent(vsb, 2);
-	PAN_CheckMagic(vsb, privs, VRT_PRIVS_MAGIC);
-	if (privs->magic == VRT_PRIVS_MAGIC) {
-		VRBT_FOREACH(vp, vrt_priv_tree, &privs->privs) {
+	if (privs != NULL) {
+		VRBT_FOREACH(vp, vrt_privs, privs) {
 			PAN_CheckMagic(vsb, vp, VRT_PRIV_MAGIC);
 			VSB_printf(vsb,
 			    "priv {p %p l %ld f %p} vmod %jx\n",
@@ -89,8 +89,7 @@ static void
 VRTPRIV_init(struct vrt_privs *privs)
 {
 
-	INIT_OBJ(privs, VRT_PRIVS_MAGIC);
-	VRBT_INIT(&privs->privs);
+	VRBT_INIT(privs);
 }
 
 static inline int
@@ -103,10 +102,10 @@ vrt_priv_dyncmp(const struct vrt_priv *vp1, const struct vrt_priv *vp2)
 	return (0);
 }
 
-VRBT_GENERATE_STATIC(vrt_priv_tree, vrt_priv, entry, vrt_priv_dyncmp)
+VRBT_GENERATE_STATIC(vrt_privs, vrt_priv, entry, vrt_priv_dyncmp)
 
 static struct vmod_priv *
-vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id,
+vrt_priv_dynamic(struct ws *ws, struct vrt_privs *privs, uintptr_t id,
     uintptr_t vmod_id)
 {
 	struct vrt_priv *vp;
@@ -115,11 +114,10 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id,
 		.vmod_id = vmod_id,
 	};
 
-	CHECK_OBJ_NOTNULL(vps, VRT_PRIVS_MAGIC);
 	AN(id);
 	AN(vmod_id);
 
-	vp = VRBT_FIND(vrt_priv_tree, &vps->privs, &needle);
+	vp = VRBT_FIND(vrt_privs, privs, &needle);
 	if (vp) {
 		CHECK_OBJ(vp, VRT_PRIV_MAGIC);
 		assert(vp->id == id);
@@ -133,16 +131,13 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id,
 	INIT_OBJ(vp, VRT_PRIV_MAGIC);
 	vp->id = id;
 	vp->vmod_id = vmod_id;
-	VRBT_INSERT(vrt_priv_tree, &vps->privs, vp);
+	VRBT_INSERT(vrt_privs, privs, vp);
 	return (vp->priv);
 }
 
 struct vmod_priv *
 VRT_priv_task(VRT_CTX, const void *vmod_id)
 {
-	uintptr_t id;
-	struct vrt_privs *vps;
-	struct vmod_priv *vp;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	assert(ctx->req == NULL || ctx->bo == NULL ||
@@ -150,27 +145,35 @@ VRT_priv_task(VRT_CTX, const void *vmod_id)
 
 	if (ctx->req) {
 		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
-		id = (uintptr_t)ctx->req;
-		CAST_OBJ_NOTNULL(vps, ctx->req->privs, VRT_PRIVS_MAGIC);
-	} else if (ctx->bo) {
+		return (vrt_priv_dynamic(
+		    ctx->ws,
+		    ctx->req->privs,
+		    (uintptr_t)ctx->req,
+		    (uintptr_t)vmod_id
+		));
+	}
+	if (ctx->bo) {
 		CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
-		id = (uintptr_t)ctx->bo;
-		CAST_OBJ_NOTNULL(vps, ctx->bo->privs, VRT_PRIVS_MAGIC);
-	} else {
-		ASSERT_CLI();
-		id = (uintptr_t)cli_task_privs;
-		CAST_OBJ_NOTNULL(vps, cli_task_privs, VRT_PRIVS_MAGIC);
+		return (vrt_priv_dynamic(
+		    ctx->ws,
+		    ctx->bo->privs,
+		    (uintptr_t)ctx->bo,
+		    (uintptr_t)vmod_id
+		));
 	}
-
-	vp = vrt_priv_dynamic(ctx->ws, vps, id, (uintptr_t)vmod_id);
-	return (vp);
+	ASSERT_CLI();
+
+	return (vrt_priv_dynamic(
+	    ctx->ws,
+	    cli_task_privs,
+	    (uintptr_t)cli_task_privs,
+	    (uintptr_t)vmod_id
+	));
 }
 
 struct vmod_priv *
 VRT_priv_top(VRT_CTX, const void *vmod_id)
 {
-	uintptr_t id;
-	struct vrt_privs *vps;
 	struct req *req;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
@@ -181,9 +184,12 @@ VRT_priv_top(VRT_CTX, const void *vmod_id)
 	}
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 	req = ctx->req->topreq;
-	id = (uintptr_t)&req->topreq;
-	CAST_OBJ_NOTNULL(vps, req->privs, VRT_PRIVS_MAGIC);
-	return (vrt_priv_dynamic(req->ws, vps, id, (uintptr_t)vmod_id));
+	return (vrt_priv_dynamic(
+	    req->ws,
+	    req->privs,
+	    (uintptr_t)&req->topreq,
+	    (uintptr_t)vmod_id
+	));
 }
 
 /*--------------------------------------------------------------------
@@ -204,7 +210,6 @@ VCL_TaskEnter(const struct vcl *vcl, struct vrt_privs *privs)
 {
 
 	AN(vcl);
-	AZ(privs->magic);
 	VRTPRIV_init(privs);
 }
 
@@ -214,12 +219,12 @@ VCL_TaskLeave(const struct vcl *vcl, struct vrt_privs *privs)
 	struct vrt_priv *vp, *vp1;
 
 	AN(vcl);
-	CHECK_OBJ_NOTNULL(privs, VRT_PRIVS_MAGIC);
-	/* NB: We don't bother removing entries as we finish them because it's
+	/*
+	 * NB: We don't bother removing entries as we finish them because it's
 	 * a costly operation. Instead we safely walk the whole tree and clear
 	 * the head at the very end.
 	 */
-	VRBT_FOREACH_SAFE(vp, vrt_priv_tree, &privs->privs, vp1)
+	VRBT_FOREACH_SAFE(vp, vrt_privs, privs, vp1)
 		VRT_priv_fini(vp->priv);
 	ZERO_OBJ(privs, sizeof *privs);
 }


More information about the varnish-commit mailing list