Skip to content

Commit 7faee5c

Browse files
edumazetdavem330
authored andcommitted
tcp: remove TCP_SKB_CB(skb)->when
After commit 740b0f1 ("tcp: switch rtt estimations to usec resolution"), we no longer need to maintain timestamps in two different fields. TCP_SKB_CB(skb)->when can be removed, as same information sits in skb_mstamp.stamp_jiffies Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Yuchung Cheng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 04317da commit 7faee5c

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

include/net/tcp.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,12 @@ void tcp_send_window_probe(struct sock *sk);
672672
*/
673673
#define tcp_time_stamp ((__u32)(jiffies))
674674

675+
static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
676+
{
677+
return skb->skb_mstamp.stamp_jiffies;
678+
}
679+
680+
675681
#define tcp_flag_byte(th) (((u_int8_t *)th)[13])
676682

677683
#define TCPHDR_FIN 0x01
@@ -698,12 +704,7 @@ struct tcp_skb_cb {
698704
} header; /* For incoming frames */
699705
__u32 seq; /* Starting sequence number */
700706
__u32 end_seq; /* SEQ + FIN + SYN + datalen */
701-
union {
702-
/* used in output path */
703-
__u32 when; /* used to compute rtt's */
704-
/* used in input path */
705-
__u32 tcp_tw_isn; /* isn chosen by tcp_timewait_state_process() */
706-
};
707+
__u32 tcp_tw_isn; /* isn chosen by tcp_timewait_state_process() */
707708
__u8 tcp_flags; /* TCP header flags. (tcp[13]) */
708709

709710
__u8 sacked; /* State flags for SACK/FACK. */

net/ipv4/tcp_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,7 +2967,8 @@ void tcp_rearm_rto(struct sock *sk)
29672967
if (icsk->icsk_pending == ICSK_TIME_EARLY_RETRANS ||
29682968
icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) {
29692969
struct sk_buff *skb = tcp_write_queue_head(sk);
2970-
const u32 rto_time_stamp = TCP_SKB_CB(skb)->when + rto;
2970+
const u32 rto_time_stamp =
2971+
tcp_skb_timestamp(skb) + rto;
29712972
s32 delta = (s32)(rto_time_stamp - tcp_time_stamp);
29722973
/* delta may not be positive if the socket is locked
29732974
* when the retrans timer fires and is rescheduled.

net/ipv4/tcp_ipv4.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
437437
skb = tcp_write_queue_head(sk);
438438
BUG_ON(!skb);
439439

440-
remaining = icsk->icsk_rto - min(icsk->icsk_rto,
441-
tcp_time_stamp - TCP_SKB_CB(skb)->when);
440+
remaining = icsk->icsk_rto -
441+
min(icsk->icsk_rto,
442+
tcp_time_stamp - tcp_skb_timestamp(skb));
442443

443444
if (remaining) {
444445
inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,

net/ipv4/tcp_output.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
550550

551551
if (likely(sysctl_tcp_timestamps && *md5 == NULL)) {
552552
opts->options |= OPTION_TS;
553-
opts->tsval = TCP_SKB_CB(skb)->when + tp->tsoffset;
553+
opts->tsval = tcp_skb_timestamp(skb) + tp->tsoffset;
554554
opts->tsecr = tp->rx_opt.ts_recent;
555555
remaining -= TCPOLEN_TSTAMP_ALIGNED;
556556
}
@@ -618,7 +618,7 @@ static unsigned int tcp_synack_options(struct sock *sk,
618618
}
619619
if (likely(ireq->tstamp_ok)) {
620620
opts->options |= OPTION_TS;
621-
opts->tsval = TCP_SKB_CB(skb)->when;
621+
opts->tsval = tcp_skb_timestamp(skb);
622622
opts->tsecr = req->ts_recent;
623623
remaining -= TCPOLEN_TSTAMP_ALIGNED;
624624
}
@@ -647,7 +647,6 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
647647
struct tcp_out_options *opts,
648648
struct tcp_md5sig_key **md5)
649649
{
650-
struct tcp_skb_cb *tcb = skb ? TCP_SKB_CB(skb) : NULL;
651650
struct tcp_sock *tp = tcp_sk(sk);
652651
unsigned int size = 0;
653652
unsigned int eff_sacks;
@@ -666,7 +665,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
666665

667666
if (likely(tp->rx_opt.tstamp_ok)) {
668667
opts->options |= OPTION_TS;
669-
opts->tsval = tcb ? tcb->when + tp->tsoffset : 0;
668+
opts->tsval = skb ? tcp_skb_timestamp(skb) + tp->tsoffset : 0;
670669
opts->tsecr = tp->rx_opt.ts_recent;
671670
size += TCPOLEN_TSTAMP_ALIGNED;
672671
}
@@ -886,8 +885,6 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
886885
skb = skb_clone(skb, gfp_mask);
887886
if (unlikely(!skb))
888887
return -ENOBUFS;
889-
/* Our usage of tstamp should remain private */
890-
skb->tstamp.tv64 = 0;
891888
}
892889

