@cryptotaxi247 / netdata-1 / commits / 31a791ff8

Add high precision timer support for plugins such as idlejitter. (#8441)

Markos Fountoulakis committed Mar 23, 2020 at 15:26 UTC 31a791ff8a6f3ff4cb001ae36c8872cf66e745c8
3 files changed +20 -2
collectors/idlejitter.plugin/plugin_idlejitter.c
+2 -2
@@ -54,9 +54,9 @@ void *cpuidlejitter_main(void *ptr) {
54 if(netdata_exit) break;
55
56 while(elapsed < update_every_ut) {
57 - now_monotonic_timeval(&before);
57 + now_monotonic_high_precision_timeval(&before);
58 sleep_usec(sleep_ut);
59 - now_monotonic_timeval(&after);
59 + now_monotonic_high_precision_timeval(&after);
60
61 usec_t dt = dt_usec(&after, &before);
62 elapsed += dt;
libnetdata/clocks/clocks.c
+12
@@ -87,6 +87,18 @@ inline int now_monotonic_timeval(struct timeval *tv) {
87 return now_timeval(likely(clock_monotonic_coarse_valid) ? CLOCK_MONOTONIC_COARSE : CLOCK_MONOTONIC, tv);
88 }
89
90 +inline time_t now_monotonic_high_precision_sec(void) {
91 + return now_sec(CLOCK_MONOTONIC);
92 +}
93 +
94 +inline usec_t now_monotonic_high_precision_usec(void) {
95 + return now_usec(CLOCK_MONOTONIC);
96 +}
97 +
98 +inline int now_monotonic_high_precision_timeval(struct timeval *tv) {
99 + return now_timeval(CLOCK_MONOTONIC, tv);
100 +}
101 +
102 inline time_t now_boottime_sec(void) {
103 return now_sec(likely(clock_boottime_valid) ? CLOCK_BOOTTIME :
104 likely(clock_monotonic_coarse_valid) ? CLOCK_MONOTONIC_COARSE : CLOCK_MONOTONIC);
libnetdata/clocks/clocks.h
+6
@@ -104,6 +104,9 @@ extern int clock_gettime(clockid_t clk_id, struct timespec *ts);
104 *
105 * All now_*_sec() functions return the time in seconds from the approriate clock, or 0 on error.
106 * All now_*_usec() functions return the time in microseconds from the approriate clock, or 0 on error.
107 + *
108 + * Most functions will attempt to use CLOCK_MONOTONIC_COARSE if available to reduce contention overhead and improve
109 + * performance scaling. If high precision is required please use one of the available now_*_high_precision_* functions.
110 */
111 extern int now_realtime_timeval(struct timeval *tv);
112 extern time_t now_realtime_sec(void);
@@ -112,6 +115,9 @@ extern usec_t now_realtime_usec(void);
115 extern int now_monotonic_timeval(struct timeval *tv);
116 extern time_t now_monotonic_sec(void);
117 extern usec_t now_monotonic_usec(void);
118 +extern int now_monotonic_high_precision_timeval(struct timeval *tv);
119 +extern time_t now_monotonic_high_precision_sec(void);
120 +extern usec_t now_monotonic_high_precision_usec(void);
121
122 extern int now_boottime_timeval(struct timeval *tv);
123 extern time_t now_boottime_sec(void);