Skip to contentSkip to conversation

virtio/ringtest: fix up need_event math

PATCH In review Michael S. Tsirkin 3 participants 6 messages Oct 26, 2017 – Oct 27, 2017 virtio core

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio/ringtest: fix up need_event math

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

---
 tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
tools/virtio/ringtest/ring.c +15 -9
index 6b70c4e..d044a88 100644
@@ -196,16 +196,18 @@ bool enable_call()
 
 void kick_available(void)
 {
+	bool need;
+
 	/* Flush in previous flags write */
 	/* Barrier C (for pairing) */
 	smp_mb();
-	if (!need_event(event->kick_index,
-			guest.avail_idx,
-			guest.kicked_avail_idx))
-		return;
+	need = need_event(event->kick_index,
+			   guest.avail_idx,
+			   guest.kicked_avail_idx);
 
 	guest.kicked_avail_idx = guest.avail_idx;
-	kick();
+	if (need)
+		kick();
 }
 
 /* host side */
@@ -265,14 +267,18 @@ bool use_buf(unsigned *lenp, void **bufp)
 
 void call_used(void)
 {
+	bool need;
+
 	/* Flush in previous flags write */
 	/* Barrier D (for pairing) */
 	smp_mb();
-	if (!need_event(event->call_index,
+
+	need = !need_event(event->call_index,
 			host.used_idx,
-			host.called_used_idx))
-		return;
+			host.called_used_idx);
 
 	host.called_used_idx = host.used_idx;
-	call();
+
+	if (need)
+		call();
 }
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Thu, 26 Oct 2017 04:48:01 +0300 "Michael S. Tsirkin" <[email protected]> wrote:

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

---
 tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

I think virtio_ring_0_9 has the same issue?

Acked-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · On Thu, 26 Oct 2017 04:48:01 +0300 "Michael S. Tsirkin" <[email protected]> wrote:

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

---
 tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

I think virtio_ring_0_9 has the same issue?

Acked-by on v1 1/1
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 50 lines · Michael S. Tsirkin

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

---
  tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
  1 file changed, 15 insertions(+), 9 deletions(-)
tools/virtio/ringtest/ring.c +11 -6
index 6b70c4e..d044a88 100644
@@ -196,16 +196,18 @@ bool enable_call()
 
  void kick_available(void)
  {
+	bool need;
+
  	/* Flush in previous flags write */
  	/* Barrier C (for pairing) */
  	smp_mb();
-	if (!need_event(event->kick_index,
-			guest.avail_idx,
-			guest.kicked_avail_idx))
-		return;
+	need = need_event(event->kick_index,
+			   guest.avail_idx,
+			   guest.kicked_avail_idx);
 
  	guest.kicked_avail_idx = guest.avail_idx;
-	kick();
+	if (need)
+		kick();
  }
 
  /* host side */
@@ -265,14 +267,18 @@ bool use_buf(unsigned *lenp, void **bufp)
 
  void call_used(void)
  {
+	bool need;
+
  	/* Flush in previous flags write */
  	/* Barrier D (for pairing) */
  	smp_mb();
-	if (!need_event(event->call_index,
+
+	need = !need_event(event->call_index,
  			host.used_idx,

tools/virtio/ringtest/ring.c bool use_buf(unsigned *lenp, void **bufp) · line 284

Quoted 10 lines
tools/virtio/ringtest/ring.c +4 -3
-			host.called_used_idx))
-		return;
+			host.called_used_idx);
 
  	host.called_used_idx = host.used_idx;
-	call();
+
+	if (need)
+		call();
  }

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 1/1
#5 lore raw
In reply to Michael S. Tsirkin
Quoted 50 lines · Michael S. Tsirkin

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

---
  tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
  1 file changed, 15 insertions(+), 9 deletions(-)
tools/virtio/ringtest/ring.c +11 -6
index 6b70c4e..d044a88 100644
@@ -196,16 +196,18 @@ bool enable_call()
 
  void kick_available(void)
  {
+	bool need;
+
  	/* Flush in previous flags write */
  	/* Barrier C (for pairing) */
  	smp_mb();
-	if (!need_event(event->kick_index,
-			guest.avail_idx,
-			guest.kicked_avail_idx))
-		return;
+	need = need_event(event->kick_index,
+			   guest.avail_idx,
+			   guest.kicked_avail_idx);
 
  	guest.kicked_avail_idx = guest.avail_idx;
-	kick();
+	if (need)
+		kick();
  }
 
  /* host side */
@@ -265,14 +267,18 @@ bool use_buf(unsigned *lenp, void **bufp)
 
  void call_used(void)
  {
+	bool need;
+
  	/* Flush in previous flags write */
  	/* Barrier D (for pairing) */
  	smp_mb();
-	if (!need_event(event->call_index,
+
+	need = !need_event(event->call_index,
  			host.used_idx,

tools/virtio/ringtest/ring.c bool use_buf(unsigned *lenp, void **bufp) · line 284

Quoted 10 lines
tools/virtio/ringtest/ring.c +4 -3
-			host.called_used_idx))
-		return;
+			host.called_used_idx);
 
  	host.called_used_idx = host.used_idx;
-	call();
+
+	if (need)
+		call();
  }
author maintainer
#3 lore raw
In reply to Cornelia Huck
Quoted 7 lines · Cornelia Huck
Quoted 4 lines · On Thu, 26 Oct 2017 04:48:01 +0300 "Michael S. Tsirkin" <[email protected]> wrote:

last kicked event index must be updated unconditionally:
even if we don't need to kick, we do not want to re-check the same entry for events.

Quoted 6 lines
Quoted 4 lines
---
 tools/virtio/ringtest/ring.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Actually it seems to sometimes trigger stalls when host and guest are on the same physical core. To trigger:

./ring --sleep --host-affinity 0 --guest-affinity 0

This worries me since it's similar to what vhost does.

Still debugging - anyone see anything suspicious?

Quoted 1 line

I think virtio_ring_0_9 has the same issue?

I think it does, posted a patch.

Signature · 1 line
MST