mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 06:40:59 +01:00
MINOR: clock: add now_mono_time_fast() function
Same as now_mono_time(), but for fast queries (less accurate) Relies on coarse clock source (also known as fast clock source on some systems). Fallback to now_mono_time() if coarse source is not supported on the system.
This commit is contained in:
parent
be336620b7
commit
07cbd8e074
@ -34,6 +34,7 @@ extern THREAD_LOCAL struct timeval date; /* the real current date (wall
|
|||||||
|
|
||||||
uint64_t now_cpu_time_thread(int thr);
|
uint64_t now_cpu_time_thread(int thr);
|
||||||
uint64_t now_mono_time(void);
|
uint64_t now_mono_time(void);
|
||||||
|
uint64_t now_mono_time_fast(void);
|
||||||
uint64_t now_cpu_time(void);
|
uint64_t now_cpu_time(void);
|
||||||
void clock_set_local_source(void);
|
void clock_set_local_source(void);
|
||||||
void clock_update_local_date(int max_wait, int interrupted);
|
void clock_update_local_date(int max_wait, int interrupted);
|
||||||
|
|||||||
@ -295,6 +295,14 @@ typedef struct { } empty_t;
|
|||||||
*/
|
*/
|
||||||
#define MAX_SEND_FD 252
|
#define MAX_SEND_FD 252
|
||||||
|
|
||||||
|
/* Some bsd kernels (ie: FreeBSD) offer the FAST clock source as equivalent
|
||||||
|
* to Linux COARSE clock source. Aliasing COARSE to FAST on such systems when
|
||||||
|
* COARSE is not already defined.
|
||||||
|
*/
|
||||||
|
#if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC_FAST)
|
||||||
|
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _HAPROXY_COMPAT_H */
|
#endif /* _HAPROXY_COMPAT_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
21
src/clock.c
21
src/clock.c
@ -60,6 +60,27 @@ uint64_t now_mono_time(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the system's monotonic time in nanoseconds.
|
||||||
|
* Uses the coarse clock source if supported (for fast but
|
||||||
|
* less precise queries with limited resource usage).
|
||||||
|
* Fallback to now_mono_time() if coarse source is not supported,
|
||||||
|
* which may itself return 0 if not supported either.
|
||||||
|
*/
|
||||||
|
uint64_t now_mono_time_fast(void)
|
||||||
|
{
|
||||||
|
#if defined(CLOCK_MONOTONIC_COARSE)
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
|
||||||
|
return (ts.tv_sec * 1000000000ULL + ts.tv_nsec);
|
||||||
|
#else
|
||||||
|
/* fallback to regular mono time,
|
||||||
|
* returns 0 if not supported
|
||||||
|
*/
|
||||||
|
return now_mono_time();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* returns the current thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
|
/* returns the current thread's cumulated CPU time in nanoseconds if supported, otherwise zero */
|
||||||
uint64_t now_cpu_time(void)
|
uint64_t now_cpu_time(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user