]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: add each thread's clockid into the global thread_info
authorWilly Tarreau <w@1wt.eu>
Fri, 3 May 2019 15:21:18 +0000 (17:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 09:42:25 +0000 (11:42 +0200)
This is the per-thread CPU runtime clock, it will be used to measure
the CPU usage of each thread and by the lockup detection mechanism. It
must only be retrieved at the beginning of run_thread_poll_loop() since
the thread must already have been started for this. But it must be done
before performing any per-thread initcall so that all thread init
functions have access to the clock ID.

Note that it could make sense to always have this clockid available even
in non-threaded situations and place the process' clock there instead.
But it would add portability issues which are currently easy to deal
with by disabling threads so it may not be worth it for now.

include/types/global.h
src/haproxy.c

index db8829567c3a88a8c9bf77132fe57145c7f82057..030a553e28a8ba812c704d5e5eede05ed7a7a3a1 100644 (file)
@@ -245,6 +245,7 @@ extern int atexit_flag;
 
 extern struct thread_info {
        __decl_hathreads(pthread_t pthread);
+       __decl_hathreads(clockid_t clock_id);
 } thread_info[MAX_THREADS];
 
 /* bit values to go with "warned" above */
index 74226817232fa638bbf38426b81f2b131be502e5..692c333f0bb5083cd8f603aec1f3ce5f18245bb1 100644 (file)
@@ -2497,6 +2497,11 @@ static void *run_thread_poll_loop(void *data)
        struct per_thread_deinit_fct *ptdf;
 
        ha_set_tid((unsigned long)data);
+
+#ifdef USE_THREAD
+       pthread_getcpuclockid(pthread_self(), &thread_info[tid].clock_id);
+#endif
+
        tv_update_date(-1,-1);
 
        /* per-thread init calls performed here are not allowed to snoop on