]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sched: let's permit to share the local ctx between threads
authorWilly Tarreau <w@1wt.eu>
Tue, 30 Sep 2025 16:56:41 +0000 (18:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 1 Oct 2025 08:18:53 +0000 (10:18 +0200)
The watchdog timer has to go through complex operations due to not being
able to check if another thread's scheduler is still ticking. This is
simply because the scheduler status is marked as thread-local while it
could in fact also be an array. Let's do that (and align the array to
avoid false sharing) so that it's now possible to check any scheduler's
status.

src/task.c

index 4f7ef2bb2a5de2bcbf041f333ed22213c15e91d1..78bc486164186f1a97e204d2a6f665d490c202f3 100644 (file)
@@ -43,7 +43,9 @@ DECLARE_TYPED_POOL(pool_head_notification, "notification", struct notification);
 __decl_aligned_rwlock(wq_lock);
 
 /* used to detect if the scheduler looks stuck (for warnings) */
-static THREAD_LOCAL int sched_stuck;
+static struct {
+       int sched_stuck ALIGNED(64);
+} sched_ctx[MAX_THREADS];
 
 /* Flags the task <t> for immediate destruction and puts it into its first
  * thread's shared tasklet list if not yet queued/running. This will bypass
@@ -677,7 +679,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                done++;
        next:
                th_ctx->current = NULL;
-               sched_stuck = 0; // scheduler is not stuck (don't warn)
+               sched_ctx[tid].sched_stuck = 0; // scheduler is not stuck (don't warn)
                __ha_barrier_store();
 
                /* stats are only registered for non-zero wake dates */
@@ -914,11 +916,11 @@ void process_runnable_tasks()
  */
 int is_sched_alive(void)
 {
-       if (sched_stuck)
+       if (sched_ctx[tid].sched_stuck)
                return 0;
 
        /* next time we'll know if any progress was made */
-       sched_stuck = 1;
+       sched_ctx[tid].sched_stuck = 1;
        return 1;
 }