]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: task: replace t->thread_mask with 1<<t->tid when thread mask is needed
authorWilly Tarreau <w@1wt.eu>
Wed, 15 Jun 2022 13:44:00 +0000 (15:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
At a few places where the task's thread mask. Now we know that it's always
either one bit or all bits of all_threads_mask, so we can replace it with
either 1<<tid or all_threads_mask depending on what's expected.

It's worth noting that the global_tasks_mask is still set this way and
that it's reaching its limits. Similarly, the task_new() API would deserve
an update to stop using a thread mask and use a thread number instead.
Similarly, task_set_affinity() should be updated to directly take a
thread number.

At this point the task's thread mask is not used anymore.

src/task.c

index cbf657a5ca7ebf3c4efba32c8838a92c86ae5e0e..c32b9e4db5cec421ae0f1b5837b9e7ec38845474 100644 (file)
@@ -239,7 +239,10 @@ void __task_wakeup(struct task *t)
                _HA_ATOMIC_INC(&grq_total);
                HA_SPIN_LOCK(TASK_RQ_LOCK, &rq_lock);
 
-               global_tasks_mask |= t->thread_mask;
+               if (t->tid < 0)
+                       global_tasks_mask = all_threads_mask;
+               else
+                       global_tasks_mask |= 1UL << thr;
                t->rq.key = ++global_rqueue_ticks;
                __ha_barrier_store();
        } else
@@ -260,7 +263,7 @@ void __task_wakeup(struct task *t)
        if (th_ctx->flags & TH_FL_TASK_PROFILING)
                t->call_date = now_mono_time();
 
-       eb32sc_insert(root, &t->rq, t->thread_mask);
+       eb32sc_insert(root, &t->rq, 1UL << thr);
 
 #ifdef USE_THREAD
        if (thr != tid) {
@@ -270,9 +273,8 @@ void __task_wakeup(struct task *t)
                /* If all threads that are supposed to handle this task are sleeping,
                 * wake one.
                 */
-               if ((((t->thread_mask & all_threads_mask) & sleeping_thread_mask) ==
-                    (t->thread_mask & all_threads_mask))) {
-                       unsigned long m = (t->thread_mask & all_threads_mask) &~ tid_bit;
+               if (sleeping_thread_mask & (1UL << thr)) {
+                       unsigned long m = 1UL << thr;
 
                        _HA_ATOMIC_AND(&sleeping_thread_mask, ~m);
                        wake_thread(thr);