diff options
Diffstat (limited to '')
-rw-r--r-- | libnetdata/clocks/Makefile.am | 8 | ||||
-rw-r--r-- | libnetdata/clocks/README.md | 10 | ||||
-rw-r--r-- | src/libnetdata/clocks/clocks.c (renamed from libnetdata/clocks/clocks.c) | 44 | ||||
-rw-r--r-- | src/libnetdata/clocks/clocks.h (renamed from libnetdata/clocks/clocks.h) | 7 |
4 files changed, 40 insertions, 29 deletions
diff --git a/libnetdata/clocks/Makefile.am b/libnetdata/clocks/Makefile.am deleted file mode 100644 index 161784b8f..000000000 --- a/libnetdata/clocks/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -AUTOMAKE_OPTIONS = subdir-objects -MAINTAINERCLEANFILES = $(srcdir)/Makefile.in - -dist_noinst_DATA = \ - README.md \ - $(NULL) diff --git a/libnetdata/clocks/README.md b/libnetdata/clocks/README.md deleted file mode 100644 index 33b0f0e85..000000000 --- a/libnetdata/clocks/README.md +++ /dev/null @@ -1,10 +0,0 @@ -<!-- -custom_edit_url: "https://github.com/netdata/netdata/edit/master/libnetdata/clocks/README.md" -title: "Clocks" -sidebar_label: "Clocks" -learn_status: "Published" -learn_topic_type: "References" -learn_rel_path: "Developers/libnetdata" ---> - -# Clocks
\ No newline at end of file diff --git a/libnetdata/clocks/clocks.c b/src/libnetdata/clocks/clocks.c index adbad045f..5da450a2d 100644 --- a/libnetdata/clocks/clocks.c +++ b/src/libnetdata/clocks/clocks.c @@ -60,7 +60,7 @@ static usec_t get_clock_resolution(clockid_t clock) { if(clock_getres(clock, &ts) == 0) { usec_t ret = (usec_t)ts.tv_sec * USEC_PER_SEC + (usec_t)ts.tv_nsec / NSEC_PER_USEC; - if(!ret && ts.tv_nsec > 0 && ts.tv_nsec < NSEC_PER_USEC) + if(!ret && ts.tv_nsec > 0 && ts.tv_nsec < (long int)NSEC_PER_USEC) return (usec_t)1; else if(ret > MAX_CLOCK_RESOLUTION_UT) { @@ -92,7 +92,7 @@ void clocks_init(void) { inline time_t now_sec(clockid_t clk_id) { struct timespec ts; if(unlikely(clock_gettime(clk_id, &ts) == -1)) { - netdata_log_error("clock_gettime(%d, ×pec) failed.", clk_id); + netdata_log_error("clock_gettime(%ld, ×pec) failed.", (long int)clk_id); return 0; } return ts.tv_sec; @@ -101,7 +101,7 @@ inline time_t now_sec(clockid_t clk_id) { inline usec_t now_usec(clockid_t clk_id) { struct timespec ts; if(unlikely(clock_gettime(clk_id, &ts) == -1)) { - netdata_log_error("clock_gettime(%d, ×pec) failed.", clk_id); + netdata_log_error("clock_gettime(%ld, ×pec) failed.", (long int)clk_id); return 0; } return (usec_t)ts.tv_sec * USEC_PER_SEC + (usec_t)(ts.tv_nsec % NSEC_PER_SEC) / NSEC_PER_USEC; @@ -111,7 +111,7 @@ inline int now_timeval(clockid_t clk_id, struct timeval *tv) { struct timespec ts; if(unlikely(clock_gettime(clk_id, &ts) == -1)) { - netdata_log_error("clock_gettime(%d, ×pec) failed.", clk_id); + netdata_log_error("clock_gettime(%ld, ×pec) failed.", (long int)clk_id); tv->tv_sec = 0; tv->tv_usec = 0; return -1; @@ -243,7 +243,7 @@ void sleep_to_absolute_time(usec_t usec) { sleep_usec(usec); } } -}; +} #endif #define HEARTBEAT_ALIGNMENT_STATISTICS_SIZE 10 @@ -343,7 +343,7 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { } if(unlikely(now < next)) { - errno = 0; + errno_clear(); nd_log_limit_static_global_var(erl, 10, 0); nd_log_limit(&erl, NDLS_DAEMON, NDLP_NOTICE, "heartbeat clock: woke up %"PRIu64" microseconds earlier than expected " @@ -351,7 +351,7 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { next - now); } else if(unlikely(now - next > tick / 2)) { - errno = 0; + errno_clear(); nd_log_limit_static_global_var(erl, 10, 0); nd_log_limit(&erl, NDLS_DAEMON, NDLP_NOTICE, "heartbeat clock: woke up %"PRIu64" microseconds later than expected " @@ -368,6 +368,35 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { return dt; } +#ifdef OS_WINDOWS + +#include "windows.h" + +void sleep_usec_with_now(usec_t usec, usec_t started_ut) +{ + if (!started_ut) + started_ut = now_realtime_usec(); + + usec_t end_ut = started_ut + usec; + usec_t remaining_ut = usec; + + timeBeginPeriod(1); + + while (remaining_ut >= 1000) + { + DWORD sleep_ms = (DWORD) (remaining_ut / USEC_PER_MS); + Sleep(sleep_ms); + + usec_t now_ut = now_realtime_usec(); + if (now_ut >= end_ut) + break; + + remaining_ut = end_ut - now_ut; + } + + timeEndPeriod(1); +} +#else void sleep_usec_with_now(usec_t usec, usec_t started_ut) { // we expect microseconds (1.000.000 per second) // but timespec is nanoseconds (1.000.000.000 per second) @@ -411,6 +440,7 @@ void sleep_usec_with_now(usec_t usec, usec_t started_ut) { } } } +#endif static inline collected_number uptime_from_boottime(void) { #ifdef CLOCK_BOOTTIME_IS_AVAILABLE diff --git a/libnetdata/clocks/clocks.h b/src/libnetdata/clocks/clocks.h index 2beb14ed9..f989fd6b8 100644 --- a/libnetdata/clocks/clocks.h +++ b/src/libnetdata/clocks/clocks.h @@ -5,15 +5,14 @@ #include "../libnetdata.h" -#ifndef HAVE_STRUCT_TIMESPEC +#ifndef HAVE_CLOCK_GETTIME struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; #endif -#ifndef HAVE_CLOCKID_T -typedef int clockid_t; +#ifndef HAVE_CLOCK_GETTIME #endif typedef uint64_t nsec_t; @@ -143,7 +142,7 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick); void heartbeat_statistics(usec_t *min_ptr, usec_t *max_ptr, usec_t *average_ptr, size_t *count_ptr); void sleep_usec_with_now(usec_t usec, usec_t started_ut); -#define sleep_usec(usec) sleep_usec_with_now(usec, 0); +#define sleep_usec(usec) sleep_usec_with_now(usec, 0) void clocks_init(void); |