[master] c122a39 Also move VSC::LCK to The New World Order

Poul-Henning Kamp phk at FreeBSD.org
Tue May 23 14:11:06 CEST 2017


commit c122a396936906bf583d986fe08d069ac74afb85
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 23 12:00:02 2017 +0000

    Also move VSC::LCK to The New World Order

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index c03ff70..5586cf4 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -107,8 +107,7 @@ varnishd_SOURCES = \
 	waiter/cache_waiter_epoll.c \
 	waiter/cache_waiter_kqueue.c \
 	waiter/cache_waiter_poll.c \
-	waiter/cache_waiter_ports.c \
-	VSC_main.c
+	waiter/cache_waiter_ports.c
 
 nodist_varnishd_SOURCES = \
 	builtin_vcl.c
@@ -219,10 +218,21 @@ DISTCLEANFILES	+=	vhp_hufdec.h
 
 #######################################################################
 VSC_main.c VSC_main.h: $(srcdir)/main.vsc $(top_builddir)/lib/libvcc/vsctool.py
-	$(PYTHON) $(top_builddir)/lib/libvcc/vsctool.py $(srcdir)/main.vsc
+	$(PYTHON) $(top_srcdir)/lib/libvcc/vsctool.py $(srcdir)/main.vsc
 
 $(varnishd_OBJECTS):	VSC_main.h
 
 EXTRA_DIST	+=	main.vsc
 DISTCLEANFILES	+=	VSC_main.c VSC_main.h
+nodist_varnishd_SOURCES +=	VSC_main.c
 
+#######################################################################
+
+VSC_lck.c VSC_lck.h: $(srcdir)/lck.vsc $(top_builddir)/lib/libvcc/vsctool.py
+	$(PYTHON) $(top_srcdir)/lib/libvcc/vsctool.py $(srcdir)/lck.vsc
+
+$(varnishd_OBJECTS):	VSC_lck.h
+
+EXTRA_DIST	+=	lck.vsc
+DISTCLEANFILES	+=	VSC_lck.c VSC_lck.h
+nodist_varnishd_SOURCES +=	VSC_lck.c
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a5fcef8..5256c3f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -95,7 +95,7 @@ enum {
 
 /*--------------------------------------------------------------------*/
 
-struct VSC_C_lck;
+struct VSC_lck;
 struct ban;
 struct ban_proto;
 struct backend;
@@ -828,7 +828,7 @@ extern pthread_key_t witness_key;
 void Lck__Lock(struct lock *lck, const char *p,  int l);
 void Lck__Unlock(struct lock *lck, const char *p,  int l);
 int Lck__Trylock(struct lock *lck, const char *p,  int l);
-void Lck__New(struct lock *lck, struct VSC_C_lck *, const char *);
+void Lck__New(struct lock *lck, struct VSC_lck *, const char *);
 int Lck__Held(const struct lock *lck);
 int Lck__Owned(const struct lock *lck);
 
@@ -846,9 +846,9 @@ int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double);
 		assert(Lck__Owned(a));	\
 	} while (0)
 
-struct VSC_C_lck *Lck_CreateClass(const char *name);
+struct VSC_lck *Lck_CreateClass(const char *name);
 
-#define LOCK(nam) extern struct VSC_C_lck *lck_##nam;
+#define LOCK(nam) extern struct VSC_lck *lck_##nam;
 #include "tbl/locks.h"
 
 /* cache_mempool.c */
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index bf8151f..eb39cbd 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -41,6 +41,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#include "VSC_lck.h"
+
 struct ilck {
 	unsigned		magic;
 #define ILCK_MAGIC		0x7b86c8a5
@@ -48,7 +50,7 @@ struct ilck {
 	pthread_mutex_t		mtx;
 	pthread_t		owner;
 	const char		*w;
-	struct VSC_C_lck	*stat;
+	struct VSC_lck		*stat;
 };
 
 static pthread_mutexattr_t attr;
@@ -214,7 +216,7 @@ Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double when)
 }
 
 void
-Lck__New(struct lock *lck, struct VSC_C_lck *st, const char *w)
+Lck__New(struct lock *lck, struct VSC_lck *st, const char *w)
 {
 	struct ilck *ilck;
 
@@ -242,14 +244,13 @@ Lck_Delete(struct lock *lck)
 	FREE_OBJ(ilck);
 }
 
-struct VSC_C_lck *
+struct VSC_lck *
 Lck_CreateClass(const char *name)
 {
-	return(VSM_Alloc(sizeof(struct VSC_C_lck),
-	   VSC_CLASS, VSC_type_lck, name));
+	return(VSC_lck_New(name));
 }
 
-#define LOCK(nam) struct VSC_C_lck *lck_##nam;
+#define LOCK(nam) struct VSC_lck *lck_##nam;
 #include "tbl/locks.h"
 
 void
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 113d0fc..5429a14 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -37,6 +37,8 @@
 
 #include "common/heritage.h"
 
