Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CLOCK_REALTIME when logging and CLOCK_MONOTONIC when timing #290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE])

# Detect Operatingsystem
AC_CANONICAL_TARGET
only_clock_realtime=no

case "${target}" in
*darwin*)
only_clock_realtime=yes
;;
*freebsd*)
only_clock_realtime=yes
;;
*openbsd*)
only_clock_realtime=yes
;;
esac

dnl --disable-ipv4
AC_ARG_ENABLE([ipv4],
Expand Down Expand Up @@ -60,7 +47,6 @@ dnl Test if --enable-timestamp is explicitely enabled and make an error if this
AS_IF([test "x$enable_timestamp" = "xyes" -a "x$have_so_timestamp" = "xno"], [
AC_MSG_ERROR([--enable-timestamp not supported on this platform])
])
AS_IF([test "x$only_clock_realtime" = "xyes"], [AC_DEFINE(ONLY_CLOCK_REALTIME, [1], [ONLY_CLOCK_REALTIME is defined])])

AC_ARG_ENABLE([safe-limits],
AS_HELP_STRING([--enable-safe-limits], [Restrict timing parameters (-i, -p) within "safe" limits]))
Expand Down
26 changes: 6 additions & 20 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,6 @@ extern int h_errno;
}
#endif /* __cplusplus */

/*** Constants ***/

/* CLOCK_MONTONIC starts under macOS, OpenBSD and FreeBSD with undefined positive point and can not be use
* see github PR #217
* The configure script detect the predefined operating systems an set CLOCK_REALTIME using over ONLY_CLOCK_REALTIME variable
*/
#if HAVE_SO_TIMESTAMPNS || ONLY_CLOCK_REALTIME
#define CLOCKID CLOCK_REALTIME
#endif

#if !defined(CLOCKID)
#if defined(CLOCK_MONOTONIC)
#define CLOCKID CLOCK_MONOTONIC
#else
#define CLOCKID CLOCK_REALTIME
#endif
#endif

/*** Ping packet defines ***/

#define MAX_IP_PACKET 65536 /* (theoretical) max IP packet size */
Expand Down Expand Up @@ -1510,8 +1492,12 @@ void signal_handler(int signum)

void update_current_time()
{
clock_gettime(CLOCKID, &current_time);
current_time_ns = timespec_ns(&current_time);
/* pull the realtime clock for logging */
clock_gettime(CLOCK_REALTIME, &current_time);
/* pull the monotonic clock for timing */
struct timespec monotonic_time;
clock_gettime(CLOCK_MONOTONIC, &monotonic_time);
current_time_ns = timespec_ns(&monotonic_time);
}

/************************************************************
Expand Down
6 changes: 3 additions & 3 deletions src/seqmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, int64_t t
/* check if expired (note that unused seqmap values will have fields set to
* 0, so will be seen as expired */
next_value = &seqmap_map[seqmap_next_id];
if (timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id);
if (next_value->ping_ts != 0 && timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d ping_st=%" PRId64 ")\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id, next_value->ping_ts);
exit(4);
}

Expand Down
Loading