From: Amaury Denoyelle Date: Thu, 7 Nov 2024 15:37:10 +0000 (+0100) Subject: MINOR: build: define DEBUG_STRESS X-Git-Tag: v3.2-dev2~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d19fc4cf752f1e22ba8b810328ecb04be34a6a2;p=thirdparty%2Fhaproxy.git MINOR: build: define DEBUG_STRESS 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 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. --- diff --git a/Makefile b/Makefile index a0e10c1608..62d2588f75 100644 --- 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 diff --git a/doc/configuration.txt b/doc/configuration.txt index cd8617f2ea..69d1061e92 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3035,6 +3035,13 @@ stats-file 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 + 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 index 0000000000..a6c616354e --- /dev/null +++ b/include/haproxy/stress.h @@ -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 */ diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index d2648a573d..f050b5b492 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -24,6 +24,7 @@ #include #include #include +#include #include 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 }, }}; diff --git a/src/haproxy.c b/src/haproxy.c index 0d7f784d27..b915740bab 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -299,6 +299,8 @@ struct build_opts_str { int must_free; }; +int mode_stress_level = 0; + /*********************************************************************/ /* general purpose functions ***************************************/ /*********************************************************************/