Thread (13 messages) 13 messages, 2 authors, 2025-02-08
STALE494d
Revisions (3)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]

[PATCH net-next 1/7] tcp: only initialize sockcm tsflags field

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2025-02-06 19:35:28
Subsystem: networking [general], networking [tcp], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Neal Cardwell, Linus Torvalds

From: Willem de Bruijn <willemb@google.com>

TCP only reads the tsflags field. Don't bother initializing others.

Signed-off-by: Willem de Bruijn <willemb@google.com>

---

Another option is to entirely avoid sockcm_cookie in the tcp hot path.
Limit its use to the sock_cmsg_send branch:

	@@ -1123,13 +1123,17 @@ int tcp_sendmsg_locked(struct sock *sk, struct
	msghdr *msg, size_t size)
			/* 'common' sending to sendq */
		}

	-       sockcm_init(&sockc, sk);
	+       tsflags = READ_ONCE(sk->sk_tsflags);
		if (msg->msg_controllen) {
	+               struct sockcm_cookie sockc = { .tsflags = tsflags };
	+
			err = sock_cmsg_send(sk, msg, &sockc);
			if (unlikely(err)) {
				err = -EINVAL;
				goto out_err;
			}
	+
	+               tsflags = sockc.tsflags;

This involves a bit more rework, to have sock_tx_timestamp take a u32
tsflags directly.
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 0d704bda6c41..1f94b4e6c7ec 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1123,7 +1123,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
 		/* 'common' sending to sendq */
 	}
 
-	sockcm_init(&sockc, sk);
+	sockc = (struct sockcm_cookie) { .tsflags = READ_ONCE(sk->sk_tsflags)};
 	if (msg->msg_controllen) {
 		err = sock_cmsg_send(sk, msg, &sockc);
 		if (unlikely(err)) {
-- 
2.48.1.502.g6dc24dfdaf-goog
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help