]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 years agoMINOR: threads: set the tid, ltid and their bit in thread_cfg
Willy Tarreau [Tue, 28 Sep 2021 06:53:11 +0000 (08:53 +0200)] 
MINOR: threads: set the tid, ltid and their bit in thread_cfg

This will be a convenient way to communicate the thread ID and its
local ID in the group, as well as their respective bits when creating
the threads or when only a pointer is given.

3 years agoMINOR: threads: set the group ID and its bit in the thread group
Willy Tarreau [Tue, 28 Sep 2021 06:50:02 +0000 (08:50 +0200)] 
MINOR: threads: set the group ID and its bit in the thread group

This will ease the reporting of the current thread group ID when coming
from the thread itself, especially since it returns the visible ID,
starting at 1.

3 years agoMEDIUM: threads: automatically assign threads to groups
Willy Tarreau [Mon, 27 Sep 2021 08:10:26 +0000 (10:10 +0200)] 
MEDIUM: threads: automatically assign threads to groups

This takes care of unassigned threads groups and places unassigned
threads there, in a more or less balanced way. Too sparse allocations
may still fail though. For now with a maximum group number fixed to 1
nothing can really fail.

3 years agoMINOR: threads: make tg point to the current thread's group
Willy Tarreau [Tue, 28 Sep 2021 06:58:49 +0000 (08:58 +0200)] 
MINOR: threads: make tg point to the current thread's group

A the "tg" thread-local variable now always points to the current
thread group. It's pre-initializd to the first one during boot and is
set to point to the thread's one by ha_set_tid(). This last one takes
care of checking whether the thread group was assigned or not because
it may be called during boot before threads are initialized.

3 years agoMINOR: global: add a new "thread-group" directive
Willy Tarreau [Mon, 27 Sep 2021 11:55:10 +0000 (13:55 +0200)] 
MINOR: global: add a new "thread-group" directive

This registers a mapping of threads to groups by enumerating for each thread
what group it belongs to, and marking the group as assigned. It takes care of
checking for redefinitions, overlaps, and holes. It supports both individual
numbers and ranges. The thread group is referenced from the thread config.

3 years agoMINOR: global: add a new "thread-groups" directive
Willy Tarreau [Wed, 22 Sep 2021 10:07:23 +0000 (12:07 +0200)] 
MINOR: global: add a new "thread-groups" directive

This is used to configure the number of thread groups. For now it can
only be 1.

3 years agoMINOR: threads: introduce a minimalistic notion of thread-group
Willy Tarreau [Mon, 13 Sep 2021 16:11:26 +0000 (18:11 +0200)] 
MINOR: threads: introduce a minimalistic notion of thread-group

This creates a struct tgroup_info which knows the thread ID of the first
thread in a group, and the number of threads in it. For now there's only
one thread group supported in the configuration, but it may be forced to
other values for development purposes by defining MAX_TGROUPS, and it's
enabled even when threads are disabled and will need to remain accessible
during boot to keep a simple enough internal API.

For the purpose of easing the configurations which do not specify a thread
group, we're starting group numbering at 1 so that thread group 0 can be
"undefined" (i.e. for "bind" lines or when binding tasks).

The goal will be to later move there some global items that must be
made per-group.

3 years agoMINOR: thread: make "ti" a const pointer and clean up thread_info a bit
Willy Tarreau [Fri, 1 Oct 2021 14:29:27 +0000 (16:29 +0200)] 
MINOR: thread: make "ti" a const pointer and clean up thread_info a bit

We want to make sure that the current thread_info accessed via "ti" will
remain constant, so that we don't accidentally place new variable parts
there and so that the compiler knows that info retrieved from there is
not expected to have changed between two function calls.

Only a few init locations had to be adjusted to use the array and the
rest is unaffected.

3 years agoREORG: thread/sched: move the last dynamic thread_info to thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 17:02:18 +0000 (19:02 +0200)] 
REORG: thread/sched: move the last dynamic thread_info to thread_ctx

The last 3 fields were 3 list heads that are per-thread, and which are:
  - the pool's LRU head
  - the buffer_wq
  - the streams list head

Moving them into thread_ctx completes the removal of dynamic elements
from the struct thread_info. Now all these dynamic elements are packed
together at a single place for a thread.

3 years agoREORG: thread/sched: move the thread_info flags to the thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 16:48:37 +0000 (18:48 +0200)] 
REORG: thread/sched: move the thread_info flags to the thread_ctx

The TI_FL_STUCK flag is manipulated by the watchdog and scheduler
and describes the apparent life/death of a thread so it changes
all the time and it makes sense to move it to the thread's context
for an active thread.

3 years agoREORG: thread/clock: move the clock parts of thread_info to thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 16:28:49 +0000 (18:28 +0200)] 
REORG: thread/clock: move the clock parts of thread_info to thread_ctx

The "thread_info" name was initially chosen to store all info about
threads but since we now have a separate per-thread context, there is
no point keeping some of its elements in the thread_info struct.

As such, this patch moves prev_cpu_time, prev_mono_time and idle_pct to
thread_ctx, into the thread context, with the scheduler parts. Instead
of accessing them via "ti->" we now access them via "th_ctx->", which
makes more sense as they're totally dynamic, and will be required for
future evolutions. There's no room problem for now, the structure still
has 84 bytes available at the end.

3 years agoREORG: thread/sched: move the task_per_thread stuff to thread_ctx
Willy Tarreau [Fri, 1 Oct 2021 09:30:33 +0000 (11:30 +0200)] 
REORG: thread/sched: move the task_per_thread stuff to thread_ctx

The scheduler contains a lot of stuff that is thread-local and not
exclusively tied to the scheduler. Other parts (namely thread_info)
contain similar thread-local context that ought to be merged with
it but that is even less related to the scheduler. However moving
more data into this structure isn't possible since task.h is high
level and cannot be included everywhere (e.g. activity) without
causing include loops.

