From: Willy Tarreau Date: Wed, 4 Mar 2020 09:48:18 +0000 (+0100) Subject: MEDIUM: wdt: fall back to CLOCK_REALTIME if CLOCK_THREAD_CPUTIME is not available X-Git-Tag: v2.2-dev4~84 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=d6f19665434234f27916e550826a9bb62928064b;p=haproxy.git 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. --- 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))