xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Zoltan Kiss <zoltan.kiss@citrix.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Wei Liu <wei.liu2@citrix.com>, Tim Deegan <tim@xen.org>
Subject: Re: RING_HAS_UNCONSUMED_REQUESTS oddness
Date: Wed, 12 Mar 2014 17:14:13 +0000	[thread overview]
Message-ID: <532095E5.2080807@citrix.com> (raw)
In-Reply-To: <1394638643.3457.8.camel@kazak.uk.xensource.com>

On 12/03/14 15:37, Ian Campbell wrote:
> On Wed, 2014-03-12 at 15:14 +0000, Zoltan Kiss wrote:
>> On 12/03/14 14:30, Ian Campbell wrote:
>>> On Wed, 2014-03-12 at 14:27 +0000, Zoltan Kiss wrote:
>>>> On 12/03/14 10:28, Ian Campbell wrote:
>>>>> On Tue, 2014-03-11 at 23:24 +0000, Zoltan Kiss wrote:
>>>>>> On 11/03/14 15:44, Ian Campbell wrote:
>>>>>
>>>>>>> Is it the case that this macro considers a request to be unconsumed if
>>>>>>> the *response* to a request is outstanding as well as if the request
>>>>>>> itself is still on the ring?
>>>>>> I don't think that would make sense. I think everywhere where this macro
>>>>>> is called the caller is not interested in pending request (pending means
>>>>>> consumed but not responded)
>>>>>
>>>>> It might be interested in such pending requests in some of the
>>>>> pathological cases I allude to in the next paragraph though?
>>>>>
>>>>> For example if the ring has unconsumed requests but there are no slots
>>>>> free for a response, it would be better to treat it as no unconsumed
>>>>> requests until space opens up for a response, otherwise something else
>>>>> just has to abort the processing of the request when it notices the lack
>>>>> of space.
>>>>>
>>>>> (I'm totally speculating here BTW, I don't have any concrete idea why
>>>>> things are done this way...)
>>>>>
>>>>>
>>>>>>> I wonder if this apparently weird construction is due to pathological
>>>>>>> cases when one or the other end is not picking up requests/responses?
>>>>>>> i.e. trying to avoid deadlocking the ring or generating an interrupt
>>>>>>> storm when the ring it is full of one or the other or something along
>>>>>>> those lines?
>>>>>
>>>>>
>>>>
>>>> Also, let me quote again my example about when rsp makes sense:
>>>>
>>>> "To clarify what does this do, let me show an example:
>>>> req_prod = 253
>>>> req_cons = 256
>>>> rsp_prod_pvt = 0
>>>
>>> I think to make sense of this I need to see the sequence of reads/writes
>>> from both parties in a sensible ordering which would result in reads
>>> showing the above. i.e. a demonstration of the race not just an
>>> assertion that if the values are read as is things makes sense.
>>
>> Let me extend it:
>>
>> - callback reads req_prod = 253
>
> callback == backend? Which context is this code running in? Which part
> of the system is the callback logically part of?
Yes, it is part of the backend, the function which handles when we can 
release a slot back. With grant copy we don't have such thing, but with 
mapping xenvif_zerocopy_callback does this (or in classic kernel, it had 
a different name, but we called it page destructor). It can run from any 
context, it depends on who calls kfree_skb.

>
>> - frontend writes req_prod, now its 256
>> - backend picks it up, and consumes those slots, req_cons become 256
>
> "it"? Do you mean req_prod? Please be precise.
Yes, I meant req_prod. And backend means NAPI instance here.

>
>> - callback reads req_cons = 256
>
> But the backend has also seen req_prod at 256 at this point, hasn't it?
> You said so above but said "it" so I'm not sure. If the callback is part
> of the backend then why hasn't it also seen this?
Yes, the NAPI instance have seen it, but the callback has not. It were 
called from another context.

>
>> - req is UINT_MAX-3 therefore, but actually there isn't any request to
>> consume, it should be 0
>
> Only if something is ignoring the fact that it has seen req_prod == 256.
>
> If callback is some separate entity to backend within dom0 then what you
> have here is an internal inconsistency in dom0 AFAICT. IOW it seems like
> you are missing some synchronisation and/or have two different entities
> acting as backend.
The callback only needs to know whether it should poke the NAPI instance 
or not. There is this special case, if there are still a few unconsumed 
request, but the ring is nearly full of pending requests and 
xenvif_tx_pending_slots_available says NAPI should bail out, we have to 
schedule it back once we have enough free pending slots again.
As I said in an another mail of this thread, this poking happens in the 
callback, but actually it should be moved to the dealloc thread. However 
thinking further, this whole xenvif_tx_pending_slots_available stuff 
seems to be unnecessary to me:
It supposed to check if we have enough slot in the pending ring for the 
maximum number of possible slots, otherwise the backend bails out. It 
does so because if the backend start to consume the requests from the 
shared ring but runs out free slots in the pending ring, we are in 
trouble. But the pending ring supposed to have the same amount of slots 
as the shared one. And a consumed but not responded slot from the shared 
ring means a used slot in the pending ring. Therefore the frontend won't 
be able to push more than (MAX_PENDING_REQS - nr_pending_reqs(vif)) 
requests to the ring anyway. At least in practice, as MAX_PENDING_REQS = 
RING_SIZE(...). If we could bind the two to each other directly, we can 
get rid of this unnecessary checking, and whoever release the used 
pending slots should not poke the NAPI instance, because the frontend 
will call an interrupt if it sends a new packet anyway.

