tcp: improve delivered counts in SCM_TSTAMP_ACK
Subsystems (3)
cover tcp: improve delivered counts in SCM_TSTAMP_ACK
Currently delivered and delivered_ce in OPT_STATS of SCM_TSTAMP_ACK do not fully reflect the current ack being timestamped. Also they are not in sync as the delivered count includes packets being sacked and some of cumulatively acked but delivered_ce includes none.
This patch series updates tp->delivered and tp->delivered_ce together to keep them in sync. It also moves generating SCM_TSTAMP_ACK to later in tcp_clean_rtx_queue() to reflect packets being cumulatively acked up until the current skb for sack-enabled connections.
Yousuk Seung (4):
tcp: stamp SCM_TSTAMP_ACK later in tcp_clean_rtx_queue()
tcp: add ece_ack flag to reno sack functions
tcp: count sacked packets in tcp_sacktag_state
tcp: update delivered_ce with delivered
net/ipv4/tcp_input.c | 59 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 20 deletions(-)
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
PATCH 1/4 tcp: stamp SCM_TSTAMP_ACK later in tcp_clean_rtx_queue()
Currently tp->delivered is updated with sacked packets but not cumulatively acked when SCP_TSTAMP_ACK is timestamped. This patch moves a tcp_ack_tstamp() call in tcp_clean_rtx_queue() to later in the loop so that when a skb is fully acked OPT_STATS of SCM_TSTAMP_ACK will include the current skb in the delivered count. When not fully acked tcp_ack_tstamp() is a no-op and there is no change in behavior.
--- net/ipv4/tcp_input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +2 -2
@@ -3078,8 +3078,6 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,u8 sacked = scb->sacked;u32 acked_pcount; -tcp_ack_tstamp (sk, skb, prior_snd_una); -/* Determine how many packets and what bytes were acked, tso and else */ if (after (scb->end_seq, tp->snd_una)) { if (tcp_skb_pcount(skb) == 1 ||
@@ -3143,6 +3141,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,if (!fully_acked)break ; +tcp_ack_tstamp (sk, skb, prior_snd_una); + next =skb_rb_next (skb);if (unlikely (skb == tp->retransmit_skb_hint)) tp->retransmit_skb_hint =NULL ;
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
Re: [PATCH net-next 1/4] tcp: stamp SCM_TSTAMP_ACK later in tcp_clean_rtx_queue()
Quoted 31 lines · Yousuk Seung
Currently
tp->deliveredis updated with sacked packets but not cumulatively acked whenSCP_TSTAMP_ACKis timestamped. This patch moves atcp_ack_tstamp()call intcp_clean_rtx_queue()to later in the loop so that when a skb is fully ackedOPT_STATSofSCM_TSTAMP_ACKwill include the current skb in the delivered count. When not fully ackedtcp_ack_tstamp()is a no-op and there is no change in behavior.Signed-off-by Yousuk Seung <[email protected]>Signed-off-by Yuchung Cheng <[email protected]>Acked-by Eric Dumazet <[email protected]>Acked-by Neal Cardwell <[email protected]>--- net/ipv4/tcp_input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/ipv4/tcp_input.c +0
-2@@ -3078,8 +3078,6 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,u8 sacked = scb->sacked;u32 acked_pcount; -tcp_ack_tstamp (sk, skb, prior_snd_una); -/* Determine how many packets and what bytes were acked, tso and else */ if (after (scb->end_seq, tp->snd_una)) { if (tcp_skb_pcount(skb) == 1 ||
net/ipv4/tcp_input.c static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack, · line 3148
Quoted 8 lines
net/ipv4/tcp_input.c +2
-0@@ -3143,6 +3141,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,if (!fully_acked)break ; +tcp_ack_tstamp (sk, skb, prior_snd_una); + next =skb_rb_next (skb);if (unlikely (skb == tp->retransmit_skb_hint)) tp->retransmit_skb_hint =NULL ;
This moves tcp_ack_tstamp beyond these two breaks:
tcp_ack_tstamp(sk, skb, prior_snd_una);
/* Determine how many packets and what bytes were
acked, tso and else */
if (after(scb->end_seq, tp->snd_una)) {
if (tcp_skb_pcount(skb) == 1 ||
!after(tp->snd_una, scb->seq))
break;
acked_pcount = tcp_tso_acked(sk, skb);
if (!acked_pcount)
break;
fully_acked = false;
} else {
acked_pcount = tcp_skb_pcount(skb);
}but tcp_ack_tstamp does not necessarily act on the end_seq in the packet, it acts on shinfo->tskey:
if (!before(shinfo->tskey, prior_snd_una) &&
before(shinfo->tskey, tcp_sk(sk)->snd_una)) {
tcp_skb_tsorted_save(skb) {
__skb_tstamp_tx(skb, NULL, sk, SCM_TSTAMP_ACK);
} tcp_skb_tsorted_restore(skb);
}on the next call to tcp_clean_rtx_queue tcp_sk(sk)->snd_una will be beyond tskey, so can this result in missing notifications?
PATCH 2/4 tcp: add ece_ack flag to reno sack functions
In reply to Yousuk SeungPass a boolean flag that tells the ECE state of the current ack to reno sack functions. This is pure refactor for future patches to improve tracking delivered counts.
--- net/ipv4/tcp_input.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
net/ipv4/tcp_input.c +12 -10
@@ -1893,7 +1893,7 @@ static void tcp_check_reno_reordering(struct sock *sk, const int addend)/* Emulate SACKs for SACKless connection: account for a new dupack. */ -static void tcp_add_reno_sack (struct sock *sk,int num_dupack) +static void tcp_add_reno_sack (struct sock *sk,int num_dupack,bool ece_ack) {if (num_dupack) {struct tcp_sock *tp =tcp_sk (sk);
@@ -1911,7 +1911,7 @@ static void tcp_add_reno_sack(struct sock *sk, int num_dupack)/* Account for ACK, ACKing some data in Reno Recovery phase. */ -static void tcp_remove_reno_sacks (struct sock *sk,int acked) +static void tcp_remove_reno_sacks (struct sock *sk,int acked,bool ece_ack) {struct tcp_sock *tp =tcp_sk (sk);
@@ -2697,7 +2697,7 @@ static void tcp_process_loss(struct sock *sk, int flag, int num_dupack,* delivered. Lower inflight to clock out (re)tranmissions. */ if (after (tp->snd_nxt, tp->high_seq) && num_dupack) -tcp_add_reno_sack (sk, num_dupack); +tcp_add_reno_sack (sk, num_dupack, flag &FLAG_ECE );else if (flag &FLAG_SND_UNA_ADVANCED )tcp_reset_reno_sack (tp); }
@@ -2779,6 +2779,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,struct inet_connection_sock *icsk =inet_csk (sk);struct tcp_sock *tp =tcp_sk (sk);int fast_rexmit =0 , flag = *ack_flag; +bool ece_ack = flag &FLAG_ECE ;bool do_lost = num_dupack || ((flag &FLAG_DATA_SACKED ) &&tcp_force_fast_retransmit (sk));
@@ -2787,7 +2788,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,/* Now state machine starts. * A. ECE, hence prohibit cwnd undoing, the reduction is required. */ -if (flag &FLAG_ECE ) +if (ece_ack) tp->prior_ssthresh =0 ;/* B. In all the states check for reneging SACKs. */
@@ -2828,7 +2829,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,case TCP_CA_Recovery:if (!(flag &FLAG_SND_UNA_ADVANCED )) {if (tcp_is_reno (tp)) -tcp_add_reno_sack (sk, num_dupack); +tcp_add_reno_sack (sk, num_dupack, ece_ack); }else {if (tcp_try_undo_partial (sk, prior_snd_una))return ;
@@ -2853,7 +2854,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,if (tcp_is_reno (tp)) {if (flag &FLAG_SND_UNA_ADVANCED )tcp_reset_reno_sack (tp); -tcp_add_reno_sack (sk, num_dupack); +tcp_add_reno_sack (sk, num_dupack, ece_ack); }if (icsk->icsk_ca_state <= TCP_CA_Disorder)
@@ -2877,7 +2878,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una, }/* Otherwise enter Recovery state */ -tcp_enter_recovery (sk, (flag &FLAG_ECE )); +tcp_enter_recovery (sk, ece_ack); fast_rexmit =1 ; }
@@ -3053,7 +3054,7 @@ static void tcp_ack_tstamp(struct sock *sk, struct sk_buff *skb,*/ static int tcp_clean_rtx_queue (struct sock *sk,u32 prior_fack,u32 prior_snd_una, -struct tcp_sacktag_state *sack) +struct tcp_sacktag_state *sack,bool ece_ack) {const struct inet_connection_sock *icsk =inet_csk (sk);u64 first_ackt, last_ackt;
@@ -3191,7 +3192,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack, }if (tcp_is_reno (tp)) { -tcp_remove_reno_sacks (sk, pkts_acked); +tcp_remove_reno_sacks (sk, pkts_acked, ece_ack);/* If any of the cumulatively ACKed segments was * retransmitted, non-SACK case cannot confirm that
@@ -3685,7 +3686,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) goto no_queue;/* See if we can take anything off of the retransmit queue. */ - flag |=tcp_clean_rtx_queue (sk, prior_fack, prior_snd_una, &sack_state); + flag |=tcp_clean_rtx_queue (sk, prior_fack, prior_snd_una, &sack_state, + flag &FLAG_ECE );tcp_rack_update_reo_wnd (sk, &rs);
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
PATCH 3/4 tcp: count sacked packets in tcp_sacktag_state
In reply to Yousuk SeungAdd sack_delivered to tcp_sacktag_state and count the number of sacked and dsacked packets. This is pure refactor for future patches to improve tracking delivered counts.
--- net/ipv4/tcp_input.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/tcp_input.c +4 -0
@@ -1138,6 +1138,7 @@ struct tcp_sacktag_state {struct rate_sample *rate;int flag;unsigned int mss_now; +u32 sack_delivered; };/* Check if skb is fully within the SACK block. In presence of GSO skbs,
@@ -1259,6 +1260,7 @@ static u8 tcp_sacktag_one(struct sock *sk, state->flag |=FLAG_DATA_SACKED ; tp->sacked_out += pcount; tp->delivered += pcount;/* Out-of-order packets delivered */ + state->sack_delivered += pcount;/* Lost marker hint past SACKed? Tweak RFC3517 cnt */ if (tp->lost_skb_hint &&
@@ -1685,6 +1687,7 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb,if (found_dup_sack) { state->flag |=FLAG_DSACKING_ACK ; tp->delivered++;/* A spurious retransmission is delivered */ + state->sack_delivered++; }/* Eliminate too old ACKs, but take into
@@ -3586,6 +3589,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) sack_state.first_sackt =0 ; sack_state.rate = &rs; + sack_state.sack_delivered =0 ;/* We very likely will need to access rtx queue. */ prefetch (sk->tcp_rtx_queue.rb_node);
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
PATCH 4/4 tcp: update delivered_ce with delivered
In reply to Yousuk SeungCurrently tp->delivered is updated in various places in tcp_ack() but tp->delivered_ce is updated once at the end. As a result two counts in OPT_STATS of SCM_TSTAMP_ACK timestamps generated in tcp_ack() may not be in sync. This patch updates both counts at the same in tcp_ack().
--- net/ipv4/tcp_input.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
net/ipv4/tcp_input.c +21 -8
@@ -962,6 +962,15 @@ void tcp_skb_mark_lost_uncond_verify(struct tcp_sock *tp, struct sk_buff *skb) } } +/* Updates the delivered and delivered_ce counts */ +static void tcp_count_delivered (struct tcp_sock *tp,u32 delivered, +bool ece_ack) +{ + tp->delivered += delivered; +if (ece_ack) + tp->delivered_ce += delivered; +} +/* This procedure tags the retransmission queue when SACKs arrive. * * We have three tag bits: SACKED(S), RETRANS(R) and LOST(L).
@@ -1259,7 +1268,7 @@ static u8 tcp_sacktag_one(struct sock *sk, sacked |=TCPCB_SACKED_ACKED ; state->flag |=FLAG_DATA_SACKED ; tp->sacked_out += pcount; - tp->delivered += pcount;/* Out-of-order packets delivered */ +/* Out-of-order packets delivered */ state->sack_delivered += pcount;/* Lost marker hint past SACKed? Tweak RFC3517 cnt */
@@ -1686,7 +1695,7 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb, num_sacks, prior_snd_una);if (found_dup_sack) { state->flag |=FLAG_DSACKING_ACK ; - tp->delivered++;/* A spurious retransmission is delivered */ +/* A spurious retransmission is delivered */ state->sack_delivered++; }
@@ -1907,7 +1916,7 @@ static void tcp_add_reno_sack(struct sock *sk, int num_dupack, bool ece_ack)tcp_check_reno_reordering (sk,0 ); delivered = tp->sacked_out - prior_sacked;if (delivered >0 ) - tp->delivered += delivered; +tcp_count_delivered (tp, delivered, ece_ack);tcp_verify_left_out (tp); } }
@@ -1920,7 +1929,8 @@ static void tcp_remove_reno_sacks(struct sock *sk, int acked, bool ece_ack)if (acked >0 ) {/* One ACK acked hole. The rest eat duplicate ACKs. */ - tp->delivered +=max_t (int, acked - tp->sacked_out,1 ); +tcp_count_delivered (tp,max_t (int, acked - tp->sacked_out,1 ), + ece_ack);if (acked -1 >= tp->sacked_out) tp->sacked_out =0 ;else
@@ -3116,7 +3126,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,if (sacked &TCPCB_SACKED_ACKED ) { tp->sacked_out -= acked_pcount; }else if (tcp_is_sack (tp)) { - tp->delivered += acked_pcount; +tcp_count_delivered (tp, acked_pcount, ece_ack);if (!tcp_skb_spurious_retrans (tp, skb))tcp_rack_advance (tp, sacked, scb->end_seq,tcp_skb_timestamp_us (skb));
@@ -3562,10 +3572,9 @@ static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered, int flag) delivered = tp->delivered - prior_delivered;NET_ADD_STATS (net,LINUX_MIB_TCPDELIVERED , delivered); -if (flag &FLAG_ECE ) { - tp->delivered_ce += delivered; +if (flag &FLAG_ECE )NET_ADD_STATS (net,LINUX_MIB_TCPDELIVEREDCE , delivered); - } +return delivered; }
@@ -3665,6 +3674,10 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) ack_ev_flags |=CA_ACK_ECE ; } +if (sack_state.sack_delivered) +tcp_count_delivered (tp, sack_state.sack_delivered, + flag &FLAG_ECE ); +if (flag &FLAG_WIN_UPDATE ) ack_ev_flags |=CA_ACK_WIN_UPDATE ;
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
David Miller
maintainerFrom: Yousuk Seung <[email protected]>
Date: Fri, 26 Jun 2020 21:05:31 -0700
Quoted 9 lines
Currently delivered and
delivered_ceinOPT_STATSofSCM_TSTAMP_ACKdo not fully reflect the current ack being timestamped. Also they are not in sync as the delivered count includes packets being sacked and some of cumulatively acked butdelivered_ceincludes none.This patch series updates
tp->deliveredandtp->delivered_cetogether to keep them in sync. It also moves generatingSCM_TSTAMP_ACKto later intcp_clean_rtx_queue()to reflect packets being cumulatively acked up until the current skb for sack-enabled connections.
Series applied, thank you.