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.
This commit is contained in:
Willy Tarreau 2020-03-04 10:48:18 +01:00
parent c0bbdc196d
commit d6f1966543

View File

@ -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))