]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: wdt: use is_sched_alive() instead of keeping a local ctxsw copy
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2025 13:26:30 +0000 (15:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2025 14:25:47 +0000 (16:25 +0200)
Now we can simply call is_sched_alive() on the local thread to verify
that the scheduler is still ticking instead of having to keep a copy of
the ctxsw and comparing it. It's cleaner, doesn't require to maintain
a local copy, doesn't rely on activity[] (whose purpose is mainly for
observation and debugging), and shows how this could be extended later
to cover other use cases. Practically speaking this doesn't change
anything however, the algorithm is still the same.

src/wdt.c

index 0a17991dd0b229282986e5c661399f609ff30018..1863cc35d609b1d72a8a71cfb45d320ca5aa0892 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -20,6 +20,7 @@
 #include <haproxy/errors.h>
 #include <haproxy/global.h>
 #include <haproxy/signal-t.h>
+#include <haproxy/task.h>
 #include <haproxy/thread.h>
 #include <haproxy/tools.h>
 
@@ -40,7 +41,6 @@
  */
 static struct {
        timer_t timer;
-       uint prev_ctxsw;
 } per_thread_wd_ctx[MAX_THREADS];
 
 /* warn about stuck tasks after this delay (ns) */
@@ -65,7 +65,6 @@ int wdt_ping(int thr)
 void wdt_handler(int sig, siginfo_t *si, void *arg)
 {
        unsigned long long n, p;
-       uint prev_ctxsw, curr_ctxsw;
        ulong thr_bit;
        int thr, tgrp;
 
@@ -185,13 +184,9 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
        if (_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_STUCK)
                ha_panic();
 
-       prev_ctxsw = per_thread_wd_ctx[tid].prev_ctxsw;
-       curr_ctxsw = activity[tid].ctxsw;
-
-       if (curr_ctxsw == prev_ctxsw)
+       if (!is_sched_alive())
                ha_stuck_warning();
-       else
-               per_thread_wd_ctx[tid].prev_ctxsw = curr_ctxsw;
+
        /* let's go on */
 
  update_and_leave: