From: Zoltan Kiss <zoltan.kiss@citrix.com>
To: <netdev@vger.kernel.org>, Eric Dumazet <eric.dumazet@gmail.com>,
David Miller <davem@davemloft.net>
Cc: David Vrabel <david.vrabel@citrix.com>,
<xen-devel@lists.xenproject.org>,
Ian Campbell <ian.campbell@citrix.com>,
Wei Liu <wei.liu2@citrix.com>
Subject: interrupt moving and NAPI scheduling
Date: Thu, 15 May 2014 17:26:28 +0100 [thread overview]
Message-ID: <5374EAB4.2000701@citrix.com> (raw)
In-Reply-To: <533195B6.5090305@citrix.com>
Hi,
Let me bump this question: how does the kernel make sure that if an
interrupt is moved away from CPU X to Y (e.g. by irqbalance), the NAPI
instance already scheduled on CPU Y won't race with the interrupt? I
mean the following scenario:
1. instance calls napi_complete on CPU X
2. that removes the instance from the list
3. interrupt happens on CPU Y
4. "!test_and_set_bit(NAPI_STATE_SCHED, &n->state)" fails, as the bit is
still set
5. instance not added to the list therefore
6. napi_complete on CPU X clear the bit
My assumption is that when the interrupt moved, the kernel makes sure
the NAPI instance won't get scheduled on the old CPU, but I'm not sure
about it
On 25/03/14 14:41, Zoltan Kiss wrote:
> My idea was that the current code can't race with interrupt running on a
> different CPU, because if the interrupt was moved since the last
> napi_schedule (which scheduled NAPI on the same CPU as the interrupt),
> the kernel would make sure that the NAPI instance is moved along with
> it. However I couldn't find any trace of this in the kernel so far, but
> the current code actually works for me, even when I used a bash script
> to aggressively move the interrupts around while running.
> I've added David and Eric to the mailing, maybe they can quickly shed
> some light on this: how does the kernel make sure that if the interrupt
> is moved away from a CPU (e.g. by irqbalance), the NAPI instance already
> scheduled there won't race with it?
>
> Zoli
>
> On 25/03/14 14:08, David Vrabel wrote:
>> When the NAPI budget was not all used, xenvif_poll() would call
>> napi_complete() /after/ enabling the interrupt. This resulted in a
>> race between the napi_complete() and the napi_schedule() in the
>> interrupt handler. The use of local_irq_save/restore() avoided by
>> race iff the handler is running on the same CPU but not if it was
>> running on a different CPU.
>>
>> Fix this properly by calling napi_complete() before reenabling
>> interrupts (in the xenvif_check_rx_xenvif() call).
>>
>> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
>> ---
>> drivers/net/xen-netback/interface.c | 28 ++--------------------------
>> 1 files changed, 2 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/net/xen-netback/interface.c
>> b/drivers/net/xen-netback/interface.c
>> index 7669d49..ee322d9 100644
>> --- a/drivers/net/xen-netback/interface.c
>> +++ b/drivers/net/xen-netback/interface.c
>> @@ -65,32 +65,8 @@ static int xenvif_poll(struct napi_struct *napi,
>> int budget)
>> work_done = xenvif_tx_action(vif, budget);
>>
>> if (work_done < budget) {
>> - int more_to_do = 0;
>> - unsigned long flags;
>> -
>> - /* It is necessary to disable IRQ before calling
>> - * RING_HAS_UNCONSUMED_REQUESTS. Otherwise we might
>> - * lose event from the frontend.
>> - *
>> - * Consider:
>> - * RING_HAS_UNCONSUMED_REQUESTS
>> - * <frontend generates event to trigger napi_schedule>
>> - * __napi_complete
>> - *
>> - * This handler is still in scheduled state so the
>> - * event has no effect at all. After __napi_complete
>> - * this handler is descheduled and cannot get
>> - * scheduled again. We lose event in this case and the ring
>> - * will be completely stalled.
>> - */
>> -
>> - local_irq_save(flags);
>> -
>> - RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, more_to_do);
>> - if (!more_to_do)
>> - __napi_complete(napi);
>> -
>> - local_irq_restore(flags);
>> + napi_complete(napi);
>> + xenvif_check_rx_xenvif(vif);
>> }
>>
>> return work_done;
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-05-15 16:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-25 14:08 [PATCH] xen-netback: fix race between napi_complete() and interrupt handler David Vrabel
2014-03-25 14:41 ` Zoltan Kiss
2014-05-15 16:26 ` Zoltan Kiss [this message]
2014-05-15 17:33 ` interrupt moving and NAPI scheduling Eric Dumazet
2014-03-25 14:50 ` [PATCH] xen-netback: fix race between napi_complete() and interrupt handler Wei Liu
2014-03-25 15:08 ` David Vrabel
2014-03-26 20:33 ` David Miller
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=5374EAB4.2000701@citrix.com \
--to=zoltan.kiss@citrix.com \
--cc=davem@davemloft.net \
--cc=david.vrabel@citrix.com \
--cc=eric.dumazet@gmail.com \
--cc=ian.campbell@citrix.com \
--cc=netdev@vger.kernel.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/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).