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.
This commit is contained in:
Willy Tarreau 2021-09-13 18:11:26 +02:00
parent 6036342f58
commit f9662848f2
4 changed files with 30 additions and 1 deletions

View File

@ -27,16 +27,25 @@
* but may be lowered to save resources on embedded systems.
*/
#ifndef USE_THREAD
/* threads disabled, 1 thread max */
/* threads disabled, 1 thread max, 1 group max (note: group ids start at 1) */
#define MAX_THREADS 1
#define MAX_THREADS_MASK 1
#define MAX_TGROUPS 1
#define MAX_THREADS_PER_GROUP 1
#else
/* threads enabled, max_threads defaults to long bits */
#ifndef MAX_THREADS
#define MAX_THREADS LONGBITS
#endif
#define MAX_THREADS_MASK (~0UL >> (LONGBITS - MAX_THREADS))
/* still limited to 1 group for now by default (note: group ids start at 1) */
#ifndef MAX_TGROUPS
#define MAX_TGROUPS 1
#endif
#define MAX_THREADS_PER_GROUP LONGBITS
#endif
/*

View File

@ -38,6 +38,20 @@ enum {
/* thread_ctx flags, for ha_thread_ctx[].flags */
#define TH_FL_STUCK 0x00000001
/* Thread group information. This defines a base and a count of global thread
* IDs which belong to it, and which can be looked up into thread_info/ctx. It
* is set up during parsing and is stable during operation. Thread groups start
* at 1 so tgroup[0] describes thread group 1.
*/
struct tgroup_info {
uint base; /* first thread in this group */
uint count; /* number of threads in this group */
/* pad to cache line (64B) */
char __pad[0]; /* unused except to check remaining room */
char __end[0] __attribute__((aligned(64)));
};
/* This structure describes all the per-thread info we need. When threads are
* disabled, it contains the same info for the single running thread. This is
* stable across all of a thread's life, and is being pointed to by the

View File

@ -26,6 +26,9 @@
#include <haproxy/tinfo-t.h>
/* the structs are in thread.c */
extern struct tgroup_info ha_tgroup_info[MAX_TGROUPS];
extern THREAD_LOCAL const struct tgroup_info *tg;
extern struct thread_info ha_thread_info[MAX_THREADS];
extern THREAD_LOCAL const struct thread_info *ti; /* thread_info for the current thread */

View File

@ -50,6 +50,9 @@
#include <haproxy/thread.h>
#include <haproxy/tools.h>
struct tgroup_info ha_tgroup_info[MAX_TGROUPS] = { };
THREAD_LOCAL const struct tgroup_info *tg = &ha_tgroup_info[0];
struct thread_info ha_thread_info[MAX_THREADS] = { };
THREAD_LOCAL const struct thread_info *ti = &ha_thread_info[0];