893890
inet = inet_sk(sk);
@@ -975,7 +972,10 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
975972
TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS,
976973
tcp_skb_pcount(skb));
977974

975+
/* Our usage of tstamp should remain private */
976+
skb->tstamp.tv64 = 0;
978977
err = icsk->icsk_af_ops->queue_xmit(sk, skb, &inet->cork.fl);
978+
979979
if (likely(err <= 0))
980980
return err;
981981

@@ -1149,7 +1149,6 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
11491149
/* Looks stupid, but our code really uses when of
11501150
* skbs, which it never sent before. --ANK
11511151
*/
1152-
TCP_SKB_CB(buff)->when = TCP_SKB_CB(skb)->when;
11531152
buff->tstamp = skb->tstamp;
11541153
tcp_fragment_tstamp(skb, buff);
11551154

@@ -1874,8 +1873,8 @@ static int tcp_mtu_probe(struct sock *sk)
18741873
tcp_init_tso_segs(sk, nskb, nskb->len);
18751874

18761875
/* We're ready to send. If this fails, the probe will
1877-
* be resegmented into mss-sized pieces by tcp_write_xmit(). */
1878-
TCP_SKB_CB(nskb)->when = tcp_time_stamp;
1876+
* be resegmented into mss-sized pieces by tcp_write_xmit().
1877+
*/
18791878
if (!tcp_transmit_skb(sk, nskb, 1, GFP_ATOMIC)) {
18801879
/* Decrement cwnd here because we are sending
18811880
* effectively two packets. */
@@ -1935,8 +1934,8 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
19351934
BUG_ON(!tso_segs);
19361935

19371936
if (unlikely(tp->repair) && tp->repair_queue == TCP_SEND_QUEUE) {
1938-
/* "when" is used as a start point for the retransmit timer */
1939-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
1937+
/* "skb_mstamp" is used as a start point for the retransmit timer */
1938+
skb_mstamp_get(&skb->skb_mstamp);
19401939
goto repair; /* Skip network transmission */
19411940
}
19421941

@@ -2000,8 +1999,6 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
20001999
unlikely(tso_fragment(sk, skb, limit, mss_now, gfp)))
20012000
break;
20022001

2003-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
2004-
20052002
if (unlikely(tcp_transmit_skb(sk, skb, 1, gfp)))
20062003
break;
20072004

@@ -2499,7 +2496,6 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
24992496
/* Make a copy, if the first transmission SKB clone we made
25002497
* is still in somebody's hands, else make a clone.
25012498
*/
2502-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
25032499

25042500
/* make sure skb->data is aligned on arches that require it
25052501
* and check if ack-trimming & collapsing extended the headroom
@@ -2544,7 +2540,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
25442540

25452541
/* Save stamp of the first retransmit. */
25462542
if (!tp->retrans_stamp)
2547-
tp->retrans_stamp = TCP_SKB_CB(skb)->when;
2543+
tp->retrans_stamp = tcp_skb_timestamp(skb);
25482544

