patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Victor Kaplansky <vkaplans@redhat.com>
Cc: dev@dpdk.org, stable@dpdk.org,
	Jens Freimann <jfreiman@redhat.com>,
	Yuanhan Liu <yliu@fridaylinux.org>,
	Tiwei Bie <tiwei.bie@intel.com>,
	Jianfeng Tan <jianfeng.tan@intel.com>
Subject: Re: [dpdk-stable] [PATCH v3] vhost_user: protect active rings from async ring changes
Date: Thu, 14 Dec 2017 18:28:46 +0100	[thread overview]
Message-ID: <7253e36a-e41a-f2a7-2395-fe654e7d3ab2@redhat.com> (raw)
In-Reply-To: <1818102083.54728632.1513261303965.JavaMail.zimbra@redhat.com>



On 12/14/2017 03:21 PM, Victor Kaplansky wrote:
> 
> 
> ----- Original Message -----
>> From: "Maxime Coquelin" <maxime.coquelin@redhat.com>
>> To: "Victor Kaplansky" <victork@redhat.com>, dev@dpdk.org
>> Cc: stable@dpdk.org, "Jens Freimann" <jfreiman@redhat.com>, "Yuanhan Liu" <yliu@fridaylinux.org>, "Tiwei Bie"
>> <tiwei.bie@intel.com>, "Jianfeng Tan" <jianfeng.tan@intel.com>
>> Sent: Thursday, December 14, 2017 2:16:23 PM
>> Subject: Re: [PATCH v3] vhost_user: protect active rings from async ring changes
>>
>> Hi Victor,
>>
>> On 12/14/2017 12:35 PM, Victor Kaplansky wrote:
>>> When performing live migration or memory hot-plugging,
>>> the changes to the device and vrings made by message handler
>>> done independently from vring usage by PMD threads.
>>>
>>> This causes for example segfaults during live-migration
>>> with MQ enable, but in general virtually any request
>>> sent by qemu changing the state of device can cause
>>> problems.
>>>
>>> These patches fixes all above issues by adding a spinlock
>>> to every vring and requiring message handler to start operation
>>> only after ensuring that all PMD threads related to the device
>>> are out of critical section accessing the vring data.
>>>
>>> Each vring has its own lock in order to not create contention
>>> between PMD threads of different vrings and to prevent
>>> performance degradation by scaling queue pair number.
>>>
>>> See https://bugzilla.redhat.com/show_bug.cgi?id=1450680
>>>
>>> Signed-off-by: Victor Kaplansky <victork@redhat.com>
>>> Tested-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>>
>> Sorry, but I didn't tested this patch. I just benchmarked the fact to
>> add a lock in the hot paths.
>>
>>> ---
>>>
>>> v3:
>>>      o Added locking to enqueue flow.
>>>      o Enqueue path guarded as well as dequeue path.
>>>      o Changed name of active_lock.
>>>      o Added initialization of guarding spinlock.
>>>      o Reworked functions skimming over all virt-queues.
>>>      o Performance measurements done by Maxime Coquelin shows
>>>        no degradation in bandwidth and throughput.
>>>      o Spelling.
>>>      o Taking lock only on set operations.
>>>      o IOMMU messages are not guarded by access lock.
>>>
>>> v2:
>>>      o Fixed checkpatch complains.
>>>      o Added Signed-off-by.
>>>      o Refined placement of guard to exclude IOMMU messages.
>>>      o TODO: performance degradation measurement.
>>>
>>>
>>>    lib/librte_vhost/vhost.h      | 15 ++++++++++
>>>    lib/librte_vhost/vhost.c      |  1 +
>>>    lib/librte_vhost/vhost_user.c | 65
>>>    +++++++++++++++++++++++++++++++++++++++++++
>>>    lib/librte_vhost/virtio_net.c | 20 +++++++++++--
>>>    4 files changed, 99 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
>>> index 1cc81c17..26e2c571 100644
>>> --- a/lib/librte_vhost/vhost.h
>>> +++ b/lib/librte_vhost/vhost.h
>>> @@ -137,6 +137,8 @@ struct vhost_virtqueue {
>>>    	TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;
>>>    	int				iotlb_cache_nr;
>>>    	TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;
>>> +
>>> +	rte_spinlock_t	access_lock;
>>
>> On previous revision of the patch, Jianfeng mentioned taking the lock
>> has an impact when nothing to enqueue/dequeue (80 cycles vs. 50 cycles
>> IIRC). I wonder whether moving the lock closer to enabled field would
>> make it be in same cache line and so might improve performance.
> 
> Good point, I'll move it closer to enable.
> 
> 
>>> +	switch (msg.request.master) {
>>> +	case VHOST_USER_SET_FEATURES:
>>> +	case VHOST_USER_SET_PROTOCOL_FEATURES:
>>> +	case VHOST_USER_SET_OWNER:
>>> +	case VHOST_USER_RESET_OWNER:
>>> +	case VHOST_USER_SET_MEM_TABLE:
>>> +	case VHOST_USER_SET_LOG_BASE:
>>> +	case VHOST_USER_SET_LOG_FD:
>>> +	case VHOST_USER_SET_VRING_NUM:
>>> +	case VHOST_USER_SET_VRING_ADDR:
>>> +	case VHOST_USER_SET_VRING_BASE:
>>> +	case VHOST_USER_SET_VRING_KICK:
>>> +	case VHOST_USER_SET_VRING_CALL:
>>> +	case VHOST_USER_SET_VRING_ERR:
>>> +	case VHOST_USER_SET_VRING_ENABLE:
>>
>> For the VRING specific requests, I think we could only take the
>> corresponding VQ lock instead of blocking all queues.
>>
>> There might be some exceptions, like GET_VRING_BASE.
>>
>> Maybe only protecting critical sections would be better?
> 
> I agree in general, but requests are so rare, that I prefer to
> have a robust solution instead of dealing with questionable
> optimizations prone to bugs. Anyway, we can add more fine tuning
> later on case by case basis, as we become aware of more performance
> bottlenecks.

Ok, but take care of avoiding the possible with GET_VRING_BASE as we
discussed on IRC.

>>>    
>>>    #include "iotlb.h"
>>>    #include "vhost.h"
>>> @@ -326,8 +327,11 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t
>>> queue_id,
>>>    	}
>>>    
>>>    	vq = dev->virtqueue[queue_id];
>>> +
>>> +	vhost_user_access_lock(vq);
>> I suggested to use rte_spinlock_trylock() when reviewing previous
>> revision. It would have the advantage to not block other devices being
>> handled on the same CPU whlie handling the message.
>>
>> Any thoughts?
> 
> If we want trylock, we have two options in this case.  One is just
> return zero if trylock fails and give the caller to decide what to
> do: retry, issue an error, or yield the cpu to another thread, etc.
> I don't think any caller of rte_eth_tx_burst in current dpdk source
> doing this. Most frequently it is just considered as an error.

Good point. It could be used for the dequeue path though.
But maybe better not to do it for consistency.

> The second option is to invoke sched_yield() yielding the cpu to
> other threads.  I'm in favor of second option, but looking into
> current dpdk code base I don't see any instances of using
> sched_yield(). Maybe it is for a reason?

Yes, because CPU running PMD threads are likely to be isolated from
kernel scheduling.

Maxime

      reply	other threads:[~2017-12-14 17:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14 11:35 Victor Kaplansky
2017-12-14 12:16 ` Maxime Coquelin
2017-12-14 14:21   ` Victor Kaplansky
2017-12-14 17:28     ` Maxime Coquelin [this message]

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=7253e36a-e41a-f2a7-2395-fe654e7d3ab2@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jfreiman@redhat.com \
    --cc=jianfeng.tan@intel.com \
    --cc=stable@dpdk.org \
    --cc=tiwei.bie@intel.com \
    --cc=vkaplans@redhat.com \
    --cc=yliu@fridaylinux.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).