+#include "vend.h"
+#include "vgz.h"
 #include "vsl_priv.h"
 #include "vmb.h"
 #include "vtim.h"
@@ -471,16 +473,32 @@ VSL_End(struct vsl_log *vsl)
 /*--------------------------------------------------------------------*/
 
 void *
-VSC_Alloc(const char *nm, size_t sj, const unsigned char *zj, size_t szj,
+VSC_Alloc(const char *nm, size_t sd,
+    size_t sj, const unsigned char *zj, size_t szj,
     const char *fmt, va_list va)
 {
+	char *p;
+	z_stream vz;
+
 	(void)nm;
-	(void)zj;
-	(void)szj;
-	(void)sj;
 	(void)fmt;
 	(void)va;
-	return (0);
+
+	p = VSM_Alloc(sd + sj, VSC_CLASS, nm, fmt);
+	AN(p);
+
+	memset(p, 0, sd);
+	vbe64enc(p, sd);		// fills .zero
+
+	memset(&vz, 0, sizeof vz);
+	assert(Z_OK == inflateInit2(&vz, 31));
+	vz.next_in = TRUST_ME(zj);
+	vz.avail_in = szj;
+	vz.next_out = (void*)(p + sd);
+	vz.avail_out = sj;
+	assert(Z_STREAM_END == inflate(&vz, Z_FINISH));
+	assert(Z_OK == inflateEnd(&vz));
+	return (p);
 }
 
 void
@@ -540,10 +558,8 @@ VSM_Init(void)
 	VWMB();
 	memcpy(vsl_head->marker, VSL_HEAD_MARKER, sizeof vsl_head->marker);
 
-	VSC_C_main = VSM_Alloc(sizeof *VSC_C_main,
-	    VSC_CLASS, VSC_type_main, "");
+	VSC_C_main = VSC_main_New("");
 	AN(VSC_C_main);
-	memset(VSC_C_main, 0, sizeof *VSC_C_main);
 
 	AZ(pthread_create(&tp, NULL, vsm_cleaner, NULL));
 }
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index 107f5b8..2fbe5d2 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -91,7 +91,7 @@ void VSM_common_copy(struct vsm_sc *to, const struct vsm_sc *from);
 void VSM_common_cleaner(struct vsm_sc *sc, struct VSC_C_main *stats);
 void VSM_common_ageupdate(const struct vsm_sc *sc);
 
