[master] 48cbc79 Put the VSC prefix data in a struct.

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 21 16:52:06 UTC 2017


commit 48cbc79b3c9d43693f74ee229b00c8630a896d0b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Dec 21 16:33:55 2017 +0000

    Put the VSC prefix data in a struct.
    
    ...Now that we will need more than one integer.

diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c
index 8b9bcd7..7f9f239 100644
--- a/bin/varnishd/common/common_vsc.c
+++ b/bin/varnishd/common/common_vsc.c
@@ -40,8 +40,8 @@
 
 #include "miniobj.h"
 #include "vas.h"
-#include "vend.h"
 #include "vmb.h"
+#include "vsc_priv.h"
 #include "vsmw.h"
 #include "vqueue.h"
 
@@ -56,6 +56,7 @@ struct vsc_segs {
 	const char		*nm;
 	VTAILQ_ENTRY(vsc_segs)	list;
 	void			*seg;
+	struct vsc_head		*head;
 	void			*ptr;
 };
 
@@ -72,6 +73,7 @@ VRT_VSC_Alloc(const char *nm, size_t sd, const unsigned char *jp,
 	char *p;
 	struct vsc_segs *vsg;
 	char buf[1024];
+	uint64_t co, jo;
 
 	if (vsc_lock != NULL)
 		vsc_lock();
@@ -81,22 +83,27 @@ VRT_VSC_Alloc(const char *nm, size_t sd, const unsigned char *jp,
 	else
 		bprintf(buf, "%s.%s", nm, fmt);
 
+	co = PRNDUP(sizeof(struct vsc_head));
+	jo = co + PRNDUP(sd);
 	AN(heritage.proc_vsmw);
-	p = VSMW_Allocv(heritage.proc_vsmw, "Stat", 8 + sd + sj, buf, va);
+	p = VSMW_Allocv(heritage.proc_vsmw, VSC_CLASS,
+	    jo + PRNDUP(sj), buf, va);
 	AN(p);
 
-	memcpy(p + 8 + sd, jp, sj);
 	ALLOC_OBJ(vsg, VSC_SEGS_MAGIC);
 	AN(vsg);
 	vsg->seg = p;
-	vsg->ptr = p + 8;
+	vsg->head = (void*)p;
+	vsg->head->ctr_offset = co;
+	vsg->ptr = p + co;
 	VTAILQ_INSERT_TAIL(&vsc_seglist, vsg, list);
+	memcpy(p + jo, jp, sj);
 	VWMB();
-	vbe64enc(p, sd);
+	vsg->head->json_offset = jo;
 	vsg->nm = nm;
 	if (vsc_unlock != NULL)
 		vsc_unlock();
-	return (p + 8);
+	return (vsg->ptr);
 }
 
 void
diff --git a/include/Makefile.am b/include/Makefile.am
index 99d6622..822dcdd 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -90,6 +90,7 @@ nobase_noinst_HEADERS = \
 	vmb.h \
 	vnum.h \
 	vpf.h \
+	vsc_priv.h \
 	vsl_priv.h \
 	vsmw.h \
 	vsm_priv.h \
diff --git a/include/vsc_priv.h b/include/vsc_priv.h
new file mode 100644
index 0000000..e0d9f2e
--- /dev/null
+++ b/include/vsc_priv.h
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2017 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ * Author: Martin Blix Grydeland <martin at varnish-software.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Define the layout of the statistics VSM segments
+ *
+ * NB: THIS IS NOT A PUBLIC API TO VARNISH!
+ */
+
+#ifdef VSC_PRIV_H_INCLUDED
+#  error "vsc_priv.h included more than once"
+#endif
+#define VSC_PRIV_H_INCLUDED
+
+#define VSC_CLASS		"Stat"
+
+struct vsc_head {
+	volatile uint64_t	json_offset;
+	uint64_t		ctr_offset;
+};
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index b13550f..92a4939 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -45,7 +45,7 @@
 #include "vqueue.h"
 #include "vjsn.h"
 #include "vsb.h"
-#include "vend.h"
+#include "vsc_priv.h"
 #include "vmb.h"
 
 #include "vapi/vsc.h"
@@ -70,6 +70,7 @@ struct vsc_seg {
 	VTAILQ_ENTRY(vsc_seg)	list;
 	struct vsm_fantom	fantom[1];
 	struct vjsn		*vj;
+	struct vsc_head		*head;
 	unsigned		npoints;
 	struct vsc_pt		*points;
 };
@@ -204,7 +205,7 @@ vsc_clean_point(struct vsc_pt *point)
 }
 
 static int