In the end, it appears that the task_per_thread represents most of
the per-thread context defined with generic types and should simply
move to tinfo.h so that everyone can use them.

The struct was renamed to thread_ctx and the variable "sched" was
renamed to "th_ctx". "sched" used to be initialized manually from
run_thread_poll_loop(), now it's initialized by ha_set_tid() just
like ti, tid, tid_bit.

The memset() in init_task() was removed in favor of a bss initialization
of the array, so that other subsystems can put their stuff in this array.

Since the tasklet array has TL_CLASSES elements, the TL_* definitions
was moved there as well, but it's not a problem.

The vast majority of the change in this patch is caused by the
renaming of the structures.

3 years agoCLEANUP: wdt: do not remap SI_TKILL to SI_LWP, test the values directly
Willy Tarreau [Fri, 8 Oct 2021 13:31:04 +0000 (15:31 +0200)] 
CLEANUP: wdt: do not remap SI_TKILL to SI_LWP, test the values directly

We used to remap SI_TKILL to SI_LWP when SI_TKILL was not available
(e.g. FreeBSD) but that's ugly and since we need this only in a single
switch/case block in wdt.c it's even simpler and cleaner to perform the
two tests there, so let's do this.

3 years agoMINOR: wdt: move wd_timer to wdt.c
Willy Tarreau [Fri, 8 Oct 2021 13:23:26 +0000 (15:23 +0200)] 
MINOR: wdt: move wd_timer to wdt.c

The watchdog timer had no more reason for being shared with the struct
thread_info since the watchdog is the only user now. Let's remove it
from the struct and move it to a static array in wdt.c. This removes
some ifdefs and the need for the ugly mapping to empty_t that might be
subject to a cast to a long when compared to TIMER_INVALID. Now timer_t
is not known outside of wdt.c and clock.c anymore.

3 years agoMINOR: clock: move the clock_ids to clock.c
Willy Tarreau [Fri, 8 Oct 2021 13:09:17 +0000 (15:09 +0200)] 
MINOR: clock: move the clock_ids to clock.c

This removes the knowledge of clockid_t from anywhere but clock.c, thus
eliminating a source of includes burden. The unused clock_id field was
removed from thread_info, and the definition setting of clockid_t was
removed from compat.h. The most visible change is that the function
now_cpu_time_thread() now takes the thread number instead of a tinfo
pointer.

3 years agoREORG: clock/wdt: move wdt timer initialization to clock.c
Willy Tarreau [Fri, 8 Oct 2021 12:48:30 +0000 (14:48 +0200)] 
REORG: clock/wdt: move wdt timer initialization to clock.c

The code that deals with timer creation for the WDT was moved to clock.c
and is called with the few relevant arguments. This removes the need for
awareness of clock_id from wdt.c and as such saves us from having to
share it outside. The timer_t is also known only from both ends but not
from the public API so that we don't have to create a fake timer_t
anymore on systems which do not support it (e.g. macos).

3 years agoREORG: clock: move the clock_id initialization to clock.c
Willy Tarreau [Fri, 8 Oct 2021 10:27:54 +0000 (12:27 +0200)] 
REORG: clock: move the clock_id initialization to clock.c

This was previously open-coded in run_thread_poll_loop(). Now that
we have clock.c dedicated to such stuff, let's move the code there
so that we don't need to keep such ifdefs nor to depend on the
clock_id.

3 years agoCLEANUP: clock: stop exporting before_poll and after_poll
Willy Tarreau [Fri, 8 Oct 2021 09:38:30 +0000 (11:38 +0200)] 
CLEANUP: clock: stop exporting before_poll and after_poll

We don't need to export them anymore so let's make them static.

3 years agoMINOR: activity: get the run_time from the clock updates
Willy Tarreau [Fri, 8 Oct 2021 09:34:46 +0000 (11:34 +0200)] 
MINOR: activity: get the run_time from the clock updates

Instead of fiddling with before_poll and after_poll in
activity_count_runtime(), the function is now called by
clock_entering_poll() which passes it the number of microseconds
spent working. This allows to remove all calls to
activity_count_runtime() from the pollers.

3 years agoREORG: clock: move the updates of cpu/mono time to clock.c
Willy Tarreau [Fri, 8 Oct 2021 08:43:59 +0000 (10:43 +0200)] 
REORG: clock: move the updates of cpu/mono time to clock.c

The entering_poll/leaving_poll/measure_idle functions that were hard
to classify and used to move to various locations have now been placed
into clock.c since it's precisely about time-keeping. The functions
were renamed to clock_*. The samp_time and idle_time values are now
static since there is no reason for them to be read from outside.

3 years agoREORG: time: move time-keeping code and variables to clock.c
Willy Tarreau [Fri, 8 Oct 2021 07:33:24 +0000 (09:33 +0200)] 
REORG: time: move time-keeping code and variables to clock.c

There is currently a problem related to time keeping. We're mixing
the functions to perform calculations with the os-dependent code
needed to retrieve and adjust the local time.

This patch extracts from time.{c,h} the parts that are solely dedicated
to time keeping. These are the "now" or "before_poll" variables for
example, as well as the various now_*() functions that make use of
gettimeofday() and clock_gettime() to retrieve the current time.

The "tv_*" functions moved there were also more appropriately renamed
to "clock_*".

Other parts used to compute stolen time are in other files, they will
have to be picked next.

3 years agoBUILD: init: avoid a build warning on FreeBSD with USE_PROCCTL
Willy Tarreau [Fri, 8 Oct 2021 13:55:13 +0000 (15:55 +0200)] 
BUILD: init: avoid a build warning on FreeBSD with USE_PROCCTL

