summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorMarkos Fountoulakis <44345837+mfundul@users.noreply.github.com>2020-03-23 15:26:49 +0200
committerGitHub <noreply@github.com>2020-03-23 15:26:49 +0200
commit31a791ff8a6f3ff4cb001ae36c8872cf66e745c8 (patch)
treeb58a7dffb53fa4736ae08a40927037e4afdff5fb /libnetdata
parent2e6b1f1e0409be6bdebeae5772dcf53851efd519 (diff)
Add high precision timer support for plugins such as idlejitter. (#8441)
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/clocks/clocks.c12
-rw-r--r--libnetdata/clocks/clocks.h6
2 files changed, 18 insertions, 0 deletions
diff --git a/libnetdata/clocks/clocks.c b/libnetdata/clocks/clocks.c
index 3875b2a255..4ec5fa98b4 100644
--- a/libnetdata/clocks/clocks.c
+++ b/libnetdata/clocks/clocks.c
@@ -87,6 +87,18 @@ inline int now_monotonic_timeval(struct timeval *tv) {
return now_timeval(likely(clock_monotonic_coarse_valid) ? CLOCK_MONOTONIC_COARSE : CLOCK_MONOTONIC, tv);
}
+inline time_t now_monotonic_high_precision_sec(void) {
+ return now_sec(CLOCK_MONOTONIC);
+}
+
+inline usec_t now_monotonic_high_precision_usec(void) {
+ return now_usec(CLOCK_MONOTONIC);
+}
+
+inline int now_monotonic_high_precision_timeval(struct timeval *tv) {
+ return now_timeval(CLOCK_MONOTONIC, tv);
+}
+
inline time_t now_boottime_sec(void) {
return now_sec(likely(clock_boottime_valid) ? CLOCK_BOOTTIME :
likely(clock_monotonic_coarse_valid) ? CLOCK_MONOTONIC_COARSE : CLOCK_MONOTONIC);
diff --git a/libnetdata/clocks/clocks.h b/libnetdata/clocks/clocks.h
index 7938cb0d36..83e7c48a2d 100644
--- a/libnetdata/clocks/clocks.h
+++ b/libnetdata/clocks/clocks.h
@@ -104,6 +104,9 @@ extern int clock_gettime(clockid_t clk_id, struct timespec *ts);
*
* All now_*_sec() functions return the time in seconds from the approriate clock, or 0 on error.
* All now_*_usec() functions return the time in microseconds from the approriate clock, or 0 on error.
+ *
+ * Most functions will attempt to use CLOCK_MONOTONIC_COARSE if available to reduce contention overhead and improve
+ * performance scaling. If high precision is required please use one of the available now_*_high_precision_* functions.
*/
extern int now_realtime_timeval(struct timeval *tv);
extern time_t now_realtime_sec(void);
@@ -112,6 +115,9 @@ extern usec_t now_realtime_usec(void);
extern int now_monotonic_timeval(struct timeval *tv);
extern time_t now_monotonic_sec(void);
extern usec_t now_monotonic_usec(void);
+extern int now_monotonic_high_precision_timeval(struct timeval *tv);
+extern time_t now_monotonic_high_precision_sec(void);
+extern usec_t now_monotonic_high_precision_usec(void);
extern int now_boottime_timeval(struct timeval *tv);
extern time_t now_boottime_sec(void);