]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: task: make __tasklet_wakeup_on() only accept non-local threads
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Jun 2026 14:29:02 +0000 (16:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Jun 2026 17:08:00 +0000 (19:08 +0200)
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.

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

index 3da256d11141bceeb662d5425add5b77cffde959..a1a33defee4ff2c22ddcab63f8383f52ff0ebbfc 100644 (file)
@@ -474,12 +474,9 @@ static inline void _tasklet_wakeup_here(struct tasklet *tl, uint f, const struct
        __tasklet_wakeup_here(tl);
 }
 
-/* schedules tasklet <tl> to run onto thread <thr> or the current thread if
- * <thr> 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
- * <file>:<line> from the call place are stored into the tasklet for tracing
- * purposes.
+/* schedules tasklet <tl> to run onto thread <thr> which must be valid. With
+ * DEBUG_TASK, the <file>:<line> 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
index 4c6700407c733ec00e386bd721c4633d2e6d2f24..f264e2644988dcf7ace4dc439a302406950c1586 100644 (file)
@@ -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 <thr> 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