]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: thread/sched: move the thread_info flags to the thread_ctx
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Sep 2021 16:48:37 +0000 (18:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
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.

include/haproxy/tinfo-t.h
src/debug.c
src/fd.c
src/listener.c
src/task.c
src/wdt.c

index afbf191d46aa3e35da5ef00857055ff7cdd4c249..dc6268e21f3ff545c488fb8618608916e4177579 100644 (file)
@@ -35,15 +35,13 @@ enum {
        TL_CLASSES       /* must be last */
 };
 
-/* thread info flags, for ha_thread_info[].flags */
-#define TI_FL_STUCK             0x00000001
+/* thread_ctx flags, for ha_thread_ctx[].flags */
+#define TH_FL_STUCK             0x00000001
 
 /* This structure describes all the per-thread info we need. When threads are
  * disabled, it contains the same info for the single running thread.
  */
 struct thread_info {
-       unsigned int flags;        /* thread info flags, TI_FL_* */
-
 #ifdef CONFIG_HAP_POOLS
        struct list pool_lru_head;                         /* oldest objects   */
 #endif
@@ -68,9 +66,10 @@ struct thread_ctx {
        unsigned int rqueue_ticks;          /* Insertion counter for the run queue */
        int current_queue;                  /* points to current tasklet list being run, -1 if none */
        unsigned int nb_tasks;              /* number of tasks allocated on this thread */
+       uint flags;                         /* thread flags, TH_FL_* */
        uint8_t tl_class_mask;              /* bit mask of non-empty tasklets classes */
 
-       // 11 bytes hole here
+       // 7 bytes hole here
        ALWAYS_ALIGN(2*sizeof(void*));
        struct list tasklets[TL_CLASSES];   /* tasklets (and/or tasks) to run, by class */
 
index aafa378394c639056d3fe03bdb46b6ca24ae78ab..b1472ae6dfe9cb982be55b9e39b423b5f4b8ec48 100644 (file)
@@ -152,7 +152,7 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
        unsigned long thr_bit = 1UL << thr;
        unsigned long long p = ha_thread_ctx[thr].prev_cpu_time;
        unsigned long long n = now_cpu_time_thread(thr);
-       int stuck = !!(ha_thread_info[thr].flags & TI_FL_STUCK);
+       int stuck = !!(ha_thread_ctx[thr].flags & TH_FL_STUCK);
 
        chunk_appendf(buf,
                      "%c%cThread %-2u: id=0x%llx act=%d glob=%d wq=%d rq=%d tl=%d tlsz=%d rqsz=%d\n"
@@ -1145,7 +1145,7 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
         * if it didn't move.
         */
        if (!((threads_harmless_mask|sleeping_thread_mask) & tid_bit))
-               ti->flags |= TI_FL_STUCK;
+               th_ctx->flags |= TH_FL_STUCK;
 }
 
 static int init_debug_per_thread()
index b796b1ae4b39c772e2f24358469e6b438de96635..fd2e134948723d6d41f5b58ff0b02b88527a3040 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -437,7 +437,7 @@ int fd_update_events(int fd, uint evts)
        uint new_flags, must_stop;
        ulong rmask, tmask;
 
-       ti->flags &= ~TI_FL_STUCK; // this thread is still running
+       th_ctx->flags &= ~TH_FL_STUCK; // this thread is still running
 
        /* do nothing if the FD was taken over under us */
        do {
index 0ba2ce6e54065ff328d5c0b8b568546fdec1cc55..a1e9edc1a1e78262ef562dd2e671dba28ff42406 100644 (file)
@@ -1047,7 +1047,7 @@ void listener_accept(struct listener *l)
                }
 #endif
 
-               ti->flags &= ~TI_FL_STUCK; // this thread is still running
+               th_ctx->flags &= ~TH_FL_STUCK; // this thread is still running
        } /* end of for (max_accept--) */
 
  end:
index 65aa6465eaad82868fb4e219bcd5377e9e830dd5..e2a0b236235b71e4183f81b08aba6f2d22e96e61 100644 (file)
@@ -529,7 +529,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                t = (struct task *)LIST_ELEM(tl_queues[queue].n, struct tasklet *, list);
                state = t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING|TASK_HEAVY|TASK_F_TASKLET|TASK_KILLED|TASK_F_USR1|TASK_KILLED);
 
-               ti->flags &= ~TI_FL_STUCK; // this thread is still running
+               th_ctx->flags &= ~TH_FL_STUCK; // this thread is still running
                activity[tid].ctxsw++;
                ctx = t->context;
                process = t->process;
@@ -685,7 +685,7 @@ void process_runnable_tasks()
        int heavy_queued = 0;
        int budget;
 
-       ti->flags &= ~TI_FL_STUCK; // this thread is still running
+       th_ctx->flags &= ~TH_FL_STUCK; // this thread is still running
 
        if (!thread_has_tasks()) {
                activity[tid].empty_rq++;
index b789fbeae9d97e2f26c89c63b572ed18245a86bd..b9d6ca7589d5db1b8548fd4c898db9581ef429d2 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -92,13 +92,13 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
                 * certain that we're not witnessing an exceptional spike of
                 * CPU usage due to a configuration issue (like running tens
                 * of thousands of tasks in a single loop), we'll check if the
-                * scheduler is still alive by setting the TI_FL_STUCK flag
+                * scheduler is still alive by setting the TH_FL_STUCK flag
                 * that the scheduler clears when switching to the next task.
                 * If it's already set, then it's our second call with no
                 * progress and the thread is dead.
                 */
-               if (!(ha_thread_info[thr].flags & TI_FL_STUCK)) {
-                       _HA_ATOMIC_OR(&ha_thread_info[thr].flags, TI_FL_STUCK);
+               if (!(ha_thread_ctx[thr].flags & TH_FL_STUCK)) {
+                       _HA_ATOMIC_OR(&ha_thread_ctx[thr].flags, TH_FL_STUCK);
                        goto update_and_leave;
                }