>
>> - callback reads rsp_prod_pvt = 0, because backend haven't responded to
>> any requests
>> - rsp is therefore 256 - (256 -0) = 0
>> - the macro returns rsp, as it is smaller. And that's good, because
>> despite the macro failed to determine the number of unconsumed requests,
>> at least it detected that the ring is full with consumed but not replied
>> requests, so there shouldn't be any unconsumed req
>>
>> And I call this best effort because if rsp_prod_pvt is e.g. 10, rsp will
>> be then 10 as well, we return it, and the caller thinks there are
>> unconsumed requests, despite there isn't any.
>>
>> Zoli
>
>

  reply	other threads:[~2014-03-12 17:14 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06 15:47 RING_HAS_UNCONSUMED_REQUESTS oddness Zoltan Kiss
2014-03-06 15:53 ` Ian Campbell
2014-03-06 16:31   ` Zoltan Kiss
2014-03-06 17:30     ` Tim Deegan
2014-03-06 21:39       ` Zoltan Kiss
2014-03-07  9:23         ` Paul Durrant
2014-03-07 17:43           ` Zoltan Kiss
2014-03-07 12:02         ` Wei Liu
2014-03-07 18:58           ` Zoltan Kiss
2014-03-11 15:55         ` Ian Campbell
2014-03-11 23:34           ` Zoltan Kiss
2014-03-13 16:38       ` [PATCH RFC] xen/public/ring.h: simplify RING_HAS_UNCONSUMED_REQUESTS() Tim Deegan
2014-03-22 14:18         ` Zoltan Kiss
2014-03-22 17:14           ` Tim Deegan
2014-03-24  7:38             ` Jan Beulich
2014-03-24  9:39               ` Paul Durrant
2014-03-24  9:59                 ` Jan Beulich
2014-03-24 11:03                   ` Paul Durrant
2014-03-24 12:23               ` Zoltan Kiss
2014-03-24 13:52                 ` Paul Durrant
2014-03-24 23:55                   ` Zoltan Kiss
2014-04-03  9:38         ` Tim Deegan
2014-04-03 15:34           ` Zoltan Kiss
2014-03-11 15:44 ` RING_HAS_UNCONSUMED_REQUESTS oddness Ian Campbell
2014-03-11 23:24   ` Zoltan Kiss
2014-03-12 10:28     ` Ian Campbell
2014-03-12 10:48       ` Roger Pau Monné
2014-03-12 11:25       ` Paul Durrant
2014-03-12 11:38       ` Paul Durrant
2014-03-12 14:41         ` Zoltan Kiss
2014-03-12 15:23           ` Paul Durrant
2014-03-12 15:42             ` Wei Liu
2014-03-12 15:56               ` Paul Durrant
2014-03-12 16:02               ` Paul Durrant
2014-03-12 16:13               ` Zoltan Kiss
2014-03-12 16:42                 ` Paul Durrant
2014-03-12 19:06                   ` Zoltan Kiss
2014-03-13  9:26                     ` Paul Durrant
2014-03-13 10:02                       ` Ian Campbell
2014-03-13 10:58                         ` Paul Durrant
2014-03-13 12:19                           ` Ian Campbell
2014-03-13 12:28                             ` Zoltan Kiss
2014-03-13 12:29                               ` Paul Durrant
2014-03-13 12:44                               ` Ian Campbell
2014-03-12 14:25       ` Zoltan Kiss
2014-03-12 14:27       ` Zoltan Kiss
2014-03-12 14:30         ` Ian Campbell
2014-03-12 15:14           ` Zoltan Kiss
2014-03-12 15:37             ` Ian Campbell
2014-03-12 17:14               ` Zoltan Kiss [this message]
2014-03-12 17:43                 ` Ian Campbell
2014-03-12 21:10                   ` Zoltan Kiss
2014-03-13 10:04                     ` Ian Campbell

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=532095E5.2080807@citrix.com \
    --to=zoltan.kiss@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=tim@xen.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).