From patchwork Thu Jul 13 18:37:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9839505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BB26B60A16 for ; Thu, 13 Jul 2017 18:02:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD788287BE for ; Thu, 13 Jul 2017 20:58:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C245B287C1; Thu, 13 Jul 2017 20:58:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8A822855E for ; Thu, 13 Jul 2017 20:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752527AbdGMShk (ORCPT ); Thu, 13 Jul 2017 14:37:40 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:58255 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752435AbdGMShk (ORCPT ); Thu, 13 Jul 2017 14:37:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=GUXbURmjTUxRtkUaqrjJ8OtXpnkgr6GleO4GXwj5hTk=; b=0ckm31XN0AcYcMbmEdeGtLSIT5zK7OnAj6OhGsz1RtArRhz4oGplw16LA5VtggVT9JFMyFeNAZpl6ajNMoChYWdlYX6exsqVyWYduaHKjI2gXODnugqo73XL8a+QQtg+96/f38MRjtb1wFDXnTScF5LCsDzHH39dCEhGEPl9Jic=; Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1dVizZ-0004Jw-6V; Thu, 13 Jul 2017 12:37:37 -0600 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.86_2) (envelope-from ) id 1dVizZ-0001aK-4U; Thu, 13 Jul 2017 12:37:37 -0600 Date: Thu, 13 Jul 2017 12:37:37 -0600 From: Jason Gunthorpe To: Bart Van Assche Cc: "hch@infradead.org" , "linux-rdma@vger.kernel.org" , "yishaih@mellanox.com" Subject: Re: [PATCH rdma-core 4/8] mlx5: Avoid sparse complaints about !! Message-ID: <20170713183737.GF11069@obsidianresearch.com> References: <1499894262-10761-1-git-send-email-jgunthorpe@obsidianresearch.com> <1499894262-10761-5-git-send-email-jgunthorpe@obsidianresearch.com> <20170713075116.GA11233@infradead.org> <20170713172035.GB11069@obsidianresearch.com> <1499968325.2740.12.camel@wdc.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1499968325.2740.12.camel@wdc.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Jul 13, 2017 at 05:52:06PM +0000, Bart Van Assche wrote: > On Thu, 2017-07-13 at 11:20 -0600, Jason Gunthorpe wrote: > > On Thu, Jul 13, 2017 at 12:51:16AM -0700, Christoph Hellwig wrote: > > > > if (qp->qp_cap_cache & MLX5_RX_CSUM_VALID) > > > > - wc->wc_flags |= (!!(cqe->hds_ip_ext & MLX5_CQE_L4_OK) & > > > > - !!(cqe->hds_ip_ext & MLX5_CQE_L3_OK) & > > > > - (get_cqe_l3_hdr_type(cqe) == > > > > - MLX5_CQE_L3_HDR_TYPE_IPV4)) << > > > > - IBV_WC_IP_CSUM_OK_SHIFT; > > > > + wc->wc_flags |= > > > > + ((bool)(cqe->hds_ip_ext & MLX5_CQE_L4_OK) & > > > > + (bool)(cqe->hds_ip_ext & MLX5_CQE_L3_OK) & > > > > + (get_cqe_l3_hdr_type(cqe) == > > > > + MLX5_CQE_L3_HDR_TYPE_IPV4)) > > > > + << IBV_WC_IP_CSUM_OK_SHIFT; > > > > > > Meh. This code is complete crap. Please factor it out into a little > > > helper that mere humans can read first. And then replace the odd ^ used > > > as && with proper if constructs and all should make much more sense. > > > > As far as I could make out, this ugly thing is designed like this for > > performance. > > Hello Jason, > > How about using an expression like the below to avoid that branches get inserted > for testing the MLX5_CQE_L4_OK and MLX5_CQE_L3_OK flags? > > (cqe->hds_ip_ext & (MLX5_CQE_L4_OK | MLX5_CQE_L3_OK)) == MLX5_CQE_L4_OK | MLX5_CQE_L3_OK Yes, thanks, that seems a reasonable middle ground: --- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/providers/mlx5/cq.c b/providers/mlx5/cq.c index b845127de937d0..0a6274e6878d3c 100644 --- a/providers/mlx5/cq.c +++ b/providers/mlx5/cq.c @@ -182,6 +182,15 @@ static inline int handle_responder_lazy(struct mlx5_cq *cq, struct mlx5_cqe64 *c return err; } +/* Returns IBV_WC_IP_CSUM_OK or 0 */ +static inline int get_csum_ok(struct mlx5_cqe64 *cqe) +{ + return (((cqe->hds_ip_ext & (MLX5_CQE_L4_OK | MLX5_CQE_L3_OK)) == + (MLX5_CQE_L4_OK | MLX5_CQE_L3_OK)) & + (get_cqe_l3_hdr_type(cqe) == MLX5_CQE_L3_HDR_TYPE_IPV4)) + << IBV_WC_IP_CSUM_OK_SHIFT; +} + static inline int handle_responder(struct ibv_wc *wc, struct mlx5_cqe64 *cqe, struct mlx5_resource *cur_rsc, struct mlx5_srq *srq) { @@ -206,12 +215,7 @@ static inline int handle_responder(struct ibv_wc *wc, struct mlx5_cqe64 *cqe, if (likely(cur_rsc->type == MLX5_RSC_TYPE_QP)) { wq = &qp->rq; if (qp->qp_cap_cache & MLX5_RX_CSUM_VALID) - wc->wc_flags |= - ((bool)(cqe->hds_ip_ext & MLX5_CQE_L4_OK) & - (bool)(cqe->hds_ip_ext & MLX5_CQE_L3_OK) & - (get_cqe_l3_hdr_type(cqe) == - MLX5_CQE_L3_HDR_TYPE_IPV4)) - << IBV_WC_IP_CSUM_OK_SHIFT; + wc->wc_flags |= get_csum_ok(cqe); } else { wq = &(rsc_to_mrwq(cur_rsc)->rq); } @@ -1106,11 +1110,7 @@ static inline int mlx5_cq_read_wc_flags(struct ibv_cq_ex *ibcq) int wc_flags = 0; if (cq->flags & MLX5_CQ_FLAGS_RX_CSUM_VALID) - wc_flags = ((bool)(cq->cqe64->hds_ip_ext & MLX5_CQE_L4_OK) & - (bool)(cq->cqe64->hds_ip_ext & MLX5_CQE_L3_OK) & - (get_cqe_l3_hdr_type(cq->cqe64) == - MLX5_CQE_L3_HDR_TYPE_IPV4)) - << IBV_WC_IP_CSUM_OK_SHIFT; + wc_flags = get_csum_ok(cq->cqe64); switch (mlx5dv_get_cqe_opcode(cq->cqe64)) { case MLX5_CQE_RESP_WR_IMM: