netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vhost-net: switch to smp barriers
@ 2010-02-01 17:21 Michael S. Tsirkin
  2010-02-07  9:07 ` Michael S. Tsirkin
  2010-02-07  9:42 ` Avi Kivity
  0 siblings, 2 replies; 8+ messages in thread
From: Michael S. Tsirkin @ 2010-02-01 17:21 UTC (permalink / raw)
  To: Michael S. Tsirkin, Rusty Russell, kvm, virtualization, netdev,
	linux-kernel

vhost-net only uses memory barriers to control SMP effects
(communication with userspace potentially running on a different CPU),
so it should use SMP barriers and not mandatory barriers for memory
access ordering, as suggested by Documentation/memory-barriers.txt

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/vhost.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

The above applies on top of net-next-2.6. Does not seem to give any
measureable performance gain, but seems to generate less code
and I think it's better to use correct APIs.

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index c8c25db..6eb1525 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -685,7 +685,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
 	int i, r;
 
 	/* Make sure data written is seen before log. */
-	wmb();
+	smp_wmb();
 	for (i = 0; i < log_num; ++i) {
 		u64 l = min(log[i].len, len);
 		r = log_write(vq->log_base, log[i].addr, l);
@@ -884,7 +884,7 @@ unsigned vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq,
 		return vq->num;
 
 	/* Only get avail ring entries after they have been exposed by guest. */
-	rmb();
+	smp_rmb();
 
 	/* Grab the next descriptor number they're advertising, and increment
 	 * the index we've seen. */
@@ -996,14 +996,14 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len)
 		return -EFAULT;
 	}
 	/* Make sure buffer is written before we update index. */
-	wmb();
+	smp_wmb();
 	if (put_user(vq->last_used_idx + 1, &vq->used->idx)) {
 		vq_err(vq, "Failed to increment used idx");
 		return -EFAULT;
 	}
 	if (unlikely(vq->log_used)) {
 		/* Make sure data is seen before log. */
-		wmb();
+		smp_wmb();
 		log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring *
 			  (vq->last_used_idx % vq->num),
 			  sizeof *vq->used->ring);
@@ -1060,7 +1060,7 @@ bool vhost_enable_notify(struct vhost_virtqueue *vq)
 	}
 	/* They could have slipped one in as we were doing that: make
 	 * sure it's written, then check again. */
