Skip to content

Commit f58ed36

Browse files
dhowellsgregkh
authored andcommitted
rxrpc: Abstract out the calculation of whether there's Tx space
[ Upstream commit 158fe66 ] Abstract out the calculation of there being sufficient Tx buffer space. This is reproduced several times in the rxrpc sendmsg code. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 08b43e0 commit f58ed36

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎net/rxrpc/sendmsg.c‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
#include <net/af_rxrpc.h>
1818
#include "ar-internal.h"
1919

20+
/*
21+
* Return true if there's sufficient Tx queue space.
22+
*/
23+
static bool rxrpc_check_tx_space(struct rxrpc_call *call, rxrpc_seq_t *_tx_win)
24+
{
25+
unsigned int win_size =
26+
min_t(unsigned int, call->tx_winsize,
27+
call->cong_cwnd + call->cong_extra);
28+
rxrpc_seq_t tx_win = READ_ONCE(call->tx_hard_ack);
29+
30+
if (_tx_win)
31+
*_tx_win = tx_win;
32+
return call->tx_top - tx_win < win_size;
33+
}
34+
2035
/*
2136
* Wait for space to appear in the Tx queue or a signal to occur.
2237
*/
@@ -26,9 +41,7 @@ static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx,
2641
{
2742
for (;;) {
2843
set_current_state(TASK_INTERRUPTIBLE);
29-
if (call->tx_top - call->tx_hard_ack <
30-
min_t(unsigned int, call->tx_winsize,
31-
call->cong_cwnd + call->cong_extra))
44+
if (rxrpc_check_tx_space(call, NULL))
3245
return 0;
3346

3447
if (call->state >= RXRPC_CALL_COMPLETE)
@@ -68,9 +81,7 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
6881
set_current_state(TASK_UNINTERRUPTIBLE);
6982

7083
tx_win = READ_ONCE(call->tx_hard_ack);
71-
if (call->tx_top - tx_win <
72-
min_t(unsigned int, call->tx_winsize,
73-
call->cong_cwnd + call->cong_extra))
84+
if (rxrpc_check_tx_space(call, &tx_win))
7485
return 0;
7586

7687
if (call->state >= RXRPC_CALL_COMPLETE)
@@ -302,9 +313,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
302313

303314
_debug("alloc");
304315

305-
if (call->tx_top - call->tx_hard_ack >=
306-
min_t(unsigned int, call->tx_winsize,
307-
call->cong_cwnd + call->cong_extra)) {
316+
if (!rxrpc_check_tx_space(call, NULL)) {
308317
ret = -EAGAIN;
309318
if (msg->msg_flags & MSG_DONTWAIT)
310319
goto maybe_error;

0 commit comments

Comments
 (0)