From: Willy Tarreau Date: Wed, 24 Jun 2026 14:45:13 +0000 (+0200) Subject: MINOR: task: move the profiling checks to the called functions not callers X-Git-Tag: v3.5-dev1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fd3c8bf70a98cf62d1a0d899b9d9d657efc9a60;p=thirdparty%2Fhaproxy.git MINOR: task: move the profiling checks to the called functions not callers The checks on TH_FL_TASK_PROFILING that are used to decide whether or not to set t->wake_date from now_mono_time() used to be made in callers of __tasklet_wakeup_on() and __tasklet_wakeup_after(), but not only this needlessly inflates code by placing this in every caller (~4kB), it also renders the design fragile since each caller needs to blindly copy-paste that statement. Let's move the operation in the callees instead. As a bonus, it allows to check the flag on the target thread and not on the calling thread (which was arguably a bug though without a noticeable effect since for now profiling is for all threads or none). --- diff --git a/include/haproxy/task.h b/include/haproxy/task.h index a5b4c691d..33c24b7d9 100644 --- a/include/haproxy/task.h +++ b/include/haproxy/task.h @@ -27,7 +27,6 @@ #include -#include #include #include #include @@ -472,8 +471,6 @@ static inline void _tasklet_wakeup_on(struct tasklet *tl, int thr, uint f, const #endif } - if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING) - tl->wake_date = now_mono_time(); __tasklet_wakeup_on(tl, thr); } @@ -540,8 +537,6 @@ static inline void _task_instant_wakeup(struct task *t, unsigned int f, const st #endif } - if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING) - t->wake_date = now_mono_time(); __tasklet_wakeup_on((struct tasklet *)t, thr); } @@ -585,8 +580,6 @@ static inline struct list *_tasklet_wakeup_after(struct list *head, struct taskl #endif } - if (th_ctx->flags & TH_FL_TASK_PROFILING) - tl->wake_date = now_mono_time(); return __tasklet_wakeup_after(head, tl); } diff --git a/src/task.c b/src/task.c index 1b736d863..f8fa088f8 100644 --- a/src/task.c +++ b/src/task.c @@ -138,6 +138,9 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr) { if (likely(thr < 0)) { /* this tasklet runs on the caller thread */ + if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING) + tl->wake_date = now_mono_time(); + if (tl->state & TASK_HEAVY) { LIST_APPEND(&th_ctx->tasklets[TL_HEAVY], &tl->list); th_ctx->tl_class_mask |= 1 << TL_HEAVY; @@ -161,6 +164,9 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr) _HA_ATOMIC_INC(&th_ctx->rq_total); } else { /* this tasklet runs on a specific thread. */ + if (_HA_ATOMIC_LOAD(&ha_thread_ctx[thr].flags) & TH_FL_TASK_PROFILING) + tl->wake_date = now_mono_time(); + MT_LIST_APPEND(&ha_thread_ctx[thr].shared_tasklet_list, list_to_mt_list(&tl->list)); _HA_ATOMIC_INC(&ha_thread_ctx[thr].rq_total); wake_thread(thr); @@ -174,6 +180,10 @@ void __tasklet_wakeup_on(struct tasklet *tl, int thr) struct list *__tasklet_wakeup_after(struct list *head, struct tasklet *tl) { BUG_ON(tl->tid >= 0 && tid != tl->tid); + + if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_TASK_PROFILING) + tl->wake_date = now_mono_time(); + /* this tasklet runs on the caller thread */ if (!head) { if (tl->state & TASK_HEAVY) {