summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--collectors/idlejitter.plugin/plugin_idlejitter.c4
-rw-r--r--libnetdata/clocks/clocks.c12
-rw-r--r--libnetdata/clocks/clocks.h6
3 files changed, 20 insertions, 2 deletions
diff --git a/collectors/idlejitter.plugin/plugin_idlejitter.c b/collectors/idlejitter.plugin/plugin_idlejitter.c
index 3fe3b0306e..c59541ecba 100644
--- a/collectors/idlejitter.plugin/plugin_idlejitter.c
+++ b/collectors/idlejitter.plugin/plugin_idlejitter.c
@@ -54,9 +54,9 @@ void *cpuidlejitter_main(void *ptr) {
if(netdata_exit) break;
while(elapsed < update_every_ut) {
- now_monotonic_timeval(&before);
+ now_monotonic_high_precision_timeval(&before);
sleep_usec(sleep_ut);
- now_monotonic_timeval(&after);
+ now_monotonic_high_precision_timeval(&after);
usec_t dt = dt_usec(&after, &before);
elapsed += dt;
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);