MINOR: threads: add a timer_t per thread in thread_info

This will be used by the watchdog to detect that a thread locked up.
It's only defined on platforms supporting it. This patch only reserves
the room for the timer in the struct. A special value was reserved for
the uninitialized timer. The problem is that the POSIX API was horribly
designed, defining no invalid value, thus for each timer it is required
to keep a second variable to indicate whether it's valid. A quick check
shows that defining a 32-bit invalid value is not something uncommon
across other implementations, with ~0 being common. Let's try with this
and if it causes issues we can revisit this decision.
This commit is contained in:
Willy Tarreau 2019-05-21 20:01:26 +02:00
parent e6a02fa65a
commit 430f590b5b
2 changed files with 10 additions and 1 deletions

View File

@ -104,10 +104,17 @@ typedef struct { } empty_t;
#define F_SETPIPE_SZ (1024 + 7)
#endif
/* systems without such defines do not know clockid_t */
/* systems without such defines do not know clockid_t or timer_t */
#if !(_POSIX_TIMERS > 0) || (_POSIX_C_SOURCE < 199309L)
#undef clockid_t
#define clockid_t empty_t
#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(TPROXY) && defined(NETFILTER)

View File

@ -58,6 +58,7 @@ enum { tid = 0 };
extern struct thread_info {
clockid_t clock_id;
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) */
@ -407,6 +408,7 @@ void ha_tkillall(int sig);
extern struct thread_info {
pthread_t pthread;
clockid_t clock_id;
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) */