Skip to content

Commit d3edd06

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: provide earliest departure time in skb->tstamp
Switch internal TCP skb->skb_mstamp to skb->skb_mstamp_ns, from usec units to nsec units. Do not clear skb->tstamp before entering IP stacks in TX, so that qdisc or devices can implement pacing based on the earliest departure time instead of socket sk->sk_pacing_rate Packets are fed with tcp_wstamp_ns, and following patch will update tcp_wstamp_ns when both TCP and sch_fq switch to the earliest departure time mechanism. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9799ccb commit d3edd06

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

include/linux/skbuff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ struct sk_buff {
689689

690690
union {
691691
ktime_t tstamp;
692-
u64 skb_mstamp;
692+
u64 skb_mstamp_ns; /* earliest departure time */
693693
};
694694
/*
695695
* This is the control buffer. It is free to use for every

include/net/tcp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
761761

762762
static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
763763
{
764-
return div_u64(skb->skb_mstamp, USEC_PER_SEC / TCP_TS_HZ);
764+
return div_u64(skb->skb_mstamp_ns, NSEC_PER_SEC / TCP_TS_HZ);
765765
}
766766

767767
/* provide the departure time in us unit */
768768
static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb)
769769
{
770-
return skb->skb_mstamp;
770+
return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC);
771771
}
772772

773773

@@ -813,7 +813,7 @@ struct tcp_skb_cb {
813813
#define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */
814814
#define TCPCB_LOST 0x04 /* SKB is lost */
815815
#define TCPCB_TAGBITS 0x07 /* All tag bits */
816-
#define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp) */
816+
#define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp_ns) */
817817
#define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */
818818
#define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS| \
819819
TCPCB_REPAIRED)

net/ipv4/syncookies.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ u64 cookie_init_timestamp(struct request_sock *req)
8888
ts <<= TSBITS;
8989
ts |= options;
9090
}
91-
return (u64)ts * (USEC_PER_SEC / TCP_TS_HZ);
91+
return (u64)ts * (NSEC_PER_SEC / TCP_TS_HZ);
9292
}
9393

9494

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
12951295
copy = size_goal;
12961296

12971297
/* All packets are restored as if they have
1298-
* already been sent. skb_mstamp isn't set to
1298+
* already been sent. skb_mstamp_ns isn't set to
12991299
* avoid wrong rtt estimation.
13001300
*/
13011301
if (tp->repair)

net/ipv4/tcp_output.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ static void tcp_internal_pacing(struct sock *sk, const struct sk_buff *skb)
10141014

10151015
static void tcp_update_skb_after_send(struct tcp_sock *tp, struct sk_buff *skb)
10161016
{
1017-
skb->skb_mstamp = tp->tcp_mstamp;
1017+
skb->skb_mstamp_ns = tp->tcp_wstamp_ns;
10181018
list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue);
10191019
}
10201020

@@ -1061,7 +1061,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
10611061
if (unlikely(!skb))
10621062
return -ENOBUFS;
10631063
}
1064-
skb->skb_mstamp = tp->tcp_mstamp;
1064+
skb->skb_mstamp_ns = tp->tcp_wstamp_ns;
10651065

10661066
inet = inet_sk(sk);
10671067
tcb = TCP_SKB_CB(skb);
@@ -1165,8 +1165,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
11651165
skb_shinfo(skb)->gso_segs = tcp_skb_pcount(skb);
11661166
skb_shinfo(skb)->gso_size = tcp_skb_mss(skb);
11671167

1168-
/* Our usage of tstamp should remain private */
1169-
skb->tstamp = 0;
1168+
/* Leave earliest departure time in skb->tstamp (skb->skb_mstamp_ns) */
11701169

11711170
/* Cleanup our debris for IP stacks */
11721171
memset(skb->cb, 0, max(sizeof(struct inet_skb_parm),
@@ -3221,10 +3220,10 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
32213220
memset(&opts, 0, sizeof(opts));
32223221
#ifdef CONFIG_SYN_COOKIES
32233222
if (unlikely(req->cookie_ts))
3224-
skb->skb_mstamp = cookie_init_timestamp(req);
3223+
skb->skb_mstamp_ns = cookie_init_timestamp(req);
32253224
else
32263225
#endif
3227-
skb->skb_mstamp = tcp_clock_us();
3226+
skb->skb_mstamp_ns = tcp_clock_ns();
32283227

32293228
#ifdef CONFIG_TCP_MD5SIG
32303229
rcu_read_lock();
@@ -3440,7 +3439,7 @@ static int tcp_send_syn_data(struct sock *sk, struct sk_buff *syn)
34403439

34413440
err = tcp_transmit_skb(sk, syn_data, 1, sk->sk_allocation);
34423441

3443-
syn->skb_mstamp = syn_data->skb_mstamp;
3442+
syn->skb_mstamp_ns = syn_data->skb_mstamp_ns;
34443443

34453444
/* Now full SYN+DATA was cloned and sent (or not),
34463445
* remove the SYN from the original skb (syn_data)

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void tcp_probe_timer(struct sock *sk)
360360
*/
361361
start_ts = tcp_skb_timestamp(skb);
362362
if (!start_ts)
363-
skb->skb_mstamp = tp->tcp_mstamp;
363+
skb->skb_mstamp_ns = tp->tcp_wstamp_ns;
364364
else if (icsk->icsk_user_timeout &&
365365
(s32)(tcp_time_stamp(tp) - start_ts) > icsk->icsk_user_timeout)
366366
goto abort;

0 commit comments

Comments
 (0)