Skip to content

Commit 6ceea36

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Refactor Receive accounting
Clean up: Divide the work cleanly: - rpcrdma_wc_receive is responsible only for RDMA Receives - rpcrdma_reply_handler is responsible only for RPC Replies - the posted send and receive counts both belong in rpcrdma_ep Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent b674c4b commit 6ceea36

File tree

5 files changed

+19
-39
lines changed

5 files changed

+19
-39
lines changed

include/trace/events/rpcrdma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ TRACE_EVENT(xprtrdma_post_recvs,
570570
__entry->r_xprt = r_xprt;
571571
__entry->count = count;
572572
__entry->status = status;
573-
__entry->posted = r_xprt->rx_buf.rb_posted_receives;
573+
__entry->posted = r_xprt->rx_ep.rep_receive_count;
574574
__assign_str(addr, rpcrdma_addrstr(r_xprt));
575575
__assign_str(port, rpcrdma_portstr(r_xprt));
576576
),

net/sunrpc/xprtrdma/backchannel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ int xprt_rdma_bc_send_reply(struct rpc_rqst *rqst)
207207
if (rc < 0)
208208
goto failed_marshal;
209209

210-
rpcrdma_post_recvs(r_xprt, true);
211210
if (rpcrdma_ep_post(&r_xprt->rx_ia, &r_xprt->rx_ep, req))
212211
goto drop_connection;
213212
return 0;

net/sunrpc/xprtrdma/rpc_rdma.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,11 +1312,6 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
13121312
u32 credits;
13131313
__be32 *p;
13141314

1315-
--buf->rb_posted_receives;
1316-
1317-
if (rep->rr_hdrbuf.head[0].iov_len == 0)
1318-
goto out_badstatus;
1319-
13201315
/* Fixed transport header fields */
13211316
xdr_init_decode(&rep->rr_stream, &rep->rr_hdrbuf,
13221317
rep->rr_hdrbuf.head[0].iov_base);
@@ -1361,31 +1356,21 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
13611356
clear_bit(RPCRDMA_REQ_F_PENDING, &req->rl_flags);
13621357

13631358
trace_xprtrdma_reply(rqst->rq_task, rep, req, credits);
1364-
1365-
rpcrdma_post_recvs(r_xprt, false);
13661359
queue_work(rpcrdma_receive_wq, &rep->rr_work);
13671360
return;
13681361

13691362
out_badversion:
13701363
trace_xprtrdma_reply_vers(rep);
1371-
goto repost;
1364+
goto out;
13721365

1373-
/* The RPC transaction has already been terminated, or the header
1374-
* is corrupt.
1375-
*/
13761366
out_norqst:
13771367
spin_unlock(&xprt->queue_lock);
13781368
trace_xprtrdma_reply_rqst(rep);
1379-
goto repost;
1369+
goto out;
13801370

13811371
out_shortreply:
13821372
trace_xprtrdma_reply_short(rep);
13831373

1384-
/* If no pending RPC transaction was matched, post a replacement
1385-
* receive buffer before returning.
1386-
*/
1387-
repost:
1388-
rpcrdma_post_recvs(r_xprt, false);
1389-
out_badstatus:
1374+
out:
13901375
rpcrdma_recv_buffer_put(rep);
13911376
}

net/sunrpc/xprtrdma/verbs.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt);
7878
static void rpcrdma_mrs_destroy(struct rpcrdma_buffer *buf);
7979
static int rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt, bool temp);
8080
static void rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb);
81+
static void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp);
8182

8283
struct workqueue_struct *rpcrdma_receive_wq __read_mostly;
8384

@@ -189,11 +190,13 @@ rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
189190
struct ib_cqe *cqe = wc->wr_cqe;
190191
struct rpcrdma_rep *rep = container_of(cqe, struct rpcrdma_rep,
191192
rr_cqe);
193+
struct rpcrdma_xprt *r_xprt = rep->rr_rxprt;
192194

193-
/* WARNING: Only wr_id and status are reliable at this point */
195+
/* WARNING: Only wr_cqe and status are reliable at this point */
194196
trace_xprtrdma_wc_receive(wc);
197+
--r_xprt->rx_ep.rep_receive_count;
195198
if (wc->status != IB_WC_SUCCESS)
196-
goto out_fail;
199+
goto out_flushed;
197200

