On Sat, 18 Dec 2021 10:51:28 +0800
Yanling Song <son...@ramaxel.com> wrote:

> +#ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
> +#define CLOCK_TYPE CLOCK_MONOTONIC_RAW
> +#else
> +#define CLOCK_TYPE CLOCK_MONOTONIC
> +#endif

CLOCK_MONOTONIC_RAW was defined in Linux.2.6.28
DPDK does not support any kernels that old, so the #ifdef is not needed.


+
+static inline unsigned long clock_gettime_ms(void)
+{
+       struct timespec tv;
+
+       (void)clock_gettime(CLOCK_TYPE, &tv);
+
+       return (unsigned long)tv.tv_sec * SPNIC_S_TO_MS_UNIT +
+              (unsigned long)tv.tv_nsec / SPNIC_S_TO_NS_UNIT;
+}

If all you want is jiffie accuracy,  you could use CLOCK_MONOTONIC_COARSE.


+#define jiffies        clock_gettime_ms()
+#define msecs_to_jiffies(ms)   (ms)

+#define time_before(now, end)  ((now) < (end))

Does that simple version of the macro work right if jiffies wraps around?
Less of an issue on 64 bit platforms...

The kernel version is effectively.
#define time_before(now, end) ((long)((now) - (end)) < 0)

Reply via email to