It was brought by a variable declared after some statements in commit
21185970c ("MINOR: proc: setting the process to produce a core dump on
FreeBSD."). It's worth noting that some versions of clang seem to ignore
-Wdeclaration-after-statement by default. No backport is needed.

3 years agoBUILD: connection: avoid a build warning on FreeBSD with SO_USER_COOKIE
Willy Tarreau [Fri, 8 Oct 2021 13:52:27 +0000 (15:52 +0200)] 
BUILD: connection: avoid a build warning on FreeBSD with SO_USER_COOKIE

It was brough by an unneeded addition of a local variable after a test
in commit f7f53afcf ("BUILD/MEDIUM: tcp: set-mark setting support for
FreeBSD."). No backport needed.

3 years agoBUG/MINOR: quic: fix includes for compilation
Amaury Denoyelle [Thu, 7 Oct 2021 14:44:05 +0000 (16:44 +0200)] 
BUG/MINOR: quic: fix includes for compilation

Fix missing includes in quic code following the general recent include
reorganization. This fixes the compilation error with QUIC enabled.

3 years agoCLEANUP: mux-quic: remove unused code
Amaury Denoyelle [Tue, 5 Oct 2021 09:43:50 +0000 (11:43 +0200)] 
CLEANUP: mux-quic: remove unused code

Remove unused code in mux-quic. This is mostly code related to the
backend side. This code is untested for the moment, its removal will
simplify the code maintenance.

3 years agoMINOR: qpack: fix memory leak on huffman decoding
Amaury Denoyelle [Thu, 30 Sep 2021 15:14:55 +0000 (17:14 +0200)] 
MINOR: qpack: fix memory leak on huffman decoding

Remove an unneeded strdup invocation during QPACK huffman decoding. A
temporary storage buffer is passed by the function and exists after
decoding so no need to duplicate memory here.

3 years agoMINOR: qpack: support non-indexed http status code encoding
Amaury Denoyelle [Thu, 30 Sep 2021 12:47:55 +0000 (14:47 +0200)] 
MINOR: qpack: support non-indexed http status code encoding

If a HTTP status code is not present in the QPACK static table, encode
it with a literal field line with name reference.

3 years agoMINOR: qpack: do not encode invalid http status code
Amaury Denoyelle [Thu, 30 Sep 2021 12:47:32 +0000 (14:47 +0200)] 
MINOR: qpack: do not encode invalid http status code

Ensure that the HTTP status code is valid before encoding with QPACK. An
error is return if this is not the case.

3 years agoBUG/MEDIUM: mux_h2: Handle others remaining read0 cases on partial frames
Christopher Faulet [Fri, 8 Oct 2021 06:56:00 +0000 (08:56 +0200)] 
BUG/MEDIUM: mux_h2: Handle others remaining read0 cases on partial frames

We've found others places where the read0 is ignored because of an
incomplete frame parsing. This time, it happens during parsing of
CONTINUATION frames.

When frames are parsed, incomplete frames are properly handled and
H2_CF_DEM_SHORT_READ flag is set. It is also true for HEADERS
frames. However, for CONTINUATION frames, there is an exception. Besides
parsing the current frame, we try to peek header of the next one to merge
payload of both frames, the current one and the next one. Idea is to create
a sole HEADERS frame before parsing the payload. However, in this case, it
is possible to have an incomplete frame too, not the current one but the
next one. From the demux point of view, the current frame is complete. We
must go to the internal function h2c_decode_headers() to detect an
incomplete frame. And this case was not identified and fixed when
H2_CF_DEM_SHORT_READ flag was introduced in the commit b5f7b5296
("BUG/MEDIUM: mux-h2: Handle remaining read0 cases on partial frames")

This bug was reported in a comment of the issue #1362. The patch must be
backported as far as 2.0.

3 years agoBUG/MAJOR: quic: remove qc from receiver cids tree on free
Amaury Denoyelle [Thu, 30 Sep 2021 09:03:28 +0000 (11:03 +0200)] 
BUG/MAJOR: quic: remove qc from receiver cids tree on free

Remove the quic_conn from the receiver connection_ids tree on
quic_conn_free. This fixes a crash due to dangling references in the
tree after a quic connection release.

This operation must be conducted under the listener lock. For this
reason, the quic_conn now contains a reference to its attached listener.

3 years agoMINOR: mux-quic: release connection if no more bidir streams
Amaury Denoyelle [Fri, 24 Sep 2021 08:05:30 +0000 (10:05 +0200)] 
MINOR: mux-quic: release connection if no more bidir streams

Use the count of bidirectional streams to call qc_release in qc_detach.
We cannot inspect the by_id tree because uni-streams are never removed
from it. This allows the connection to be properly freed.

3 years agoBUG/MAJOR: xprt-quic: do not queue qc timer if not set
Amaury Denoyelle [Tue, 5 Oct 2021 12:42:25 +0000 (14:42 +0200)] 
BUG/MAJOR: xprt-quic: do not queue qc timer if not set

Do not queue the pto/loss-detection timer if set to TICK_ETERNITY. This
usage is invalid with the scheduler and cause a BUG_ON trigger.

3 years agoBUG/MEDIUM: mux-quic: reinsert all streams in by_id tree
Amaury Denoyelle [Fri, 24 Sep 2021 08:03:16 +0000 (10:03 +0200)] 
BUG/MEDIUM: mux-quic: reinsert all streams in by_id tree

It is required that all qcs streams are in the by_id tree for the xprt
to function correctly. Without this, some ACKs are not properly emitted
by xprt.

Note that this change breaks the free of the connection because the
condition eb_is_empty in qc_detach is always true. This will be fixed in
a following patch.

3 years agoMINOR: quic: Fix SSL error issues (do not use ssl_bio_and_sess_init())
Frédéric Lécaille [Tue, 28 Sep 2021 07:51:23 +0000 (09:51 +0200)] 
MINOR: quic: Fix SSL error issues (do not use ssl_bio_and_sess_init())

It seems it was a bad idea to use the same function as for TCP ssl sockets
to initialize the SSL session objects for QUIC with ssl_bio_and_sess_init().
Indeed, this had as very bad side effects to generate SSL errors due
to the fact that such BIOs initialized for QUIC could not finally be controlled
via the BIO_ctrl*() API, especially BIO_ctrl() function used by very much other
internal OpenSSL functions (BIO_push(), BIO_pop() etc).
Others OpenSSL base QUIC implementation do not use at all BIOs to configure
QUIC connections. So, we decided to proceed the same way as ngtcp2 for instance:
only initialize an SSL object and call SSL_set_quic_method() to set its
underlying method. Note that calling this function silently disable this option:
SSL_OP_ENABLE_MIDDLEBOX_COMPAT.
We implement qc_ssl_sess_init() to initialize SSL sessions for QUIC connections
to do so with a retry in case of allocation failure as this is done by
ssl_bio_and_sess_init(). We also modify the code part for haproxy servers.

3 years agoMINOR: quic: BUG_ON() SSL errors.
Frédéric Lécaille [Tue, 28 Sep 2021 07:05:59 +0000 (09:05 +0200)] 
MINOR: quic: BUG_ON() SSL errors.

As this QUIC implementation is still experimental, let's BUG_ON()
very important SSL handshake errors.
Also dump the SSL errors before BUG_ON().

3 years agoMINOR: quic: Add a function to dump SSL stack errors
Frédéric Lécaille [Tue, 28 Sep 2021 07:04:12 +0000 (09:04 +0200)] 
MINOR: quic: Add a function to dump SSL stack errors

This has been very helpful to fix SSL related issues.

3 years agoMINOR: quic: Distinguish packet and SSL read enc. level in traces
Frédéric Lécaille [Thu, 23 Sep 2021 16:10:56 +0000 (18:10 +0200)] 
MINOR: quic: Distinguish packet and SSL read enc. level in traces

This is only to distinguish the encryption level of packet traces from
the TLS stack current read encryption level.

3 years agoMINOR: pools: report the amount used by thread caches in "show pools"
Willy Tarreau [Thu, 7 Oct 2021 14:29:31 +0000 (16:29 +0200)] 
MINOR: pools: report the amount used by thread caches in "show pools"

The "show pools" command provides some "allocated" and "used" estimates
on the pools objects, but this applies to the shared pool and the "used"
includes what is currently assigned to thread-local caches. It's possible
to know how much each thread uses, so let's dump the total size allocated
by thread caches as an estimate. It's only done when pools are enabled,
which explains why the patch adds quite a lot of ifdefs.

3 years agoBUG/MINOR: task: fix missing include with DEBUG_TASK
Amaury Denoyelle [Thu, 7 Oct 2021 14:37:42 +0000 (16:37 +0200)] 
BUG/MINOR: task: fix missing include with DEBUG_TASK

Following include reorganzation, there is some missing include files for
task.h when compiling with DEBUG_TASK :
- activity.h for task_profiling_mask
- time.h for now_mono_time()

This is present since the following commit
  d8b325c74826bdb02759f62c41a00455dbae3431
  REORG: task: uninline the loop time measurement code

No need to backport this.

3 years agoDOC: configuration: add clarification on escaping in keyword arguments
Thayne McCombs [Mon, 4 Oct 2021 07:02:58 +0000 (01:02 -0600)] 
DOC: configuration: add clarification on escaping in keyword arguments

Add a more precise description on how backslash escaping is different
than the top-level parser, and give examples of how to handle single
quotes inside arguments.

3 years agoCLEANUP: thread: uninline ha_tkill/ha_tkillall/ha_cpu_relax()
Willy Tarreau [Wed, 6 Oct 2021 21:33:20 +0000 (23:33 +0200)] 
CLEANUP: thread: uninline ha_tkill/ha_tkillall/ha_cpu_relax()

These ones are rarely used or only to waste CPU cycles waiting, and are
the last ones requiring system includes in thread.h. Let's uninline them
and move them to thread.c.

3 years agoMINOR: thread: use a dedicated static pthread_t array in thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:53:51 +0000 (22:53 +0200)] 
MINOR: thread: use a dedicated static pthread_t array in thread.c

This removes the thread identifiers from struct thread_info and moves
them only in static array in thread.c since it's now the only file that
needs to touch it. It's also the only file that needs to include
pthread.h, beyond haproxy.c which needs it to start the poll loop. As
a result, much less system includes are needed and the LoC reduced by
around 3%.

3 years agoREORG: thread: move ha_get_pthread_id() to thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:44:28 +0000 (22:44 +0200)] 
REORG: thread: move ha_get_pthread_id() to thread.c

