From d6f19665434234f27916e550826a9bb62928064b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 4 Mar 2020 10:48:18 +0100 Subject: [PATCH] MEDIUM: wdt: fall back to CLOCK_REALTIME if CLOCK_THREAD_CPUTIME is not available 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wdt.c b/src/wdt.c index 0c405b9db..4adc33db2 100644 --- 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))