]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sched: pass the thread number to is_sched_alive()
authorWilly Tarreau <w@1wt.eu>
Wed, 1 Oct 2025 05:58:01 +0000 (07:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 1 Oct 2025 08:18:53 +0000 (10:18 +0200)
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.

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

index b1252ed68993fb50fadd93ae63e357337f34b2bf..e56af6e99eb30537615fe972dab09692993acbcc 100644 (file)
@@ -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 <thr>.
+ * 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
index 78bc486164186f1a97e204d2a6f665d490c202f3..a4755655c61189a9441b7383b072a26b0a9ef10e 100644 (file)
@@ -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 <thr>.
+ * 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);
 }
 
 /*
index f1159b0005a9d6bb93b1715562b4c96375a31787..4290d6115966c6e4984c6198e9bae207c13520de 100644 (file)
--- 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 */