It's the last function which directly accesses the pthread_t, let's move
it to thread.c and leave a static inline for non-thread.

3 years agoREORG: thread: move the thread init/affinity/stop to thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:22:40 +0000 (22:22 +0200)] 
REORG: thread: move the thread init/affinity/stop to thread.c

haproxy.c still has to deal with pthread-specific low-level stuff that
is OS-dependent. We should not have to deal with this there, and we do
not need to access pthread anywhere else.

Let's move these 3 functions to thread.c and keep empty inline ones for
when threads are disabled.

3 years agoCLENAUP: wdt: use ha_tkill() instead of accessing pthread directly
Willy Tarreau [Wed, 6 Oct 2021 19:43:38 +0000 (21:43 +0200)] 
CLENAUP: wdt: use ha_tkill() instead of accessing pthread directly

Instead of calling pthread_kill() directly on the pthread_t let's
call ha_tkill() which does the same by itself. This will help isolate
pthread_t.

3 years agoREORG: fd: uninline compute_poll_timeout()
Willy Tarreau [Wed, 6 Oct 2021 17:55:29 +0000 (19:55 +0200)] 
REORG: fd: uninline compute_poll_timeout()

It's not needed to inline it at all (one call per loop) and it introduces
dependencies, let's move it to fd.c.

