mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-09 23:39:55 +00:00
MINOR: wdt: move wd_timer to wdt.c
The watchdog timer had no more reason for being shared with the struct thread_info since the watchdog is the only user now. Let's remove it from the struct and move it to a static array in wdt.c. This removes some ifdefs and the need for the ugly mapping to empty_t that might be subject to a cast to a long when compared to TIMER_INVALID. Now timer_t is not known outside of wdt.c and clock.c anymore.
This commit is contained in:
parent
2169498941
commit
b474f43816
@ -24,7 +24,6 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
/* This is needed on Linux for Netfilter includes */
|
||||
#include <sys/param.h>
|
||||
@ -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 <linux/types.h>
|
||||
#include <linux/netfilter_ipv6.h>
|
||||
|
@ -22,18 +22,15 @@
|
||||
#ifndef _HAPROXY_TINFO_T_H
|
||||
#define _HAPROXY_TINFO_T_H
|
||||
|
||||
#include <time.h>
|
||||
#include <haproxy/api-t.h>
|
||||
|
||||
/* 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) */
|
||||
|
21
src/wdt.c
21
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 <thr>. 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
|
||||
|
Loading…
Reference in New Issue
Block a user