Skip to contentSkip to conversation

hub: add the support for hub own flow control

PATCH In review [email protected] 3 participants 5 messages May 25, 2012 – May 26, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 16/16 hub: add the support for hub own flow control

From: Zhi Yong Wu <[email protected]>

Only when all other hub port's *peer* .can_receive() all return 1, the source hub port .can_receive() return 1.

---
 net/hub.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
net/hub.c +24 -3
index 357ca87..478cce1 100644
@@ -15,6 +15,7 @@
 #include "monitor.h"
 #include "net.h"
 #include "hub.h"
+#include "iov.h"
 
 /*
  * A hub broadcasts incoming packets to all its ports except the source port.
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                    const struct iovec *iov, int iovcnt)
 {
     NetHubPort *port;
-    ssize_t ret = 0;
+    ssize_t len = iov_size(iov, iovcnt);
 
     QLIST_FOREACH(port, &hub->ports, next) {
         if (port == source_port) {
             continue;
         }
 
-        ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
+        qemu_sendv_packet(&port->nc, iov, iovcnt);
     }
-    return ret;
+    return len;
 }
 
 static NetHub *net_hub_new(unsigned int id)
@@ -85,6 +86,25 @@ static NetHub *net_hub_new(unsigned int id)
     return hub;
 }
 
+static int net_hub_port_can_receive(NetClientState *nc)
+{
+    NetHubPort *port;
+    NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc);
+    NetHub *hub = src_port->hub;
+
+    QLIST_FOREACH(port, &hub->ports, next) {
+        if (port == src_port) {
+            continue;
+        }
+
+        if (!qemu_can_send_packet(&port->nc)) {
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
 static ssize_t net_hub_port_receive(NetClientState *nc,
                                     const uint8_t *buf, size_t len)
 {
@@ -111,6 +131,7 @@ static void net_hub_port_cleanup(NetClientState *nc)
 static NetClientInfo net_hub_port_info = {
     .type = NET_CLIENT_TYPE_HUB,
     .size = sizeof(NetHubPort),
+    .can_receive = net_hub_port_can_receive,
     .receive = net_hub_port_receive,
     .receive_iov = net_hub_port_receive_iov,
     .cleanup = net_hub_port_cleanup,
Signature · 1 line
1.7.6
maintainer
#1 lore raw

Il 25/05/2012 12:52, [email protected] ha scritto:

Quoted 25 lines

From: Zhi Yong Wu <[email protected]>

Only when all other hub port's *peer* .can_receive() all return 1, the source hub port .can_receive() return 1.

---
 net/hub.c |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)
net/hub.c +1 -0
index 357ca87..478cce1 100644
@@ -15,6 +15,7 @@
 #include "monitor.h"
 #include "net.h"
 #include "hub.h"
+#include "iov.h"
 
 /*
  * A hub broadcasts incoming packets to all its ports except the source port.
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                    const struct iovec *iov, int iovcnt)
 {
     NetHubPort *port;

net/hub.c static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, · line 70

Quoted 10 lines
net/hub.c +2 -2
-    ssize_t ret = 0;
+    ssize_t len = iov_size(iov, iovcnt);
 
     QLIST_FOREACH(port, &hub->ports, next) {
         if (port == source_port) {
             continue;
         }
 
-        ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
+        qemu_sendv_packet(&port->nc, iov, iovcnt);

I think you still need to apply flow control, otherwise you're cheating.
But perhaps this is acceptable, I'll leave it to more expert people.

Paolo

#2 lore raw
Quoted 34 lines · Paolo Bonzini

Il 25/05/2012 12:52, [email protected] ha scritto:

Quoted 33 lines

From: Zhi Yong Wu <[email protected]>

Only when all other hub port's *peer* .can_receive() all return 1, the source hub port .can_receive() return 1.

---
 net/hub.c |   27 ++++++++++++++++++++++++---

 1 files changed, 24 insertions(+), 3 deletions(-)
net/hub.c +2 -1
index 357ca87..478cce1 100644
@@ -15,6 +15,7 @@
  #include "monitor.h"
  #include "net.h"
  #include "hub.h"
+#include "iov.h"
 
  /*
   * A hub broadcasts incoming packets to all its ports except the source port.
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                     const struct iovec *iov, int iovcnt)
  {
      NetHubPort *port;
-    ssize_t ret = 0;
+    ssize_t len = iov_size(iov, iovcnt);
 
      QLIST_FOREACH(port, &hub->ports, next) {
          if (port == source_port) {
              continue;
          }
 
Quoted 5 lines

net/hub.c static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, · line 70

Quoted 2 lines
net/hub.c +1 -1
-        ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
+        qemu_sendv_packet(&port->nc, iov, iovcnt);

I think you still need to apply flow control, otherwise you're cheating. But perhaps this is acceptable, I'll leave it to more expert people.

Great. thanks. any comments for other patches?

Quoted 2 lines

Paolo

Signature · 3 lines
Regards,

Zhi Yong Wu
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, May 25, 2012 at 06:52:14PM +0800, [email protected] wrote:
net/hub.c +1 -1
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                    const struct iovec *iov, int iovcnt)
 {
     NetHubPort *port;
-    ssize_t ret = 0;
+    ssize_t len = iov_size(iov, iovcnt);
 
     QLIST_FOREACH(port, &hub->ports, next) {

net/hub.c static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, · line 73

Quoted 10 lines
net/hub.c +2 -2
         if (port == source_port) {
             continue;
         }
 
-        ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
+        qemu_sendv_packet(&port->nc, iov, iovcnt);
     }
-    return ret;
+    return len;
 }

I think this is okay because at this point we've given it our best shot:
we already checked that port peers can receive. If they error out now there's not much we can do. The packet is dropped for that particular peer but at least we tried to deliver it when they claimed to be ready.

Stefan

#4 lore raw
Quoted 13 lines · Stefan Hajnoczi
Quoted 12 lines · On Fri, May 25, 2012 at 06:52:14PM +0800, [email protected] wrote:
net/hub.c +1 -1
@@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                     const struct iovec *iov, int iovcnt)
  {
      NetHubPort *port;
-    ssize_t ret = 0;
+    ssize_t len = iov_size(iov, iovcnt);
 
      QLIST_FOREACH(port, &hub->ports, next) {
          if (port == source_port) {
              continue;
          }
 
Quoted 11 lines

net/hub.c static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, · line 73

Quoted 6 lines
net/hub.c +2 -2
-        ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
+        qemu_sendv_packet(&port->nc, iov, iovcnt);
      }
-    return ret;
+    return len;
  }

I think this is okay because at this point we've given it our best shot:
we already checked that port peers can receive.  If they error out now there's not much we can do.  The packet is dropped for that particular peer but at least we tried to deliver it when they claimed to be ready.

Yeah, i think that he is lack of enough understanding on net subsystem code. He can't see that his thought brought a lot of issues.

Quoted 3 lines

Stefan

Signature · 3 lines
Regards,

Zhi Yong Wu