Skip to content

Commit 6b08492

Browse files
soheilhydavem330
authored andcommitted
tcp: use one bit in TCP_SKB_CB to mark ACK timestamps
Currently, to avoid a cache line miss for accessing skb_shinfo, tcp_ack_tstamp skips socket that do not have SOF_TIMESTAMPING_TX_ACK bit set in sk_tsflags. This is implemented based on an implicit assumption that the SOF_TIMESTAMPING_TX_ACK is set via socket options for the duration that ACK timestamps are needed. To implement per-write timestamps, this check should be removed and replaced with a per-packet alternative that quickly skips packets missing ACK timestamps marks without a cache-line miss. To enable per-packet marking without a cache line miss, use one bit in TCP_SKB_CB to mark a whether a SKB might need a ack tx timestamp or not. Further checks in tcp_ack_tstamp are not modified and work as before. Signed-off-by: Soheil Hassas Yeganeh <[email protected]> Acked-by: Willem de Bruijn <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6db8b96 commit 6b08492

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ struct tcp_skb_cb {
754754
TCPCB_REPAIRED)
755755

756756
__u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
757-
/* 1 byte hole */
757+
__u8 txstamp_ack:1, /* Record TX timestamp for ack? */
758+
unused:7;
758759
__u32 ack_seq; /* Sequence number ACK'd */
759760
union {
760761
struct inet_skb_parm h4;

net/ipv4/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,12 @@ static void tcp_tx_timestamp(struct sock *sk, struct sk_buff *skb)
432432
{
433433
if (sk->sk_tsflags) {
434434
struct skb_shared_info *shinfo = skb_shinfo(skb);
435+
struct tcp_skb_cb *tcb = TCP_SKB_CB(skb);
435436

436437
sock_tx_timestamp(sk, &shinfo->tx_flags);
437438
if (shinfo->tx_flags & SKBTX_ANY_TSTAMP)
438439
shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1;
440+
tcb->txstamp_ack = !!(shinfo->tx_flags & SKBTX_ACK_TSTAMP);
439441
}
440442
}
441443

net/ipv4/tcp_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,7 @@ static void tcp_ack_tstamp(struct sock *sk, struct sk_buff *skb,
30823082
const struct skb_shared_info *shinfo;
30833083

30843084
/* Avoid cache line misses to get skb_shinfo() and shinfo->tx_flags */
3085-
if (likely(!(sk->sk_tsflags & SOF_TIMESTAMPING_TX_ACK)))
3085+
if (likely(!TCP_SKB_CB(skb)->txstamp_ack))
30863086
return;
30873087

30883088
shinfo = skb_shinfo(skb);

0 commit comments

Comments
 (0)