Skip to content

Commit 98fc21d

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
svcrdma: Clean up RPC-over-RDMA Reply header encoder
Replace C structure-based XDR decoding with pointer arithmetic. Pointer arithmetic is considered more portable, and is used throughout the kernel's existing XDR encoders. The gcc optimizer generates similar assembler code either way. Byte-swapping before a memory store on x86 typically results in an instruction pipeline stall. Avoid byte-swapping when encoding a new header. svcrdma currently doesn't alter a connection's credit grant value after the connection has been accepted, so it is effectively a constant. Cache the byte-swapped value in a separate field. Christoph suggested pulling the header encoding logic into the only function that uses it. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent cbaf580 commit 98fc21d

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

include/linux/sunrpc/svc_rdma.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ struct svcxprt_rdma {
141141
atomic_t sc_sq_avail; /* SQEs ready to be consumed */
142142
unsigned int sc_sq_depth; /* Depth of SQ */
143143
unsigned int sc_rq_depth; /* Depth of RQ */
144-
u32 sc_max_requests; /* Forward credits */
144+
__be32 sc_fc_credits; /* Forward credits */
145+
u32 sc_max_requests; /* Max requests */
145146
u32 sc_max_bc_requests;/* Backward credits */
146147
int sc_max_req_size; /* Size of each RQ WR buf */
147148

@@ -214,10 +215,6 @@ extern void svc_rdma_xdr_encode_write_list(struct rpcrdma_msg *, int);
214215
extern void svc_rdma_xdr_encode_reply_array(struct rpcrdma_write_array *, int);
215216
extern void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *, int,
216217
__be32, __be64, u32);
217-
extern void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *,
218-
struct rpcrdma_msg *,
219-
struct rpcrdma_msg *,
220-
enum rpcrdma_proc);
221218
extern unsigned int svc_rdma_xdr_get_reply_hdr_len(__be32 *rdma_resp);
222219

223220
/* svc_rdma_recvfrom.c */

net/sunrpc/xprtrdma/svc_rdma_marshal.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int svc_rdma_xdr_encode_error(struct svcxprt_rdma *xprt,
249249

250250
*va++ = rmsgp->rm_xid;
251251
*va++ = rmsgp->rm_vers;
252-
*va++ = cpu_to_be32(xprt->sc_max_requests);
252+
*va++ = xprt->sc_fc_credits;
253253
*va++ = rdma_error;
254254
*va++ = cpu_to_be32(err);
255255
if (err == ERR_VERS) {
@@ -329,19 +329,3 @@ void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *ary,
329329
seg->rs_offset = rs_offset;
330330
seg->rs_length = cpu_to_be32(write_len);
331331
}
332-
333-
void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *xprt,
334-
struct rpcrdma_msg *rdma_argp,
335-
struct rpcrdma_msg *rdma_resp,
336-
enum rpcrdma_proc rdma_type)
337-
{
338-
rdma_resp->rm_xid = rdma_argp->rm_xid;
339-
rdma_resp->rm_vers = rdma_argp->rm_vers;
340-
rdma_resp->rm_credit = cpu_to_be32(xprt->sc_max_requests);
341-
rdma_resp->rm_type = cpu_to_be32(rdma_type);
342-
343-
/* Encode <nul> chunks lists */
344-
rdma_resp->rm_body.rm_chunks[0] = xdr_zero;
345-
rdma_resp->rm_body.rm_chunks[1] = xdr_zero;
346-
rdma_resp->rm_body.rm_chunks[2] = xdr_zero;
347-
}

net/sunrpc/xprtrdma/svc_rdma_sendto.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
560560
struct rpcrdma_msg *rdma_argp;
561561
struct rpcrdma_msg *rdma_resp;
562562
struct rpcrdma_write_array *wr_ary, *rp_ary;
563-
enum rpcrdma_proc reply_type;
564563
int ret;
565564
int inline_bytes;
566565
struct page *res_page;
567566
struct svc_rdma_req_map *vec;
568567
u32 inv_rkey;
568+
__be32 *p;
569569

570570
dprintk("svcrdma: sending response for rqstp=%p\n", rqstp);
571571

@@ -597,12 +597,17 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
597597
if (!res_page)
598598
goto err0;
599599
rdma_resp = page_address(res_page);
600-
if (rp_ary)
601-
reply_type = RDMA_NOMSG;
602-
else
603-
reply_type = RDMA_MSG;
604-
svc_rdma_xdr_encode_reply_header(rdma, rdma_argp,
605-
rdma_resp, reply_type);
600+
601+
p = &rdma_resp->rm_xid;
602+
*p++ = rdma_argp->rm_xid;
603+
*p++ = rdma_argp->rm_vers;
604+
*p++ = rdma->sc_fc_credits;
605+
*p++ = rp_ary ? rdma_nomsg : rdma_msg;
606+
607+
/* Start with empty chunks */
608+
*p++ = xdr_zero;
609+
*p++ = xdr_zero;
610+
*p = xdr_zero;
606611

607612
/* Send any write-chunk data and build resp write-list */
608613
if (wr_ary) {

net/sunrpc/xprtrdma/svc_rdma_transport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
10021002
newxprt->sc_max_req_size = svcrdma_max_req_size;
10031003
newxprt->sc_max_requests = min_t(u32, dev->attrs.max_qp_wr,
10041004
svcrdma_max_requests);
1005+
newxprt->sc_fc_credits = cpu_to_be32(newxprt->sc_max_requests);
10051006
newxprt->sc_max_bc_requests = min_t(u32, dev->attrs.max_qp_wr,
10061007
svcrdma_max_bc_requests);
10071008
newxprt->sc_rq_depth = newxprt->sc_max_requests +

0 commit comments

Comments
 (0)