25492545
/* snd_nxt is stored to detect loss of retransmitted segment,
25502546
* see tcp_input.c tcp_sacktag_write_queue().
@@ -2752,7 +2748,6 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)
27522748
tcp_init_nondata_skb(skb, tcp_acceptable_seq(sk),
27532749
TCPHDR_ACK | TCPHDR_RST);
27542750
/* Send it off. */
2755-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
27562751
if (tcp_transmit_skb(sk, skb, 0, priority))
27572752
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTFAILED);
27582753

@@ -2791,7 +2786,6 @@ int tcp_send_synack(struct sock *sk)
27912786
TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ACK;
27922787
TCP_ECN_send_synack(tcp_sk(sk), skb);
27932788
}
2794-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
27952789
return tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
27962790
}
27972791

@@ -2835,10 +2829,10 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
28352829
memset(&opts, 0, sizeof(opts));
28362830
#ifdef CONFIG_SYN_COOKIES
28372831
if (unlikely(req->cookie_ts))
2838-
TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
2832+
skb->skb_mstamp.stamp_jiffies = cookie_init_timestamp(req);
28392833
else
28402834
#endif
2841-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
2835+
skb_mstamp_get(&skb->skb_mstamp);
28422836
tcp_header_size = tcp_synack_options(sk, req, mss, skb, &opts, &md5,
28432837
foc) + sizeof(*th);
28442838

@@ -3086,7 +3080,7 @@ int tcp_connect(struct sock *sk)
30863080
skb_reserve(buff, MAX_TCP_HEADER);
30873081

30883082
tcp_init_nondata_skb(buff, tp->write_seq++, TCPHDR_SYN);
3089-
tp->retrans_stamp = TCP_SKB_CB(buff)->when = tcp_time_stamp;
3083+
tp->retrans_stamp = tcp_time_stamp;
30903084
tcp_connect_queue_skb(sk, buff);
30913085
TCP_ECN_send_syn(sk, buff);
30923086

@@ -3194,7 +3188,7 @@ void tcp_send_ack(struct sock *sk)
31943188
tcp_init_nondata_skb(buff, tcp_acceptable_seq(sk), TCPHDR_ACK);
31953189

31963190
/* Send it off, this clears delayed acks for us. */
3197-
TCP_SKB_CB(buff)->when = tcp_time_stamp;
3191+
skb_mstamp_get(&buff->skb_mstamp);
31983192
tcp_transmit_skb(sk, buff, 0, sk_gfp_atomic(sk, GFP_ATOMIC));
31993193
}
32003194

@@ -3226,7 +3220,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
32263220
* send it.
32273221
*/
32283222
tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPHDR_ACK);
3229-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
3223+
skb_mstamp_get(&skb->skb_mstamp);
32303224
return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC);
32313225
}
32323226

@@ -3270,7 +3264,6 @@ int tcp_write_wakeup(struct sock *sk)
32703264
tcp_set_skb_tso_segs(sk, skb, mss);
32713265

32723266
TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_PSH;
3273-
TCP_SKB_CB(skb)->when = tcp_time_stamp;
32743267
err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
32753268
if (!err)
32763269
tcp_event_new_data_sent(sk, skb);

net/ipv4/tcp_timer.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,9 @@ static bool retransmits_timed_out(struct sock *sk,
135135
if (!inet_csk(sk)->icsk_retransmits)
136136
return false;
137137

138-
if (unlikely(!tcp_sk(sk)->retrans_stamp))
139-
start_ts = TCP_SKB_CB(tcp_write_queue_head(sk))->when;
140-
else
141-
start_ts = tcp_sk(sk)->retrans_stamp;
138+
start_ts = tcp_sk(sk)->retrans_stamp;
139+
if (unlikely(!start_ts))
140+
start_ts = tcp_skb_timestamp(tcp_write_queue_head(sk));
142141

143142
if (likely(timeout == 0)) {
144143
linear_backoff_thresh = ilog2(TCP_RTO_MAX/rto_base);

0 commit comments

Comments
 (0)