]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: clock: move the clock_id initialization to clock.c
authorWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 10:27:54 +0000 (12:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
This was previously open-coded in run_thread_poll_loop(). Now that
we have clock.c dedicated to such stuff, let's move the code there
so that we don't need to keep such ifdefs nor to depend on the
clock_id.

include/haproxy/clock.h
src/clock.c
src/haproxy.c

index 73d4ef37c2856f61d5ede4fb236b89c38f5a3b46..77fd7ec7889ae531ddef312c1c53ae10c1bb1872 100644 (file)
@@ -35,6 +35,7 @@ extern THREAD_LOCAL struct timeval date;          /* the real current date (wall
 uint64_t now_cpu_time_thread(const struct thread_info *thr);
 uint64_t now_mono_time(void);
 uint64_t now_cpu_time(void);
+void clock_set_local_source(void);
 void clock_update_date(int max_wait, int interrupted);
 void clock_init_process_date(void);
 void clock_init_thread_date(void);
index ccb59c3cb39987bde0915a619b3bf00db1f5526e..5a3447f2be79f2ae2c489be07d24dae257d2b2d2 100644 (file)
 #include <sys/time.h>
 #include <time.h>
 
+#ifdef USE_THREAD
+#include <pthread.h>
+#endif
+
 #include <haproxy/api.h>
 #include <haproxy/activity.h>
 #include <haproxy/clock.h>
@@ -73,6 +77,18 @@ uint64_t now_cpu_time_thread(const struct thread_info *thr)
        return ret;
 }
 
+/* set the clock source for the local thread */
+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);
+#else
+       ti->clock_id = CLOCK_THREAD_CPUTIME_ID;
+#endif
+#endif
+}
+
 /* clock_update_date: sets <date> to system time, and sets <now> to something as
  * close as possible to real time, following a monotonic function. The main
  * principle consists in detecting backwards and forwards time jumps and adjust
index 618efb362f1295ef0a1a89f07d320f39c72c291d..885cc264c8b17271e3793993bae805bdcf7474a2 100644 (file)
@@ -2700,14 +2700,8 @@ static void *run_thread_poll_loop(void *data)
        ha_set_tid((unsigned long)data);
        set_thread_cpu_affinity();
        sched = &task_per_thread[tid];
+       clock_set_local_source();
 
-#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
-#ifdef USE_THREAD
-       pthread_getcpuclockid(pthread_self(), &ti->clock_id);
-#else
-       ti->clock_id = CLOCK_THREAD_CPUTIME_ID;
-#endif
-#endif
        /* Now, initialize one thread init at a time. This is better since
         * some init code is a bit tricky and may release global resources
         * after reallocating them locally. This will also ensure there is