From: Willy Tarreau Date: Fri, 8 Oct 2021 10:27:54 +0000 (+0200) Subject: REORG: clock: move the clock_id initialization to clock.c X-Git-Tag: v2.5-dev9~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44c58da52f741ebdddaf873561f5d7e827117600;p=thirdparty%2Fhaproxy.git REORG: clock: move the clock_id initialization to clock.c 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. --- diff --git a/include/haproxy/clock.h b/include/haproxy/clock.h index 73d4ef37c2..77fd7ec788 100644 --- a/include/haproxy/clock.h +++ b/include/haproxy/clock.h @@ -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); diff --git a/src/clock.c b/src/clock.c index ccb59c3cb3..5a3447f2be 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,6 +13,10 @@ #include #include +#ifdef USE_THREAD +#include +#endif + #include #include #include @@ -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 to system time, and sets 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 diff --git a/src/haproxy.c b/src/haproxy.c index 618efb362f..885cc264c8 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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