Removing the few remaining includes that came with it further reduced
by ~0.2% the LoC and the build time is now below 6s.

3 years agoCLEANUP: fd: do not include time.h
Willy Tarreau [Wed, 6 Oct 2021 17:44:15 +0000 (19:44 +0200)] 
CLEANUP: fd: do not include time.h

It's not needed at all here.

3 years agoCLEANUP: time: move a few configurable defines to defaults.h
Willy Tarreau [Wed, 6 Oct 2021 17:36:47 +0000 (19:36 +0200)] 
CLEANUP: time: move a few configurable defines to defaults.h

TV_ETERNITY, TV_ETERNITY_MS and MAX_DELAY_MS may be configured and
ought to be in defaults.h so that they can be inherited from everywhere
without including time.h and could also be redefined if neede
(particularly for MAX_DELAY_MS).

3 years agoREORG: task: uninline the loop time measurement code
Willy Tarreau [Wed, 6 Oct 2021 17:25:38 +0000 (19:25 +0200)] 
REORG: task: uninline the loop time measurement code

It's pointless to inline this, it's called exactly once per poll loop,
and it depends on time.h which is quite deep. Let's move that to task.c
along with sched_report_idle().

3 years agoREORG: connection: uninline the rest of the alloc/free stuff
Willy Tarreau [Wed, 6 Oct 2021 17:11:10 +0000 (19:11 +0200)] 
REORG: connection: uninline the rest of the alloc/free stuff

The remaining large functions are those allocating/initializing and
occasionally freeing connections, conn_streams and sockaddr. Let's
move them to connection.c. In fact, cs_free() is the only one-liner
but let's move it along with the other ones since a call will be
small compared to the rest of the work done there.

3 years agoCLEANUP: connection: remove unneeded tcpcheck-t.h and use only session-t.h
Willy Tarreau [Wed, 6 Oct 2021 17:03:12 +0000 (19:03 +0200)] 
CLEANUP: connection: remove unneeded tcpcheck-t.h and use only session-t.h

No need to include the full session stuff, we only need the type. Also,
remove the unneeded tcpcheck types.

3 years agoCLEANUP: connection: do not include http_ana!
Willy Tarreau [Wed, 6 Oct 2021 16:57:44 +0000 (18:57 +0200)] 
CLEANUP: connection: do not include http_ana!

It makes no sense to have http_ana here, that's used at higher levels.

3 years agoREORG: connection: move the largest inlines from connection.h to connection.c
Willy Tarreau [Wed, 6 Oct 2021 16:48:28 +0000 (18:48 +0200)] 
REORG: connection: move the largest inlines from connection.h to connection.c

The following inlined functions are particularly large (and probably not
inlined at all by the compiler), and together represent roughly half of
the file, while they're used at most once per connection. They were moved
to connection.c.

  conn_upgrade_mux_fe, conn_install_mux_fe, conn_install_mux_be,
  conn_install_mux_chk, conn_delete_from_tree, conn_init, conn_new,
  conn_free

3 years agoCLEANUP: tree-wide: only include ebtree-t from type files
Willy Tarreau [Wed, 6 Oct 2021 16:31:48 +0000 (18:31 +0200)] 
CLEANUP: tree-wide: only include ebtree-t from type files

No need to include the full tree management code, type files only
need the definitions. Doing so reduces the whole code size by around
3.6% and the build time is down to just 6s.

3 years agoREORG: ebtree: split structures into their own file ebtree-t.h
Willy Tarreau [Wed, 6 Oct 2021 15:55:45 +0000 (17:55 +0200)] 
REORG: ebtree: split structures into their own file ebtree-t.h

ebtree is one piece using a lot of inlines and each tree root or node
definition needed by many of our structures requires to parse and
compile all these includes, which is large and painfully slow. Let's
move the very basic definitions to their own file and include it from
ebtree.h.

3 years agoREORG: server: uninline the idle conns management functions
Willy Tarreau [Wed, 6 Oct 2021 16:30:04 +0000 (18:30 +0200)] 
REORG: server: uninline the idle conns management functions

The following functions are quite heavy and have no reason to be kept
inlined:

   srv_release_conn, srv_lookup_conn, srv_lookup_conn_next,
   srv_add_to_idle_list

They were moved to server.c. It's worth noting that they're a bit
at the edge between server and connection and that maybe we could
create an idle-conn file for these in the near future.

3 years agoREORG: connection: uninline conn_notify_mux() and conn_delete_from_tree()
Willy Tarreau [Wed, 6 Oct 2021 16:27:28 +0000 (18:27 +0200)] 
REORG: connection: uninline conn_notify_mux() and conn_delete_from_tree()

The former is far too huge to be inlined and the second is the only
one requiring an ebmb tree through all includes, let's move them to
connection.c.

3 years agoREORG: connection: move the hash-related stuff to connection.c
Willy Tarreau [Wed, 6 Oct 2021 15:14:49 +0000 (17:14 +0200)] 
REORG: connection: move the hash-related stuff to connection.c

We do not really need to have them inlined, and having xxhash.h included
by connection.h results in this 4700-lines file being processed 101 times
over the whole project, which accounts for 13.5% of the total size!
Additionally, half of the functions are only needed from connection.c.
Let's move the functions there and get rid of the painful include.

The build time is now down to 6.2s just due to this.

3 years agoMINOR: connection: use uint64_t for the hashes
Willy Tarreau [Wed, 6 Oct 2021 15:09:41 +0000 (17:09 +0200)] 
MINOR: connection: use uint64_t for the hashes

