r4924 - in trunk/varnish-cache: bin/varnishd bin/varnishlog include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Mon Jun 7 14:56:09 CEST 2010


Author: phk
Date: 2010-06-07 14:56:09 +0200 (Mon, 07 Jun 2010)
New Revision: 4924

Modified:
   trunk/varnish-cache/bin/varnishd/cache_shmlog.c
   trunk/varnish-cache/bin/varnishd/mgt_shmem.c
   trunk/varnish-cache/bin/varnishlog/flint.lnt
   trunk/varnish-cache/include/shmlog.h
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/Makefile.am
   trunk/varnish-cache/lib/libvarnishapi/vsl.h
   trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
Log:
Tighten on the relative accesses to wrap-sequence and special marker
values in the shmlog.

PS: Sometimes I really long for the days when computers executed the
instructions in the order written.



Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.c	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c	2010-06-07 12:56:09 UTC (rev 4924)
@@ -69,12 +69,12 @@
 vsl_wrap(void)
 {
 
-	vsl_log_start[1] = vsl_w0(SLT_ENDMARKER, 0);
+	vsl_log_start[1] = VSL_ENDMARKER;
 	do
 		vsl_log_start[0]++;
 	while (vsl_log_start[0] == 0);
 	VWMB();
-	*vsl_log_nxt = vsl_w0(SLT_WRAPMARKER, 0);
+	*vsl_log_nxt = VSL_WRAPMARKER;
 	vsl_log_nxt = vsl_log_start + 1;
 	VSL_stats->shm_cycles++;
 }
@@ -106,7 +106,7 @@
 	p = vsl_log_nxt;
 	vsl_log_nxt = VSL_END(vsl_log_nxt, len);
 
-	*vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0);
+	*vsl_log_nxt = VSL_ENDMARKER;
 
 	assert(vsl_log_nxt < vsl_log_end);
 	assert(((uintptr_t)vsl_log_nxt & 0x3) == 0);

Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-07 12:56:09 UTC (rev 4924)
@@ -295,7 +295,8 @@
 	AN(vsl_log_start);
 	vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1);
 	vsl_log_nxt = vsl_log_start + 1;
-	*vsl_log_nxt = (SLT_ENDMARKER << 24);
+	*vsl_log_nxt = VSL_ENDMARKER;
+	VWMB();
 
 	do
 		*vsl_log_start = random() & 0xffff;

Modified: trunk/varnish-cache/bin/varnishlog/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishlog/flint.lnt	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/bin/varnishlog/flint.lnt	2010-06-07 12:56:09 UTC (rev 4924)
@@ -15,4 +15,5 @@
 -e574	// Signed-unsigned mix with relational
 
 -e788	// enum constant '___' not used within defaulted switch
+-e641	// Converting enum '___' to '___'
 

Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/include/shmlog.h	2010-06-07 12:56:09 UTC (rev 4924)
@@ -96,24 +96,26 @@
  *	[n + 2] ... [m]	= content
  */
 
-#define VSL_WORDS(len) (((len) + 3) / 4)
-#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len))
-#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr))
-#define VSL_LEN(ptr) ((ptr)[0] & 0xffff)
-#define VSL_TAG(ptr) ((ptr)[0] >> 24)
-#define VSL_ID(ptr) ((ptr)[1])
-#define VSL_DATA(ptr) ((char*)((ptr)+2))
+#define VSL_WORDS(len)		(((len) + 3) / 4)
+#define VSL_END(ptr, len)	((ptr) + 2 + VSL_WORDS(len))
+#define VSL_NEXT(ptr)		VSL_END(ptr, VSL_LEN(ptr))
+#define VSL_LEN(ptr)		((ptr)[0] & 0xffff)
+#define VSL_TAG(ptr)		((ptr)[0] >> 24)
+#define VSL_ID(ptr)		((ptr)[1])
+#define VSL_DATA(ptr)		((char*)((ptr)+2))
 
+#define VSL_ENDMARKER	(((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */
+#define VSL_WRAPMARKER	(((uint32_t)SLT_Reserved << 24) | 0x575757) /* "WWW" */
+
 /*
  * The identifiers in shmlogtag are "SLT_" + XML tag.  A script may be run
  * on this file to extract the table rather than handcode it
  */
 enum shmlogtag {
-	SLT_ENDMARKER = 0,
 #define SLTM(foo)	SLT_##foo,
 #include "shmlog_tags.h"
 #undef SLTM
-	SLT_WRAPMARKER = 255U
+	SLT_Reserved = 255
 };
 
 /* This function lives in both libvarnish and libvarnishapi */

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/include/varnishapi.h	2010-06-07 12:56:09 UTC (rev 4924)
@@ -50,7 +50,7 @@
 vsl_handler VSL_H_Print;
 struct VSL_data;
 struct VSL_data *VSL_New(void);
-void VSL_Select(struct VSL_data *vd, unsigned tag);
+void VSL_Select(const struct VSL_data *vd, unsigned tag);
 int VSL_OpenLog(struct VSL_data *vd);
 void VSL_NonBlocking(struct VSL_data *vd, int nb);
 int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);

Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/Makefile.am	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am	2010-06-07 12:56:09 UTC (rev 4924)
@@ -14,6 +14,7 @@
 	../libvarnish/svn_version.c \
 	../libvarnish/version.c \
 	../libvarnish/vin.c \
