[PATCH 06/16] net/udp: allow retrieving irq timestamp with SIOCGSTAMP ioctl

Philippe Gerum rpm at xenomai.org
Thu Mar 21 18:13:20 CET 2019


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 dbf9b7c16..8fe128efd 100644
--- a/kernel/drivers/net/stack/include/rtnet_socket.h
+++ b/kernel/drivers/net/stack/include/rtnet_socket.h
@@ -80,6 +80,8 @@ struct rtsocket {
 		} packet;
 	} prot;
 
+	u64 timestamp;
+
 	struct module *owner;
 };
 
diff --git a/kernel/drivers/net/stack/ipv4/udp/udp.c b/kernel/drivers/net/stack/ipv4/udp/udp.c
index d4003d2ee..8539fe87a 100644
--- a/kernel/drivers/net/stack/ipv4/udp/udp.c
+++ b/kernel/drivers/net/stack/ipv4/udp/udp.c
@@ -361,6 +361,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)
@@ -379,6 +381,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);
 	}
@@ -472,6 +480,7 @@ ssize_t rt_udp_recvmsg(struct rtdm_fd * fd, struct user_msghdr * u_msg,
 
 	/* iterate over all IP fragments */
 	do {
+		sock->timestamp = skb->time_stamp;
 		rtskb_trim(skb, data_len);
 
 		block_size = skb->len;
-- 
2.20.1




More information about the Xenomai mailing list