From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, jiri@resnulli.us,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH net-next v2 1/5] net/sched: netem: reorder struct netem_sched_data
Date: Sun, 3 May 2026 12:51:59 -0700 [thread overview]
Message-ID: <20260503195348.521225-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20260503195348.521225-1-stephen@networkplumber.org>
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 <stephen@networkplumber.org>
---
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
next prev parent reply other threads:[~2026-05-03 19:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 19:51 [PATCH net-next v2 0/5] net/sched: netem: fixes and improvements Stephen Hemminger
2026-05-03 19:51 ` Stephen Hemminger [this message]
2026-05-03 19:52 ` [PATCH net-next v2 2/5] net/sched: netem: remove useless VERSION Stephen Hemminger
2026-05-03 19:52 ` [PATCH net-next v2 3/5] net/sched: netem: replace pr_info with netlink extack error messages Stephen Hemminger
2026-05-03 19:52 ` [PATCH net-next v2 4/5] net/sched: netem: add per-impairment extended statistics Stephen Hemminger
2026-05-05 0:16 ` Stephen Hemminger
2026-05-03 19:52 ` [PATCH net-next v2 5/5] net/sched: netem: handle multi-segment skb in corruption Stephen Hemminger
2026-05-05 0:25 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260503195348.521225-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox