From: Willy Tarreau Date: Thu, 30 Sep 2021 16:48:37 +0000 (+0200) Subject: REORG: thread/sched: move the thread_info flags to the thread_ctx X-Git-Tag: v2.5-dev9~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0b99536c83e41b8419b1f8d7e14521a6020a92c;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index afbf191d46..dc6268e21f 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -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 */ diff --git a/src/debug.c b/src/debug.c index aafa378394..b1472ae6df 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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() diff --git a/src/fd.c b/src/fd.c index b796b1ae4b..fd2e134948 100644 --- 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 { diff --git a/src/listener.c b/src/listener.c index 0ba2ce6e54..a1e9edc1a1 100644 --- a/src/listener.c +++ b/src/listener.c @@ -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: diff --git a/src/task.c b/src/task.c index 65aa6465ea..e2a0b23623 100644 --- a/src/task.c +++ b/src/task.c @@ -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++; diff --git a/src/wdt.c b/src/wdt.c index b789fbeae9..b9d6ca7589 100644 --- 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; }