]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: clock: move the clock_ids to clock.c
authorWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 13:09:17 +0000 (15:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
This removes the knowledge of clockid_t from anywhere but clock.c, thus
eliminating a source of includes burden. The unused clock_id field was
removed from thread_info, and the definition setting of clockid_t was
removed from compat.h. The most visible change is that the function
now_cpu_time_thread() now takes the thread number instead of a tinfo
pointer.

include/haproxy/clock.h
include/haproxy/compat.h
include/haproxy/tinfo-t.h
src/clock.c
src/debug.c
src/wdt.c

index 2cee76da4e69f401c7e86cf8e1db465bcef4472a..dedcacb248329513927420c7e97cc5f61409384b 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <sys/time.h>
 #include <haproxy/api.h>
-#include <haproxy/tinfo-t.h>
 
 extern struct timeval              start_date;    /* the process's start date in wall-clock time */
 extern volatile ullong             global_now;    /* common monotonic date between all threads (32:32) */
@@ -32,7 +31,7 @@ extern volatile ullong             global_now;    /* common monotonic date betwe
 extern THREAD_LOCAL struct timeval now;           /* internal monotonic date derived from real clock */
 extern THREAD_LOCAL struct timeval date;          /* the real current date (wall-clock time) */
 
-uint64_t now_cpu_time_thread(const struct thread_info *thr);
+uint64_t now_cpu_time_thread(int thr);
 uint64_t now_mono_time(void);
 uint64_t now_cpu_time(void);
 void clock_set_local_source(void);
index 18eadcc565d88f2517b7c57941e2ef4aabaeca4e..be361b31ecfa24ccfd58766348242e3cf8711fec 100644 (file)
@@ -162,8 +162,6 @@ typedef struct { } empty_t;
 
 /* systems without such defines do not know clockid_t or timer_t */
 #if !(_POSIX_TIMERS > 0)
-#undef clockid_t
-#define clockid_t empty_t
 #undef timer_t
 #define timer_t empty_t
 #endif
index 6c09fc4567d511194532d8b2cd40f47741d9f962..4d3ff5b4d19aa339b158f88e519f21d1d3df7dcd 100644 (file)
@@ -33,7 +33,6 @@
  * the pthread identifier which does not exist).
  */
 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  */
index 517f0a3a53341ffdde874749a70d1f8f8704eece..33d7b4dee588b658330054a0615791d8bc615076 100644 (file)
@@ -43,6 +43,10 @@ static THREAD_LOCAL unsigned int idle_time;       /* total idle time over curren
 static THREAD_LOCAL unsigned int iso_time_sec;     /* last iso time value for this thread */
 static THREAD_LOCAL char         iso_time_str[34]; /* ISO time representation of gettimeofday() */
 
+#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
+static clockid_t per_thread_clock_id[MAX_THREADS];
+#endif
+
 /* returns the system's monotonic time in nanoseconds if supported, otherwise zero */
 uint64_t now_mono_time(void)
 {
@@ -68,12 +72,12 @@ uint64_t now_cpu_time(void)
 }
 
 /* returns another thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
-uint64_t now_cpu_time_thread(const struct thread_info *thr)
+uint64_t now_cpu_time_thread(int thr)
 {
        uint64_t ret = 0;
 #if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
        struct timespec ts;
-       clock_gettime(thr->clock_id, &ts);
+       clock_gettime(per_thread_clock_id[thr], &ts);
        ret = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
 #endif
        return ret;
@@ -84,9 +88,9 @@ void clock_set_local_source(void)
 {
 #if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
 #ifdef USE_THREAD
-       pthread_getcpuclockid(pthread_self(), &ti->clock_id);
+       pthread_getcpuclockid(pthread_self(), &per_thread_clock_id[tid]);
 #else
-       ti->clock_id = CLOCK_THREAD_CPUTIME_ID;
+       per_thread_clock_id[tid] = CLOCK_THREAD_CPUTIME_ID;
 #endif
 #endif
 }
@@ -115,7 +119,7 @@ int clock_setup_signal_timer(void *tmr, int sig, int val)
        sev.sigev_notify          = SIGEV_SIGNAL;
        sev.sigev_signo           = sig;
        sev.sigev_value.sival_int = val;
-       if (timer_create(ti->clock_id, &sev, timer) != -1 ||
+       if (timer_create(per_thread_clock_id[tid], &sev, timer) != -1 ||
            timer_create(CLOCK_REALTIME, &sev, timer) != -1)
                ret = 1;
 #endif
index c5b78edc7bd3cf02ea41b9b879e9f27efd27fb83..ae3d9aebd469f1194226ceca5ef6bb253d5709e2 100644 (file)
@@ -151,7 +151,7 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
 {
        unsigned long thr_bit = 1UL << thr;
        unsigned long long p = ha_thread_info[thr].prev_cpu_time;
-       unsigned long long n = now_cpu_time_thread(&ha_thread_info[thr]);
+       unsigned long long n = now_cpu_time_thread(thr);
        int stuck = !!(ha_thread_info[thr].flags & TI_FL_STUCK);
 
        chunk_appendf(buf,
index a893b5d89659d67eb92f30db35fca9cab114795b..87d0cda5428123dbc5e0ceb789c6ca68f8b5f334 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -65,7 +65,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
                        break;
 
                p = ha_thread_info[thr].prev_cpu_time;
-               n = now_cpu_time_thread(&ha_thread_info[thr]);
+               n = now_cpu_time_thread(thr);
 
                /* not yet reached the deadline of 1 sec */
                if (n - p < 1000000000UL)