[master] bba8fc0ca param: New experimental parameter

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Feb 21 14:32:06 UTC 2022


commit bba8fc0ca6102a515e8794dac7a26cde541f4933
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Jan 11 10:37:48 2022 +0100

    param: New experimental parameter
    
    This parameter should ease the introduction of features that may later
    be removed without being considered a breaking change. For features that
    get promoted to either being always present or behind the feature param,
    it sends a clear signal regarding when we consider a feature ready for
    production. This could have been useful for HTTP/2 support for example.
    
    The first experimental feature is the ability to drop thread pools,
    which was behind the debug param.
    
    Having EXPERIMENTAL in the code takes a lot of real estate, but exp is
    already established as short for expiry.

diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 6c77d5840..ba68a2c64 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -197,7 +197,7 @@ pool_poolherder(void *priv)
 				continue;
 			}
 		} else if (nwq > cache_param->wthread_pools &&
-				DO_DEBUG(DBG_DROP_POOLS)) {
+				EXPERIMENTAL(EXPERIMENTAL_DROP_POOLS)) {
 			Lck_Lock(&pool_mtx);
 			pp = VTAILQ_FIRST(&pools);
 			CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index b3a4b5ad4..096856bf1 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -570,6 +570,7 @@ void SMP_Ready(void);
 #endif
 
 #define FEATURE(x)	COM_FEATURE(cache_param->feature_bits, x)
+#define EXPERIMENTAL(x)	COM_EXPERIMENTAL(cache_param->experimental_bits, x)
 #define DO_DEBUG(x)	COM_DO_DEBUG(cache_param->debug_bits, x)
 
 #define DSL(debug_bit, id, ...)					\
diff --git a/bin/varnishd/common/common_param.h b/bin/varnishd/common/common_param.h
index abdfd6bab..89df97f91 100644
--- a/bin/varnishd/common/common_param.h
+++ b/bin/varnishd/common/common_param.h
@@ -52,6 +52,18 @@ COM_DO_DEBUG(const volatile uint8_t *p, enum debug_bits x)
 	return (p[(unsigned)x>>3] & (0x80U >> ((unsigned)x & 7)));
 }
 
+enum experimental_bits {
+#define EXPERIMENTAL_BIT(U, l, d) EXPERIMENTAL_##U,
+#include "tbl/experimental_bits.h"
+       EXPERIMENTAL_Reserved
+};
+
+static inline int
+COM_EXPERIMENTAL(const volatile uint8_t *p, enum experimental_bits x)
+{
+	return (p[(unsigned)x>>3] & (0x80U >> ((unsigned)x & 7)));
+}
+
 enum feature_bits {
 #define FEATURE_BIT(U, l, d) FEATURE_##U,
 #include "tbl/feature_bits.h"
@@ -64,7 +76,6 @@ COM_FEATURE(const volatile uint8_t *p, enum feature_bits x)
 	return (p[(unsigned)x>>3] & (0x80U >> ((unsigned)x & 7)));
 }
 
