#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) */
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);
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)
{
}
/* 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;
{
#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
}
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
{
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,
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)