]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: replace task_set_affinity() with task_set_thread()
authorWilly Tarreau <w@1wt.eu>
Wed, 15 Jun 2022 15:20:16 +0000 (17:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
The latter passes a thread ID instead of a mask, making the code simpler.

doc/internals/api/scheduler.txt
include/haproxy/applet.h
include/haproxy/task.h
src/check.c
src/extcheck.c

index 34695436b057319261e61528af52f0cf6fa9aede..dd1ad5f07c948353bc8f30c1af31660794e43ec0 100644 (file)
@@ -91,10 +91,12 @@ void task_queue(t)
         function for local tasks or for shared tasks who have the calling
         thread in their thread mask.
 
-void task_set_affinity(t, m)
-        Change task <t>'s thread_mask to new value <m>. This may only be
+void task_set_thread(t, id)
+        Change task <t>'s thread ID to new value <id>. This may only be
         performed by the task itself while running. This is only used to let a
-        task voluntarily migrate to another thread.
+        task voluntarily migrate to another thread. Thread id -1 is used to
+        indicate "any thread". It's ignored and replaced by zero when threads
+        are disabled.
 
 void tasklet_wakeup(tl)
         Make sure that tasklet <tl> will wake up, that is, will execute at
index 1fb3b260dec68adabd14b407d6cf7612957adf34..752a1a2b2f766d9fd4a2fdad4b85dcef0fccf786 100644 (file)
@@ -66,7 +66,7 @@ static inline int appctx_init(struct appctx *appctx)
         * eventually be created. The affinity must be set now !
         */
        BUG_ON(appctx->t->tid != tid);
-       task_set_affinity(appctx->t, tid_bit);
+       task_set_thread(appctx->t, tid);
 
        if (appctx->applet->init)
                return appctx->applet->init(appctx);
index a753cd90bb17735db9cd97e99593c3071d5b9a2c..d1613c047d7b0dce7c4213fe46062fca8f945dc0 100644 (file)
@@ -324,22 +324,22 @@ static inline void task_queue(struct task *task)
        }
 }
 
-/* change the thread affinity of a task to <thread_mask>.
+/* Change the thread affinity of a task to <thr>, which may either be a valid
+ * thread number from 0 to nbthread-1, or a negative value to allow the task
+ * to run on any thread.
+ *
  * This may only be done from within the running task itself or during its
  * initialization. It will unqueue and requeue the task from the wait queue
  * if it was in it. This is safe against a concurrent task_queue() call because
  * task_queue() itself will unlink again if needed after taking into account
  * the new thread_mask.
  */
-static inline void task_set_affinity(struct task *t, unsigned long thread_mask)
+static inline void task_set_thread(struct task *t, int thr)
 {
-       int thr;
-
-       if (atleast2(thread_mask))
-               thr = -1;
-       else
-               thr = my_ffsl(thread_mask) - 1;
-
+#ifndef USE_THREAD
+       /* no shared queue without threads */
+       thr = 0;
+#endif
        if (unlikely(task_in_wq(t))) {
                task_unlink_wq(t);
                t->tid = thr;
index ada79ed557c81456a6610ab50592c52b73e94f48..2366fc5ae0f7921ceeaf5d1d23d9c5e95fc7be96 100644 (file)
@@ -1118,7 +1118,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
                check->state |= CHK_ST_INPROGRESS;
                TRACE_STATE("init new health-check", CHK_EV_TASK_WAKE|CHK_EV_HCHK_START, check);
 
-               task_set_affinity(t, tid_bit);
+               task_set_thread(t, tid);
 
                check->current_step = NULL;
 
@@ -1217,7 +1217,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
         if (LIST_INLIST(&check->buf_wait.list))
                 LIST_DEL_INIT(&check->buf_wait.list);
 
-       task_set_affinity(t, all_threads_mask);
+       task_set_thread(t, -1);
        check_release_buf(check, &check->bi);
        check_release_buf(check, &check->bo);
        check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);
index 7b3dbbaf11d04d183788c94856f6e166fb812597..6b5b2b68520dfb2c69cad28dfdd1e286265efb9e 100644 (file)
@@ -525,7 +525,7 @@ struct task *process_chk_proc(struct task *t, void *context, unsigned int state)
                                int t_con = tick_add(now_ms, s->proxy->timeout.connect);
                                t->expire = tick_first(t->expire, t_con);
                        }
-                       task_set_affinity(t, tid_bit);
+                       task_set_thread(t, tid);
                        goto reschedule;
                }
 
@@ -588,7 +588,7 @@ struct task *process_chk_proc(struct task *t, void *context, unsigned int state)
                        /* a success was detected */
                        check_notify_success(check);
                }
-               task_set_affinity(t, 1);
+               task_set_thread(t, 0);
                check->state &= ~CHK_ST_INPROGRESS;
 
                pid_list_del(check->curpid);