-	mb();
+	smp_mb();
 	r = get_user(avail_idx, &vq->avail->idx);
 	if (r) {
 		vq_err(vq, "Failed to check avail idx at %p: %d\n",
-- 
1.6.6.144.g5c3af

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-01 17:21 [PATCH] vhost-net: switch to smp barriers Michael S. Tsirkin
@ 2010-02-07  9:07 ` Michael S. Tsirkin
  2010-02-08  8:19   ` Rusty Russell
  2010-02-07  9:42 ` Avi Kivity
  1 sibling, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2010-02-07  9:07 UTC (permalink / raw)
  To: Rusty Russell, kvm, virtualization, netdev, linux-kernel,
	David Miller

On Mon, Feb 01, 2010 at 07:21:02PM +0200, Michael S. Tsirkin wrote:
> vhost-net only uses memory barriers to control SMP effects
> (communication with userspace potentially running on a different CPU),
> so it should use SMP barriers and not mandatory barriers for memory
> access ordering, as suggested by Documentation/memory-barriers.txt
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>


Rusty, any feedback on this one?
Thanks!

> ---
>  drivers/vhost/vhost.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
> 
> The above applies on top of net-next-2.6. Does not seem to give any
> measureable performance gain, but seems to generate less code
> and I think it's better to use correct APIs.
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index c8c25db..6eb1525 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -685,7 +685,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
>  	int i, r;
>  
>  	/* Make sure data written is seen before log. */
> -	wmb();
> +	smp_wmb();
>  	for (i = 0; i < log_num; ++i) {
>  		u64 l = min(log[i].len, len);
>  		r = log_write(vq->log_base, log[i].addr, l);
> @@ -884,7 +884,7 @@ unsigned vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq,
>  		return vq->num;
>  
>  	/* Only get avail ring entries after they have been exposed by guest. */
> -	rmb();
> +	smp_rmb();
>  
>  	/* Grab the next descriptor number they're advertising, and increment
>  	 * the index we've seen. */
> @@ -996,14 +996,14 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len)
>  		return -EFAULT;
>  	}
>  	/* Make sure buffer is written before we update index. */
> -	wmb();
> +	smp_wmb();
>  	if (put_user(vq->last_used_idx + 1, &vq->used->idx)) {
>  		vq_err(vq, "Failed to increment used idx");
>  		return -EFAULT;
>  	}
>  	if (unlikely(vq->log_used)) {
>  		/* Make sure data is seen before log. */
> -		wmb();
> +		smp_wmb();
>  		log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring *
>  			  (vq->last_used_idx % vq->num),
>  			  sizeof *vq->used->ring);
> @@ -1060,7 +1060,7 @@ bool vhost_enable_notify(struct vhost_virtqueue *vq)
>  	}
>  	/* They could have slipped one in as we were doing that: make
>  	 * sure it's written, then check again. */
> -	mb();
> +	smp_mb();
>  	r = get_user(avail_idx, &vq->avail->idx);
>  	if (r) {
>  		vq_err(vq, "Failed to check avail idx at %p: %d\n",
> -- 
> 1.6.6.144.g5c3af

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-01 17:21 [PATCH] vhost-net: switch to smp barriers Michael S. Tsirkin
  2010-02-07  9:07 ` Michael S. Tsirkin
@ 2010-02-07  9:42 ` Avi Kivity
  2010-02-07  9:44   ` Michael S. Tsirkin
  1 sibling, 1 reply; 8+ messages in thread
From: Avi Kivity @ 2010-02-07  9:42 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Rusty Russell, kvm, virtualization, netdev, linux-kernel,
	David Miller

On 02/01/2010 07:21 PM, Michael S. Tsirkin wrote:
> vhost-net only uses memory barriers to control SMP effects
> (communication with userspace potentially running on a different CPU),
> so it should use SMP barriers and not mandatory barriers for memory
> access ordering, as suggested by Documentation/memory-barriers.txt
>
>    

A UP guest running on an SMP host still needs those barriers.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-07  9:42 ` Avi Kivity
@ 2010-02-07  9:44   ` Michael S. Tsirkin
  2010-02-07  9:56     ` Avi Kivity
  0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2010-02-07  9:44 UTC (permalink / raw)
  To: Avi Kivity
  Cc: Rusty Russell, kvm, virtualization, netdev, linux-kernel,
	David Miller

On Sun, Feb 07, 2010 at 11:42:29AM +0200, Avi Kivity wrote:
> On 02/01/2010 07:21 PM, Michael S. Tsirkin wrote:
>> vhost-net only uses memory barriers to control SMP effects
>> (communication with userspace potentially running on a different CPU),
>> so it should use SMP barriers and not mandatory barriers for memory
>> access ordering, as suggested by Documentation/memory-barriers.txt
>>
>>    
>
> A UP guest running on an SMP host still needs those barriers.

Correct. And since vhost net is running host-side, smp_XX
barriers will do exactly the right thing, right?

> -- 
> error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-07  9:44   ` Michael S. Tsirkin
@ 2010-02-07  9:56     ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2010-02-07  9:56 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Rusty Russell, kvm, virtualization, netdev, linux-kernel,
	David Miller

On 02/07/2010 11:44 AM, Michael S. Tsirkin wrote:
> On Sun, Feb 07, 2010 at 11:42:29AM +0200, Avi Kivity wrote:
>    
>> On 02/01/2010 07:21 PM, Michael S. Tsirkin wrote:
>>      
>>> vhost-net only uses memory barriers to control SMP effects
>>> (communication with userspace potentially running on a different CPU),
>>> so it should use SMP barriers and not mandatory barriers for memory
>>> access ordering, as suggested by Documentation/memory-barriers.txt
>>>
>>>
>>>        
>> A UP guest running on an SMP host still needs those barriers.
>>      
> Correct. And since vhost net is running host-side, smp_XX
> barriers will do exactly the right thing, right?
>    

Right, of course.  Mixed up virtio and vhost.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-07  9:07 ` Michael S. Tsirkin
@ 2010-02-08  8:19   ` Rusty Russell
  2010-02-13 17:39     ` Michael S. Tsirkin
  0 siblings, 1 reply; 8+ messages in thread
From: Rusty Russell @ 2010-02-08  8:19 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: kvm, virtualization, netdev, linux-kernel, David Miller

On Sun, 7 Feb 2010 07:37:49 pm Michael S. Tsirkin wrote:
> On Mon, Feb 01, 2010 at 07:21:02PM +0200, Michael S. Tsirkin wrote:
> > vhost-net only uses memory barriers to control SMP effects
> > (communication with userspace potentially running on a different CPU),
> > so it should use SMP barriers and not mandatory barriers for memory
> > access ordering, as suggested by Documentation/memory-barriers.txt
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> 
> Rusty, any feedback on this one?
> Thanks!

Yep.  barrier() is correct on UP to guard against preemption.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>

Thanks,
Rusty.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-08  8:19   ` Rusty Russell
@ 2010-02-13 17:39     ` Michael S. Tsirkin
  2010-02-14 19:55       ` David Miller
  0 siblings, 1 reply; 8+ messages in thread
From: Michael S. Tsirkin @ 2010-02-13 17:39 UTC (permalink / raw)
  To: Rusty Russell; +Cc: kvm, virtualization, netdev, linux-kernel, David Miller

On Mon, Feb 08, 2010 at 06:49:39PM +1030, Rusty Russell wrote:
> On Sun, 7 Feb 2010 07:37:49 pm Michael S. Tsirkin wrote:
> > On Mon, Feb 01, 2010 at 07:21:02PM +0200, Michael S. Tsirkin wrote:
> > > vhost-net only uses memory barriers to control SMP effects
> > > (communication with userspace potentially running on a different CPU),
> > > so it should use SMP barriers and not mandatory barriers for memory
> > > access ordering, as suggested by Documentation/memory-barriers.txt
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > 
> > 
> > Rusty, any feedback on this one?
> > Thanks!
> 
> Yep.  barrier() is correct on UP to guard against preemption.
> 
> Acked-by: Rusty Russell <rusty@rustcorp.com.au>
> 
> Thanks,
> Rusty.

Dave, I see it's marked "not applicable":
http://patchwork.ozlabs.org/patch/44207/
the patch applies to net-next as of
b3b3f04fb587ecb61b5baa6c1c5f0e666fd12d73.
Can this be queued up please?
Should I resubmit with Rusty's ack?

Thanks!

-- 
MST

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vhost-net: switch to smp barriers
  2010-02-13 17:39     ` Michael S. Tsirkin
@ 2010-02-14 19:55       ` David Miller
  0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2010-02-14 19:55 UTC (permalink / raw)
  To: mst; +Cc: rusty, kvm, virtualization, netdev, linux-kernel

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Sat, 13 Feb 2010 19:39:11 +0200

> Dave, I see it's marked "not applicable":
> http://patchwork.ozlabs.org/patch/44207/
> the patch applies to net-next as of
> b3b3f04fb587ecb61b5baa6c1c5f0e666fd12d73.
> Can this be queued up please?
> Should I resubmit with Rusty's ack?

Sorry about that, I must have thought Rusty would queue
it up.

I'll fix the state to under-review and process it in my
backlog.

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-02-14 19:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-01 17:21 [PATCH] vhost-net: switch to smp barriers Michael S. Tsirkin
2010-02-07  9:07 ` Michael S. Tsirkin
2010-02-08  8:19   ` Rusty Russell
2010-02-13 17:39     ` Michael S. Tsirkin
2010-02-14 19:55       ` David Miller
2010-02-07  9:42 ` Avi Kivity
2010-02-07  9:44   ` Michael S. Tsirkin
2010-02-07  9:56     ` Avi Kivity

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).