diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-30 18:47:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-30 18:47:00 +0000 |
commit | 03bf87dcb06f7021bfb2df2fa8691593c6148aff (patch) | |
tree | e16b06711a2ed77cafb4b7754be0220c3d14a9d7 /libnetdata/clocks | |
parent | Adding upstream version 1.36.1. (diff) | |
download | netdata-03bf87dcb06f7021bfb2df2fa8691593c6148aff.tar.xz netdata-03bf87dcb06f7021bfb2df2fa8691593c6148aff.zip |
Adding upstream version 1.37.0.upstream/1.37.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/clocks')
-rw-r--r-- | libnetdata/clocks/clocks.c | 31 | ||||
-rw-r--r-- | libnetdata/clocks/clocks.h | 54 |
2 files changed, 43 insertions, 42 deletions
diff --git a/libnetdata/clocks/clocks.c b/libnetdata/clocks/clocks.c index e4dca6c8b..cabc0000e 100644 --- a/libnetdata/clocks/clocks.c +++ b/libnetdata/clocks/clocks.c @@ -11,14 +11,14 @@ usec_t clock_monotonic_resolution = 1000; usec_t clock_realtime_resolution = 1000; #ifndef HAVE_CLOCK_GETTIME -inline int clock_gettime(clockid_t clk_id, struct timespec *ts) { +inline int clock_gettime(clockid_t clk_id __maybe_unused, struct timespec *ts) { struct timeval tv; if(unlikely(gettimeofday(&tv, NULL) == -1)) { error("gettimeofday() failed."); return -1; } ts->tv_sec = tv.tv_sec; - ts->tv_nsec = (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC; + ts->tv_nsec = (long)((tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC); return 0; } #endif @@ -197,28 +197,28 @@ void sleep_to_absolute_time(usec_t usec) { if (!einval_printed) { einval_printed++; error( - "Invalid time given to clock_nanosleep(): clockid = %d, tv_sec = %ld, tv_nsec = %ld", + "Invalid time given to clock_nanosleep(): clockid = %d, tv_sec = %lld, tv_nsec = %ld", clock, - req.tv_sec, + (long long)req.tv_sec, req.tv_nsec); } } else if (ret == ENOTSUP) { if (!enotsup_printed) { enotsup_printed++; error( - "Invalid clock id given to clock_nanosleep(): clockid = %d, tv_sec = %ld, tv_nsec = %ld", + "Invalid clock id given to clock_nanosleep(): clockid = %d, tv_sec = %lld, tv_nsec = %ld", clock, - req.tv_sec, + (long long)req.tv_sec, req.tv_nsec); } } else { if (!eunknown_printed) { eunknown_printed++; error( - "Unknown return value %d from clock_nanosleep(): clockid = %d, tv_sec = %ld, tv_nsec = %ld", + "Unknown return value %d from clock_nanosleep(): clockid = %d, tv_sec = %lld, tv_nsec = %ld", ret, clock, - req.tv_sec, + (long long)req.tv_sec, req.tv_nsec); } } @@ -341,20 +341,21 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { void sleep_usec(usec_t usec) { // we expect microseconds (1.000.000 per second) // but timespec is nanoseconds (1.000.000.000 per second) - struct timespec rem, req = { + struct timespec rem = { 0, 0 }, req = { .tv_sec = (time_t) (usec / USEC_PER_SEC), .tv_nsec = (suseconds_t) ((usec % USEC_PER_SEC) * NSEC_PER_USEC) }; #ifdef __linux__ - while ((errno = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem)) != 0) { + while (clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem) != 0) { #else - while ((errno = nanosleep(&req, &rem)) != 0) { + while (nanosleep(&req, &rem) != 0) { #endif - if (likely(errno == EINTR)) { - req.tv_sec = rem.tv_sec; - req.tv_nsec = rem.tv_nsec; - } else { + if (likely(errno == EINTR && (rem.tv_sec || rem.tv_nsec))) { + req = rem; + rem = (struct timespec){ 0, 0 }; + } + else { #ifdef __linux__ error("Cannot clock_nanosleep(CLOCK_REALTIME) for %llu microseconds.", usec); #else diff --git a/libnetdata/clocks/clocks.h b/libnetdata/clocks/clocks.h index 53c036ece..7738a2c8e 100644 --- a/libnetdata/clocks/clocks.h +++ b/libnetdata/clocks/clocks.h @@ -82,7 +82,7 @@ typedef struct heartbeat { * make systems without clock_gettime() support sensitive * to time jumps or hibernation/suspend side effects. */ -extern int clock_gettime(clockid_t clk_id, struct timespec *ts); +int clock_gettime(clockid_t clk_id, struct timespec *ts); #endif /* @@ -111,50 +111,50 @@ extern int clock_gettime(clockid_t clk_id, struct timespec *ts); * All now_*_usec() functions return the time in microseconds from the appropriate clock, or 0 on error. * */ -extern int now_realtime_timeval(struct timeval *tv); -extern time_t now_realtime_sec(void); -extern usec_t now_realtime_usec(void); +int now_realtime_timeval(struct timeval *tv); +time_t now_realtime_sec(void); +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); +int now_monotonic_timeval(struct timeval *tv); +time_t now_monotonic_sec(void); +usec_t now_monotonic_usec(void); +int now_monotonic_high_precision_timeval(struct timeval *tv); +time_t now_monotonic_high_precision_sec(void); +usec_t now_monotonic_high_precision_usec(void); -extern int now_boottime_timeval(struct timeval *tv); -extern time_t now_boottime_sec(void); -extern usec_t now_boottime_usec(void); +int now_boottime_timeval(struct timeval *tv); +time_t now_boottime_sec(void); +usec_t now_boottime_usec(void); -extern usec_t timeval_usec(struct timeval *tv); -extern msec_t timeval_msec(struct timeval *tv); +usec_t timeval_usec(struct timeval *tv); +msec_t timeval_msec(struct timeval *tv); -extern usec_t dt_usec(struct timeval *now, struct timeval *old); -extern susec_t dt_usec_signed(struct timeval *now, struct timeval *old); +usec_t dt_usec(struct timeval *now, struct timeval *old); +susec_t dt_usec_signed(struct timeval *now, struct timeval *old); -extern void heartbeat_init(heartbeat_t *hb); +void heartbeat_init(heartbeat_t *hb); /* Sleeps until next multiple of tick using monotonic clock. * Returns elapsed time in microseconds since previous heartbeat */ -extern usec_t heartbeat_next(heartbeat_t *hb, usec_t tick); +usec_t heartbeat_next(heartbeat_t *hb, usec_t tick); -extern void heartbeat_statistics(usec_t *min_ptr, usec_t *max_ptr, usec_t *average_ptr, size_t *count_ptr); +void heartbeat_statistics(usec_t *min_ptr, usec_t *max_ptr, usec_t *average_ptr, size_t *count_ptr); -extern void sleep_usec(usec_t usec); +void sleep_usec(usec_t usec); -extern void clocks_init(void); +void clocks_init(void); // lower level functions - avoid using directly -extern time_t now_sec(clockid_t clk_id); -extern usec_t now_usec(clockid_t clk_id); -extern int now_timeval(clockid_t clk_id, struct timeval *tv); +time_t now_sec(clockid_t clk_id); +usec_t now_usec(clockid_t clk_id); +int now_timeval(clockid_t clk_id, struct timeval *tv); -extern collected_number uptime_msec(char *filename); +collected_number uptime_msec(char *filename); extern usec_t clock_monotonic_resolution; extern usec_t clock_realtime_resolution; -extern void sleep_to_absolute_time(usec_t usec); +void sleep_to_absolute_time(usec_t usec); #endif /* NETDATA_CLOCKS_H */ |