Re: [PATCH net-next 4/4] eth: mpnic: add a NAPI depletion check
flat view
From: Harshitha Ramamurthy <hramamurthy@google.com>
Date: 2026-10-03 00:53:26
Also in:
lkml
On Thu, Oct 1, 2026 at 9:41 AM Daniel Zahka [off-list ref] wrote:
quoted hunk ↗ jump to hunk
The Rx path can wedge if page pool allocations fail in __mpnic_fill_bdq(). The problematic sequence is: page pool allocations fail, bdq rings are empty, device receives packet from the network, but drops it for lack of buffer space and does not raise interrupt, mpnic_poll() does not run, so page pool allocations are not retried. To break out of this cycle, we can add a depletion check to our service task. The depletion check checks if posted buffers are under a low watermark, and raises a completion queue interrupt, so that mpnic_poll will run on the corresponding napi vector. A note about the lock free reads: We don't bother synchronizing the ring head and tail reads with mpnic_poll(), because a false positive signal would simply raise a spurious interrupt scheduling mpnic_poll(), and a false negative signal will result in a retry, where if mpnic_poll() has truly not been running, should then report accurately whether or not posted Rx buffers are low. Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com> --- drivers/net/ethernet/meta/mpnic/mpnic_pci.c | 4 ++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.c | 31 ++++++++++++++++++++++++++++ drivers/net/ethernet/meta/mpnic/mpnic_txrx.h | 1 + 3 files changed, 36 insertions(+)diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c index 17eae5a9ba16..125fb26edf93 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_pci.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_pci.c@@ -11,6 +11,7 @@ #include "mpnic.h" #include "mpnic_netdev.h" +#include "mpnic_txrx.h" #define PCI_DEVICE_ID_META_MPNIC 0x0014@@ -61,6 +62,9 @@ static void mpnic_service_task(struct work_struct *work) netdev_lock(netdev); + if (netif_carrier_ok(netdev)) + mpnic_napi_depletion_check(netdev_priv(netdev)); + if (netif_running(netdev)) schedule_delayed_work(&mpd->service_task, HZ);diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c index 49061c7316d5..5495e9a9aa65 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c@@ -55,6 +55,12 @@ static unsigned int mpnic_desc_unused(struct mpnic_ring *ring) return (ring->head - ring->tail - 1) & ring->size_mask; } +static unsigned int mpnic_desc_used(struct mpnic_ring *ring) +{ + return (READ_ONCE(ring->tail) - READ_ONCE(ring->head)) & + ring->size_mask; +} + static struct netdev_queue *mpnic_txring_txq(const struct net_device *dev, const struct mpnic_ring *ring) {@@ -1393,3 +1399,28 @@ void mpnic_napi_enable(struct mpnic_net *mpn) mpnic_wrfl(mpn->mpd); } + +void mpnic_napi_depletion_check(struct mpnic_net *mpn) +{ + int i, j, t; + + for (i = 0; i < mpn->num_napi; i++) { + struct mpnic_napi_vector *nv = mpn->napi[i]; + + for (t = nv->txt_count, j = 0; j < nv->rxt_count; j++, t++) { + /* Check if BDs posted covers a max sized frame + * + 1 BD held by RDE as a spare + * + 1 BD of extra safety margin + */
Curious how the "+ 1 BD of extra safety margin" was decided. I understand the "+ 1 BD held by RDE as a spare" is because of HW behaviour but wondering about the extra buffer descriptor - if it came from testing or guarding against something specific.
quoted hunk ↗ jump to hunk
+ if (mpnic_desc_used(&nv->qt[t].sub0) < + MPNIC_RX_HPQ_DROP_THRS + 2 || + mpnic_desc_used(&nv->qt[t].sub1) < + MPNIC_RX_PPQ_DROP_THRS + 2) { + mpnic_nv_irq_trigger(nv); + break; + } + } + } + + mpnic_wrfl(mpn->mpd); +}diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h index 9397010557eb..767d87a36c35 100644 --- a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.h@@ -148,6 +148,7 @@ int mpnic_set_netif_queues(struct mpnic_net *mpn); void mpnic_reset_netif_queues(struct mpnic_net *mpn); void mpnic_napi_enable(struct mpnic_net *mpn); void mpnic_napi_disable(struct mpnic_net *mpn); +void mpnic_napi_depletion_check(struct mpnic_net *mpn); void mpnic_enable(struct mpnic_net *mpn); void mpnic_disable(struct mpnic_net *mpn); void mpnic_wait_all_queues_idle(struct mpnic_dev *mpd); --2.52.0