MEDIUM: wdt: fall back to CLOCK_REALTIME if CLOCK_THREAD_CPUTIME is not available
authorWilly Tarreau <w@1wt.eu>
Wed, 4 Mar 2020 09:48:18 +0000 (10:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 4 Mar 2020 11:02:27 +0000 (12:02 +0100)
At least FreeBSD has a fully functional CLOCK_THREAD_CPUTIME but it
cannot create a timer on it. This is not a problem since our timer is
only used to measure each thread's usage using now_cpu_time_thread().
So by just replacing this clock with CLOCK_REALTIME we allow such
platforms to periodically call the wdt and check the thread's CPU usage.
The consequence is that even on a totally idle system there will still
be a few extra periodic wakeups, but the watchdog becomes usable there
as well.

src/wdt.c

index 0c405b9..4adc33d 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -143,7 +143,8 @@ int init_wdt_per_thread()
        sev.sigev_notify          = SIGEV_SIGNAL;
        sev.sigev_signo           = WDTSIG;
        sev.sigev_value.sival_int = tid;
-       if (timer_create(ti->clock_id, &sev, &ti->wd_timer) == -1)
+       if (timer_create(ti->clock_id, &sev, &ti->wd_timer) == -1 &&
+           timer_create(CLOCK_REALTIME, &sev, &ti->wd_timer) == -1)
                goto fail1;
 
        if (!wdt_ping(tid))