198201
/* status == SUCCESS means all fields in wc are trustworthy */
199202
rpcrdma_set_xdrlen(&rep->rr_hdrbuf, wc->byte_len);
@@ -204,17 +207,16 @@ rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
204207
rdmab_addr(rep->rr_rdmabuf),
205208
wc->byte_len, DMA_FROM_DEVICE);
206209

207-
out_schedule:
210+
rpcrdma_post_recvs(r_xprt, false);
208211
rpcrdma_reply_handler(rep);
209212
return;
210213

211-
out_fail:
214+
out_flushed:
212215
if (wc->status != IB_WC_WR_FLUSH_ERR)
213216
pr_err("rpcrdma: Recv: %s (%u/0x%x)\n",
214217
ib_wc_status_msg(wc->status),
215218
wc->status, wc->vendor_err);
216-
rpcrdma_set_xdrlen(&rep->rr_hdrbuf, 0);
217-
goto out_schedule;
219+
rpcrdma_recv_buffer_put(rep);
218220
}
219221

220222
static void
@@ -581,6 +583,7 @@ rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
581583
init_waitqueue_head(&ep->rep_connect_wait);
582584
INIT_DELAYED_WORK(&ep->rep_disconnect_worker,
583585
rpcrdma_disconnect_worker);
586+
ep->rep_receive_count = 0;
584587

585588
sendcq = ib_alloc_cq(ia->ri_device, NULL,
586589
ep->rep_attr.cap.max_send_wr + 1,
@@ -1174,7 +1177,6 @@ rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
11741177
}
11751178

11761179
buf->rb_credits = 1;
1177-
buf->rb_posted_receives = 0;
11781180
INIT_LIST_HEAD(&buf->rb_recv_bufs);
11791181

11801182
rc = rpcrdma_sendctxs_create(r_xprt);
@@ -1511,25 +1513,20 @@ rpcrdma_ep_post(struct rpcrdma_ia *ia,
15111513
return 0;
15121514
}
15131515

1514-
/**
1515-
* rpcrdma_post_recvs - Maybe post some Receive buffers
1516-
* @r_xprt: controlling transport
1517-
* @temp: when true, allocate temp rpcrdma_rep objects
1518-
*
1519-
*/
1520-
void
1516+
static void
15211517
rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp)
15221518
{
15231519
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1520+
struct rpcrdma_ep *ep = &r_xprt->rx_ep;
15241521
struct ib_recv_wr *wr, *bad_wr;
15251522
int needed, count, rc;
15261523

15271524
rc = 0;
15281525
count = 0;
15291526
needed = buf->rb_credits + (buf->rb_bc_srv_max_requests << 1);
1530-
if (buf->rb_posted_receives > needed)
1527+
if (ep->rep_receive_count > needed)
15311528
goto out;
1532-
needed -= buf->rb_posted_receives;
1529+
needed -= ep->rep_receive_count;
15331530

15341531
count = 0;
15351532
wr = NULL;
@@ -1577,7 +1574,7 @@ rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp)
15771574
--count;
15781575
}
15791576
}
1580-
buf->rb_posted_receives += count;
1577+
ep->rep_receive_count += count;
15811578
out:
15821579
trace_xprtrdma_post_recvs(r_xprt, count, rc);
15831580
}

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct rpcrdma_ep {
102102
struct rpcrdma_connect_private rep_cm_private;
103103
struct rdma_conn_param rep_remote_cma;
104104
struct delayed_work rep_disconnect_worker;
105+
int rep_receive_count;
105106
};
106107

107108
/* Pre-allocate extra Work Requests for handling backward receives
@@ -404,7 +405,6 @@ struct rpcrdma_buffer {
404405
unsigned long rb_flags;
405406
u32 rb_max_requests;
406407
u32 rb_credits; /* most recent credit grant */
407-
int rb_posted_receives;
408408

409409
u32 rb_bc_srv_max_requests;
410410
spinlock_t rb_reqslock; /* protect rb_allreqs */
@@ -560,7 +560,6 @@ void rpcrdma_ep_disconnect(struct rpcrdma_ep *, struct rpcrdma_ia *);
560560

561561
int rpcrdma_ep_post(struct rpcrdma_ia *, struct rpcrdma_ep *,
562562
struct rpcrdma_req *);
563-
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp);
564563

565564
/*
566565
* Buffer calls - xprtrdma/verbs.c

0 commit comments

Comments
 (0)