linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Netanel Belgazal <netanel@annapurnalabs.com>
To: linux-kernel@vger.kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org
Cc: Netanel Belgazal <netanel@annapurnalabs.com>,
	dwmw@amazon.com, zorik@annapurnalabs.com, alex@annapurnalabs.com,
	saeed@annapurnalabs.com, msw@amazon.com, aliguori@amazon.com,
	nafea@annapurnalabs.com
Subject: [PATCH V2 net 10/20] net/ena: remove redundant logic in napi callback for busy poll mode
Date: Sun,  4 Dec 2016 15:19:28 +0200	[thread overview]
Message-ID: <1480857578-5065-11-git-send-email-netanel@annapurnalabs.com> (raw)
In-Reply-To: <1480857578-5065-1-git-send-email-netanel@annapurnalabs.com>

sk_busy_loop can call the napi callback few million times a sec.
For each call there is unmask interrupt.
We want to reduce the number of unmasks.

Add an atomic variable that will tell the napi handler if
it was called from irq context or not.
Unmask the interrupt only from irq context.

A schenario where the driver left with missed unmask isn't feasible.
when ena_intr_msix_io is called the driver have 2 options:
1)Before napi completes and call napi_complete_done
2)After calling napi_complete_done

In the former case the napi will unmask the interrupt as needed.
In the latter case napi_complete_done will remove napi from the schedule
list so napi will be rescheduled (by ena_intr_msix_io) and interrupt
will be unmasked as desire in the 2nd napi call.

Signed-off-by: Netanel Belgazal <netanel@annapurnalabs.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 46 +++++++++++++++++++---------
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  1 +
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index bb7eeea..5625007 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1129,26 +1129,41 @@ static int ena_io_poll(struct napi_struct *napi, int budget)
 	tx_work_done = ena_clean_tx_irq(tx_ring, tx_budget);
 	rx_work_done = ena_clean_rx_irq(rx_ring, napi, budget);
 
-	if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
+	/* If the device is about to reset or down, avoid unmask
+	 * the interrupt and return 0 so NAPI won't reschedule
+	 */
+	if (unlikely(!test_bit(ENA_FLAG_DEV_UP, &tx_ring->adapter->flags) ||
+		     test_bit(ENA_FLAG_TRIGGER_RESET, &tx_ring->adapter->flags))) {
+		napi_complete_done(napi, 0);
+		ret = 0;
+
+	} else if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
 		napi_complete_done(napi, rx_work_done);
 
 		napi_comp_call = 1;
-		/* Tx and Rx share the same interrupt vector */
-		if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
-			ena_adjust_intr_moderation(rx_ring, tx_ring);
-
-		/* Update intr register: rx intr delay, tx intr delay and
-		 * interrupt unmask
+		/* Update numa and unmask the interrupt only when schedule
+		 * from the interrupt context (vs from sk_busy_loop)
 		 */
-		ena_com_update_intr_reg(&intr_reg,
-					rx_ring->smoothed_interval,
-					tx_ring->smoothed_interval,
-					true);
+		if (atomic_cmpxchg(&ena_napi->unmask_interrupt, 1, 0)) {
+			/* Tx and Rx share the same interrupt vector */
+			if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
+				ena_adjust_intr_moderation(rx_ring, tx_ring);
+
+			/* Update intr register: rx intr delay,
+			 * tx intr delay and interrupt unmask
+			 */
+			ena_com_update_intr_reg(&intr_reg,
+						rx_ring->smoothed_interval,
+						tx_ring->smoothed_interval,
+						true);
+
+			/* It is a shared MSI-X.
+			 * Tx and Rx CQ have pointer to it.
+			 * So we use one of them to reach the intr reg
+			 */
+			ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
+		}
 
-		/* It is a shared MSI-X. Tx and Rx CQ have pointer to it.
-		 * So we use one of them to reach the intr reg
-		 */
-		ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
 
 		ena_update_ring_numa_node(tx_ring, rx_ring);
 
