Skip to contentSkip to conversation

net-timestamp: optimize sock_tx_timestamp default path

PATCH Superseded Willem de Bruijn 1 participant 2 messages Sep 8, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

PATCH 1/1 net-timestamp: optimize sock_tx_timestamp default path

Few packets have timestamping enabled. Exit sock_tx_timestamp quickly in this common case.

Packets are only possibly timestamped if one of SOF_TIMESTAMPING_(SOFTWARE|RAW_HARDWARE) is enabled.

----

I have one more short timestamping patch after this, to remove SOCK_TIMESTAMPING_RX_SOFTWARE and simplify the receive timestamp path a bit. I have not forgotten about the timestamp cookies: once these smaller changes are in, I'll take another look at that. It is a more complex change, and I didn't want to block these in the meantime.

---
 include/net/sock.h | 8 +++++++-
 net/socket.c       | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)
include/net/sock.h +7 -1
index 049ab1b..245136e 100644
@@ -2199,6 +2199,8 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
 		sk->sk_stamp = skb->tstamp;
 }
 
+void __sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags);
+
 /**
  * sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
  * @sk:		socket sending this packet
@@ -2206,7 +2208,11 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
  *
  * Note : callers should take care of initial *tx_flags value (usually 0)
  */
-void sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags);
+static inline void sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags)
+{
+	if (unlikely(sk->sk_tsflags & SOF_TIMESTAMPING_MASK))
+		__sock_tx_timestamp(sk, tx_flags);
+}
 
 /**
  * sk_eat_skb - Release a skb if it is no longer needed
net/socket.c +2 -2
index 2e2586e..2d1c2c8 100644
@@ -610,7 +610,7 @@ void sock_release(struct socket *sock)
 }
 EXPORT_SYMBOL(sock_release);
 
-void sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags)
+void __sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags)
 {
 	u8 flags = *tx_flags;
 
@@ -631,7 +631,7 @@ void sock_tx_timestamp(const struct sock *sk, __u8 *tx_flags)
 
 	*tx_flags = flags;
 }
-EXPORT_SYMBOL(sock_tx_timestamp);
+EXPORT_SYMBOL(__sock_tx_timestamp);
 
 static inline int __sock_sendmsg_nosec(struct kiocb *iocb, struct socket *sock,
 				       struct msghdr *msg, size_t size)
Signature · 1 line
2.1.0.rc2.206.gedb03e5
author maintainer
#1 lore raw
Quoted 7 lines

Few packets have timestamping enabled. Exit sock_tx_timestamp quickly in this common case.

Packets are only possibly timestamped if one of SOF_TIMESTAMPING_(SOFTWARE|RAW_HARDWARE) is enabled.

I submitted this too soon. I hadn't noticed that SOCK_WIFI_STATUS is also possibly set in sock_tx_timestamp. Let me take another look. Apologies for the churn.