From: Willy Tarreau Date: Wed, 24 Jun 2026 14:29:02 +0000 (+0200) Subject: MEDIUM: task: make __tasklet_wakeup_on() only accept non-local threads X-Git-Tag: v3.5-dev1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69c799f286344bfe3110d51fcce02a37f2ea6078;p=thirdparty%2Fhaproxy.git MEDIUM: task: make __tasklet_wakeup_on() only accept non-local threads The ambiguity in usage for __tasklet_wakeup_on() is now gone. All known callers that used to be able to pass a negative value now call __tasklet_wakeup_here(), and remaining ones always pass an explicit thread number. This means that we can remove the "if (thr<0)" branch, but still leave a BUG_ON_HOT() to catch any possibly missed case. The comment around tasklet_wakeup_on() not supporting remotely waking a tasklet whose tid<0 was also removed since it was addressed long ago. --- diff --git a/include/haproxy/task.h b/include/haproxy/task.h index 3da256d11..a1a33defe 100644 --- a/include/haproxy/task.h +++ b/include/haproxy/task.h @@ -474,12 +474,9 @@ static inline void _tasklet_wakeup_here(struct tasklet *tl, uint f, const struct __tasklet_wakeup_here(tl); } -/* schedules tasklet to run onto thread or the current thread if - * is negative. Note that it is illegal to wakeup a foreign tasklet if - * its tid is negative and it is illegal to self-assign a tasklet that was - * at least once scheduled on a specific thread. With DEBUG_TASK, the - * : from the call place are stored into the tasklet for tracing - * purposes. +/* schedules tasklet to run onto thread which must be valid. With + * DEBUG_TASK, the : from the call place are stored into the + * tasklet for tracing purposes. * * The macro accepts an optional 3rd argument that is passed as a set of flags * to be set on the tasklet, among TASK_WOKEN_*, TASK_F_UEVT* etc to indicate a diff --git a/src/task.c b/src/task.c index 4c6700407..f264e2644 100644 --- a/src/task.c +++ b/src/task.c @@ -168,46 +168,18 @@ void __tasklet_wakeup_here(struct tasklet *tl) /* Do not call this one, please use tasklet_wakeup_on() instead, as this one is * the slow path of tasklet_wakeup_on() which performs some preliminary checks - * and sets TASK_QUEUED before calling this one. A negative designates - * the current thread. + * and sets TASK_QUEUED before calling this one. */ 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(); + BUG_ON_HOT(thr < 0); - if (tl->state & TASK_HEAVY) { - LIST_APPEND(&th_ctx->tasklets[TL_HEAVY], &tl->list); - th_ctx->tl_class_mask |= 1 << TL_HEAVY; - } - else if (tl->state & TASK_SELF_WAKING) { - LIST_APPEND(&th_ctx->tasklets[TL_BULK], &tl->list); - th_ctx->tl_class_mask |= 1 << TL_BULK; - } - else if ((struct task *)tl == th_ctx->current && !(tl->state & TASK_WOKEN_ANY)) { - LIST_APPEND(&th_ctx->tasklets[TL_BULK], &tl->list); - th_ctx->tl_class_mask |= 1 << TL_BULK; - } - else if (th_ctx->current_queue < 0) { - LIST_APPEND(&th_ctx->tasklets[TL_URGENT], &tl->list); - th_ctx->tl_class_mask |= 1 << TL_URGENT; - } - else { - LIST_APPEND(&th_ctx->tasklets[TL_NORMAL], &tl->list); - th_ctx->tl_class_mask |= 1 << TL_NORMAL; - } - _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(); + 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); - } + 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); } /* Do not call this one, please use tasklet_wakeup_after_on() instead, as this one is