diff --git a/subsys/net/ip/net_stats.c b/subsys/net/ip/net_stats.c index 77915d1e51b..ff276bf27c9 100644 --- a/subsys/net/ip/net_stats.c +++ b/subsys/net/ip/net_stats.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -54,16 +55,19 @@ static const char *priority2str(enum net_priority priority) } #endif +static inline s64_t cmp_val(u64_t val1, u64_t val2) +{ + return (s64_t)(val1 - val2); +} + static inline void stats(struct net_if *iface) { - static s64_t next_print; - s64_t curr = k_uptime_get(); + static u64_t next_print; + u64_t curr = k_uptime_get(); + s64_t cmp = cmp_val(curr, next_print); int i; - if (!next_print || (next_print < curr && - (!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) { - s64_t new_print; - + if (!next_print || (abs(cmp) > PRINT_STATISTICS_INTERVAL)) { if (iface) { NET_INFO("Interface %p [%d]", iface, net_if_get_by_iface(iface)); @@ -217,14 +221,7 @@ static inline void stats(struct net_if *iface) ARG_UNUSED(i); #endif /* NET_TC_COUNT > 1 */ - new_print = curr + PRINT_STATISTICS_INTERVAL; - if (new_print > curr) { - next_print = new_print; - } else { - /* Overflow */ - next_print = PRINT_STATISTICS_INTERVAL - - (LLONG_MAX - curr); - } + next_print = curr + PRINT_STATISTICS_INTERVAL; } }