Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936569AbcKNSce (ORCPT ); Mon, 14 Nov 2016 13:32:34 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36236 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934382AbcKNSc3 (ORCPT ); Mon, 14 Nov 2016 13:32:29 -0500 From: Rob Rice To: Jassi Brar Cc: bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, Steve Lin , Rob Rice Subject: [PATCH 06/11] mailbox: bcm-pdc: Try to improve branch prediction Date: Mon, 14 Nov 2016 13:26:00 -0500 Message-Id: <1479147965-29662-7-git-send-email-rob.rice@broadcom.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1479147965-29662-1-git-send-email-rob.rice@broadcom.com> References: <1479147965-29662-1-git-send-email-rob.rice@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3624 Lines: 111 Use likely/unlikely directives to improve branch prediction. Signed-off-by: Rob Rice Reviewed-by: Andy Gospodarek --- drivers/mailbox/bcm-pdc-mailbox.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/mailbox/bcm-pdc-mailbox.c b/drivers/mailbox/bcm-pdc-mailbox.c index 2195760..7ed3f02 100644 --- a/drivers/mailbox/bcm-pdc-mailbox.c +++ b/drivers/mailbox/bcm-pdc-mailbox.c @@ -834,7 +834,7 @@ static int pdc_rx_list_init(struct pdc_state *pdcs, struct scatterlist *dst_sg, /* allocate a buffer for the dma rx status */ vaddr = dma_pool_zalloc(pdcs->rx_buf_pool, GFP_ATOMIC, &daddr); - if (!vaddr) + if (unlikely(!vaddr)) return -ENOMEM; /* @@ -945,14 +945,14 @@ static irqreturn_t pdc_irq_handler(int irq, void *cookie) struct pdc_state *pdcs = cookie; u32 intstatus = ioread32(pdcs->pdc_reg_vbase + PDC_INTSTATUS_OFFSET); - if (intstatus & PDC_RCVINTEN_0) + if (likely(intstatus & PDC_RCVINTEN_0)) set_bit(PDC_RCVINT_0, &pdcs->intstatus); /* Clear interrupt flags in device */ iowrite32(intstatus, pdcs->pdc_reg_vbase + PDC_INTSTATUS_OFFSET); /* Wakeup IRQ thread */ - if (pdcs && (irq == pdcs->pdc_irq) && (intstatus & PDC_INTMASK)) + if (likely(pdcs && (irq == pdcs->pdc_irq) && (intstatus & PDC_INTMASK))) return IRQ_WAKE_THREAD; return IRQ_NONE; @@ -976,7 +976,7 @@ static irqreturn_t pdc_irq_thread(int irq, void *cookie) bool rx_int; rx_int = test_and_clear_bit(PDC_RCVINT_0, &pdcs->intstatus); - if (pdcs && rx_int) { + if (likely(pdcs && rx_int)) { dev_dbg(&pdcs->pdev->dev, "%s() got irq %d with rx_int %s", __func__, irq, rx_int ? "set" : "clear"); @@ -1007,14 +1007,14 @@ static int pdc_ring_init(struct pdc_state *pdcs, int ringset) /* Allocate tx ring */ tx.vbase = dma_pool_zalloc(pdcs->ring_pool, GFP_KERNEL, &tx.dmabase); - if (!tx.vbase) { + if (unlikely(!tx.vbase)) { err = -ENOMEM; goto done; } /* Allocate rx ring */ rx.vbase = dma_pool_zalloc(pdcs->ring_pool, GFP_KERNEL, &rx.dmabase); - if (!rx.vbase) { + if (unlikely(!rx.vbase)) { err = -ENOMEM; goto fail_dealloc; } @@ -1219,21 +1219,21 @@ static int pdc_send_data(struct mbox_chan *chan, void *data) u32 tx_desc_req; u32 rx_desc_req; - if (mssg->type != BRCM_MESSAGE_SPU) + if (unlikely(mssg->type != BRCM_MESSAGE_SPU)) return -ENOTSUPP; src_nent = sg_nents(mssg->spu.src); - if (src_nent) { + if (likely(src_nent)) { nent = dma_map_sg(dev, mssg->spu.src, src_nent, DMA_TO_DEVICE); - if (nent == 0) + if (unlikely(nent == 0)) return -EIO; } dst_nent = sg_nents(mssg->spu.dst); - if (dst_nent) { + if (likely(dst_nent)) { nent = dma_map_sg(dev, mssg->spu.dst, dst_nent, DMA_FROM_DEVICE); - if (nent == 0) { + if (unlikely(nent == 0)) { dma_unmap_sg(dev, mssg->spu.src, src_nent, DMA_TO_DEVICE); return -EIO; @@ -1251,7 +1251,7 @@ static int pdc_send_data(struct mbox_chan *chan, void *data) */ tx_desc_req = pdc_desc_count(mssg->spu.src); rx_desc_req = pdc_desc_count(mssg->spu.dst); - if (pdc_rings_full(pdcs, tx_desc_req, rx_desc_req + 1)) + if (unlikely(pdc_rings_full(pdcs, tx_desc_req, rx_desc_req + 1))) return -ENOSPC; /* Create rx descriptors to SPU catch response */ @@ -1262,7 +1262,7 @@ static int pdc_send_data(struct mbox_chan *chan, void *data) err |= pdc_tx_list_sg_add(pdcs, mssg->spu.src); err |= pdc_tx_list_final(pdcs); /* initiate transfer */ - if (err) + if (unlikely(err)) dev_err(&pdcs->pdev->dev, "%s failed with error %d", __func__, err); -- 2.1.0