Skip to content

Commit

Permalink
net-tcp_bbr: v2: snapshot packets in flight at transmit time and pass…
Browse files Browse the repository at this point in the history
… in rate_sample

CC algorithms may want to snapshot the number of packets in flight at
transmit time and pass in rate_sample, to understand the relationship
between inflight and losses or ECN signals, to try to find the highest
inflight value that has acceptable levels of loss/ECN marking.

We split out the code to set an skb's tx.in_flight field into its own
function, so that this code can be used for the TCP_REPAIR "fake send"
code path that inserts skbs into the rtx queue without sending them.

Effort: net-tcp_bbr
Origin-9xx-SHA1: b3eb4f2d20efab4ca001f32c9294739036c493ea
Origin-9xx-SHA1: e880fc907d06ea7354333f60f712748ebce9497b
Origin-9xx-SHA1: 330f825a08a6fe92cef74d799cc468864c479f63
Change-Id: I7314047d0ff14dd261a04b1969a46dc658c8836a
Signed-off-by: Alexandre Frade <kernel@xanmod.org>
  • Loading branch information
nealcardwell authored and xanmod committed Aug 16, 2023
1 parent 2113b04 commit cfd423c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/net/tcp.h
Expand Up @@ -907,6 +907,10 @@ struct tcp_skb_cb {
u32 first_tx_mstamp;
/* when we reached the "delivered" count */
u32 delivered_mstamp;
#define TCPCB_IN_FLIGHT_BITS 20
#define TCPCB_IN_FLIGHT_MAX ((1U << TCPCB_IN_FLIGHT_BITS) - 1)
u32 in_flight:20, /* packets in flight at transmit */
unused2:12;
} tx; /* only used for outgoing skbs */
union {
struct inet_skb_parm h4;
Expand Down Expand Up @@ -1054,6 +1058,7 @@ struct rate_sample {
u64 prior_mstamp; /* starting timestamp for interval */
u32 prior_delivered; /* tp->delivered at "prior_mstamp" */
u32 prior_delivered_ce;/* tp->delivered_ce at "prior_mstamp" */
u32 tx_in_flight; /* packets in flight at starting timestamp */
s32 delivered; /* number of packets delivered over interval */
s32 delivered_ce; /* number of packets delivered w/ CE marks*/
long interval_us; /* time for tp->delivered to incr "delivered" */
Expand Down Expand Up @@ -1173,6 +1178,7 @@ static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event)
void tcp_set_ca_state(struct sock *sk, const u8 ca_state);

/* From tcp_rate.c */
void tcp_set_tx_in_flight(struct sock *sk, struct sk_buff *skb);
void tcp_rate_skb_sent(struct sock *sk, struct sk_buff *skb);
void tcp_rate_skb_delivered(struct sock *sk, struct sk_buff *skb,
struct rate_sample *rs);
Expand Down
1 change: 1 addition & 0 deletions net/ipv4/tcp_output.c
Expand Up @@ -2639,6 +2639,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
skb_set_delivery_time(skb, tp->tcp_wstamp_ns, true);
list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue);
tcp_init_tso_segs(skb, mss_now);
tcp_set_tx_in_flight(sk, skb);
goto repair; /* Skip network transmission */
}

Expand Down
20 changes: 20 additions & 0 deletions net/ipv4/tcp_rate.c
Expand Up @@ -34,6 +34,24 @@
* ready to send in the write queue.
*/

void tcp_set_tx_in_flight(struct sock *sk, struct sk_buff *skb)
{
struct tcp_sock *tp = tcp_sk(sk);
u32 in_flight;

/* Check, sanitize, and record packets in flight after skb was sent. */
in_flight = tcp_packets_in_flight(tp) + tcp_skb_pcount(skb);
if (WARN_ONCE(in_flight > TCPCB_IN_FLIGHT_MAX,
"insane in_flight %u cc %s mss %u "
"cwnd %u pif %u %u %u %u\n",
in_flight, inet_csk(sk)->icsk_ca_ops->name,
tp->mss_cache, tp->snd_cwnd,
tp->packets_out, tp->retrans_out,
tp->sacked_out, tp->lost_out))
in_flight = TCPCB_IN_FLIGHT_MAX;
TCP_SKB_CB(skb)->tx.in_flight = in_flight;
}

/* Snapshot the current delivery information in the skb, to generate
* a rate sample later when the skb is (s)acked in tcp_rate_skb_delivered().
*/
Expand Down Expand Up @@ -67,6 +85,7 @@ void tcp_rate_skb_sent(struct sock *sk, struct sk_buff *skb)
TCP_SKB_CB(skb)->tx.delivered = tp->delivered;
TCP_SKB_CB(skb)->tx.delivered_ce = tp->delivered_ce;
TCP_SKB_CB(skb)->tx.is_app_limited = tp->app_limited ? 1 : 0;
tcp_set_tx_in_flight(sk, skb);
}

/* When an skb is sacked or acked, we fill in the rate sample with the (prior)
Expand Down Expand Up @@ -96,6 +115,7 @@ void tcp_rate_skb_delivered(struct sock *sk, struct sk_buff *skb,
rs->prior_mstamp = scb->tx.delivered_mstamp;
rs->is_app_limited = scb->tx.is_app_limited;
rs->is_retrans = scb->sacked & TCPCB_RETRANS;
rs->tx_in_flight = scb->tx.in_flight;
rs->last_end_seq = scb->end_seq;

/* Record send time of most recently ACKed packet: */
Expand Down

0 comments on commit cfd423c

Please sign in to comment.