Thread (32 messages) read the whole thread 32 messages, 2 authors, 2021-12-23

Re: [PATCH v1 01/25] drivers/net: introduce a new PMD driver

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2021-12-19 19:40:37

On Sat, 18 Dec 2021 10:51:28 +0800
Yanling Song [off-list ref] 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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help