From 590116478991f3c4eb217e8eb87f1124fe12a563 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 17 Apr 2025 15:26:30 +0200 Subject: [PATCH] MINOR: wdt: use is_sched_alive() instead of keeping a local ctxsw copy 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 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/wdt.c b/src/wdt.c index 0a17991dd..1863cc35d 100644 --- a/src/wdt.c +++ b/src/wdt.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -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: