]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
svcrdma: Clean up RPC-over-RDMA Reply header encoder
authorChuck Lever <chuck.lever@oracle.com>
Tue, 7 Feb 2017 16:58:23 +0000 (11:58 -0500)
committerJ. Bruce Fields <bfields@redhat.com>
Wed, 8 Feb 2017 19:41:41 +0000 (14:41 -0500)
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>
include/linux/sunrpc/svc_rdma.h
net/sunrpc/xprtrdma/svc_rdma_marshal.c
net/sunrpc/xprtrdma/svc_rdma_sendto.c
net/sunrpc/xprtrdma/svc_rdma_transport.c

index 551c518163529d4ae5ae46a5aa3136c0caf48aa5..25ecf92cae9638e30745cce7876ddaec5f6eb2b2 100644 (file)
@@ -141,7 +141,8 @@ struct svcxprt_rdma {
        atomic_t             sc_sq_avail;       /* SQEs ready to be consumed */
        unsigned int         sc_sq_depth;       /* Depth of SQ */
        unsigned int         sc_rq_depth;       /* Depth of RQ */
-       u32                  sc_max_requests;   /* Forward credits */
+       __be32               sc_fc_credits;     /* Forward credits */
+       u32                  sc_max_requests;   /* Max requests */
        u32                  sc_max_bc_requests;/* Backward credits */
        int                  sc_max_req_size;   /* Size of each RQ WR buf */
 
@@ -214,10 +215,6 @@ extern void svc_rdma_xdr_encode_write_list(struct rpcrdma_msg *, int);
 extern void svc_rdma_xdr_encode_reply_array(struct rpcrdma_write_array *, int);
 extern void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *, int,
                                            __be32, __be64, u32);
-extern void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *,
-                                            struct rpcrdma_msg *,
-                                            struct rpcrdma_msg *,
-                                            enum rpcrdma_proc);
 extern unsigned int svc_rdma_xdr_get_reply_hdr_len(__be32 *rdma_resp);
 
 /* svc_rdma_recvfrom.c */
index 4e7203439e2fde2158f04f2eb709af29d800bba4..c7d15b1126ce5a462f4cac8c2c5901339b7d754d 100644 (file)
@@ -249,7 +249,7 @@ int svc_rdma_xdr_encode_error(struct svcxprt_rdma *xprt,
 
        *va++ = rmsgp->rm_xid;
        *va++ = rmsgp->rm_vers;
-       *va++ = cpu_to_be32(xprt->sc_max_requests);
+       *va++ = xprt->sc_fc_credits;
        *va++ = rdma_error;
        *va++ = cpu_to_be32(err);
        if (err == ERR_VERS) {
@@ -329,19 +329,3 @@ void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *ary,
        seg->rs_offset = rs_offset;
        seg->rs_length = cpu_to_be32(write_len);
 }
-
-void svc_rdma_xdr_encode_reply_header(struct svcxprt_rdma *xprt,
-                                 struct rpcrdma_msg *rdma_argp,
-                                 struct rpcrdma_msg *rdma_resp,
-                                 enum rpcrdma_proc rdma_type)
-{
-       rdma_resp->rm_xid = rdma_argp->rm_xid;
-       rdma_resp->rm_vers = rdma_argp->rm_vers;
-       rdma_resp->rm_credit = cpu_to_be32(xprt->sc_max_requests);
-       rdma_resp->rm_type = cpu_to_be32(rdma_type);
-
-       /* Encode <nul> chunks lists */
-       rdma_resp->rm_body.rm_chunks[0] = xdr_zero;
-       rdma_resp->rm_body.rm_chunks[1] = xdr_zero;
-       rdma_resp->rm_body.rm_chunks[2] = xdr_zero;
-}
index ba76f1617965d449250b21c7767573950ee7bd16..515221b16d0956ea027e91985c89606c403d5109 100644 (file)
@@ -560,12 +560,12 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        struct rpcrdma_msg *rdma_argp;
        struct rpcrdma_msg *rdma_resp;
        struct rpcrdma_write_array *wr_ary, *rp_ary;
-       enum rpcrdma_proc reply_type;
        int ret;
        int inline_bytes;
        struct page *res_page;
        struct svc_rdma_req_map *vec;
        u32 inv_rkey;
+       __be32 *p;
 
        dprintk("svcrdma: sending response for rqstp=%p\n", rqstp);
 
@@ -597,12 +597,17 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        if (!res_page)
                goto err0;
        rdma_resp = page_address(res_page);
-       if (rp_ary)
-               reply_type = RDMA_NOMSG;
-       else
-               reply_type = RDMA_MSG;
-       svc_rdma_xdr_encode_reply_header(rdma, rdma_argp,
-                                        rdma_resp, reply_type);
+
+       p = &rdma_resp->rm_xid;
+       *p++ = rdma_argp->rm_xid;
+       *p++ = rdma_argp->rm_vers;
+       *p++ = rdma->sc_fc_credits;
+       *p++ = rp_ary ? rdma_nomsg : rdma_msg;
+
+       /* Start with empty chunks */
+       *p++ = xdr_zero;
+       *p++ = xdr_zero;
+       *p   = xdr_zero;
 
        /* Send any write-chunk data and build resp write-list */
        if (wr_ary) {
index ca2799af05a6846980e2dfa2bd7c58c655a6f069..174928fe5f833fa884bef6ca7c9a5924691e030b 100644 (file)
@@ -1002,6 +1002,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
        newxprt->sc_max_req_size = svcrdma_max_req_size;
        newxprt->sc_max_requests = min_t(u32, dev->attrs.max_qp_wr,
                                         svcrdma_max_requests);
+       newxprt->sc_fc_credits = cpu_to_be32(newxprt->sc_max_requests);
        newxprt->sc_max_bc_requests = min_t(u32, dev->attrs.max_qp_wr,
                                            svcrdma_max_bc_requests);
        newxprt->sc_rq_depth = newxprt->sc_max_requests +