-vsc_fill_point(const struct vsc *vsc, const struct vsm_fantom *fantom,
+vsc_fill_point(const struct vsc *vsc, struct vsc_seg *seg,
     const struct vjsn_val *vv, struct vsb *vsb, struct vsc_pt *point)
 {
 	struct vjsn_val *vt;
@@ -217,7 +218,7 @@ vsc_fill_point(const struct vsc *vsc, const struct vsm_fantom *fantom,
 	assert(vt->type == VJSN_STRING);
 
 	VSB_clear(vsb);
-	VSB_printf(vsb, "%s.%s", fantom->ident, vt->value);
+	VSB_printf(vsb, "%s.%s", seg->fantom->ident, vt->value);
 	AZ(VSB_finish(vsb));
 
 	if (vsc_filter(vsc, VSB_data(vsb)))
@@ -285,7 +286,8 @@ vsc_fill_point(const struct vsc *vsc, const struct vsm_fantom *fantom,
 	AN(vt);
 
 	point->point.ptr = (volatile void*)
-	    ((volatile char*)fantom->b + atoi(vt->value));
+	    ((volatile char*)seg->fantom->b +
+		seg->head->ctr_offset + atoi(vt->value));
 	return (1);
 }
 
@@ -314,7 +316,6 @@ static struct vsc_seg *
 vsc_add_seg(const struct vsc *vsc, struct vsm *vsm, const struct vsm_fantom *fp)
 {
 	struct vsc_seg *sp;
-	uint64_t u;
 	const char *p;
 	const char *e;
 	struct vjsn_val *vv, *vve;
@@ -335,16 +336,14 @@ vsc_add_seg(const struct vsc *vsc, struct vsm *vsm, const struct vsm_fantom *fp)
 		FREE_OBJ(sp);
 		return (NULL);
 	}
-	// AZ(VSM_Map(vsm, sp->fantom));
 
-	u = vbe64dec(sp->fantom->b);
-	if (u == 0) {
+	sp->head = sp->fantom->b;
+	if (sp->head->json_offset == 0) {
 		VRMB();
 		usleep(100000);
-		u = vbe64dec(sp->fantom->b);
 	}
-	assert(u > 0);
-	p = (char*)sp->fantom->b + 8 + u;
+	assert(sp->head->json_offset > 0);
+	p = (char*)sp->fantom->b + sp->head->json_offset;
 	assert (p < (char*)sp->fantom->e);
 	sp->vj = vjsn_parse(p, &e);
 	XXXAZ(e);
@@ -359,7 +358,7 @@ vsc_add_seg(const struct vsc *vsc, struct vsm *vsm, const struct vsm_fantom *fp)
 	AN(vve);
 	pp = sp->points;
 	VTAILQ_FOREACH(vv, &vve->children, list) {
-		if (vsc_fill_point(vsc, sp->fantom, vv, vsb, pp) &&
+		if (vsc_fill_point(vsc, sp, vv, vsb, pp) &&
 			vsc->fnew != NULL)
 			pp->point.priv = vsc->fnew(vsc->priv, &pp->point);
 		pp++;
@@ -399,7 +398,7 @@ VSC_Iter(struct vsc *vsc, struct vsm *vsm, VSC_iter_f *fiter, void *priv)
 	AN(vsm);
 	sp = VTAILQ_FIRST(&vsc->segs);
 	VSM_FOREACH(&ifantom, vsm) {
-		if (strcmp(ifantom.class, "Stat"))
+		if (strcmp(ifantom.class, VSC_CLASS))
 			continue;
 		while (sp != NULL &&
 		    (strcmp(ifantom.ident, sp->fantom->ident) ||
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index d5ad76c..da89aee 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -79,7 +79,7 @@ class vscset(object):
 		self.mbrs = []
 		self.head = m
 		self.completed = False
-		self.off = 8
+		self.off = 0
 
 	def addmbr(self, m):
 		assert not self.completed
@@ -177,7 +177,7 @@ class vscset(object):
 		
 		for i in self.mbrs:
 			fo.write("PARANOIA(" + i.arg)
-			fo.write(", %d);\n" % (i.param["index"] - 8))
+			fo.write(", %d);\n" % (i.param["index"]))
 
 		fo.write("#undef PARANOIA\n")
 


More information about the varnish-commit mailing list