@@ -1186,6 +1201,7 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
 {
 	struct ena_napi *ena_napi = data;
 
+	atomic_set(&ena_napi->unmask_interrupt, 1);
 	napi_schedule(&ena_napi->napi);
 
 	return IRQ_HANDLED;
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 2897fab..c081fd3 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -135,6 +135,7 @@ struct ena_napi {
 	struct napi_struct napi ____cacheline_aligned;
 	struct ena_ring *tx_ring;
 	struct ena_ring *rx_ring;
+	atomic_t unmask_interrupt;
 	u32 qid;
 };
 
-- 
2.7.4

  parent reply	other threads:[~2016-12-04 13:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-04 13:19 [PATCH V2 net 00/20] Increase ENA driver version to 1.1.2 Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 01/20] net/ena: remove ntuple filter support from device feature list Netanel Belgazal
2016-12-05  4:08   ` Matt Wilson
2016-12-04 13:19 ` [PATCH V2 net 02/20] net/ena: fix error handling when probe fails Netanel Belgazal
2016-12-05  4:09   ` Matt Wilson
2016-12-05 18:23     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 03/20] net/ena: fix queues number calculation Netanel Belgazal
2016-12-05  4:11   ` Matt Wilson
2016-12-05 18:25     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 04/20] net/ena: fix ethtool RSS flow configuration Netanel Belgazal
2016-12-05  4:18   ` Matt Wilson
2016-12-05 18:26     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 05/20] net/ena: fix RSS default hash configuration Netanel Belgazal
2016-12-05  4:20   ` Matt Wilson
2016-12-05 18:32     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 06/20] net/ena: fix NULL dereference when removing the driver after device reset faild Netanel Belgazal
2016-12-05  4:29   ` Matt Wilson
2016-12-05 18:30     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 07/20] net/ena: refactor ena_get_stats64 to be atomic context safe Netanel Belgazal
2016-12-05  4:24   ` Matt Wilson
2016-12-05 18:29     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 08/20] net/ena: add hardware hints capability to the driver Netanel Belgazal
2016-12-05  4:31   ` Matt Wilson
2016-12-05 18:31     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 09/20] net/ena: fix potential access to freed memory during device reset Netanel Belgazal
2016-12-04 13:19 ` Netanel Belgazal [this message]
2016-12-05  5:45   ` [PATCH V2 net 10/20] net/ena: remove redundant logic in napi callback for busy poll mode Eric Dumazet
2016-12-05 18:29     ` Netanel Belgazal
2016-12-05 18:51       ` Eric Dumazet
2016-12-04 13:19 ` [PATCH V2 net 11/20] net/ena: use READ_ONCE to access completion descriptors Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 12/20] net/ena: reduce the severity of ena printouts Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 13/20] net/ena: change driver's default timeouts Netanel Belgazal
2016-12-05  4:35   ` Matt Wilson
2016-12-05 18:28     ` Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 14/20] net/ena: change condition for host attribute configuration Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 15/20] net/ena: change sizeof() argument to be the type pointer Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 16/20] net/ena: use napi_schedule_irqoff when possible Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 17/20] net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 18/20] net/ena: remove affinity hint from the driver Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 19/20] net/ena: restructure skb allocation Netanel Belgazal
2016-12-04 13:19 ` [PATCH V2 net 20/20] net/ena: increase driver version to 1.1.2 Netanel Belgazal
2016-12-05  2:37 ` [PATCH V2 net 00/20] Increase ENA " David Miller
2016-12-05  3:30   ` Matt Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480857578-5065-11-git-send-email-netanel@annapurnalabs.com \
    --to=netanel@annapurnalabs.com \
    --cc=alex@annapurnalabs.com \
    --cc=aliguori@amazon.com \
    --cc=davem@davemloft.net \
    --cc=dwmw@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=msw@amazon.com \
    --cc=nafea@annapurnalabs.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeed@annapurnalabs.com \
    --cc=zorik@annapurnalabs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).