From c2c6ce19663bdea4ccab6a457881ac705829a09b Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 15 Sep 2025 02:01:57 -0700 Subject: [PATCH] bpf: move MSS calculation under CE check to avoid overhead Currently, the MSS-based packet count calculation is performed for every packet, regardless of whether the IP ECN field indicates CE (congestion experienced). Since the computed value is only used when CE is set, this results in unnecessary per-packet processing. Move the MSS calculation inside the ip_ecn == 0b11 condition so that it is only executed when a CE mark is actually present. This reduces overhead on the fast path while preserving correct CE accounting. No functional change in CE handling, only an optimization in execution flow. Test: TreeHugger Flag: EXEMPT PURE_REFACTOR Signed-off-by: Sandeep Change-Id: I5cae40f914473d9f914c826d50dd91c93e047ccc --- bpf/progs/tcpAccECN.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bpf/progs/tcpAccECN.c b/bpf/progs/tcpAccECN.c index 609d09413d..4c8f5a563b 100644 --- a/bpf/progs/tcpAccECN.c +++ b/bpf/progs/tcpAccECN.c @@ -299,17 +299,16 @@ DEFINE_BPF_PROG_KVER(schedcls, ingress_accecn_eth, , AID_SYSTEM, 6_1) return TC_ACT_PIPE; } - uint32_t ce_packets = 1; - uint16_t *mss_ptr = bpf_l4s_accecn_mss_map_lookup_elem(&flow_key); - if (mss_ptr) { - uint16_t mss = *mss_ptr; - if (mss != 0xFFFF && mss != 0) { - ce_packets = (payload_size / mss) + 1; - } - } - // update the map if CE is marked if (ip_ecn == 0b11) { + uint32_t ce_packets = 1; + uint16_t *mss_ptr = bpf_l4s_accecn_mss_map_lookup_elem(&flow_key); + if (mss_ptr) { + uint16_t mss = *mss_ptr; + if (mss != 0xFFFF && mss != 0) { + ce_packets = (payload_size / mss) + 1; + } + } __sync_fetch_and_add(ce_count, ce_packets); } @@ -547,17 +546,16 @@ DEFINE_BPF_PROG_KVER(schedcls, ingress_accecn_rawip, , AID_SYSTEM, 6_1) return TC_ACT_PIPE; } - uint32_t ce_packets = 1; - uint16_t *mss_ptr = bpf_l4s_accecn_mss_map_lookup_elem(&flow_key); - if (mss_ptr) { - uint16_t mss = *mss_ptr; - if (mss != 0xFFFF && mss != 0) { - ce_packets = (payload_size / mss) + 1; - } - } - // update the map if CE is marked if (ip_ecn == 0b11) { + uint32_t ce_packets = 1; + uint16_t *mss_ptr = bpf_l4s_accecn_mss_map_lookup_elem(&flow_key); + if (mss_ptr) { + uint16_t mss = *mss_ptr; + if (mss != 0xFFFF && mss != 0) { + ce_packets = (payload_size / mss) + 1; + } + } __sync_fetch_and_add(ce_count, ce_packets); }