batman-adv: tp_meter: post fixes cleanups
Sven Eckelmann
maintainerv6 cover batman-adv: tp_meter: post fixes cleanups
After most of the problems regarding the role confusion were fixed, we should use the opportunity to split the variables completly. This can prevent some of the confusions and at the same time reduce the memory consumption significantly.
Since the sender variables are separated from the rest, also clean up the congestion control code. Make sure that everything is in short blocks which ensure that the reader is aware of the locking and the results of the calculation. Which also means that the actions (sending) are extracted from the congestion control code.
---
Changes in v6:
- add patch to initialize dec_cwnd
- add patch to fix fast recovery precondition
- extract the batadv_seq_before handling for fast recovery into a separate
fix
- add patch to finish the tp_vars initialization before adding item to the
RCU protected list
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- drop accidentally added static (in-function) reason variable
- add patch to handle potential divide-by-zero in batadv_tp_update_cwnd()
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- rebase
- add patch to fix unacked_list order
- add patch to initialize dup_acks explicitly
- extract batadv_tp_avail fix to separate patch
- split congestion control variable patch in "locking" and "structure"
patch
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- rebase patches
- fix receiver cleanup "put"
- add patch to cleanup the congestion control locking
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- fix send_result kernel-doc
- rebase patch
- add patch to avoid role mixup in search functions
- add patch to split sender and receiver sessions
- Link to v1: https://patch.msgid.link/[email protected]
---
Sven Eckelmann (11):
batman-adv: tp_meter: keep unacked list in ascending ordered
batman-adv: tp_meter: initialize dup_acks explicitly
batman-adv: tp_meter: initialize dec_cwnd explicitly
batman-adv: tp_meter: avoid window underflow
batman-adv: tp_meter: avoid divide-by-zero for dec_cwnd
batman-adv: tp_meter: fix fast recovery precondition
batman-adv: tp_meter: handle seqno wrap-around for fast recovery detection
batman-adv: tp_meter: add only finished tp_vars to lists
batman-adv: tp_meter: split vars into sender and receiver types
batman-adv: tp_meter: use locking for all congestion control variables
batman-adv: tp_meter: consolidate congestion control variables
net/batman-adv/main.c | 3 +- net/batman-adv/tp_meter.c | 739 +++++++++++++++++++++++++++------------------- net/batman-adv/types.h | 145 ++++----- 3 files changed, 513 insertions(+), 374 deletions(-)
---
base-commit: bba80ddd693e6d82a0b1f456511904cfefd5df24
change-id: 20260513-tp-reason-missing-f1aa51f3f374
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>
Sven Eckelmann
maintainerPATCH v6 1/11 batman-adv: tp_meter: keep unacked list in ascending ordered
When batadv_tp_handle_out_of_order inserts a new entry in the list of unacked (out of order) packets, it searches from the entry with the newest sequence number towards oldest sequence number. If an entry is found which is older than the newly entry, the new entry has to be added after the found one to keep the ascending order.
But for this operation list_add_tail() was used. But this function adds an entry _before_ another one. As result, the list would contain a lot of swapped sequence numbers. The consumer of this list (batadv_tp_ack_unordered()) would then fail to correctly ack packets.
--- net/batman-adv/tp_meter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/tp_meter.c +1 -1
@@ -1325,7 +1325,7 @@ static bool batadv_tp_handle_out_of_order(struct batadv_tp_vars *tp_vars,* one is attached _after_ it. In this way the list is kept in * ascending order */ -list_add_tail (&new->list, &un->list); +list_add (&new->list, &un->list); added = true;break ; }
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 2/11 batman-adv: tp_meter: initialize dup_acks explicitly
In reply to Sven EckelmannWhen an ack with a sequence number equal to the last_acked is received, the dup_acks counter is increased to decide whether fast retransmit should be performed. Only when the sequence numbers are not equal, the dup_acks is set to the initial value (0).
But if the initial packet would have the sequence number BATADV_TP_FIRST_SEQ, dup_acks would not be initialized and atomic_inc would operate on an undefined starting value. It is therefore required to have it explicitly initialized during the start of the sender session.
--- net/batman-adv/tp_meter.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/tp_meter.c +1 -0
@@ -1045,6 +1045,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, tp_vars->icmp_uid = icmp_uid; tp_vars->last_sent =BATADV_TP_FIRST_SEQ ; +atomic_set (&tp_vars->dup_acks,0 );atomic_set (&tp_vars->last_acked,BATADV_TP_FIRST_SEQ ); tp_vars->fast_recovery = false; tp_vars->recover =BATADV_TP_FIRST_SEQ ;
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 3/11 batman-adv: tp_meter: initialize dec_cwnd explicitly
In reply to Sven EckelmannWhen batadv_tp_update_cwnd() is called, dec_cwnd is increased. But dec_cwnd is only initialixed (to 0) when a duplicate Ack was received or when cwnd is below the ss_threshold.
Just initialize the cwnd during the initialization to avoid any potential access of uninitialized data.
--- net/batman-adv/tp_meter.c | 2 ++ 1 file changed, 2 insertions(+)
net/batman-adv/tp_meter.c +2 -0
@@ -1055,6 +1055,8 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,* mesh_interface, hence its MTU */ tp_vars->cwnd =BATADV_TP_PLEN *3 ; + tp_vars->dec_cwnd =0 ; +/* at the beginning initialise the SS threshold to the biggest possible * window size, hence the AWND size */
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 4/11 batman-adv: tp_meter: avoid window underflow
In reply to Sven EckelmannIn batadv_tp_avail(), win_left is calculated with 32-bit unsigned
arithmetic: win_left = win_limit - tp_vars->last_sent;
During Fast Recovery, cwnd is inflated and last_sent advances rapidly. When Fast Recovery ends, cwnd drops abruptly back to ss_threshold. If the newly shrunk win_limit is less than last_sent, the unsigned subtraction will underflow, wrapping to a massive positive value. Instead of returning that the window is full (unavailable), it returns that the sender can continue sending.
To handle this situation, it must be checked whether the windows end sequence number (win_limit) has to be compared with the last sent sequence number. If it would be before the last sent sequence number, then more acks are needed before the transmission can be started again.
--- net/batman-adv/tp_meter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/batman-adv/tp_meter.c +6 -1
@@ -817,10 +817,15 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,static bool batadv_tp_avail (struct batadv_tp_vars *tp_vars,size_t payload_len) { +u32 last_sent = tp_vars->last_sent;u32 win_left, win_limit; win_limit =atomic_read (&tp_vars->last_acked) + tp_vars->cwnd; - win_left = win_limit - tp_vars->last_sent; + +if (batadv_seq_before (last_sent, win_limit)) + win_left = win_limit - last_sent; +else + win_left =0 ;return win_left >= payload_len; }
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 5/11 batman-adv: tp_meter: avoid divide-by-zero for dec_cwnd
In reply to Sven EckelmannThe cwnd is always MSS <= cwnd <= 0x20000000. But the calculation in batadv_tp_update_cwnd() assumes unsigned 32 bit arithmetics.
((mss * 8) ** 2) / (cwnd * 8)
In case cwnd is actually 0x20000000, it will be shifted by 3 bit to the left end up at 0x100000000 or U32_MAX + 1. It will therefore wrap around and be 0 - resulting in:
((mss * 8) ** 2) / 0
This is of course invalid and cannot be calculated. The calculation should must be simplified to avoid this overflow:
(mss ** 2) * 8 / cwnd
It will keep the precision enhancement from the scaling (by 8) but avoid the overflow in the divisor.
In theory, there could still be an overflow in the dividend. It is at the moment fixed to BATADV_TP_PLEN in batadv_tp_recv_ack() - so it is not an imminent problem. But allowing it to use the whole u32 bit range, would mean that it can still use up to 67 bits. To keep this calculation safe for 32 bit arithmetic, mss must never use more than floor((32 - 3) / 2) bits - or in other words: must never be larger than 16383.
--- net/batman-adv/tp_meter.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/batman-adv/tp_meter.c +4 -1
@@ -154,9 +154,12 @@ static void batadv_tp_update_cwnd(struct batadv_tp_vars *tp_vars, u32 mss)return ; } +/* prevent overflow in (mss * mss) << 3 */ + mss =min_t (u32, mss, (1U <<14 ) -1 ); +/* increment CWND at least of 1 (section 3.1 of RFC5681) */ tp_vars->dec_cwnd +=max_t (u32,1U <<3 , - ((mss * mss) <<6 ) / (tp_vars->cwnd <<3 )); + ((mss * mss) <<3 ) / tp_vars->cwnd);if (tp_vars->dec_cwnd < (mss <<3 )) {spin_unlock_bh (&tp_vars->cwnd_lock);return ;
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 6/11 batman-adv: tp_meter: fix fast recovery precondition
In reply to Sven EckelmannThe fast recovery precondition checks if the recover (initialized to BATADV_TP_FIRST_SEQ) is bigger than the received ack. But since recover is only updated when this check is successful, it will never enter the fast recovery mode.
According to RFC6582 Section 3.2 step 2, the check should actually be different:
Quoted 3 lines
When the third duplicate ACK is received, the TCP sender first checks the value of recover to see if the Cumulative Acknowledgment field covers more than recover
The precondition must therefore check if recover is smaller than the received ack - basically swapping the operands of the current check.
--- net/batman-adv/tp_meter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/tp_meter.c +1 -1
@@ -733,7 +733,7 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,if (atomic_read (&tp_vars->dup_acks) !=3 ) goto out; -if (recv_ack >= tp_vars->recover) +if (tp_vars->recover >= recv_ack) goto out;/* if this is the third duplicate ACK do Fast Retransmit */
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 7/11 batman-adv: tp_meter: handle seqno wrap-around for fast recovery detection
In reply to Sven EckelmannThe recover variable and the last_sent sequence number are initialized on purpose as a really high value which will wrap-around after the first 2000 bytes. The fast recovery precondition must therefore not use simple integer comparisons but use helpers which are aware of the sequence number wrap-arounds.
--- net/batman-adv/tp_meter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/tp_meter.c +1 -1
@@ -733,7 +733,7 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,if (atomic_read (&tp_vars->dup_acks) !=3 ) goto out; -if (tp_vars->recover >= recv_ack) +if (!batadv_seq_before (tp_vars->recover, recv_ack)) goto out;/* if this is the third duplicate ACK do Fast Retransmit */
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 8/11 batman-adv: tp_meter: add only finished tp_vars to lists
In reply to Sven EckelmannWhen the receiver variables (aka "session") are initialized, then they are added to the list of sessions before the timer is set up. A RCU protected reader could therefore find the entry and run mod_setup before batadv_tp_init_recv() finished the timer initialization.
The same is true for batadv_tp_start(), which must first initialize the finish_work and the test_length to avoid a similar problem.
--- net/batman-adv/tp_meter.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
net/batman-adv/tp_meter.c +9 -9
@@ -1096,21 +1096,21 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, tp_vars->prerandom_offset =0 ;spin_lock_init (&tp_vars->prerandom_lock); -kref_get (&tp_vars->refcount); -hlist_add_head_rcu (&tp_vars->list, &bat_priv->tp_list); -spin_unlock_bh (&bat_priv->tp_list_lock); - tp_vars->test_length = test_length;if (!tp_vars->test_length) tp_vars->test_length =BATADV_TP_DEF_TEST_LENGTH ; +/* init work item for finished tp tests */ +INIT_DELAYED_WORK (&tp_vars->finish_work, batadv_tp_sender_finish); + +kref_get (&tp_vars->refcount); +hlist_add_head_rcu (&tp_vars->list, &bat_priv->tp_list); +spin_unlock_bh (&bat_priv->tp_list_lock); +batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: starting throughput meter towards %pM (length=%ums)\n" , dst, test_length); -/* init work item for finished tp tests */ -INIT_DELAYED_WORK (&tp_vars->finish_work, batadv_tp_sender_finish); -/* start tp kthread. This way the write() call issued from userspace can * happily return and avoid to block */
@@ -1430,10 +1430,10 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv,INIT_LIST_HEAD (&tp_vars->unacked_list);kref_get (&tp_vars->refcount); -hlist_add_head_rcu (&tp_vars->list, &bat_priv->tp_list); +timer_setup (&tp_vars->timer, batadv_tp_receiver_shutdown,0 );kref_get (&tp_vars->refcount); -timer_setup (&tp_vars->timer, batadv_tp_receiver_shutdown,0 ); +hlist_add_head_rcu (&tp_vars->list, &bat_priv->tp_list);batadv_tp_reset_receiver_timer (tp_vars);
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 9/11 batman-adv: tp_meter: split vars into sender and receiver types
In reply to Sven EckelmannThe monolithic batadv_tp_vars struct holds fields for both sender and receiver roles, distinguished only by a runtime enum role. This makes it easy to accidentally access a field intended for the opposite role, since neither the compiler nor the type system provide any guard against such mistakes. The role check also adds unnecessary branching in several code paths.
Introduce batadv_tp_vars_common to hold fields shared across both roles, then derive two separate types (sender/receiver) from it. The functions can operate on them without any ambiguity about the available fields. This also reduces the memory footprint of receiver sessions, which no longer carry the substantial sender-only fields.
Care must be taken to prevent concurrent TP sessions between the same two peers in opposite directions, since sender and receiver sessions are now tracked in separate lists and a lookup in one list no longer detects a session in the other.
--- net/batman-adv/main.c | 3 +- net/batman-adv/tp_meter.c | 396 ++++++++++++++++++++++++++-------------------- net/batman-adv/types.h | 101 ++++++------ 3 files changed, 281 insertions(+), 219 deletions(-)
net/batman-adv/main.c +2 -1
@@ -194,7 +194,8 @@ int batadv_mesh_init(struct net_device *mesh_iface)INIT_HLIST_HEAD (&bat_priv->tvlv.container_list);INIT_HLIST_HEAD (&bat_priv->tvlv.handler_list);INIT_HLIST_HEAD (&bat_priv->meshif_vlan_list); -INIT_HLIST_HEAD (&bat_priv->tp_list); +INIT_HLIST_HEAD (&bat_priv->tp_sender_list); +INIT_HLIST_HEAD (&bat_priv->tp_receiver_list); bat_priv->gw.generation =0 ;
net/batman-adv/tp_meter.c +228 -168
859 lines not on this page · raw message
net/batman-adv/types.h +51 -50
163 lines not on this page · raw message
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 10/11 batman-adv: tp_meter: use locking for all congestion control variables
In reply to Sven EckelmannSome variables used atomic_t for concurrent access while others relied on cwnd_lock, leading to an inconsistent locking model. This can be simplified by:
* keeping all congestion control decisions inside the cc_lock
* variables which can be accessed without a lock must use READ_ONCE/WRITE_ONE
This is only possible, by extracting the congestion control logic from batadv_tp_recv_ack() into a new helper batadv_tp_handle_ack(). Its decisions are returned as a batadv_tp_ack_reaction enum value and then applied by the caller. This separates the algorithm (deciding what to do) from the mechanism (actually doing it).
--- net/batman-adv/tp_meter.c | 330 +++++++++++++++++++++++++++------------------- net/batman-adv/types.h | 8 +- 2 files changed, 199 insertions(+), 139 deletions(-)
net/batman-adv/tp_meter.c +195 -135
@@ -143,14 +143,12 @@ static u32 batadv_tp_cwnd(u32 base, u32 increment, u32 min)* increased by MSS * MSS / CWND for every unique received ACK */ static void batadv_tp_update_cwnd (struct batadv_tp_sender *tp_vars,u32 mss) + __must_hold(&tp_vars->cwnd_lock) { -spin_lock_bh (&tp_vars->cwnd_lock); -/* slow start... */ if (tp_vars->cwnd <= tp_vars->ss_threshold) { tp_vars->dec_cwnd =0 ; tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, mss, mss); -spin_unlock_bh (&tp_vars->cwnd_lock);return ; }
@@ -160,15 +158,11 @@ static void batadv_tp_update_cwnd(struct batadv_tp_sender *tp_vars, u32 mss)/* increment CWND at least of 1 (section 3.1 of RFC5681) */ tp_vars->dec_cwnd +=max_t (u32,1U <<3 , ((mss * mss) <<3 ) / tp_vars->cwnd); -if (tp_vars->dec_cwnd < (mss <<3 )) { -spin_unlock_bh (&tp_vars->cwnd_lock); +if (tp_vars->dec_cwnd < (mss <<3 ))return ; - } tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, mss, mss); tp_vars->dec_cwnd =0 ; - -spin_unlock_bh (&tp_vars->cwnd_lock); }/**
@@ -178,6 +172,7 @@ static void batadv_tp_update_cwnd(struct batadv_tp_sender *tp_vars, u32 mss)*/ static void batadv_tp_update_rto (struct batadv_tp_sender *tp_vars,u32 new_rtt) + __must_hold(&tp_vars->cwnd_lock) {long m = new_rtt;
@@ -197,14 +192,14 @@ static void batadv_tp_update_rto(struct batadv_tp_sender *tp_vars, tp_vars->rttvar += m;/* mdev ~= 3/4 rttvar + 1/4 new */ }else {/* first measure getting in */ - tp_vars->srtt = m <<3 ;/* take the measured time to be srtt */ + tp_vars->srtt = m <<3 ;/* take the measured time to be srtt */ tp_vars->rttvar = m <<1 ;/* new_rtt / 2 */ }/* rto = srtt + 4 * rttvar. * rttvar is scaled by 4, therefore doesn't need to be multiplied */ - tp_vars->rto = (tp_vars->srtt >>3 ) + tp_vars->rttvar; +WRITE_ONCE (tp_vars->rto, (tp_vars->srtt >>3 ) + tp_vars->rttvar); }/**
@@ -525,7 +520,8 @@ static void batadv_tp_reset_sender_timer(struct batadv_tp_sender *tp_vars)/* timer ref will be dropped in batadv_tp_sender_cleanup */ return ; -mod_timer (&tp_vars->common.timer, jiffies +msecs_to_jiffies (tp_vars->rto)); +mod_timer (&tp_vars->common.timer, + jiffies +msecs_to_jiffies (READ_ONCE (tp_vars->rto))); }/**
@@ -544,8 +540,11 @@ static void batadv_tp_sender_timeout(struct timer_list *t)if (batadv_tp_sender_stopped (tp_vars))return ; +spin_lock_bh (&tp_vars->cwnd_lock); +/* if the user waited long enough...shutdown the test */ if (unlikely (tp_vars->rto >=BATADV_TP_MAX_RTO )) { +spin_unlock_bh (&tp_vars->cwnd_lock);batadv_tp_sender_shutdown (tp_vars,BATADV_TP_REASON_DST_UNREACHABLE );return ;
@@ -554,9 +553,7 @@ static void batadv_tp_sender_timeout(struct timer_list *t)/* RTO exponential backoff * Details in Section 5.5 of RFC6298 */ - tp_vars->rto <<=1 ; - -spin_lock_bh (&tp_vars->cwnd_lock); +WRITE_ONCE (tp_vars->rto, tp_vars->rto *2 ); tp_vars->ss_threshold = tp_vars->cwnd >>1 ;if (tp_vars->ss_threshold <BATADV_TP_PLEN *2 )
@@ -565,14 +562,15 @@ static void batadv_tp_sender_timeout(struct timer_list *t)batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: RTO fired during test towards %pM! cwnd=%u new ss_thr=%u, resetting last_sent to %u\n" , tp_vars->common.other_end, tp_vars->cwnd, tp_vars->ss_threshold, -atomic_read (&tp_vars->last_acked)); + tp_vars->last_acked); tp_vars->cwnd =BATADV_TP_PLEN *3 ; +WRITE_ONCE (tp_vars->last_sent, tp_vars->last_acked); +spin_unlock_bh (&tp_vars->cwnd_lock);/* resend the non-ACKed packets.. */ - tp_vars->last_sent =atomic_read (&tp_vars->last_acked);wake_up (&tp_vars->more_bytes);batadv_tp_reset_sender_timer (tp_vars);
@@ -671,80 +669,58 @@ static int batadv_tp_send_msg(struct batadv_tp_sender *tp_vars, const u8 *src, }/** -* batadv_tp_recv_ack() - ACK receiving function -* @bat_priv: the bat priv with all the mesh interface information -* @skb: the buffer containing the received packet -* -* Process a received TP ACK packet +* enum batadv_tp_ack_reaction - expected reaction to ack packet */ -static void batadv_tp_recv_ack (struct batadv_priv *bat_priv, -const struct sk_buff *skb) +enum batadv_tp_ack_reaction { +/** @BATADV_TP_ACK_REACTION_OLD_ACK: ignore old ack packet */ +BATADV_TP_ACK_REACTION_OLD_ACK , + +/** @BATADV_TP_ACK_REACTION_IGNORE: ignore duplicated ack but reset timer */ +BATADV_TP_ACK_REACTION_IGNORE , + +/** @BATADV_TP_ACK_REACTION_RESEND_WAKEUP: resend data and wakeup "more_bytes" */ +BATADV_TP_ACK_REACTION_RESEND_WAKEUP , + +/** @BATADV_TP_ACK_REACTION_WAKEUP: wakeup "more_bytes" */ +BATADV_TP_ACK_REACTION_WAKEUP , +}; + +/** +* batadv_tp_handle_ack() - Calculate reaction to ACK and update congestion control +* @bat_priv: the bat priv with all the mesh interface information +* @tp_vars: the private data of the current TP meter session +* @recv_ack: received ACK seqno +* @mss: maximum segment size for transmission +* +* Return: expected reaction to this ack +*/ +static enum batadv_tp_ack_reaction +batadv_tp_handle_ack (struct batadv_priv *bat_priv, +struct batadv_tp_sender *tp_vars, +u32 recv_ack,size_t mss) + __must_hold(&tp_vars->cwnd_lock) { -struct batadv_hard_iface *primary_if =NULL ; -struct batadv_orig_node *orig_node =NULL ; -const struct batadv_icmp_tp_packet *icmp; -struct batadv_tp_sender *tp_vars; -const unsigned char *dev_addr; -size_t packet_len, mss; -u32 rtt, recv_ack, cwnd; +enum batadv_tp_ack_reaction reaction; - packet_len =BATADV_TP_PLEN ; - mss =BATADV_TP_PLEN ; - packet_len +=sizeof (struct batadv_unicast_packet ); - - icmp = (struct batadv_icmp_tp_packet *)skb->data; - -/* find the tp_vars */ - tp_vars =batadv_tp_list_find_sender_session (bat_priv, icmp->orig, - icmp->session); -if (unlikely (!tp_vars)) -return ; - -if (unlikely (batadv_tp_sender_stopped (tp_vars))) - goto out; - -/* old ACK? silently drop it.. */ -if (batadv_seq_before (ntohl (icmp->seqno), - (u32 )atomic_read (&tp_vars->last_acked))) - goto out; - - primary_if =batadv_primary_if_get_selected (bat_priv); -if (unlikely (!primary_if)) - goto out; - - orig_node =batadv_orig_hash_find (bat_priv, icmp->orig); -if (unlikely (!orig_node)) - goto out; - -/* update RTO with the new sampled RTT, if any */ - rtt =jiffies_to_msecs (jiffies) -ntohl (icmp->timestamp); -if (icmp->timestamp && rtt) -batadv_tp_update_rto (tp_vars, rtt); - -/* ACK for new data... reset the timer */ -batadv_tp_reset_sender_timer (tp_vars); - - recv_ack =ntohl (icmp->seqno); +if (batadv_seq_before (recv_ack, tp_vars->last_acked)) +return BATADV_TP_ACK_REACTION_OLD_ACK ;/* check if this ACK is a duplicate */ -if (atomic_read (&tp_vars->last_acked) == recv_ack) { -atomic_inc (&tp_vars->dup_acks); -if (atomic_read (&tp_vars->dup_acks) !=3 ) - goto out; +if (tp_vars->last_acked == recv_ack) { +/* if this is the third duplicate ACK do Fast Retransmit */ +if (tp_vars->dup_acks >3 ) +return BATADV_TP_ACK_REACTION_IGNORE ; + + tp_vars->dup_acks++; +if (tp_vars->dup_acks !=3 ) +return BATADV_TP_ACK_REACTION_IGNORE ;if (!batadv_seq_before (tp_vars->recover, recv_ack)) - goto out; - -/* if this is the third duplicate ACK do Fast Retransmit */ -batadv_tp_send_msg (tp_vars, primary_if->net_dev->dev_addr, - orig_node, recv_ack, packet_len, - icmp->session, icmp->uid, -jiffies_to_msecs (jiffies)); - -spin_lock_bh (&tp_vars->cwnd_lock); +return BATADV_TP_ACK_REACTION_IGNORE ;/* Fast Recovery */ tp_vars->fast_recovery = true; +/* Set recover to the last outstanding seqno when Fast Recovery * is entered. RFC6582, Section 3.2, step 1 */
@@ -757,52 +733,128 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv, tp_vars->cwnd =batadv_tp_cwnd (tp_vars->ss_threshold,3 * mss, mss); tp_vars->dec_cwnd =0 ; - tp_vars->last_sent = recv_ack; +WRITE_ONCE (tp_vars->last_sent, recv_ack); -spin_unlock_bh (&tp_vars->cwnd_lock); - }else { -/* count the acked data */ -atomic64_add (recv_ack -atomic_read (&tp_vars->last_acked), - &tp_vars->tot_sent); -/* reset the duplicate ACKs counter */ -atomic_set (&tp_vars->dup_acks,0 ); - -if (tp_vars->fast_recovery) { -/* partial ACK */ -if (batadv_seq_before (recv_ack, tp_vars->recover)) { -/* this is another hole in the window. React -* immediately as specified by NewReno (see -* Section 3.2 of RFC6582 for details) -*/ - dev_addr = primary_if->net_dev->dev_addr; -batadv_tp_send_msg (tp_vars, dev_addr, - orig_node, recv_ack, - packet_len, icmp->session, - icmp->uid, -jiffies_to_msecs (jiffies)); - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, - mss, mss); - }else { - tp_vars->fast_recovery = false; -/* set cwnd to the value of ss_threshold at the -* moment that Fast Recovery was entered. -* RFC6582, Section 3.2, step 3 -*/ - cwnd =batadv_tp_cwnd (tp_vars->ss_threshold,0 , - mss); - tp_vars->cwnd = cwnd; - } - goto move_twnd; - } - -if (recv_ack -atomic_read (&tp_vars->last_acked) >= mss) -batadv_tp_update_cwnd (tp_vars, mss); -move_twnd: -/* move the Transmit Window */ -atomic_set (&tp_vars->last_acked, recv_ack); +return BATADV_TP_ACK_REACTION_RESEND_WAKEUP ; + } + +/* count the acked data */ +atomic64_add (recv_ack - tp_vars->last_acked, &tp_vars->tot_sent); + +/* reset the duplicate ACKs counter */ + tp_vars->dup_acks =0 ; + +if (tp_vars->fast_recovery) { +/* partial ACK */ +if (batadv_seq_before (recv_ack, tp_vars->recover)) { +/* this is another hole in the window. React +* immediately as specified by NewReno (see +* Section 3.2 of RFC6582 for details) +*/ + reaction =BATADV_TP_ACK_REACTION_RESEND_WAKEUP ; + tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, + mss, mss); + }else { + tp_vars->fast_recovery = false; +/* set cwnd to the value of ss_threshold at the +* moment that Fast Recovery was entered. +* RFC6582, Section 3.2, step 3 +*/ + tp_vars->cwnd =batadv_tp_cwnd (tp_vars->ss_threshold, +0 , mss); + reaction =BATADV_TP_ACK_REACTION_WAKEUP ; + } + }else { +if (recv_ack - tp_vars->last_acked >= mss) +batadv_tp_update_cwnd (tp_vars, mss); + + reaction =BATADV_TP_ACK_REACTION_WAKEUP ; + } + +/* move the Transmit Window */ +WRITE_ONCE (tp_vars->last_acked, recv_ack); + +return reaction; +} + +/** +* batadv_tp_recv_ack() - ACK receiving function +* @bat_priv: the bat priv with all the mesh interface information +* @skb: the buffer containing the received packet +* +* Process a received TP ACK packet +*/ +static void batadv_tp_recv_ack (struct batadv_priv *bat_priv, +const struct sk_buff *skb) +{ +struct batadv_hard_iface *primary_if =NULL ; +struct batadv_orig_node *orig_node =NULL ; +const struct batadv_icmp_tp_packet *icmp; +enum batadv_tp_ack_reaction reaction; +struct batadv_tp_sender *tp_vars; +size_t packet_len; +u32 recv_ack; +size_t mss; +u32 rtt; + + packet_len =BATADV_TP_PLEN ; + mss =BATADV_TP_PLEN ; + packet_len +=sizeof (struct batadv_unicast_packet ); + + icmp = (struct batadv_icmp_tp_packet *)skb->data; + recv_ack =ntohl (icmp->seqno); + +/* find the tp_vars */ + tp_vars =batadv_tp_list_find_sender_session (bat_priv, icmp->orig, + icmp->session); +if (unlikely (!tp_vars)) +return ; + +if (unlikely (batadv_tp_sender_stopped (tp_vars))) + goto out; + +/* old ACK? silently drop it.. */ +if (batadv_seq_before (recv_ack,READ_ONCE (tp_vars->last_acked))) + goto out; + + primary_if =batadv_primary_if_get_selected (bat_priv); +if (unlikely (!primary_if)) + goto out; + + orig_node =batadv_orig_hash_find (bat_priv, icmp->orig); +if (unlikely (!orig_node)) + goto out; + +spin_lock_bh (&tp_vars->cwnd_lock); +/* update RTO with the new sampled RTT, if any */ + rtt =jiffies_to_msecs (jiffies) -ntohl (icmp->timestamp); +if (icmp->timestamp && rtt) +batadv_tp_update_rto (tp_vars, rtt); + + reaction =batadv_tp_handle_ack (bat_priv, tp_vars, recv_ack, mss); +spin_unlock_bh (&tp_vars->cwnd_lock); + +if (reaction ==BATADV_TP_ACK_REACTION_OLD_ACK ) + goto out; + +/* ACK for new data... reset the timer */ +batadv_tp_reset_sender_timer (tp_vars); + +switch (reaction) { +default : +case BATADV_TP_ACK_REACTION_IGNORE : + goto out; +case BATADV_TP_ACK_REACTION_RESEND_WAKEUP : +batadv_tp_send_msg (tp_vars, primary_if->net_dev->dev_addr, + orig_node, recv_ack, packet_len, + icmp->session, icmp->uid, +jiffies_to_msecs (jiffies)); + fallthrough; +case BATADV_TP_ACK_REACTION_WAKEUP : +wake_up (&tp_vars->more_bytes); +break ; } -wake_up (&tp_vars->more_bytes); out:batadv_hardif_put (primary_if);batadv_orig_node_put (orig_node);
@@ -819,16 +871,19 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,static bool batadv_tp_avail (struct batadv_tp_sender *tp_vars,size_t payload_len) { -u32 last_sent = tp_vars->last_sent;u32 win_left, win_limit; - win_limit =atomic_read (&tp_vars->last_acked) + tp_vars->cwnd; +spin_lock_bh (&tp_vars->cwnd_lock); -if (batadv_seq_before (last_sent, win_limit)) - win_left = win_limit - last_sent; + win_limit = tp_vars->last_acked + tp_vars->cwnd; + +if (batadv_seq_before (tp_vars->last_sent, win_limit)) + win_left = win_limit - tp_vars->last_sent;else win_left =0 ; +spin_unlock_bh (&tp_vars->cwnd_lock); +return win_left >= payload_len; }
@@ -867,6 +922,7 @@ static int batadv_tp_send(void *arg)struct batadv_hard_iface *primary_if =NULL ;struct batadv_orig_node *orig_node =NULL ;size_t payload_len, packet_len; +u32 last_sent;int err =0 ; orig_node =batadv_orig_hash_find (bat_priv, tp_vars->common.other_end);
@@ -908,10 +964,10 @@ static int batadv_tp_send(void *arg)* the size of the unicast header */ packet_len = payload_len +sizeof (struct batadv_unicast_packet ); + last_sent =READ_ONCE (tp_vars->last_sent); err =batadv_tp_send_msg (tp_vars, primary_if->net_dev->dev_addr, - orig_node, tp_vars->last_sent, - packet_len, + orig_node, last_sent, packet_len, tp_vars->common.session, tp_vars->icmp_uid,jiffies_to_msecs (jiffies));
@@ -926,8 +982,12 @@ static int batadv_tp_send(void *arg) }/* right-shift the TWND */ -if (!err) - tp_vars->last_sent += payload_len; +if (!err) { +spin_lock_bh (&tp_vars->cwnd_lock); +if (tp_vars->last_sent == last_sent) +WRITE_ONCE (tp_vars->last_sent, last_sent + payload_len); +spin_unlock_bh (&tp_vars->cwnd_lock); + }cond_resched (); }
@@ -1044,9 +1104,9 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,memcpy (tp_vars->common.session, session_id,sizeof (session_id)); tp_vars->icmp_uid = icmp_uid; - tp_vars->last_sent =BATADV_TP_FIRST_SEQ ; -atomic_set (&tp_vars->dup_acks,0 ); -atomic_set (&tp_vars->last_acked,BATADV_TP_FIRST_SEQ ); +WRITE_ONCE (tp_vars->last_sent,BATADV_TP_FIRST_SEQ ); +WRITE_ONCE (tp_vars->dup_acks,0 ); +WRITE_ONCE (tp_vars->last_acked,BATADV_TP_FIRST_SEQ ); tp_vars->fast_recovery = false; tp_vars->recover =BATADV_TP_FIRST_SEQ ;
@@ -1065,7 +1125,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,/* RTO initial value is 3 seconds. * Details in Section 2.1 of RFC6298 */ - tp_vars->rto =1000 ; +WRITE_ONCE (tp_vars->rto,1000 ); tp_vars->srtt =0 ; tp_vars->rttvar =0 ;
net/batman-adv/types.h +4 -4
@@ -1387,7 +1387,7 @@ struct batadv_tp_sender {u32 last_sent;/** @fast_recovery: true if in Fast Recovery mode */ - unsigned char fast_recovery:1; + bool fast_recovery:1;/** @recover: last sent seqno when entering Fast Recovery */ u32 recover;
@@ -1410,7 +1410,7 @@ struct batadv_tp_sender {/** @cwnd: current size of the congestion window */ u32 cwnd; -/** @cwnd_lock: lock do protect @cwnd & @dec_cwnd */ +/** @cwnd_lock: lock do protect congestion control variables */ spinlock_t cwnd_lock;/**
@@ -1420,13 +1420,13 @@ struct batadv_tp_sender {u32 ss_threshold;/** @last_acked: last acked byte */ -atomic_t last_acked; +u32 last_acked;/** @tot_sent: amount of data sent/ACKed so far */ atomic64_t tot_sent;/** @dup_acks: duplicate ACKs counter */ -atomic_t dup_acks; +u8 dup_acks;/** @rto: sender timeout */ u32 rto;
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerPATCH v6 11/11 batman-adv: tp_meter: consolidate congestion control variables
In reply to Sven EckelmannCongestion control variables in batadv_tp_sender were scattered across the struct without clear grouping, making it difficult to reason about which fields require cwnd_lock (now "cc_lock") protection. These should be combined in a structure to make it more easily visible which variable should be read/modified with the cc_lock held.
--- net/batman-adv/tp_meter.c | 170 +++++++++++++++++++++++----------------------- net/batman-adv/types.h | 80 ++++++++++++---------- 2 files changed, 128 insertions(+), 122 deletions(-)
net/batman-adv/tp_meter.c +85 -85
@@ -143,12 +143,12 @@ static u32 batadv_tp_cwnd(u32 base, u32 increment, u32 min)* increased by MSS * MSS / CWND for every unique received ACK */ static void batadv_tp_update_cwnd (struct batadv_tp_sender *tp_vars,u32 mss) - __must_hold(&tp_vars->cwnd_lock) + __must_hold(&tp_vars->cc_lock) {/* slow start... */ -if (tp_vars->cwnd <= tp_vars->ss_threshold) { - tp_vars->dec_cwnd =0 ; - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, mss, mss); +if (tp_vars->cc.cwnd <= tp_vars->cc.ss_threshold) { + tp_vars->cc.dec_cwnd =0 ; + tp_vars->cc.cwnd =batadv_tp_cwnd (tp_vars->cc.cwnd, mss, mss);return ; }
@@ -156,13 +156,13 @@ static void batadv_tp_update_cwnd(struct batadv_tp_sender *tp_vars, u32 mss) mss =min_t (u32, mss, (1U <<14 ) -1 );/* increment CWND at least of 1 (section 3.1 of RFC5681) */ - tp_vars->dec_cwnd +=max_t (u32,1U <<3 , - ((mss * mss) <<3 ) / tp_vars->cwnd); -if (tp_vars->dec_cwnd < (mss <<3 )) + tp_vars->cc.dec_cwnd +=max_t (u32,1U <<3 , + ((mss * mss) <<3 ) / tp_vars->cc.cwnd); +if (tp_vars->cc.dec_cwnd < (mss <<3 ))return ; - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, mss, mss); - tp_vars->dec_cwnd =0 ; + tp_vars->cc.cwnd =batadv_tp_cwnd (tp_vars->cc.cwnd, mss, mss); + tp_vars->cc.dec_cwnd =0 ; }/**
@@ -172,7 +172,7 @@ static void batadv_tp_update_cwnd(struct batadv_tp_sender *tp_vars, u32 mss)*/ static void batadv_tp_update_rto (struct batadv_tp_sender *tp_vars,u32 new_rtt) - __must_hold(&tp_vars->cwnd_lock) + __must_hold(&tp_vars->cc_lock) {long m = new_rtt;
@@ -182,24 +182,24 @@ static void batadv_tp_update_rto(struct batadv_tp_sender *tp_vars,* It's tricky to understand. Don't lose hair please. * Inspired by tcp_rtt_estimator() tcp_input.c */ -if (tp_vars->srtt !=0 ) { - m -= (tp_vars->srtt >>3 );/* m is now error in rtt est */ - tp_vars->srtt += m;/* rtt = 7/8 srtt + 1/8 new */ +if (tp_vars->cc.srtt !=0 ) { + m -= (tp_vars->cc.srtt >>3 );/* m is now error in rtt est */ + tp_vars->cc.srtt += m;/* rtt = 7/8 srtt + 1/8 new */ if (m <0 ) m = -m; - m -= (tp_vars->rttvar >>2 ); - tp_vars->rttvar += m;/* mdev ~= 3/4 rttvar + 1/4 new */ + m -= (tp_vars->cc.rttvar >>2 ); + tp_vars->cc.rttvar += m;/* mdev ~= 3/4 rttvar + 1/4 new */ }else {/* first measure getting in */ - tp_vars->srtt = m <<3 ;/* take the measured time to be srtt */ - tp_vars->rttvar = m <<1 ;/* new_rtt / 2 */ + tp_vars->cc.srtt = m <<3 ;/* take the measured time to be srtt */ + tp_vars->cc.rttvar = m <<1 ;/* new_rtt / 2 */ }/* rto = srtt + 4 * rttvar. * rttvar is scaled by 4, therefore doesn't need to be multiplied */ -WRITE_ONCE (tp_vars->rto, (tp_vars->srtt >>3 ) + tp_vars->rttvar); +WRITE_ONCE (tp_vars->cc.rto, (tp_vars->cc.srtt >>3 ) + tp_vars->cc.rttvar); }/**
@@ -450,11 +450,11 @@ static void batadv_tp_sender_end(struct batadv_priv *bat_priv,batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Last timing stats: SRTT=%ums RTTVAR=%ums RTO=%ums\n" , - tp_vars->srtt >>3 , tp_vars->rttvar >>2 , tp_vars->rto); + tp_vars->cc.srtt >>3 , tp_vars->cc.rttvar >>2 , tp_vars->cc.rto);batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Final values: cwnd=%u ss_threshold=%u\n" , - tp_vars->cwnd, tp_vars->ss_threshold); + tp_vars->cc.cwnd, tp_vars->cc.ss_threshold); session_cookie =batadv_tp_session_cookie (tp_vars->common.session, tp_vars->icmp_uid);
@@ -521,7 +521,7 @@ static void batadv_tp_reset_sender_timer(struct batadv_tp_sender *tp_vars)return ;mod_timer (&tp_vars->common.timer, - jiffies +msecs_to_jiffies (READ_ONCE (tp_vars->rto))); + jiffies +msecs_to_jiffies (READ_ONCE (tp_vars->cc.rto))); }/**
@@ -540,11 +540,11 @@ static void batadv_tp_sender_timeout(struct timer_list *t)if (batadv_tp_sender_stopped (tp_vars))return ; -spin_lock_bh (&tp_vars->cwnd_lock); +spin_lock_bh (&tp_vars->cc_lock);/* if the user waited long enough...shutdown the test */ -if (unlikely (tp_vars->rto >=BATADV_TP_MAX_RTO )) { -spin_unlock_bh (&tp_vars->cwnd_lock); +if (unlikely (tp_vars->cc.rto >=BATADV_TP_MAX_RTO )) { +spin_unlock_bh (&tp_vars->cc_lock);batadv_tp_sender_shutdown (tp_vars,BATADV_TP_REASON_DST_UNREACHABLE );return ;
@@ -553,22 +553,22 @@ static void batadv_tp_sender_timeout(struct timer_list *t)/* RTO exponential backoff * Details in Section 5.5 of RFC6298 */ -WRITE_ONCE (tp_vars->rto, tp_vars->rto *2 ); +WRITE_ONCE (tp_vars->cc.rto, tp_vars->cc.rto *2 ); - tp_vars->ss_threshold = tp_vars->cwnd >>1 ; -if (tp_vars->ss_threshold <BATADV_TP_PLEN *2 ) - tp_vars->ss_threshold =BATADV_TP_PLEN *2 ; + tp_vars->cc.ss_threshold = tp_vars->cc.cwnd >>1 ; +if (tp_vars->cc.ss_threshold <BATADV_TP_PLEN *2 ) + tp_vars->cc.ss_threshold =BATADV_TP_PLEN *2 ;batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: RTO fired during test towards %pM! cwnd=%u new ss_thr=%u, resetting last_sent to %u\n" , - tp_vars->common.other_end, tp_vars->cwnd, tp_vars->ss_threshold, - tp_vars->last_acked); + tp_vars->common.other_end, tp_vars->cc.cwnd, tp_vars->cc.ss_threshold, + tp_vars->cc.last_acked); - tp_vars->cwnd =BATADV_TP_PLEN *3 ; + tp_vars->cc.cwnd =BATADV_TP_PLEN *3 ; -WRITE_ONCE (tp_vars->last_sent, tp_vars->last_acked); +WRITE_ONCE (tp_vars->cc.last_sent, tp_vars->cc.last_acked); -spin_unlock_bh (&tp_vars->cwnd_lock); +spin_unlock_bh (&tp_vars->cc_lock);/* resend the non-ACKed packets.. */ wake_up (&tp_vars->more_bytes);
@@ -698,81 +698,81 @@ static enum batadv_tp_ack_reaction batadv_tp_handle_ack(struct batadv_priv *bat_priv, struct batadv_tp_sender *tp_vars, u32 recv_ack, size_t mss) - __must_hold(&tp_vars->cwnd_lock) + __must_hold(&tp_vars->cc_lock) { enum batadv_tp_ack_reaction reaction; -if (batadv_seq_before (recv_ack, tp_vars->last_acked)) +if (batadv_seq_before (recv_ack, tp_vars->cc.last_acked))return BATADV_TP_ACK_REACTION_OLD_ACK ;/* check if this ACK is a duplicate */ -if (tp_vars->last_acked == recv_ack) { +if (tp_vars->cc.last_acked == recv_ack) {/* if this is the third duplicate ACK do Fast Retransmit */ -if (tp_vars->dup_acks >3 ) +if (tp_vars->cc.dup_acks >3 )return BATADV_TP_ACK_REACTION_IGNORE ; - tp_vars->dup_acks++; -if (tp_vars->dup_acks !=3 ) + tp_vars->cc.dup_acks++; +if (tp_vars->cc.dup_acks !=3 )return BATADV_TP_ACK_REACTION_IGNORE ; -if (!batadv_seq_before (tp_vars->recover, recv_ack)) +if (!batadv_seq_before (tp_vars->cc.recover, recv_ack))return BATADV_TP_ACK_REACTION_IGNORE ;/* Fast Recovery */ - tp_vars->fast_recovery = true; + tp_vars->cc.fast_recovery = true;/* Set recover to the last outstanding seqno when Fast Recovery * is entered. RFC6582, Section 3.2, step 1 */ - tp_vars->recover = tp_vars->last_sent; - tp_vars->ss_threshold = tp_vars->cwnd >>1 ; + tp_vars->cc.recover = tp_vars->cc.last_sent; + tp_vars->cc.ss_threshold = tp_vars->cc.cwnd >>1 ;batadv_dbg (BATADV_DBG_TP_METER , bat_priv,"Meter: Fast Recovery, (cur cwnd=%u) ss_thr=%u last_sent=%u recv_ack=%u\n" , - tp_vars->cwnd, tp_vars->ss_threshold, - tp_vars->last_sent, recv_ack); - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->ss_threshold,3 * mss, - mss); - tp_vars->dec_cwnd =0 ; -WRITE_ONCE (tp_vars->last_sent, recv_ack); + tp_vars->cc.cwnd, tp_vars->cc.ss_threshold, + tp_vars->cc.last_sent, recv_ack); + tp_vars->cc.cwnd =batadv_tp_cwnd (tp_vars->cc.ss_threshold,3 * mss, + mss); + tp_vars->cc.dec_cwnd =0 ; +WRITE_ONCE (tp_vars->cc.last_sent, recv_ack);return BATADV_TP_ACK_REACTION_RESEND_WAKEUP ; }/* count the acked data */ -atomic64_add (recv_ack - tp_vars->last_acked, &tp_vars->tot_sent); +atomic64_add (recv_ack - tp_vars->cc.last_acked, &tp_vars->tot_sent);/* reset the duplicate ACKs counter */ - tp_vars->dup_acks =0 ; + tp_vars->cc.dup_acks =0 ; -if (tp_vars->fast_recovery) { +if (tp_vars->cc.fast_recovery) {/* partial ACK */ -if (batadv_seq_before (recv_ack, tp_vars->recover)) { +if (batadv_seq_before (recv_ack, tp_vars->cc.recover)) {/* this is another hole in the window. React * immediately as specified by NewReno (see * Section 3.2 of RFC6582 for details) */ reaction =BATADV_TP_ACK_REACTION_RESEND_WAKEUP ; - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->cwnd, - mss, mss); + tp_vars->cc.cwnd =batadv_tp_cwnd (tp_vars->cc.cwnd, + mss, mss); }else { - tp_vars->fast_recovery = false; + tp_vars->cc.fast_recovery = false;/* set cwnd to the value of ss_threshold at the * moment that Fast Recovery was entered. * RFC6582, Section 3.2, step 3 */ - tp_vars->cwnd =batadv_tp_cwnd (tp_vars->ss_threshold, -0 , mss); + tp_vars->cc.cwnd =batadv_tp_cwnd (tp_vars->cc.ss_threshold, +0 , mss); reaction =BATADV_TP_ACK_REACTION_WAKEUP ; } }else { -if (recv_ack - tp_vars->last_acked >= mss) +if (recv_ack - tp_vars->cc.last_acked >= mss)batadv_tp_update_cwnd (tp_vars, mss); reaction =BATADV_TP_ACK_REACTION_WAKEUP ; }/* move the Transmit Window */ -WRITE_ONCE (tp_vars->last_acked, recv_ack); +WRITE_ONCE (tp_vars->cc.last_acked, recv_ack);return reaction; }
@@ -814,7 +814,7 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv, goto out;/* old ACK? silently drop it.. */ -if (batadv_seq_before (recv_ack,READ_ONCE (tp_vars->last_acked))) +if (batadv_seq_before (recv_ack,READ_ONCE (tp_vars->cc.last_acked))) goto out; primary_if =batadv_primary_if_get_selected (bat_priv);
@@ -825,14 +825,14 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,if (unlikely (!orig_node)) goto out; -spin_lock_bh (&tp_vars->cwnd_lock); +spin_lock_bh (&tp_vars->cc_lock);/* update RTO with the new sampled RTT, if any */ rtt =jiffies_to_msecs (jiffies) -ntohl (icmp->timestamp);if (icmp->timestamp && rtt)batadv_tp_update_rto (tp_vars, rtt); reaction =batadv_tp_handle_ack (bat_priv, tp_vars, recv_ack, mss); -spin_unlock_bh (&tp_vars->cwnd_lock); +spin_unlock_bh (&tp_vars->cc_lock);if (reaction ==BATADV_TP_ACK_REACTION_OLD_ACK ) goto out;
@@ -873,16 +873,16 @@ static bool batadv_tp_avail(struct batadv_tp_sender *tp_vars, {u32 win_left, win_limit; -spin_lock_bh (&tp_vars->cwnd_lock); +spin_lock_bh (&tp_vars->cc_lock); - win_limit = tp_vars->last_acked + tp_vars->cwnd; + win_limit = tp_vars->cc.last_acked + tp_vars->cc.cwnd; -if (batadv_seq_before (tp_vars->last_sent, win_limit)) - win_left = win_limit - tp_vars->last_sent; +if (batadv_seq_before (tp_vars->cc.last_sent, win_limit)) + win_left = win_limit - tp_vars->cc.last_sent;else win_left =0 ; -spin_unlock_bh (&tp_vars->cwnd_lock); +spin_unlock_bh (&tp_vars->cc_lock);return win_left >= payload_len; }
@@ -964,7 +964,7 @@ static int batadv_tp_send(void *arg)* the size of the unicast header */ packet_len = payload_len +sizeof (struct batadv_unicast_packet ); - last_sent =READ_ONCE (tp_vars->last_sent); + last_sent =READ_ONCE (tp_vars->cc.last_sent); err = batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr, orig_node, last_sent, packet_len,
@@ -983,10 +983,10 @@ static int batadv_tp_send(void *arg)/* right-shift the TWND */ if (!err) { -spin_lock_bh (&tp_vars->cwnd_lock); -if (tp_vars->last_sent == last_sent) -WRITE_ONCE (tp_vars->last_sent, last_sent + payload_len); -spin_unlock_bh (&tp_vars->cwnd_lock); +spin_lock_bh (&tp_vars->cc_lock); +if (tp_vars->cc.last_sent == last_sent) +WRITE_ONCE (tp_vars->cc.last_sent, last_sent + payload_len); +spin_unlock_bh (&tp_vars->cc_lock); }cond_resched ();
@@ -1104,30 +1104,30 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,memcpy (tp_vars->common.session, session_id,sizeof (session_id)); tp_vars->icmp_uid = icmp_uid; -WRITE_ONCE (tp_vars->last_sent,BATADV_TP_FIRST_SEQ ); -WRITE_ONCE (tp_vars->dup_acks,0 ); -WRITE_ONCE (tp_vars->last_acked,BATADV_TP_FIRST_SEQ ); - tp_vars->fast_recovery = false; - tp_vars->recover =BATADV_TP_FIRST_SEQ ; +WRITE_ONCE (tp_vars->cc.last_sent,BATADV_TP_FIRST_SEQ ); +WRITE_ONCE (tp_vars->cc.dup_acks,0 ); +WRITE_ONCE (tp_vars->cc.last_acked,BATADV_TP_FIRST_SEQ ); + tp_vars->cc.fast_recovery = false; + tp_vars->cc.recover =BATADV_TP_FIRST_SEQ ;/* initialise the CWND to 3*MSS (Section 3.1 in RFC5681). * For batman-adv the MSS is the size of the payload received by the * mesh_interface, hence its MTU */ - tp_vars->cwnd =BATADV_TP_PLEN *3 ; - tp_vars->dec_cwnd =0 ; + tp_vars->cc.cwnd =BATADV_TP_PLEN *3 ; + tp_vars->cc.dec_cwnd =0 ;/* at the beginning initialise the SS threshold to the biggest possible * window size, hence the AWND size */ - tp_vars->ss_threshold =BATADV_TP_AWND ; + tp_vars->cc.ss_threshold =BATADV_TP_AWND ;/* RTO initial value is 3 seconds. * Details in Section 2.1 of RFC6298 */ -WRITE_ONCE (tp_vars->rto,1000 ); - tp_vars->srtt =0 ; - tp_vars->rttvar =0 ; +WRITE_ONCE (tp_vars->cc.rto,1000 ); + tp_vars->cc.srtt =0 ; + tp_vars->cc.rttvar =0 ;atomic64_set (&tp_vars->tot_sent,0 );
@@ -1143,7 +1143,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,spin_lock_init (&tp_vars->common.unacked_lock);INIT_LIST_HEAD (&tp_vars->common.unacked_list); -spin_lock_init (&tp_vars->cwnd_lock); +spin_lock_init (&tp_vars->cc_lock); tp_vars->prerandom_offset =0 ;spin_lock_init (&tp_vars->prerandom_lock);
net/batman-adv/types.h +43 -37
103 lines not on this page · raw message
Signature · 1 line
2.47.3