The hash type stored everywhere is XXH64_hash_t, which annoyingly forces
everyone to include the huge xxhash file. We know it's an uint64_t because
that's its purpose and the type is only made to abstract it on machines
where uint64_t is not availble. Let's switch the type to uint64_t
everywhere and avoid including xxhash from the type file.

3 years agoCLEANUP: stick-table: no need to include socket nor in.h
Willy Tarreau [Wed, 6 Oct 2021 14:43:14 +0000 (16:43 +0200)] 
CLEANUP: stick-table: no need to include socket nor in.h

The types provided by these are never present in stick_table-t.h,
let's drop them.

3 years agoCLEANUP: stream: remove many unneeded includes from stream-t.h
Willy Tarreau [Wed, 6 Oct 2021 14:39:28 +0000 (16:39 +0200)] 
CLEANUP: stream: remove many unneeded includes from stream-t.h

Plenty of includes were present there only for struct pointers resulting
in them being used from many other places. The LoC reduced again by more
than 1% by cleaning this.

3 years agoREORG: acitvity: uninline sched_activity_entry()
Willy Tarreau [Wed, 6 Oct 2021 14:26:33 +0000 (16:26 +0200)] 
REORG: acitvity: uninline sched_activity_entry()

This one is expensive in code size because it comes with xxhash.h at a
low level of dependency that's inherited at plenty of places, and for
a function does doesn't benefit from inlining and could possibly even
benefit from not being inline given that it's large and called from the
scheduler.

Moving it to activity.c reduces the LoC by 1.2% and the binary size by
~1kB.

3 years agoREORG: activity: uninline activity_count_runtime()
Willy Tarreau [Wed, 6 Oct 2021 14:22:09 +0000 (16:22 +0200)] 
REORG: activity: uninline activity_count_runtime()

This function has no reason for being inlined, it's called from non
critical places (once in pollers), is quite large and comes with
dependencies (time and freq_ctr). Let's move it to acitvity.c. That's
another 0.4% less LoC to build.

3 years agoCLEANUP: tree-wide: remove unneeded include time.h in ~20 files
Willy Tarreau [Wed, 6 Oct 2021 14:18:40 +0000 (16:18 +0200)] 
CLEANUP: tree-wide: remove unneeded include time.h in ~20 files

20 files used to have haproxy/time.h included only for now_ms, and two
were missing it for other things but used to inherit from it via other
files.

3 years agoREORG: time/ticks: move now_ms and global_now_ms definitions to ticks.h
Willy Tarreau [Wed, 6 Oct 2021 14:03:19 +0000 (16:03 +0200)] 
REORG: time/ticks: move now_ms and global_now_ms definitions to ticks.h

These are ticks, not timeval, and they're a cause for plenty of files
including time.h just to access now_ms that's only used with ticks
functions. Let's move them over there.

3 years agoREORG: sched: moved samp_time and idle_time to task.c as well
Willy Tarreau [Wed, 6 Oct 2021 13:58:46 +0000 (15:58 +0200)] 
REORG: sched: moved samp_time and idle_time to task.c as well

The idle time calculation stuff was moved to task.h by commit 6dfab112e
("REORG: sched: move idle time calculation from time.h to task.h") but
these two variables that are only maintained by task.{c,h} were still
left in time.{c,h}. They have to move as well.

3 years agoREORG: sample: move the crypto samples to ssl_sample.c
Willy Tarreau [Wed, 6 Oct 2021 13:37:17 +0000 (15:37 +0200)] 
REORG: sample: move the crypto samples to ssl_sample.c

These ones require openssl and are only built when it's enabled. There's
no point keeping them in sample.c when ssl_sample.c already deals with this
and the required includes. This also allows to remove openssl-compat.h
from sample.c and to further reduce the number of inclusions of openssl
includes, and the build time is now down to under 8 seconds.

3 years agoREORG: ssl-sock: move the sslconns/totalsslconns counters to global
Willy Tarreau [Wed, 6 Oct 2021 10:15:18 +0000 (12:15 +0200)] 
REORG: ssl-sock: move the sslconns/totalsslconns counters to global

These two counters were the only ones not in the global struct, while
the SSL freq counters or the req counts are already in it, this forces
stats.c to include ssl_sock just to know about them. Let's move them
over there with their friends. This reduces from 408 to 384 the number
of includes of opensslconf.h.

3 years agoCLEANUP: ssl/server: move ssl_sock_set_srv() to srv_set_ssl() in server.c
Willy Tarreau [Wed, 6 Oct 2021 09:48:34 +0000 (11:48 +0200)] 
CLEANUP: ssl/server: move ssl_sock_set_srv() to srv_set_ssl() in server.c

This one has nothing to do with ssl_sock as it manipulates the struct
server only. Let's move it to server.c and remove unneeded dependencies
on ssl_sock.h. This further reduces by 10% the number of includes of
opensslconf.h and by 0.5% the number of compiled lines.

3 years agoCLEANUP: mux_fcgi: remove dependency on ssl_sock
Willy Tarreau [Wed, 6 Oct 2021 09:40:11 +0000 (11:40 +0200)] 
CLEANUP: mux_fcgi: remove dependency on ssl_sock

It's not needed anymore (used to be needed for ssl_sock_is_ssl()).

3 years agoREORG: ssl: move ssl_sock_is_ssl() to connection.h and rename it
Willy Tarreau [Wed, 6 Oct 2021 09:38:44 +0000 (11:38 +0200)] 
REORG: ssl: move ssl_sock_is_ssl() to connection.h and rename it

This one doesn't use anything from an SSL context, it only checks the
type of the transport layer of a connection, thus it belongs to
connection.h. This is particularly visible due to all the ifdefs
around it in various call places.