-void *VSC_Alloc(const char *, size_t, const unsigned char *, size_t,
+void *VSC_Alloc(const char *, size_t, size_t, const unsigned char *, size_t,
     const char *, va_list);
 void VSC_Destroy(const char *, void *);
 
diff --git a/bin/varnishd/hash/hash_classic.c b/bin/varnishd/hash/hash_classic.c
index 6ad5a0d..e89e411 100644
--- a/bin/varnishd/hash/hash_classic.c
+++ b/bin/varnishd/hash/hash_classic.c
@@ -38,7 +38,7 @@
 
 #include "hash/hash_slinger.h"
 
-static struct VSC_C_lck *lck_hcl;
+static struct VSC_lck *lck_hcl;
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/hash/hash_simple_list.c b/bin/varnishd/hash/hash_simple_list.c
index a946d16..ffaa2d5 100644
--- a/bin/varnishd/hash/hash_simple_list.c
+++ b/bin/varnishd/hash/hash_simple_list.c
@@ -35,7 +35,7 @@
 
 #include "hash/hash_slinger.h"
 
-static struct VSC_C_lck *lck_hsl;
+static struct VSC_lck *lck_hsl;
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/lck.vsc b/bin/varnishd/lck.vsc
new file mode 100644
index 0000000..936df89
--- /dev/null
+++ b/bin/varnishd/lck.vsc
@@ -0,0 +1,30 @@
+..
+	This is *NOT* a RST file but the syntax has been chosen so
+	that it may become an RST file at some later date.
+
+	XXX: For now this file must be kept in 100% agreement with
+	XXX: include/tbl/vsc_fields.h
+
+.. varnish_vsc_begin::	lck
+	:oneliner:	LOCK COUNTERS (LCK.*)
+
+.. varnish_vsc:: creat
+	:type:	counter
+	:level:	debug
+	:oneliner:	Created locks
+
+
+.. varnish_vsc:: destroy
+	:type:	counter
+	:level:	debug
+	:oneliner:	Destroyed locks
+
+
+.. varnish_vsc:: locks
+	:type:	counter
+	:level:	debug
+	:oneliner:	Lock Operations
+
+
+.. varnish_vsc_end::	lck
+
diff --git a/bin/varnishd/main.vsc b/bin/varnishd/main.vsc
index f901fca..242681d 100644
--- a/bin/varnishd/main.vsc
+++ b/bin/varnishd/main.vsc
@@ -753,4 +753,4 @@ to communicate with tools like varnishstat, varnishlog etc. If this
 counter is not zero, consider increasing the runtime variable
 vsm_space.
 
-.. varnish_vsc_end::	MAIN
+.. varnish_vsc_end::	main
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index 143ab9d..7de1a34 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -64,7 +64,7 @@
  */
 #define NBUCKET			(128 / 4 + 1)
 
-static struct VSC_C_lck *lck_smf;
+static struct VSC_lck *lck_smf;
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index 0361e52..19a37ba 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -59,7 +59,7 @@ struct sma {
 	struct sma_sc		*sc;
 };
 
-static struct VSC_C_lck *lck_sma;
+static struct VSC_lck *lck_sma;
 
 static struct storage * __match_proto__(sml_alloc_f)
 sma_alloc(const struct stevedore *st, size_t size)
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 9d2cc92..b4283f3 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -55,7 +55,7 @@
 
 static struct obj_methods smp_oc_realmethods;
 
-static struct VSC_C_lck *lck_smp;
+static struct VSC_lck *lck_smp;
 
 static void smp_init(void);
 
diff --git a/include/vapi/vsc_int.h b/include/vapi/vsc_int.h
index 352c8ba..9d20665 100644
--- a/include/vapi/vsc_int.h
+++ b/include/vapi/vsc_int.h
@@ -43,7 +43,7 @@ enum VSC_level_e {
 #include "tbl/vsc_types.h"
 
 /* Define the vsc type structs */
-#define VSC_DO(u,l,t,h)			struct VSC_C_##l {
+#define VSC_DO(u,l,t,h)			struct VSC_C_##l { uint64_t zero;
 #define VSC_F(n,t,l,s,f,v,d,e)			t n;
 #define VSC_DONE(u,l,t)			};
 #include "tbl/vsc_all.h"
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index afc2ffb..ee70033 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -49,8 +49,8 @@ def genhdr(fo, name):
 	fo.write(' * NB:  This file is machine generated, DO NOT EDIT!\n')
 	fo.write(' *\n')
 	fo.write(' * Edit %s.vsc run lib/libvcc/vsctool.py instead.\n' % name)
- 	fo.write(' */\n')
- 	fo.write('\n')
+	fo.write(' */\n')
+	fo.write('\n')
 
 #######################################################################
 
@@ -90,11 +90,11 @@ class vscset(object):
 			ed["1line"] = i.param["oneliner"].strip()
 			ed["docs"] = i.getdoc()
 		s=json.dumps(dd, separators=(",",":"))
-		fo.write("\nstatic const size_t %s_jsonlen = %dL;\n" %
+		fo.write("\nstatic const size_t vsc_%s_jsonlen = %dL;\n" %
 		    (self.name, len(s)))
 		z = gzip_str(s)
 		fo.write("\nstatic const unsigned char");
-		fo.write(" %s_zjson[%d] = {\n" % (self.name, len(z)))
+		fo.write(" vsc_%s_zjson[%d] = {\n" % (self.name, len(z)))
 		bz = bytearray(z)
 		t = "\t"
 		for i in bz:
@@ -116,6 +116,7 @@ class vscset(object):
 		fo = open(fon, "w")
 		genhdr(fo, self.name)
 		fo.write(self.struct + " {\n")
+		fo.write("\tuint64_t\tzero;\n")
 		for i in self.mbrs:
 			fo.write("\tuint64_t\t%s;\n" % i.arg)
 		fo.write("};\n")
@@ -135,6 +136,10 @@ class vscset(object):
 		fo.write('#include <stdint.h>\n')
 		fo.write('#include "common/common.h"\n')
 		fo.write('#include "VSC_%s.h"\n' % self.name)
+		fo.write("\n")
+		fo.write('static const char vsc_%s_name[] = "%s";\n' %
+		    (self.name, self.name.upper()))
+
 		self.emit_json(fo)
 		fo.write("\n")
 		fo.write(self.struct + "*\n");
@@ -146,10 +151,11 @@ class vscset(object):
 		fo.write("\n")
 		fo.write("\tva_start(ap, fmt);\n")
 		fo.write("\tretval = VSC_Alloc")
-		fo.write('("' + self.name + '", ')
-		fo.write(self.name + "_jsonlen, ")
-		fo.write(self.name + "_zjson, ")
-		fo.write("sizeof " + self.name + "_zjson,\n")
+		fo.write("(vsc_" + self.name + "_name, ")
+		fo.write("sizeof(" + self.struct + "),\n\t    ")
+		fo.write("vsc_" + self.name + "_jsonlen, ")
+		fo.write("vsc_" + self.name + "_zjson, ")
+		fo.write("sizeof vsc_" + self.name + "_zjson,\n")
 		fo.write("\t    fmt, ap);\n")
 		fo.write("\tva_end(ap);\n")
 		fo.write("\treturn(retval);\n")
@@ -309,6 +315,6 @@ if __name__ == "__main__":
 		exit(2)
 
 	vf = vsc_file(args[0])
-	vf.emit_rst("_.rst")
+	# vf.emit_rst("_.rst")
 	vf.emit_h()
 	vf.emit_c()



More information about the varnish-commit mailing list