summary refs log tree commit diff
path: root/include/net/sock.h
diff options
context:
space:
mode:
authorPaolo Abeni <pabeni@redhat.com>2017-06-21 11:45:31 +0200
committerDavid S. Miller <davem@davemloft.net>2017-06-21 11:43:01 -0400
commit34cfb542b5b1762c73479a4a61e0a3b77253f876 (patch)
tree0e7db516c60cf9e2b9c306be6b18fc0f50099a2c /include/net/sock.h
parent28b5ba2aa0f55d80adb2624564ed2b170c19519e (diff)
downloadlinux-34cfb542b5b1762c73479a4a61e0a3b77253f876.tar.gz
sock: avoid dirtying incoming_cpu if not needed
for connected socket, the incoming_cpu field in the sock struct
is not going to change frequently, but we are setting it
unconditionally for each packet.

Since sk_incoming_cpu and sk_flags share the same cacheline,
and the latter is access by udp_recvmsg(), this cause a cache
miss for each packet for UDP connected socket.

With this patch, we set the incoming cpu field only when the
ingress cpu really changes.

This gives a small but measurable performance improvement for
connected UDP socket.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sock.h')
-rw-r--r--include/net/sock.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 858891c36f94..00d09140e354 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -907,7 +907,10 @@ static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 
 static inline void sk_incoming_cpu_update(struct sock *sk)
 {
-	sk->sk_incoming_cpu = raw_smp_processor_id();
+	int cpu = raw_smp_processor_id();
+
+	if (unlikely(sk->sk_incoming_cpu != cpu))
+		sk->sk_incoming_cpu = cpu;
 }
 
 static inline void sock_rps_record_flow_hash(__u32 hash)