[PATCH 07/31] net/udp: allow retrieving irq timestamp with SIOCGSTAMP ioctl

Jean-Baptiste Tr├ędez jean-baptiste.tredez at alstefgroup.com
Tue May 11 18:05:11 CEST 2021


From: Gilles Chanteperdrix <gilles.chanteperdrix at xenomai.org>

Signed-off-by: Philippe Gerum <rpm at xenomai.org>
---
 kernel/drivers/net/stack/include/rtnet_socket.h | 2 ++
 kernel/drivers/net/stack/ipv4/udp/udp.c         | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/kernel/drivers/net/stack/include/rtnet_socket.h b/kernel/drivers/net/stack/include/rtnet_socket.h
index af972c1a5..61bf8bea5 100644
--- a/kernel/drivers/net/stack/include/rtnet_socket.h
+++ b/kernel/drivers/net/stack/include/rtnet_socket.h
@@ -79,6 +79,8 @@ struct rtsocket {
 			int ifindex;
 		} packet;
 	} prot;
+
+	u64 timestamp;
 };
 
 static inline struct rtdm_fd *rt_socket_fd(struct rtsocket *sock)
diff --git a/kernel/drivers/net/stack/ipv4/udp/udp.c b/kernel/drivers/net/stack/ipv4/udp/udp.c
index dcaec5618..beceb28cf 100644
--- a/kernel/drivers/net/stack/ipv4/udp/udp.c
+++ b/kernel/drivers/net/stack/ipv4/udp/udp.c
@@ -359,6 +359,8 @@ int rt_udp_ioctl(struct rtdm_fd *fd, unsigned int request, void __user *arg)
 	struct rtsocket *sock = rtdm_fd_to_private(fd);
 	const struct _rtdm_setsockaddr_args *setaddr;
 	struct _rtdm_setsockaddr_args _setaddr;
+	unsigned long ns;
+	struct timeval tv;
 
 	/* fast path for common socket IOCTLs */
 	if (_IOC_TYPE(request) == RTIOC_TYPE_NETWORK)
@@ -377,6 +379,12 @@ int rt_udp_ioctl(struct rtdm_fd *fd, unsigned int request, void __user *arg)
 		return rt_udp_connect(fd, sock, setaddr->addr,
 				      setaddr->addrlen);
 
+	case SIOCGSTAMP:
+		tv.tv_sec = xnclock_divrem_billion(sock->timestamp, &ns);
+		tv.tv_usec = ns / 1000;
+
+		return copy_to_user(arg, &tv, sizeof(tv));
+
 	default:
 		return rt_ip_ioctl(fd, request, arg);
 	}
@@ -464,6 +472,7 @@ ssize_t rt_udp_recvmsg(struct rtdm_fd *fd, struct user_msghdr *msg,
 
 	/* iterate over all IP fragments */
 	do {
+		sock->timestamp = skb->time_stamp;
 		rtskb_trim(skb, data_len);
 
 		block_size = skb->len;
-- 
2.17.1




More information about the Xenomai mailing list