+	../libvarnish/vmb.c \
 	../libvarnish/vre.c \
 	base64.c \
 	vsl.c \

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.h	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.h	2010-06-07 12:56:09 UTC (rev 4924)
@@ -66,10 +66,12 @@
 
 	/* Stuff relating the log records below here */
 
-	uint32_t		*log_start;
-	uint32_t		*log_end;
-	uint32_t		*log_ptr;
+	volatile uint32_t	*log_start;
+	volatile uint32_t	*log_end;
+	volatile uint32_t	*log_ptr;
 
+	volatile uint32_t	last_seq;
+
 	/* for -r option */
 	int			r_fd;
 	unsigned		rbuflen;

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-07 08:38:36 UTC (rev 4923)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-07 12:56:09 UTC (rev 4924)
@@ -49,6 +49,7 @@
 #include "varnishapi.h"
 
 #include "vsl.h"
+#include "vmb.h"
 
 static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp);
 
@@ -63,7 +64,7 @@
 /*--------------------------------------------------------------------*/
 
 void
-VSL_Select(struct VSL_data *vd, unsigned tag)
+VSL_Select(const struct VSL_data *vd, unsigned tag)
 {
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -88,9 +89,8 @@
 vsl_nextlog(struct VSL_data *vd, uint32_t **pp)
 {
 	unsigned w, l;
-	uint8_t t;
+	uint32_t t;
 	int i;
-	uint32_t seq;
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
 	if (vd->r_fd != -1) {
@@ -111,27 +111,26 @@
 		*pp = vd->rbuf;
 		return (1);
 	}
-	seq = vd->log_start[0];
 	for (w = 0; w < TIMEOUT_USEC;) {
-		t = VSL_TAG(vd->log_ptr);
+		t = *vd->log_ptr;
 
-		if (t != SLT_ENDMARKER) {
-			*pp = vd->log_ptr;
-			vd->log_ptr = VSL_NEXT(vd->log_ptr);
-			return (1);
-		}
-
-		if (t == SLT_WRAPMARKER || vd->log_start[0] != seq) {
+		if (t == VSL_WRAPMARKER ||
+		    (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) {
 			vd->log_ptr = vd->log_start + 1;
-			seq = vd->log_start[0];
+			vd->last_seq = vd->log_start[0];
+			VRMB();
 			continue;
 		}
-
-		/* XXX: check log_start[0] */
-		if (vd->flags & F_NON_BLOCKING)
-			return (-1);
-		w += SLEEP_USEC;
-		usleep(SLEEP_USEC);
+		if (t == VSL_ENDMARKER) {
+			if (vd->flags & F_NON_BLOCKING)
+				return (-1);
+			w += SLEEP_USEC;
+			AZ(usleep(SLEEP_USEC));
+			continue;
+		}
+		*pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */
+		vd->log_ptr = VSL_NEXT(vd->log_ptr);
+		return (1);
 	}
 	*pp = NULL;
 	return (0);
@@ -142,7 +141,7 @@
 {
 	uint32_t *p;
 	unsigned char t;
-	unsigned u, l;
+	unsigned u;
 	int i;
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -151,7 +150,6 @@
 		if (i != 1)
 			return (i);
 		u = VSL_ID(p);
-		l = VSL_LEN(p);
 		t = VSL_TAG(p);
 		switch(t) {
 		case SLT_SessionOpen:
@@ -186,18 +184,14 @@
 		if (vd->c_opt && !vbit_test(vd->vbm_client, u))
 			continue;
 		if (vd->regincl != NULL) {
-			i = VRE_exec(vd->regincl,
-				     VSL_DATA(p),
-				     VSL_LEN(p), /* Length */
-				     0, 0, NULL, 0);
+			i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+			    0, 0, NULL, 0);
 			if (i == VRE_ERROR_NOMATCH)
 				continue;
 		}
 		if (vd->regexcl != NULL) {
-			i = VRE_exec(vd->regincl,
-				     VSL_DATA(p),
-				     VSL_LEN(p), /* Length */
-				     0, 0, NULL, 0);
+			i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+			    0, 0, NULL, 0);
 			if (i != VRE_ERROR_NOMATCH)
 				continue;
 		}
@@ -247,7 +241,7 @@
 	    (spec & VSL_S_BACKEND) ? 'b' : '-';
 
 	if (tag == SLT_Debug) {
-		fprintf(fo, "%5d %-12s %c \"", fd, VSL_tags[tag], type);
+		fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type);
 		while (len-- > 0) {
 			if (*ptr >= ' ' && *ptr <= '~')
 				fprintf(fo, "%c", *ptr);
@@ -258,7 +252,7 @@
 		fprintf(fo, "\"\n");
 		return (0);
 	}
-	fprintf(fo, "%5d %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr);
+	fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr);
 	return (0);
 }
 
@@ -276,13 +270,14 @@
 	assert(sha != NULL);
 
 	vd->log_start = SHA_PTR(sha);
-	vd->log_end = (void*)((char *)vd->log_start + sha->len - sizeof *sha);
+	vd->log_end = SHA_NEXT(sha);
 	vd->log_ptr = vd->log_start + 1;
 
+	vd->last_seq = vd->log_start[0];
+	VRMB();
 	if (!vd->d_opt && vd->r_fd == -1) {
-		while (VSL_TAG(vd->log_ptr) != SLT_ENDMARKER)
+		while (*vd->log_ptr != VSL_ENDMARKER)
 			vd->log_ptr = VSL_NEXT(vd->log_ptr);
 	}
 	return (0);
 }
-




More information about the varnish-commit mailing list