From 9470c449236afef22210803b359fe44d74e32636 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 6 Apr 2020 01:41:14 +0200 Subject: [PATCH] Fix RTT measurement. Commit 723d8c8b2d96834135f00c0ac4147282e1f0cc2c introduced a bug where we fail to subtract two timespecs correctly, resulting in incorrect RTT values. --- utcp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utcp.c b/utcp.c index 383e27f..10d026e 100644 --- a/utcp.c +++ b/utcp.c @@ -61,8 +61,7 @@ static void timespec_sub(const struct timespec *a, const struct timespec *b, str } static int32_t timespec_diff_usec(const struct timespec *a, const struct timespec *b) { - int64_t diff = (a->tv_sec - b->tv_sec) * 1000000000 + a->tv_sec - b->tv_sec; - return diff / 1000; + return (a->tv_sec - b->tv_sec) * 1000000 + (a->tv_nsec - b->tv_nsec) / 1000; } static bool timespec_lt(const struct timespec *a, const struct timespec *b) { -- 2.39.2