Skip to content

Commit f0e7040

Browse files
Paolo Abenikuba-moo
authored andcommitted
net: avoid unconditionally touching sk_tsflags on RX
After commit 5d4cc87 ("net: reorganize "struct sock" fields"), the sk_tsflags field shares the same cacheline with sk_forward_alloc. The UDP protocol does not acquire the sock lock in the RX path; forward allocations are protected via the receive queue spinlock; additionally udp_recvmsg() calls sock_recv_cmsgs() unconditionally touching sk_tsflags on each packet reception. Due to the above, under high packet rate traffic, when the BH and the user-space process run on different CPUs, UDP packet reception experiences a cache miss while accessing sk_tsflags. The receive path doesn't strictly need to access the problematic field; change sock_set_timestamping() to maintain the relevant information in a newly allocated sk_flags bit, so that sock_recv_cmsgs() can take decisions accessing the latter field only. With this patch applied, on an AMD epic server with i40e NICs, I measured a 10% performance improvement for small packets UDP flood performance tests - possibly a larger delta could be observed with more recent H/W. Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/dbd18c8a1171549f8249ac5a8b30b1b5ec88a425.1739294057.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ea80f2d commit f0e7040

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

include/net/sock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ enum sock_flags {
954954
SOCK_TSTAMP_NEW, /* Indicates 64 bit timestamps always */
955955
SOCK_RCVMARK, /* Receive SO_MARK ancillary data with packet */
956956
SOCK_RCVPRIORITY, /* Receive SO_PRIORITY ancillary data with packet */
957+
SOCK_TIMESTAMPING_ANY, /* Copy of sk_tsflags & TSFLAGS_ANY */
957958
};
958959

959960
#define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE))
@@ -2664,13 +2665,13 @@ static inline void sock_recv_cmsgs(struct msghdr *msg, struct sock *sk,
26642665
{
26652666
#define FLAGS_RECV_CMSGS ((1UL << SOCK_RXQ_OVFL) | \
26662667
(1UL << SOCK_RCVTSTAMP) | \
2667-
(1UL << SOCK_RCVMARK) |\
2668-
(1UL << SOCK_RCVPRIORITY))
2668+
(1UL << SOCK_RCVMARK) | \
2669+
(1UL << SOCK_RCVPRIORITY) | \
2670+
(1UL << SOCK_TIMESTAMPING_ANY))
26692671
#define TSFLAGS_ANY (SOF_TIMESTAMPING_SOFTWARE | \
26702672
SOF_TIMESTAMPING_RAW_HARDWARE)
26712673

2672-
if (sk->sk_flags & FLAGS_RECV_CMSGS ||
2673-
READ_ONCE(sk->sk_tsflags) & TSFLAGS_ANY)
2674+
if (READ_ONCE(sk->sk_flags) & FLAGS_RECV_CMSGS)
26742675
__sock_recv_cmsgs(msg, sk, skb);
26752676
else if (unlikely(sock_flag(sk, SOCK_TIMESTAMP)))
26762677
sock_write_timestamp(sk, skb->tstamp);

net/core/sock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ int sock_set_timestamping(struct sock *sk, int optname,
938938

939939
WRITE_ONCE(sk->sk_tsflags, val);
940940
sock_valbool_flag(sk, SOCK_TSTAMP_NEW, optname == SO_TIMESTAMPING_NEW);
941+
sock_valbool_flag(sk, SOCK_TIMESTAMPING_ANY, !!(val & TSFLAGS_ANY));
941942

942943
if (val & SOF_TIMESTAMPING_RX_SOFTWARE)
943944
sock_enable_timestamp(sk,

0 commit comments

Comments
 (0)