diff --git a/include/haproxy/compat.h b/include/haproxy/compat.h index be361b31e..edcbcd50e 100644 --- a/include/haproxy/compat.h +++ b/include/haproxy/compat.h @@ -24,7 +24,6 @@ #include #include -#include #include /* This is needed on Linux for Netfilter includes */ #include @@ -160,17 +159,6 @@ typedef struct { } empty_t; #define SI_TKILL SI_LWP #endif -/* systems without such defines do not know clockid_t or timer_t */ -#if !(_POSIX_TIMERS > 0) -#undef timer_t -#define timer_t empty_t -#endif - -/* define a dummy value to designate "no timer". Use only 32 bits. */ -#ifndef TIMER_INVALID -#define TIMER_INVALID ((timer_t)(unsigned long)(0xfffffffful)) -#endif - #if defined(USE_TPROXY) && defined(USE_NETFILTER) #include #include diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index 4d3ff5b4d..1d32d66c0 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -22,18 +22,15 @@ #ifndef _HAPROXY_TINFO_T_H #define _HAPROXY_TINFO_T_H -#include #include /* thread info flags, for ha_thread_info[].flags */ #define TI_FL_STUCK 0x00000001 /* This structure describes all the per-thread info we need. When threads are - * disabled, it contains the same info for the single running thread (except - * the pthread identifier which does not exist). + * disabled, it contains the same info for the single running thread. */ struct thread_info { - timer_t wd_timer; /* valid timer or TIMER_INVALID if not set */ uint64_t prev_cpu_time; /* previous per thread CPU time */ uint64_t prev_mono_time; /* previous system wide monotonic time */ unsigned int idle_pct; /* idle to total ratio over last sample (percent) */ diff --git a/src/wdt.c b/src/wdt.c index 87d0cda54..d1428a556 100644 --- a/src/wdt.c +++ b/src/wdt.c @@ -26,7 +26,14 @@ * It relies on timer_create() and timer_settime() which are only available in * this case. */ -#if defined(USE_RT) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME) +#if defined(USE_RT) && defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME) + +/* define a dummy value to designate "no timer". Use only 32 bits. */ +#ifndef TIMER_INVALID +#define TIMER_INVALID ((timer_t)(unsigned long)(0xfffffffful)) +#endif + +static timer_t per_thread_wd_timer[MAX_THREADS]; /* Setup (or ping) the watchdog timer for thread . Returns non-zero on * success, zero on failure. It interrupts once per second of CPU time. It @@ -39,7 +46,7 @@ int wdt_ping(int thr) its.it_value.tv_sec = 1; its.it_value.tv_nsec = 0; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; - return timer_settime(ha_thread_info[thr].wd_timer, 0, &its, NULL) == 0; + return timer_settime(per_thread_wd_timer[thr], 0, &its, NULL) == 0; } /* This is the WDTSIG signal handler */ @@ -127,7 +134,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg) int init_wdt_per_thread() { - if (!clock_setup_signal_timer(&ti->wd_timer, WDTSIG, tid)) + if (!clock_setup_signal_timer(&per_thread_wd_timer[tid], WDTSIG, tid)) goto fail1; if (!wdt_ping(tid)) @@ -136,17 +143,17 @@ int init_wdt_per_thread() return 1; fail2: - timer_delete(ti->wd_timer); + timer_delete(per_thread_wd_timer[tid]); fail1: - ti->wd_timer = TIMER_INVALID; + per_thread_wd_timer[tid] = TIMER_INVALID; ha_warning("Failed to setup watchdog timer for thread %u, disabling lockup detection.\n", tid); return 1; } void deinit_wdt_per_thread() { - if (ti->wd_timer != TIMER_INVALID) - timer_delete(ti->wd_timer); + if (per_thread_wd_timer[tid] != TIMER_INVALID) + timer_delete(per_thread_wd_timer[tid]); } /* registers the watchdog signal handler and returns 0. This sets up the signal