From: Willy Tarreau Date: Wed, 1 Oct 2025 05:58:01 +0000 (+0200) Subject: MINOR: sched: pass the thread number to is_sched_alive() X-Git-Tag: v3.3-dev9~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25f5f357cc70d45ec63e5ba1f2954ba0a4c4dd00;p=thirdparty%2Fhaproxy.git MINOR: sched: pass the thread number to is_sched_alive() Now it will be possible to query any thread's scheduler state, not only the current one. This aims at simplifying the watchdog checks for reported threads. The operation is now a simple atomic xchg. --- diff --git a/include/haproxy/task.h b/include/haproxy/task.h index b1252ed68..e56af6e99 100644 --- a/include/haproxy/task.h +++ b/include/haproxy/task.h @@ -123,11 +123,11 @@ void wake_expired_tasks(void); */ int next_timer_expiry(void); -/* Pings the scheduler to verify that tasks continue running. - * Returns 1 if the scheduler made progress since last call, - * 0 if it looks stuck. +/* Pings the scheduler to verify that tasks continue running for thread . + * Returns 1 if the scheduler made progress since last call, 0 if it looks + * stuck. It marks it as stuck for next visit. */ -int is_sched_alive(void); +int is_sched_alive(int thr); /* * Delete every tasks before running the master polling loop diff --git a/src/task.c b/src/task.c index 78bc48616..a4755655c 100644 --- a/src/task.c +++ b/src/task.c @@ -910,18 +910,13 @@ void process_runnable_tasks() activity[tid].long_rq++; } -/* Pings the scheduler to verify that tasks continue running. - * Returns 1 if the scheduler made progress since last call, - * 0 if it looks stuck. +/* Pings the scheduler to verify that tasks continue running for thread . + * Returns 1 if the scheduler made progress since last call, 0 if it looks + * stuck. It marks it as stuck for next visit. */ -int is_sched_alive(void) +int is_sched_alive(int thr) { - if (sched_ctx[tid].sched_stuck) - return 0; - - /* next time we'll know if any progress was made */ - sched_ctx[tid].sched_stuck = 1; - return 1; + return !HA_ATOMIC_XCHG(&sched_ctx[thr].sched_stuck, 1); } /* diff --git a/src/wdt.c b/src/wdt.c index f1159b000..4290d6115 100644 --- a/src/wdt.c +++ b/src/wdt.c @@ -189,7 +189,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg) if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_STUCK) ha_panic(); - if (!is_sched_alive()) + if (!is_sched_alive(thr)) ha_stuck_warning(); /* let's go on */