Skip to content

Commit eea63ca

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Initialize rb_credits in one place
Clean up/code de-duplication. Nit: RPC_CWNDSHIFT is incorrect as the initial value for xprt->cwnd. This mistake does not appear to have operational consequences, since the cwnd value is replaced with a valid value upon the first Receive completion. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent a31b2f9 commit eea63ca

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

‎net/sunrpc/xprtrdma/rpc_rdma.c‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,40 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
916916
return ret;
917917
}
918918

919+
static void __rpcrdma_update_cwnd_locked(struct rpc_xprt *xprt,
920+
struct rpcrdma_buffer *buf,
921+
u32 grant)
922+
{
923+
buf->rb_credits = grant;
924+
xprt->cwnd = grant << RPC_CWNDSHIFT;
925+
}
926+
927+
static void rpcrdma_update_cwnd(struct rpcrdma_xprt *r_xprt, u32 grant)
928+
{
929+
struct rpc_xprt *xprt = &r_xprt->rx_xprt;
930+
931+
spin_lock(&xprt->transport_lock);
932+
__rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, grant);
933+
spin_unlock(&xprt->transport_lock);
934+
}
935+
936+
/**
937+
* rpcrdma_reset_cwnd - Reset the xprt's congestion window
938+
* @r_xprt: controlling transport instance
939+
*
940+
* Prepare @r_xprt for the next connection by reinitializing
941+
* its credit grant to one (see RFC 8166, Section 3.3.3).
942+
*/
943+
void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt)
944+
{
945+
struct rpc_xprt *xprt = &r_xprt->rx_xprt;
946+
947+
spin_lock(&xprt->transport_lock);
948+
xprt->cong = 0;
949+
__rpcrdma_update_cwnd_locked(xprt, &r_xprt->rx_buf, 1);
950+
spin_unlock(&xprt->transport_lock);
951+
}
952+
919953
/**
920954
* rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs
921955
* @rqst: controlling RPC request
@@ -1356,12 +1390,8 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
13561390
credits = 1; /* don't deadlock */
13571391
else if (credits > buf->rb_max_requests)
13581392
credits = buf->rb_max_requests;
1359-
if (buf->rb_credits != credits) {
1360-
spin_lock(&xprt->transport_lock);
1361-
buf->rb_credits = credits;
1362-
xprt->cwnd = credits << RPC_CWNDSHIFT;
1363-
spin_unlock(&xprt->transport_lock);
1364-
}
1393+
if (buf->rb_credits != credits)
1394+
rpcrdma_update_cwnd(r_xprt, credits);
13651395

13661396
req = rpcr_to_rdmar(rqst);
13671397
if (req->rl_reply) {

‎net/sunrpc/xprtrdma/transport.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,6 @@ void xprt_rdma_close(struct rpc_xprt *xprt)
425425
return;
426426
rpcrdma_ep_disconnect(ep, ia);
427427

428-
/* Prepare @xprt for the next connection by reinitializing
429-
* its credit grant to one (see RFC 8166, Section 3.3.3).
430-
*/
431-
spin_lock(&xprt->transport_lock);
432-
r_xprt->rx_buf.rb_credits = 1;
433-
xprt->cong = 0;
434-
xprt->cwnd = RPC_CWNDSHIFT;
435-
spin_unlock(&xprt->transport_lock);
436-
437428
out:
438429
xprt->reestablish_timeout = 0;
439430
++xprt->connect_cookie;

‎net/sunrpc/xprtrdma/verbs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
727727
ep->rep_connected = 0;
728728
xprt_clear_connected(xprt);
729729

730+
rpcrdma_reset_cwnd(r_xprt);
730731
rpcrdma_post_recvs(r_xprt, true);
731732

732733
rc = rdma_connect(ia->ri_id, &ep->rep_remote_cma);
@@ -1163,7 +1164,6 @@ int rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
11631164
list_add(&req->rl_list, &buf->rb_send_bufs);
11641165
}
11651166

1166-
buf->rb_credits = 1;
11671167
init_llist_head(&buf->rb_free_reps);
11681168

11691169
rc = rpcrdma_sendctxs_create(r_xprt);

‎net/sunrpc/xprtrdma/xprt_rdma.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
576576
void rpcrdma_sendctx_unmap(struct rpcrdma_sendctx *sc);
577577
int rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst);
578578
void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *);
579+
void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt);
579580
void rpcrdma_complete_rqst(struct rpcrdma_rep *rep);
580581
void rpcrdma_reply_handler(struct rpcrdma_rep *rep);
581582

0 commit comments

Comments
 (0)