]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: introduce a minimalistic notion of thread-group
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Sep 2021 16:11:26 +0000 (18:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
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.

include/haproxy/defaults.h
include/haproxy/tinfo-t.h
include/haproxy/tinfo.h
src/thread.c

index a6337e9c39b88caa929e19628274267e3e84b834..35ad50d04ab213be300cae15ab128636af2c9bac 100644 (file)
  * 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
 
 /*
index fe9ef9bd025286e93303b336ab373f82684abbb7..963d0a937d75b51ed1f7583eb9a59cb8e73799e0 100644 (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
index a1b73463f0515cc97aaca39f5742f76a189d7703..6b654f987349f08c930f2a7603ee2bc2f3f8a2da 100644 (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 */
 
index 14bf21eba60e8ef2cf82b161c297ef2454ce5ea8..445a73fa8c1cdf509f610fe59115c53d5dc0846d 100644 (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];