]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: hns3: minor optimization for barrier in IO path
authorYunsheng Lin <linyunsheng@huawei.com>
Sat, 19 Oct 2019 08:03:51 +0000 (16:03 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 21 Oct 2019 16:22:09 +0000 (09:22 -0700)
Currently, the TX and RX ring in a queue is bounded to the
same IRQ, there may be unnecessary barrier op when only one of
the ring need to be processed.

This patch adjusts the location of rmb() in hns3_clean_tx_ring()
and adds a checking in hns3_clean_rx_ring() to avoid unnecessary
barrier op when there is nothing to do for the ring.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

index 635bddae4a07ad9e4b55c4ed57f1b4aeaa94a533..089cd58275a27ca817fb95d62b2599d772bfc563 100644 (file)
@@ -2485,11 +2485,12 @@ void hns3_clean_tx_ring(struct hns3_enet_ring *ring)
        int head;
 
        head = readl_relaxed(ring->tqp->io_base + HNS3_RING_TX_RING_HEAD_REG);
-       rmb(); /* Make sure head is ready before touch any data */
 
        if (is_ring_empty(ring) || head == ring->next_to_clean)
                return; /* no data to poll */
 
+       rmb(); /* Make sure head is ready before touch any data */
+
        if (unlikely(!is_valid_clean_head(ring, head))) {
                netdev_err(netdev, "wrong head (%d, %d-%d)\n", head,
                           ring->next_to_use, ring->next_to_clean);
@@ -3105,11 +3106,14 @@ int hns3_clean_rx_ring(struct hns3_enet_ring *ring, int budget,
        int err, num;
 
        num = readl_relaxed(ring->tqp->io_base + HNS3_RING_RX_RING_FBDNUM_REG);
-       rmb(); /* Make sure num taken effect before the other data is touched */
-
        num -= unused_count;
        unused_count -= ring->pending_buf;
 
+       if (num <= 0)
+               goto out;
+
+       rmb(); /* Make sure num taken effect before the other data is touched */
+
        while (recv_pkts < budget && recv_bds < num) {
                /* Reuse or realloc buffers */
                if (unused_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) {