From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DCB049550A for ; Tue, 5 May 2026 17:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778002867; cv=none; b=dqQMzyjnInYWYvFtmdHem2aSLv0mAdg8Ds1o3+pywZo/+qT9bUR+e44vYYYF6cNac0+9XqYqRN1muLSXPU2J4ngobdSuW6GYcPTorcmX3nLh92fIa7m5DF82Q2g86Ctei+xWEzBiJ9vosXQda6eomfSiSNbP3nL0e4sKQtde+V4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778002867; c=relaxed/simple; bh=ETBgXWvuGUMvNTgMZSFEQOcUtlGp2R15xSPoE/AyTkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MG9W8C4TUQEcF08vN+pJdmYNHL0S5DxPpF0bopk9+BB6wZAA4eV2w3f+1qCJ0UwR/bgBKTETf0+rS3vulVRiMnTw4dVURqYx72XOVbxFRVywpIRFl23Q/HmRdUtCcvzcBVGr+LSID8IAk8GXS1dKHKAzFEx2/PqVq9OedVMHnlM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20251104.gappssmtp.com header.i=@networkplumber-org.20251104.gappssmtp.com header.b=erbBXxUm; arc=none smtp.client-ip=209.85.167.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20251104.gappssmtp.com header.i=@networkplumber-org.20251104.gappssmtp.com header.b="erbBXxUm" Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-479dd56d016so3972076b6e.3 for ; Tue, 05 May 2026 10:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20251104.gappssmtp.com; s=20251104; t=1778002864; x=1778607664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HY5nzQn5cAP1hhmSxoB6k29oHeedYWHjPnLvZY8TJyw=; b=erbBXxUmlY8E/BqtEclf+KIl34Oix8P3m9wUMSw2GRkYdM+WxvaZlvfBv0z/5b84eP KmYWkifGU+bDsH/AeJpj7pOVZXTUqjvqwyw0pggA6P/am03BsqERkf6vds708Pf0rjOQ FZgVeUPTGzPJjSIIA2WlIa9qk6H3FZ2yRTVJcsG8B9uMS0H4ZjXBD5yUB/zBeRPjTsYA W0AAFqAwj1FxGR/RveYJ8aBlvFSD8HJSirdWSfgj78wLJBWGGpV9NNYWFnKWv87GMOZL VLMA5EvSQeMmklbtFBhb2nPHJJ/ZGLKUlIxTeBscMa+IjvfBZZymGWhTzR5/B28u/V1t W/Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778002864; x=1778607664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HY5nzQn5cAP1hhmSxoB6k29oHeedYWHjPnLvZY8TJyw=; b=SlCLzBn3bZH0oZW7WptodV/ov8+cfZyozgfmyzEQd4whnmHLTIASuW8Rb6tqXJB27r FDHghIX98W4TVnA5zkR6Uw79m48cPNI8VymU9JLe9CZifl8nTaP2jxYXUweQkdLkAUGW r+MIm9Vqw4I+Z1YizxXwWhcXPCvjQo6X6rR/Hmc3SUvydu7A6z9TMVRQ8mlbTIu0Z+Z+ PkJ8YvMxhrDR/epCU4U1cE/048uyZF9zQk86TZFl1k3DxI/qtMwbpcLVGCNphUXtCyBs eHBrWvZUAPzbIW58xBy0S6Q2X3hKX0cWz0Unamk5uhZxPWvS1W86F6bxWZztdaAJxNvF 2p0g== X-Forwarded-Encrypted: i=1; AFNElJ/akWYxgDXQ0J6xerEOsujhy9GTMbymmOU3Jph8Q0EvxFYRV3WYGFdl4UEey4uCb5Eh5STPOh5mumC9Jmg=@vger.kernel.org X-Gm-Message-State: AOJu0YzmqmmNTLjY6PXNbRbzlosUm10rKbzoqsyXxLVVKWYL4FsYqjxq WV9UkWRXTbIGLUZG5bu8AXc3aWicd4hE+YtytRB9Z84a5IlYSzFM4dFNRvwIDixZZuo= X-Gm-Gg: AeBDieui/30wFVuf3EPO3+rZjPMnZZ97lJFQljpcaK1IaXxUlDtX/LsK6tU5fJcdSJu 6vhu94bttINClmY75ais0gye2B6a5Dy6/0DLgjyd6bex5qG7nYELKuSqSn3iA9iLyWNewkOyaXI AIL8zrIKWx9rZLmeyMcHbZTO1aJ4gHbfNwg5jEN/X9QhQco1OWQFROeCcgZqEiP8KrNoGyvxKzs 0J5oss8jz3L8nuuP7FknvWisStGNdJpFVTDo2/YhlLAxQF/ootACS7GNDua28XeO01fB0DYJ6D/ tZPSKaYd5CUnNqLDD2H7vAgZCYmy9sGBg2QxnLYg0rqU/RGvZN5Vi9olvvHKqg6Y9dTepx9ieEl hdYTONJ9lrGl7sW3FgHBVY+nIWfLxO+EJgzZ4wJgfw19CozuVTTJyXAdM/tQz4kkQwhTzQPz99u agrobs65TA6thWx2fldjLOZ7YVNE6h1AtBGUZKuPmH1No= X-Received: by 2002:a05:6808:3a14:b0:479:db65:8db0 with SMTP id 5614622812f47-480420941a1mr35193b6e.3.1778002864114; Tue, 05 May 2026 10:41:04 -0700 (PDT) Received: from phoenix.lan ([104.202.41.210]) by smtp.gmail.com with ESMTPSA id 5614622812f47-47c769c9b12sm9006504b6e.17.2026.05.05.10.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 10:41:03 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, jiri@resnulli.us, Stephen Hemminger , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v3 1/5] net/sched: netem: reorder struct netem_sched_data Date: Tue, 5 May 2026 10:38:41 -0700 Message-ID: <20260505174059.651260-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260505174059.651260-1-stephen@networkplumber.org> References: <20260505174059.651260-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The current layout of struct netem_sched_data can be improved by optimizing cache locality, compacting data types (use u8 for enum) and eliminating unused elements. Reorganize the struct as follows: - Cacheline 0 holds the tfifo state (t_root/t_head/t_tail/t_len), counter, and the unconditional enqueue scalars latency/jitter/rate/gap/loss. - Cacheline 1 holds the remaining zero-check scalars (duplicate/reorder/corrupt/ecn), all five crndstate correlation structures, and loss_model. - Cacheline 2 holds prng, delay_dist, the slot dequeue state, slot_dist, and the inner classful qdisc pointer. - Rate-shaping fields, q->limit (config-only; the fast path reads sch->limit), and the CLG Markov state move to the warm tail. - tc_netem_slot slot_config and qdisc_watchdog (only consulted on slot reschedule and watchdog wake) move to the cold tail. Also reorder struct clgstate to place the u8 state member after the u32 transition probabilities. This removes the 3-byte interior hole without changing the struct's size. Should have no functional change. Signed-off-by: Stephen Hemminger --- net/sched/sch_netem.c | 123 +++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index bc18e1976b6e..616d33879fdc 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -71,89 +71,92 @@ struct disttable { s16 table[] __counted_by(size); }; -struct netem_sched_data { - /* internal t(ime)fifo qdisc uses t_root and sch->limit */ - struct rb_root t_root; - - /* a linear queue; reduces rbtree rebalancing when jitter is low */ - struct sk_buff *t_head; - struct sk_buff *t_tail; - - u32 t_len; - - /* optional qdisc for classful handling (NULL at netem init) */ - struct Qdisc *qdisc; - - struct qdisc_watchdog watchdog; +/* Loss models */ +enum { + CLG_RANDOM, + CLG_4_STATES, + CLG_GILB_ELL, +}; - s64 latency; - s64 jitter; +/* States in GE model */ +enum { + GOOD_STATE = 1, + BAD_STATE, +}; - u32 loss; - u32 ecn; - u32 limit; - u32 counter; - u32 gap; - u32 duplicate; - u32 reorder; - u32 corrupt; - u64 rate; - s32 packet_overhead; - u32 cell_size; - struct reciprocal_value cell_size_reciprocal; - s32 cell_overhead; +/* States in 4 state model */ +enum { + TX_IN_GAP_PERIOD = 1, + TX_IN_BURST_PERIOD, + LOST_IN_GAP_PERIOD, + LOST_IN_BURST_PERIOD, +}; +struct netem_sched_data { + /* Cacheline 0: tfifo state and per-packet enqueue/dequeue scalars. */ + struct rb_root t_root; + struct sk_buff *t_head; + struct sk_buff *t_tail; + u32 t_len; + u32 counter; + s64 latency; + s64 jitter; + u64 rate; + u32 gap; + u32 loss; + + /* Cacheline 1: zero-check scalars and correlation states. */ + u32 duplicate; + u32 reorder; + u32 corrupt; + u32 ecn; struct crndstate { u32 last; u32 rho; } delay_cor, loss_cor, dup_cor, reorder_cor, corrupt_cor; + u8 loss_model; - struct prng { + /* Cacheline 2: PRNG, distribution tables, slot dequeue state etc. */ + struct prng { u64 seed; struct rnd_state prng_state; } prng; + struct disttable *delay_dist; + struct slotstate { + u64 slot_next; + s32 packets_left; + s32 bytes_left; + } slot; + struct disttable *slot_dist; + struct Qdisc *qdisc; - struct disttable *delay_dist; - - enum { - CLG_RANDOM, - CLG_4_STATES, - CLG_GILB_ELL, - } loss_model; - - enum { - TX_IN_GAP_PERIOD = 1, - TX_IN_BURST_PERIOD, - LOST_IN_GAP_PERIOD, - LOST_IN_BURST_PERIOD, - } _4_state_model; - - enum { - GOOD_STATE = 1, - BAD_STATE, - } GE_state_model; + /* + * Warm: rate-shaping parameters (only read when rate != 0) and + * configuration-only fields. The fast path reads sch->limit, not + * q->limit. + */ + s32 packet_overhead; + u32 cell_size; + struct reciprocal_value cell_size_reciprocal; + s32 cell_overhead; + u32 limit; /* Correlated Loss Generation models */ struct clgstate { - /* state of the Markov chain */ - u8 state; - /* 4-states and Gilbert-Elliot models */ u32 a1; /* p13 for 4-states or p for GE */ u32 a2; /* p31 for 4-states or r for GE */ u32 a3; /* p32 for 4-states or h for GE */ u32 a4; /* p14 for 4-states or 1-k for GE */ u32 a5; /* p23 used only in 4-states */ - } clg; - struct tc_netem_slot slot_config; - struct slotstate { - u64 slot_next; - s32 packets_left; - s32 bytes_left; - } slot; + /* state of the Markov chain */ + u8 state; + } clg; - struct disttable *slot_dist; + /* Cold tail: slot reschedule config and the watchdog timer. */ + struct tc_netem_slot slot_config; + struct qdisc_watchdog watchdog; }; /* Time stamp put into socket buffer control block -- 2.53.0