3 years agoCLEANUP: servers: do not include openssl-compat
Willy Tarreau [Wed, 6 Oct 2021 09:23:32 +0000 (11:23 +0200)] 
CLEANUP: servers: do not include openssl-compat

This is exactly the same as for listeners, servers only include
openssl-compat to provide the SSL_CTX type to use as two pointers to
contexts, and to detect if NPN, ALPN, and cipher suites are supported,
and save up to 5 pointers in the ssl_ctx struct if not supported. This
is pointless, as these ones have all been supported for about a decade,
and including this file comes with a long dependency chain that impacts
lots of other files. The ctx was made a void*.

Now the build time was significantly reduced, from 9.2 to 8.1 seconds,
thanks to opensslconf.h being included "only" 456 times instead of 2424
previously!

The total number of lines of code compiled was reduced by 15%.

3 years agoCLEANUP: listeners: do not include openssl-compat
Willy Tarreau [Wed, 6 Oct 2021 09:16:02 +0000 (11:16 +0200)] 
CLEANUP: listeners: do not include openssl-compat

Listeners only include openssl-compat to provide the SSL_CTX type to
use as two pointers to contexts, and to detect if NPN, ALPN, and cipher
suites are supported, and save up to 5 pointers in the ssl_bind_conf
struct if not supported. This is pointless, as these ones have all been
supported for about a decade, and including this file comes with a long
dependency chain that impacts lots of other files. The initial_ctx and
default_ctx can perfectly remain void* instead of SSL_CTX*.

3 years agoREORG: listener: move bind_conf_alloc() and listener_state_str() to listener.c
Willy Tarreau [Wed, 6 Oct 2021 07:05:08 +0000 (09:05 +0200)] 
REORG: listener: move bind_conf_alloc() and listener_state_str() to listener.c

These functions have no reason for being inlined, and they require some
includes with long dependencies. Let's move them to listener.c and trim
unused includes in listener.h.

3 years agoCLEANUP: remove some unneeded includes from applet-t.h
Willy Tarreau [Wed, 6 Oct 2021 06:54:05 +0000 (08:54 +0200)] 
CLEANUP: remove some unneeded includes from applet-t.h

This file includes streams, proxies, Lua just for some definitions of
structures for which we only have a pointer. Let's drop this. That's
responsible for 0.2% of all the lines of code.

3 years agoMINOR: thread/debug: replace nsec_now() with now_mono_time()
Willy Tarreau [Tue, 5 Oct 2021 16:48:23 +0000 (18:48 +0200)] 
MINOR: thread/debug: replace nsec_now() with now_mono_time()

The two functions do exactly the same except that the second one
is already provided by time.h and still defined if not available.

3 years agoREORG: thread: uninline the lock-debugging code
Willy Tarreau [Tue, 5 Oct 2021 16:39:27 +0000 (18:39 +0200)] 
REORG: thread: uninline the lock-debugging code

The lock-debugging code in thread.h has no reason to be inlined. the
functions are quite fat and perform a lot of operations so there's no
saving keeping them inlined. Worse, most of them are in fact not
inlined, resulting in a significantly bigger executable.

This patch moves all this part from thread.h to thread.c. The functions
are still exported in thread.h of course. This results in ~166kB less
code:

     text    data     bss     dec     hex filename
  3165938   99424  897376 4162738  3f84b2 haproxy-before
  2991987   99424  897376 3988787  3cdd33 haproxy-after

In addition the build time with thread debugging enabled has shrunk
from 19.2 to 17.7s thanks to much less code to be parsed in thread.h
that is included virtually everywhere.

3 years agoREORG: pools: uninline the UAF allocator and force-inline the rest
Willy Tarreau [Tue, 5 Oct 2021 16:14:11 +0000 (18:14 +0200)] 
REORG: pools: uninline the UAF allocator and force-inline the rest

pool-os.h relies on a number of includes solely because the
pool_alloc_area() function was inlined, and this only because we want
the normal version to be inlined so that we can track the calling
places for the memory profiler. It's worth noting that it already
does not work at -O0, and that when UAF is enabled we don't care a
dime about profiling.

This patch does two things at once:
  - force-inline the functions so that pool_alloc_area() is still
    inlined at -O0 to help track malloc() users ;

  - uninline the UAF version of these (that rely on mmap/munmap)
    and move them to pools.c so that we can remove all unneeded
    includes.

Doing so reduces by ~270kB or 0.15% the total build size.

3 years agoCLEANUP: pools: pools-t.h doesn't need to include thread-t.h
Willy Tarreau [Tue, 5 Oct 2021 16:04:48 +0000 (18:04 +0200)] 
CLEANUP: pools: pools-t.h doesn't need to include thread-t.h

This is probably a leftover from an older version to access MAX_THREADS.

3 years agoBUILD: compat: fix -Wundef on SO_REUSEADDR
Willy Tarreau [Wed, 6 Oct 2021 18:06:06 +0000 (20:06 +0200)] 
BUILD: compat: fix -Wundef on SO_REUSEADDR

If USE_NETFILTER is set and not SO_REUSEPORT, we evaluate SO_REUSEADDR,
let's fix that to check that it's defined.

3 years agoBUILD: tree-wide: add several missing activity.h
Willy Tarreau [Wed, 6 Oct 2021 17:54:09 +0000 (19:54 +0200)] 
BUILD: tree-wide: add several missing activity.h

A number of files currently access activity counters but rely on their
definitions to be inherited from other files (task.c, backend.c hlua.c,
sock.c, pool.c, stats.c, fd.c).

3 years agoBUILD: mworker: mworker-prog needs time.h for the 'now' variable
Willy Tarreau [Wed, 6 Oct 2021 17:31:06 +0000 (19:31 +0200)] 
BUILD: mworker: mworker-prog needs time.h for the 'now' variable

It wasn't included and it used to get them through other includes.