-
 struct poolparam {
 	unsigned		min_pool;
 	unsigned		max_pool;
@@ -75,6 +86,7 @@ struct poolparam {
 
 PARAM_BITMAP(vsl_mask_t,	256);
 PARAM_BITMAP(debug_t,		DBG_Reserved);
+PARAM_BITMAP(experimental_t,	EXPERIMENTAL_Reserved);
 PARAM_BITMAP(feature_t,		FEATURE_Reserved);
 #undef PARAM_BITMAP
 
@@ -114,5 +126,6 @@ struct params {
 
 	vsl_mask_t		vsl_mask;
 	debug_t			debug_bits;
+	experimental_t		experimental_bits;
 	feature_t		feature_bits;
 };
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 9065d9eaa..5df9f5fff 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -244,5 +244,6 @@ extern const char *mgt_vmod_path;
 #error "Keep pthreads out of in manager process"
 #endif
 
-#define MGT_FEATURE(x)	COM_FEATURE(mgt_param.feature_bits, x)
-#define MGT_DO_DEBUG(x)	COM_DO_DEBUG(mgt_param.debug_bits, x)
+#define MGT_FEATURE(x)		COM_FEATURE(mgt_param.feature_bits, x)
+#define MGT_EXPERIMENTAL(x)	COM_EXPERIMENTAL(mgt_param.experimental_bits, x)
+#define MGT_DO_DEBUG(x)		COM_DO_DEBUG(mgt_param.debug_bits, x)
diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c
index 89d1a1aa3..5151d9598 100644
--- a/bin/varnishd/mgt/mgt_param_bits.c
+++ b/bin/varnishd/mgt/mgt_param_bits.c
@@ -204,6 +204,51 @@ tweak_debug(struct vsb *vsb, const struct parspec *par, const char *arg)
 	return (0);
 }
 
+/*--------------------------------------------------------------------
+ * The experimental parameter
+ */
+
+static const char * const experimental_tags[] = {
+#  define EXPERIMENTAL_BIT(U, l, d) [EXPERIMENTAL_##U] = #l,
+#  include "tbl/experimental_bits.h"
+       NULL
+};
+
+static int v_matchproto_(tweak_t)
+tweak_experimental(struct vsb *vsb, const struct parspec *par, const char *arg)
+{
+	const char *s;
+	unsigned j;
+	(void)par;
+
+	if (arg != NULL && arg != JSON_FMT) {
+		if (!strcmp(arg, "none")) {
+			memset(mgt_param.experimental_bits,
+			    0, sizeof mgt_param.experimental_bits);
+		} else {
+			return (bit_tweak(vsb, mgt_param.experimental_bits,
+			    EXPERIMENTAL_Reserved, arg, experimental_tags,
+			    "experimental bit", "+"));
+		}
+	} else {
+		if (arg == JSON_FMT)
+			VSB_putc(vsb, '"');
+		s = "";
+		for (j = 0; j < (unsigned)EXPERIMENTAL_Reserved; j++) {
+			if (bit(mgt_param.experimental_bits, j, BTST)) {
+				VSB_printf(vsb, "%s+%s", s,
+				    experimental_tags[j]);
+				s = ",";
+			}
+		}
+		if (*s == '\0')
+			VSB_cat(vsb, "none");
+		if (arg == JSON_FMT)
+			VSB_putc(vsb, '"');
+	}
+	return (0);
+}
+
 /*--------------------------------------------------------------------
  * The feature parameter
  */
@@ -273,7 +318,15 @@ struct parspec VSL_parspec[] = {
 		"Use +/- prefix to set/reset individual bits:"
 #define DEBUG_BIT(U, l, d) "\n\t" #l "\t" d
 #include "tbl/debug_bits.h"
-#undef DEBUG_BIT
+		},
+	{ "experimental", tweak_experimental, NULL,
+		NULL, NULL, "none",
+		NULL,
+		"Enable/Disable experimental features.\n"
+		"\tnone\tDisable all experimental features\n\n"
+		"Use +/- prefix to set/reset individual bits:"
+#define EXPERIMENTAL_BIT(U, l, d) "\n\t" #l "\t" d
+#include "tbl/experimental_bits.h"
 		},
 	{ "feature", tweak_feature, NULL,
 		NULL, NULL, "default",
@@ -284,7 +337,6 @@ struct parspec VSL_parspec[] = {
 		"Use +/- prefix to enable/disable individual feature:"
 #define FEATURE_BIT(U, l, d) "\n\t" #l "\t" d
 #include "tbl/feature_bits.h"
-#undef FEATURE_BIT
 		},
 	{ NULL, NULL, NULL }
 };
diff --git a/bin/varnishtest/tests/c00080.vtc b/bin/varnishtest/tests/c00080.vtc
index 5a50fffcb..e4e151848 100644
--- a/bin/varnishtest/tests/c00080.vtc
+++ b/bin/varnishtest/tests/c00080.vtc
@@ -9,7 +9,7 @@ server s1 {
 
 varnish v1 -vcl+backend {} -start
 
-varnish v1 -cliok "param.set debug +drop_pools"
+varnish v1 -cliok "param.set experimental +drop_pools"
 varnish v1 -cliok "param.set debug +slow_acceptor"
 varnish v1 -cliok "param.set thread_pools 1"
 
@@ -40,7 +40,7 @@ server s1 {
 
 varnish v2 -arg "-Wpoll" -vcl+backend {} -start
 
-varnish v2 -cliok "param.set debug +drop_pools"
+varnish v2 -cliok "param.set experimental +drop_pools"
 varnish v2 -cliok "param.set debug +slow_acceptor"
 varnish v2 -cliok "param.set thread_pools 1"
 
diff --git a/include/Makefile.am b/include/Makefile.am
index 62395ce2a..6ab8a8f5e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -13,6 +13,7 @@ nobase_pkginclude_HEADERS = \
 	tbl/body_status.h \
 	tbl/cli_cmds.h \
 	tbl/debug_bits.h \
+	tbl/experimental_bits.h \
 	tbl/feature_bits.h \
 	tbl/h2_error.h \
 	tbl/h2_frames.h \
diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h
index 6002cecd9..0e60d2547 100644
--- a/include/tbl/debug_bits.h
+++ b/include/tbl/debug_bits.h
@@ -45,7 +45,6 @@ DEBUG_BIT(FLUSH_HEAD,		flush_head,	"Flush after http1 head")
 DEBUG_BIT(VTC_MODE,		vtc_mode,	"Varnishtest Mode")
 DEBUG_BIT(WITNESS,		witness,	"Emit WITNESS lock records")
 DEBUG_BIT(VSM_KEEP,		vsm_keep,	"Keep the VSM file on restart")
-DEBUG_BIT(DROP_POOLS,		drop_pools,	"Drop thread pools (testing)")
 DEBUG_BIT(SLOW_ACCEPTOR,	slow_acceptor,	"Slow down Acceptor")
 DEBUG_BIT(H2_NOCHECK,		h2_nocheck,	"Disable various H2 checks")
 DEBUG_BIT(VMOD_SO_KEEP,		vmod_so_keep,	"Keep copied VMOD libraries")
diff --git a/include/tbl/experimental_bits.h b/include/tbl/experimental_bits.h
new file mode 100644
index 000000000..ba1ff2e79
--- /dev/null
+++ b/include/tbl/experimental_bits.h
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2022 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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.
+ *
+ * Fields in the experimental parameter
+ *
+ */
+
+/*lint -save -e525 -e539 */
+
+EXPERIMENTAL_BIT(DROP_POOLS,	drop_pools,	"Drop thread pools")
+#undef EXPERIMENTAL_BIT
+
+/*lint -restore */
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 596429518..348b75a06 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1736,6 +1736,23 @@ PARAM(
 	"	vtc_mode	Varnishtest Mode"
 )
 
+/* actual location mgt_param_bits.c*/
+/* see tbl/experimental_bits.h */
+PARAM(
+	/* name */	experimental,
+	/* type */	experimental,
+	/* min */	NULL,
+	/* max */	NULL,
+	/* def */	NULL,
+	/* units */	NULL,
+	/* descr */
+	"Enable/Disable experimental features.\n"
+	"	none	Disable all experimental features\n"
+	"\n"
+	"Use +/- prefix to set/reset individual bits:\n"
+	"	drop_pools	Drop thread pools\n"
+)
+
 /* actual location mgt_param_bits.c*/
 /* See tbl/feature_bits.h */
 PARAM(


More information about the varnish-commit mailing list