diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index a6337e9c3..35ad50d04 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -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 /* diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index fe9ef9bd0..963d0a937 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -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 diff --git a/include/haproxy/tinfo.h b/include/haproxy/tinfo.h index a1b73463f..6b654f987 100644 --- a/include/haproxy/tinfo.h +++ b/include/haproxy/tinfo.h @@ -26,6 +26,9 @@ #include /* 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 */ diff --git a/src/thread.c b/src/thread.c index 14bf21eba..445a73fa8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -50,6 +50,9 @@ #include #include +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];