3 years agoBUILD: tcp_sample: include missing errors.h and session-t.h
Willy Tarreau [Wed, 6 Oct 2021 17:01:21 +0000 (19:01 +0200)] 
BUILD: tcp_sample: include missing errors.h and session-t.h

Both are used without being defined as they were inherited from other
files.

3 years agoBUILD: cfgparse-ssl: add missing errors.h
Willy Tarreau [Wed, 6 Oct 2021 17:00:49 +0000 (19:00 +0200)] 
BUILD: cfgparse-ssl: add missing errors.h

ha_warning(), ha_alert() and friends are in errors.h and it used
to be inherited via other files.

3 years agoBUILD: tree-wide: add missing http_ana.h from many places
Willy Tarreau [Wed, 6 Oct 2021 16:56:42 +0000 (18:56 +0200)] 
BUILD: tree-wide: add missing http_ana.h from many places

At least 6 files make use of s->txn without including http_ana which
defines it. They used to get it from other includes.

3 years agoBUILD: connection: connection.h needs list.h and server.h
Willy Tarreau [Wed, 6 Oct 2021 16:48:01 +0000 (18:48 +0200)] 
BUILD: connection: connection.h needs list.h and server.h

It manipulates lists and calls srv_add_conn().

3 years agoBUILD: idleconns: include missing ebmbtree.h at several places
Willy Tarreau [Wed, 6 Oct 2021 16:23:40 +0000 (18:23 +0200)] 
BUILD: idleconns: include missing ebmbtree.h at several places

backend.c, all muxes, backend.c started manipulating ebmb_nodes with
the introduction of idle conns but the types were inherited through
other includes. Let's add ebmbtree.h there.

3 years agoBUILD: compiler: add the container_of() and container_of_safe() macros
Willy Tarreau [Wed, 6 Oct 2021 16:11:38 +0000 (18:11 +0200)] 
BUILD: compiler: add the container_of() and container_of_safe() macros

These ones are called from a few places in the code and are only provided
by ebtree.h, which is not normal given that some callers do not even use
ebtree.

3 years agoBUILD: ssl_ckch: include ebpttree.h in ssl_ckch.c
Willy Tarreau [Wed, 6 Oct 2021 15:54:12 +0000 (17:54 +0200)] 
BUILD: ssl_ckch: include ebpttree.h in ssl_ckch.c

It's used but is only found through other includes.

3 years agoBUILD: peers: need to include eb{32/mb/pt}tree.h
Willy Tarreau [Wed, 6 Oct 2021 15:53:19 +0000 (17:53 +0200)] 
BUILD: peers: need to include eb{32/mb/pt}tree.h

peers.c uses them all and used to only find them through other includes.

3 years agoBUILD: vars: need to include xxhash
Willy Tarreau [Wed, 6 Oct 2021 15:11:51 +0000 (17:11 +0200)] 
BUILD: vars: need to include xxhash

It's needed for XXH3(), and it used to get it through other includes.

3 years agoBUILD: http_rules: requires http_ana-t.h for REDIRECT_*
Willy Tarreau [Wed, 6 Oct 2021 14:38:53 +0000 (16:38 +0200)] 
BUILD: http_rules: requires http_ana-t.h for REDIRECT_*

It used to inherit it through other includes.

3 years agoBUILD: http_ana: need to include proxy-t to get redirect_rule
Willy Tarreau [Wed, 6 Oct 2021 14:37:40 +0000 (16:37 +0200)] 
BUILD: http_ana: need to include proxy-t to get redirect_rule

The struct was only defined inside function arguments there and
inherited from other files.

3 years agoBUILD: sample: include openssl-compat
Willy Tarreau [Wed, 6 Oct 2021 09:29:03 +0000 (11:29 +0200)] 
BUILD: sample: include openssl-compat

It's needed for EVP_*.

3 years agoBUILD: httpclient: include missing ssl_sock-t
Willy Tarreau [Wed, 6 Oct 2021 09:28:24 +0000 (11:28 +0200)] 
BUILD: httpclient: include missing ssl_sock-t

It's needed for SSL_SOCK_VERIFY_NONE.

3 years agoBUILD: resolvers: define missing types in resolvers.h
Willy Tarreau [Wed, 6 Oct 2021 07:18:37 +0000 (09:18 +0200)] 
BUILD: resolvers: define missing types in resolvers.h

proxy, server, stream_interface and list were used but not defined. Let's
define them as well as act_rule and drop action-t.h.

3 years agoBUILD: stats: define several missing structures in stats.h
Willy Tarreau [Wed, 6 Oct 2021 07:14:06 +0000 (09:14 +0200)] 
BUILD: stats: define several missing structures in stats.h

channel, stream_interface, appctx, buffer, proxy and htx ones are used
in function arguments and most of them are not defined but were inherited
from intermediary inclues. Let's define them here and drop the unneeded
includes.

3 years agoBUILD: hlua: needs to include stream-t.h
Willy Tarreau [Wed, 6 Oct 2021 07:12:44 +0000 (09:12 +0200)] 
BUILD: hlua: needs to include stream-t.h

It uses the SF_ERR_* error codes and currently gets them via
intermediary includes.

3 years agoBUILD: extcheck: needs to include stream-t.h
Willy Tarreau [Wed, 6 Oct 2021 07:11:54 +0000 (09:11 +0200)] 
BUILD: extcheck: needs to include stream-t.h

It uses the SF_ERR_* error codes and currently gets them via
intermediary includes.

3 years agoBUILD: action: add the relevant structures for function arguments
Willy Tarreau [Wed, 6 Oct 2021 07:09:01 +0000 (09:09 +0200)] 
BUILD: action: add the relevant structures for function arguments

Some structures are inherited via intermediary includes (e.g. dns_counters
comes from a long path). Let's define the missing ones and includes vars-t
that is needed in the structure.