]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: build: define DEBUG_STRESS
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 7 Nov 2024 15:37:10 +0000 (16:37 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 12 Dec 2024 10:19:10 +0000 (11:19 +0100)
Define a new build mode DEBUG_STRESS. This will be used to stress some
code parts which cannot be reproduce easily with an alternative
suboptimal code.

First, a global <mode_stress> is set either to 1 or 0 depending on
DEBUG_STRESS compilation. A new global keyword "stress-level" is also
defined. It allows to specify a level from 0 to 9, to increase the
stress incurred on the code.

Helper macro STRESS_RUN* are defined for each stress level. This allows
to easily specify an instruction in default execution and a stress
counterpart if running on the corresponding stress level.

Makefile
doc/configuration.txt
include/haproxy/stress.h [new file with mode: 0644]
src/cfgparse-global.c
src/haproxy.c

index a0e10c1608f0b988b25210344c4900dcdccac7ba..62d2588f75722a978a5e784ebf86c772cbc9a330 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -263,7 +263,7 @@ endif
 # DEBUG_NO_POOLS, DEBUG_FAIL_ALLOC, DEBUG_STRICT_ACTION=[0-3], DEBUG_HPACK,
 # DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF, DEBUG_THREAD, DEBUG_STRICT, DEBUG_DEV,
 # DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST,
-# DEBUG_GLITCHES.
+# DEBUG_GLITCHES, DEBUG_STRESS.
 DEBUG =
 
 #### Trace options
index cd8617f2ea8b05ba946239ed80d64c8a99c2a4af..69d1061e929f4f72eae681ec7fb825e56b8b1747 100644 (file)
@@ -3035,6 +3035,13 @@ stats-file <path>
   values to its internal counters. Use the CLI command "dump stats-file" to
   produce such stats-file. See the management manual for more details.
 
+stress-level <level>
+  Activate alternative code to stress haproxy binary. Level is an integer from
+  0 to 9. The default value 0 disable any stressing execution. Levels from 1 to
+  9 will increase the stress pressure on the haproxy binary. Note that using
+  any positive level can significantly hurt performance. As such it should
+  never be activated unless for debugging purpose and on a developer request.
+
 strict-limits
   Makes process fail at startup when a setrlimit fails. HAProxy tries to set the
   best setrlimit according to what has been calculated. If it fails, it will
diff --git a/include/haproxy/stress.h b/include/haproxy/stress.h
new file mode 100644 (file)
index 0000000..a6c6163
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _HAPROXY_STRESS_H
+#define _HAPROXY_STRESS_H
+
+#ifdef DEBUG_STRESS
+enum { mode_stress = 1 };
+#else
+enum { mode_stress = 0 };
+#endif
+
+extern int mode_stress_level;
+
+#define STRESS_RUN1(a,b) (mode_stress && unlikely(mode_stress_level >= 1) ? (a) : (b))
+#define STRESS_RUN2(a,b) (mode_stress && unlikely(mode_stress_level >= 2) ? (a) : (b))
+#define STRESS_RUN3(a,b) (mode_stress && unlikely(mode_stress_level >= 3) ? (a) : (b))
+#define STRESS_RUN4(a,b) (mode_stress && unlikely(mode_stress_level >= 4) ? (a) : (b))
+#define STRESS_RUN5(a,b) (mode_stress && unlikely(mode_stress_level >= 5) ? (a) : (b))
+#define STRESS_RUN6(a,b) (mode_stress && unlikely(mode_stress_level >= 6) ? (a) : (b))
+#define STRESS_RUN7(a,b) (mode_stress && unlikely(mode_stress_level >= 7) ? (a) : (b))
+#define STRESS_RUN8(a,b) (mode_stress && unlikely(mode_stress_level >= 8) ? (a) : (b))
+#define STRESS_RUN9(a,b) (mode_stress && unlikely(mode_stress_level >= 9) ? (a) : (b))
+
+#endif /* _HAPROXY_STRESS_H */
index d2648a573dba6c1149683f02869faa5e3b1e339e..f050b5b492e0e0d85594ea9fa8f76422156319d9 100644 (file)
@@ -24,6 +24,7 @@
 #include <haproxy/log.h>
 #include <haproxy/peers.h>
 #include <haproxy/protocol.h>
+#include <haproxy/stress.h>
 #include <haproxy/tools.h>
 
 int cluster_secret_isset;
@@ -1642,6 +1643,32 @@ static int cfg_parse_global_localpeer(char **args, int section_type, struct prox
        return 0;
 }
 
+static int cfg_parse_global_stress_level(char **args, int section_type, struct proxy *curpx,
+                                         const struct proxy *defpx, const char *file, int line,
+                                         char **err)
+{
+       char *stop;
+       int level;
+
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       if (*(args[1]) == 0) {
+               memprintf(err, "'%s' expects a level as an argument.", args[0]);
+               return -1;
+       }
+
+       level = strtol(args[1], &stop, 10);
+       if ((*stop != '\0') || level < 0 || level > 9) {
+               memprintf(err, "'%s' level must be between 0 and 9 inclusive.", args[0]);
+               return -1;
+       }
+
+       mode_stress_level = level;
+
+       return 0;
+}
+
 static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_GLOBAL, "prealloc-fd", cfg_parse_prealloc_fd },
        { CFG_GLOBAL, "force-cfg-parser-pause", cfg_parse_global_parser_pause, KWF_EXPERIMENTAL },
@@ -1687,6 +1714,7 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_GLOBAL, "presetenv", cfg_parse_global_env_opts, KWF_DISCOVERY },
        { CFG_GLOBAL, "chroot", cfg_parse_global_chroot },
        { CFG_GLOBAL, "localpeer", cfg_parse_global_localpeer, KWF_DISCOVERY },
+       { CFG_GLOBAL, "stress-level", cfg_parse_global_stress_level },
        { 0, NULL, NULL },
 }};
 
index 0d7f784d27543d819d821248893c579e484b1f33..b915740bab54f119a53e2e779c20cf5762d61f9d 100644 (file)
@@ -299,6 +299,8 @@ struct build_opts_str {
        int must_free;
 };
 
+int mode_stress_level = 0;
+
 /*********************************************************************/
 /*  general purpose functions  ***************************************/
 /*********************************************************************/