From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 030E82FD695 for ; Sat, 9 May 2026 17:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778346690; cv=none; b=mXPDJD6siJlO75z/HW4bcOduX+jdwBSDoQTEu5xiSkSvvydXXBk/sT4PglKQWnTyo3c0Yz6rFOPAmogkx/Vqtuh4qVtTrSe2kJt4unUbgjie0CSvezqZ8ZAD8HcCGe8eRzvLhkVLx8JPdJ//Y26UMztLBhtfP2yQyj8mg0N/qzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778346690; c=relaxed/simple; bh=ETBgXWvuGUMvNTgMZSFEQOcUtlGp2R15xSPoE/AyTkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sohK1ENaePp7U4Pq4wGHRB/UnZpDqMnR06uU0oE8qlV0kfRMhtmoFYzoXUbi0b6JsdxZ7nUC6WizSOnKwGPFD1ZypCt4LpPOG0Qe81n9/61mLGZ74TBVAwiPXGOXH3UJPIRcnWsSaJ0LxRrGeF9ACnUJPKXhipcu1e+U+EtBjgM= 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=HkZqO/XM; arc=none smtp.client-ip=74.125.82.172 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="HkZqO/XM" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-2f0d3e07e30so7715426eec.0 for ; Sat, 09 May 2026 10:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20251104.gappssmtp.com; s=20251104; t=1778346688; x=1778951488; 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=HkZqO/XMIODi8hhRXwTck8d7ZKmaCsJWqz/Pi7r+JK01qvxS51XuSXkwpufmz/XFGa 4tzzXrIXPTnFGM8Bl8HnQXVYCUSICLU8Q08F0IaR4fjA6FV+gzhbHjtMncnV+XYvXuOC RnBH082y4a/LJwaWVSW53KoQGmsuAi33V1Bi47tp9Oj0DAWANHScNifm1KJqrQf4b1Pm BySfjLjyPrNtFcIfjYY5OcbpYeNzmbOjya50uSkOBPLkUNxiPBYcH5uXfRrJOqJHyZrX kNl7IJwVSDB5EY1ko/wH0/k/spZbOXIScF4vAFO26Cr1EZAGBlqtrvamUjbuXG+wX329 jzYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778346688; x=1778951488; 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=LIkPRp4c8lhHiW1NebVl58nx1YUgGOc/aVmOmloyte+4dd+P5phB+Uxlgd8kqpiI7s +O1AmkU8esC9cnqpQWD7UOMedWIzPG8XvDS8gbgbEMibYzMeJlQJgzm1nT63zC2DIV0q sUe8qCNeP9b5VYxcWBlK6sAPGxT52MhdiSDqeAR90oEiUqCjFz0Vhhx4Ce71DA413o1Z j42ImFy84Qbn5pF1EPP51emqZFLfxmO5OUpHrTEcvWXChNr3FYKrUL/EvamfTMRgQ0WY 57fv3M0W9gGvittF3UHrG9MO7QT1aGDPzZ9RX1DEmZz9GH4aKHnJ7GYLGkMr15EzG242 /mEQ== X-Forwarded-Encrypted: i=1; AFNElJ/Hv1am9a9vsqLuIVLn+HJZZvovZbam+yUTxrxWzQaLAqIogRyqFkPQ7T7/8LYG0aZORkYrC0lWQyVlmAw=@vger.kernel.org X-Gm-Message-State: AOJu0YxiOlO2R02/5Y/BTiLybccAvwIJTmSptjhKdsmfQHh+Sf2ZTzvY q5+tq7h0VqFvRk/+eVBdwzaKunSSAlrYDF1CAGMe9N9hBWlWzIZDhYfy+K4/EV7bgt0= X-Gm-Gg: Acq92OGlL5Dk5aiJqFhDW0PrQYNR5zNYJjYQeLx+5qGsJYfgXSgWiYlD+GPiAtbUIcm FHhaq2znblN3kWsKbbciZIjvCEkx/21kw3au58hggsUTcRZr5RZY1VrbZBNHLJQtqCgcGn6LSVT s6P6MCnUvEVeq/aAuKTUvHxsgkrdHCKThsL97KUL2HpO1uWEXkaAXpGqqo/2YK1G77v/lj9ni6Z rGp+B3unJLSSNNQXfnYsHNdxSWRjxcqENoYib3feUAjLVyC4cpc8qePXywg9Gvri9CBJggtRuFF eVjr3KT03nBJWvsGOfs+f7Ka3hUa9mTHE6Nza3H2aGyIYJRIwD7sJLMKBEFD1ejdAbCtozVYkkD fv2ENp4kdN/TlSynFosgJ+5VvhLVrn8f7wYdOClkwnQkltT64yQiqyWhyqpnVDkgNih/D1he9qZ N7Ps776N2zX582maCwS4QPU7MtMSDr0+JG3vxhFhZABeE= X-Received: by 2002:a05:7300:d704:b0:2c1:7b61:8731 with SMTP id 5a478bee46e88-2f5490931d5mr9146989eec.10.1778346687769; Sat, 09 May 2026 10:11:27 -0700 (PDT) Received: from phoenix.lan ([104.202.41.210]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2f8859eafcdsm8524568eec.6.2026.05.09.10.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2026 10:11:27 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, Stephen Hemminger , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net-next v5 1/5] net/sched: netem: reorder struct netem_sched_data Date: Sat, 9 May 2026 10:03:22 -0700 Message-ID: <20260509171123.307549-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260509171123.307549-1-stephen@networkplumber.org> References: <20260509171123.307549-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