]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: move the profiling checks to the called functions not callers
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Jun 2026 14:45:13 +0000 (16:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Jun 2026 16:01:33 +0000 (18:01 +0200)
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).

include/haproxy/task.h
src/task.c

index a5b4c691d9efc64458dea4d8d1e6fb12e6ac0b99..33c24b7d97258105ebc455eac7ae0a670e7c4470 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <import/eb32tree.h>
 
-#include <haproxy/activity.h>
 #include <haproxy/api.h>
 #include <haproxy/clock.h>
 #include <haproxy/fd.h>
@@ -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);
 }
 
index 1b736d86396946f423b25fdcbe751618f61825f8..f8fa088f8e21999b4e3e42b81fd42993f9006ba4 100644 (file)
@@ -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) {