[PATCH net-next v5 1/4] tcp: export CE count in rate_sample
From: chia-yu . chang
Date: Mon Nov 30 2026 - 07:57:30 EST
From: Ilpo Järvinen <ij@xxxxxxxxxx>
Store the number of newly ACKed/SACKed CE-marked packets in rate_sample.
This will be used by upcoming congestion control algorithms, e.g.,
TCP Prague, that need access to AccECN-derived congestion info.
For RFC3168 ECN mode, acked_sacked_ce equals delivered when FLAG_ECE
is present. For AccECN mode, it carries the derived CE-marked packets
from AccECN options or ACE field based on RFC9768.
Signed-off-by: Ilpo Järvinen <ij@xxxxxxxxxx>
Co-developed-by: Olivier Tilmans <olivier.tilmans@xxxxxxxxx>
Signed-off-by: Olivier Tilmans <olivier.tilmans@xxxxxxxxx>
Co-developed-by: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
---
v5:
- Rebase to the latest net-next tree
- Clarify acked_sacked_ce comment to document that it carries
the exact CE-marked packet count under AccECN, while under RFC3168
ECN it equals acked_sacked when the ECE flag is present.
v3:
- Improve commit message
- Rename ece_delta to acked_sacked_ce
- Remove redundant rate_sample initializer
---
include/net/tcp.h | 7 +++++++
net/ipv4/tcp_input.c | 36 ++++++++++++++++--------------------
2 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 68a60268d19d..12129ae8b06b 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1369,6 +1369,13 @@ struct rate_sample {
long rtt_us; /* RTT of last (S)ACKed packet (or -1) */
int losses; /* number of packets marked lost upon ACK */
u32 acked_sacked; /* number of packets newly (S)ACKed upon ACK */
+ /*
+ * Number of packets newly (S)ACked associated with congestion
+ * signalling upon ACK.
+ * For AccECN, this is the number of newly CE-marked packets.
+ * For RFC3168, this equals acked_sacked when the ECE flag is present.
+ */
+ u32 acked_sacked_ce;
u32 prior_in_flight; /* in flight before this ACK */
u32 last_end_seq; /* end_seq of most recently ACKed packet */
bool is_app_limited; /* is sample from packet with bubble in pipe? */
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 801c76744ed8..a37660275e35 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -606,9 +606,9 @@ static u32 __tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,
return safe_delta;
}
-static u32 tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,
- u32 delivered_pkts, u32 delivered_bytes,
- int *flag)
+static void tcp_accecn_process(struct sock *sk, struct rate_sample *rs,
+ const struct sk_buff *skb, u32 delivered_pkts,
+ u32 delivered_bytes, int *flag)
{
struct tcp_sock *tp = tcp_sk(sk);
u32 delta;
@@ -618,11 +618,11 @@ static u32 tcp_accecn_process(struct sock *sk, const struct sk_buff *skb,
if (delta > 0) {
tcp_count_delivered_ce(tp, delta);
*flag |= FLAG_ECE;
+ rs->acked_sacked_ce = delta;
/* Recalculate header predictor */
if (tp->pred_flags)
tcp_fast_path_on(tp);
}
- return delta;
}
/* Buffer size and advertised window tuning.
@@ -4249,8 +4249,8 @@ static void tcp_xmit_recovery(struct sock *sk, int rexmit)
}
/* Returns the number of packets newly acked or sacked by the current ACK */
-static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered,
- u32 ecn_count, int flag)
+static u32 tcp_newly_delivered(struct sock *sk, struct rate_sample *rs,
+ u32 prior_delivered, int flag)
{
const struct net *net = sock_net(sk);
struct tcp_sock *tp = tcp_sk(sk);
@@ -4261,8 +4261,9 @@ static u32 tcp_newly_delivered(struct sock *sk, u32 prior_delivered,
if (flag & FLAG_ECE) {
if (tcp_ecn_mode_rfc3168(tp))
- ecn_count = delivered;
- NET_ADD_STATS(net, LINUX_MIB_TCPDELIVEREDCE, ecn_count);
+ rs->acked_sacked_ce = delivered;
+ NET_ADD_STATS(net, LINUX_MIB_TCPDELIVEREDCE,
+ rs->acked_sacked_ce);
}
return delivered;
@@ -4327,7 +4328,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
u32 delivered = tp->delivered;
u32 lost = tp->lost;
int rexmit = REXMIT_NONE; /* Flag to (re)transmit to recover losses */
- u32 ecn_count = 0; /* Did we receive ECE/an AccECN ACE update? */
u32 prior_fack;
sack_state.first_sackt = 0;
@@ -4445,10 +4445,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
tcp_rack_update_reo_wnd(sk, &rs);
if (tcp_ecn_mode_accecn(tp))
- ecn_count = tcp_accecn_process(sk, skb,
- tp->delivered - delivered,
- sack_state.delivered_bytes,
- &flag);
+ tcp_accecn_process(sk, &rs, skb, tp->delivered - delivered,
+ sack_state.delivered_bytes, &flag);
tcp_in_ack_event(sk, flag);
@@ -4474,7 +4472,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP))
sk_dst_confirm(sk);
- delivered = tcp_newly_delivered(sk, delivered, ecn_count, flag);
+ delivered = tcp_newly_delivered(sk, &rs, delivered, flag);
lost = tp->lost - lost; /* freshly marked lost */
rs.is_ack_delayed = !!(flag & FLAG_ACK_MAYBE_DELAYED);
@@ -4485,16 +4483,14 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
no_queue:
if (tcp_ecn_mode_accecn(tp))
- ecn_count = tcp_accecn_process(sk, skb,
- tp->delivered - delivered,
- sack_state.delivered_bytes,
- &flag);
+ tcp_accecn_process(sk, &rs, skb, tp->delivered - delivered,
+ sack_state.delivered_bytes, &flag);
tcp_in_ack_event(sk, flag);
/* If data was DSACKed, see if we can undo a cwnd reduction. */
if (flag & FLAG_DSACKING_ACK) {
tcp_fastretrans_alert(sk, prior_snd_una, num_dupack, &flag,
&rexmit);
- tcp_newly_delivered(sk, delivered, ecn_count, flag);
+ tcp_newly_delivered(sk, &rs, delivered, flag);
}
/* If this ack opens up a zero window, clear backoff. It was
* being used to time the probes, and is probably far higher than
@@ -4521,7 +4517,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
&sack_state);
tcp_fastretrans_alert(sk, prior_snd_una, num_dupack, &flag,
&rexmit);
- tcp_newly_delivered(sk, delivered, ecn_count, flag);
+ tcp_newly_delivered(sk, &rs, delivered, flag);
tcp_xmit_recovery(sk, rexmit);
}
--
2.34.1