From: carlos.bilbao@kernel.org
To: jv@jvosburgh.net, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: sforshee@kernel.org, bilbao@vt.edu,
Carlos Bilbao <carlos.bilbao@kernel.org>
Subject: [PATCH] bonding: Switch periodic LACPDU state machine from counter to jiffies
Date: Tue, 15 Jul 2025 15:57:33 -0500 [thread overview]
Message-ID: <20250715205733.50911-1-carlos.bilbao@kernel.org> (raw)
From: Carlos Bilbao <carlos.bilbao@kernel.org>
Replace the bonding periodic state machine for LACPDU transmission of
function ad_periodic_machine() with a jiffies-based mechanism, which is
more accurate and can help reduce drift under contention.
Signed-off-by: Carlos Bilbao (DigitalOcean) <carlos.bilbao@kernel.org>
---
drivers/net/bonding/bond_3ad.c | 79 +++++++++++++---------------------
include/net/bond_3ad.h | 2 +-
2 files changed, 32 insertions(+), 49 deletions(-)
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index c6807e473ab7..8654a51266a3 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -1421,44 +1421,24 @@ static void ad_periodic_machine(struct port *port, struct bond_params *bond_para
(!(port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY) && !(port->partner_oper.port_state & LACP_STATE_LACP_ACTIVITY)) ||
!bond_params->lacp_active) {
port->sm_periodic_state = AD_NO_PERIODIC;
- }
- /* check if state machine should change state */
- else if (port->sm_periodic_timer_counter) {
- /* check if periodic state machine expired */
- if (!(--port->sm_periodic_timer_counter)) {
- /* if expired then do tx */
- port->sm_periodic_state = AD_PERIODIC_TX;
- } else {
- /* If not expired, check if there is some new timeout
- * parameter from the partner state
- */
- switch (port->sm_periodic_state) {
- case AD_FAST_PERIODIC:
- if (!(port->partner_oper.port_state
- & LACP_STATE_LACP_TIMEOUT))
- port->sm_periodic_state = AD_SLOW_PERIODIC;
- break;
- case AD_SLOW_PERIODIC:
- if ((port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT)) {
- port->sm_periodic_timer_counter = 0;
- port->sm_periodic_state = AD_PERIODIC_TX;
- }
- break;
- default:
- break;
- }
- }
+ } else if (port->sm_periodic_state == AD_NO_PERIODIC)
+ port->sm_periodic_state = AD_FAST_PERIODIC;
+ /* check if periodic state machine expired */
+ else if (time_after_eq(jiffies, port->sm_periodic_next_jiffies)) {
+ /* if expired then do tx */
+ port->sm_periodic_state = AD_PERIODIC_TX;
} else {
+ /* If not expired, check if there is some new timeout
+ * parameter from the partner state
+ */
switch (port->sm_periodic_state) {
- case AD_NO_PERIODIC:
- port->sm_periodic_state = AD_FAST_PERIODIC;
- break;
- case AD_PERIODIC_TX:
- if (!(port->partner_oper.port_state &
- LACP_STATE_LACP_TIMEOUT))
+ case AD_FAST_PERIODIC:
+ if (!(port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT))
port->sm_periodic_state = AD_SLOW_PERIODIC;
- else
- port->sm_periodic_state = AD_FAST_PERIODIC;
+ break;
+ case AD_SLOW_PERIODIC:
+ if ((port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT))
+ port->sm_periodic_state = AD_PERIODIC_TX;
break;
default:
break;
@@ -1471,21 +1451,24 @@ static void ad_periodic_machine(struct port *port, struct bond_params *bond_para
"Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n",
port->actor_port_number, last_state,
port->sm_periodic_state);
+
switch (port->sm_periodic_state) {
- case AD_NO_PERIODIC:
- port->sm_periodic_timer_counter = 0;
- break;
- case AD_FAST_PERIODIC:
- /* decrement 1 tick we lost in the PERIODIC_TX cycle */
- port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_FAST_PERIODIC_TIME))-1;
- break;
- case AD_SLOW_PERIODIC:
- /* decrement 1 tick we lost in the PERIODIC_TX cycle */
- port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TIME))-1;
- break;
case AD_PERIODIC_TX:
port->ntt = true;
- break;
+ if (!(port->partner_oper.port_state &
+ LACP_STATE_LACP_TIMEOUT))
+ port->sm_periodic_state = AD_SLOW_PERIODIC;
+ else
+ port->sm_periodic_state = AD_FAST_PERIODIC;
+ fallthrough;
+ case AD_SLOW_PERIODIC:
+ case AD_FAST_PERIODIC:
+ if (port->sm_periodic_state == AD_SLOW_PERIODIC)
+ port->sm_periodic_next_jiffies = jiffies
+ + HZ * AD_SLOW_PERIODIC_TIME;
+ else /* AD_FAST_PERIODIC */
+ port->sm_periodic_next_jiffies = jiffies
+ + HZ * AD_FAST_PERIODIC_TIME;
default:
break;
}
@@ -1987,7 +1970,7 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
port->sm_rx_state = 0;
port->sm_rx_timer_counter = 0;
port->sm_periodic_state = 0;
- port->sm_periodic_timer_counter = 0;
+ port->sm_periodic_next_jiffies = 0;
port->sm_mux_state = 0;
port->sm_mux_timer_counter = 0;
port->sm_tx_state = 0;
diff --git a/include/net/bond_3ad.h b/include/net/bond_3ad.h
index 2053cd8e788a..aabb8c97caf4 100644
--- a/include/net/bond_3ad.h
+++ b/include/net/bond_3ad.h
@@ -227,7 +227,7 @@ typedef struct port {
rx_states_t sm_rx_state; /* state machine rx state */
u16 sm_rx_timer_counter; /* state machine rx timer counter */
periodic_states_t sm_periodic_state; /* state machine periodic state */
- u16 sm_periodic_timer_counter; /* state machine periodic timer counter */
+ unsigned long sm_periodic_next_jiffies; /* state machine periodic next expected sent */
mux_states_t sm_mux_state; /* state machine mux state */
u16 sm_mux_timer_counter; /* state machine mux timer counter */
tx_states_t sm_tx_state; /* state machine tx state */
--
2.43.0
next reply other threads:[~2025-07-15 20:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 20:57 carlos.bilbao [this message]
2025-07-15 20:59 ` [PATCH] bonding: Switch periodic LACPDU state machine from counter to jiffies Carlos Bilbao
2025-07-16 15:30 ` Jay Vosburgh
2025-07-16 19:44 ` Carlos Bilbao
2025-07-16 23:33 ` Jay Vosburgh
2025-08-05 13:14 ` Hangbin Liu
2025-07-16 9:09 ` Simon Horman
2025-07-16 19:45 ` Carlos Bilbao
2025-07-17 4:35 ` kernel test robot
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=20250715205733.50911-1-carlos.bilbao@kernel.org \
--to=carlos.bilbao@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bilbao@vt.edu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jv@jvosburgh.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sforshee@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;
as well as URLs for NNTP newsgroup(s).