]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: add a timer_t per thread in thread_info
authorWilly Tarreau <w@1wt.eu>
Tue, 21 May 2019 18:01:26 +0000 (20:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 May 2019 09:50:48 +0000 (11:50 +0200)
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.

include/common/compat.h
include/common/hathreads.h

index e0f00dcf1eb096584a015e78255c99c4dde0eed7..9b97d821440dcdb5ed18680c9b5a07a84703656c 100644 (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)
index 32099094c0ddc6a38a1b87529eebac16ed0af4cc..268dd6349f429b9edfbbd6fbc5cf5ac59d571009 100644 (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) */