All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
@ 2015-07-07  6:30 Fam Zheng
  2015-07-07  8:37 ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Fam Zheng @ 2015-07-07  6:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Stefan Hajnoczi

This moves the semantics from net_hub_port_can_receive to receive
functions, by returning 0 if all receiving ports return 0. Also,
remember to flush the source port's queue in that case.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/net/hub.c b/net/hub.c
index 3047f12..5697fad 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -31,6 +31,7 @@ typedef struct NetHubPort {
     QLIST_ENTRY(NetHubPort) next;
     NetHub *hub;
     int id;
+    bool needs_flush;
 } NetHubPort;
 
 struct NetHub {
@@ -42,35 +43,58 @@ struct NetHub {
 
 static QLIST_HEAD(, NetHub) hubs = QLIST_HEAD_INITIALIZER(&hubs);
 
+static void net_hub_port_send_cb(NetClientState *nc, ssize_t ret)
+{
+    NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
+    NetHub *hub = port->hub;
+
+    QLIST_FOREACH(port, &hub->ports, next) {
+        if (port->needs_flush) {
+            port->needs_flush = false;
+            qemu_flush_queued_packets(&port->nc);
+        }
+    }
+}
+
 static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port,
                                const uint8_t *buf, size_t len)
 {
     NetHubPort *port;
+    ssize_t ret = -1;
 
     QLIST_FOREACH(port, &hub->ports, next) {
+        ssize_t r;
         if (port == source_port) {
             continue;
         }
 
-        qemu_send_packet(&port->nc, buf, len);
+        r = qemu_send_packet_async(&port->nc, buf, len,
+                                   net_hub_port_send_cb);
+        ret = MAX(r, ret);
     }
-    return len;
+    source_port->needs_flush = ret == 0;
+
+    return ret;
 }
 
 static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
                                    const struct iovec *iov, int iovcnt)
 {
     NetHubPort *port;
-    ssize_t len = iov_size(iov, iovcnt);
+    ssize_t ret = -1;
 
     QLIST_FOREACH(port, &hub->ports, next) {
+        ssize_t r;
         if (port == source_port) {
             continue;
         }
 
-        qemu_sendv_packet(&port->nc, iov, iovcnt);
+        r = qemu_sendv_packet_async(&port->nc, iov,
+                                    iovcnt, net_hub_port_send_cb);
+        ret = MAX(r, ret);
     }
-    return len;
+    source_port->needs_flush = ret == 0;
+    return ret;
 }
 
 static NetHub *net_hub_new(int id)
@@ -87,25 +111,6 @@ static NetHub *net_hub_new(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 1;
-        }
-    }
-
-    return 0;
-}
-
 static ssize_t net_hub_port_receive(NetClientState *nc,
                                     const uint8_t *buf, size_t len)
 {
@@ -132,7 +137,6 @@ static void net_hub_port_cleanup(NetClientState *nc)
 static NetClientInfo net_hub_port_info = {
     .type = NET_CLIENT_OPTIONS_KIND_HUBPORT,
     .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,
-- 
2.4.3

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-07  6:30 [Qemu-devel] [PATCH v2] net-hub: Drop can_receive Fam Zheng
@ 2015-07-07  8:37 ` Stefan Hajnoczi
  2015-07-07  9:41   ` Fam Zheng
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2015-07-07  8:37 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Jason Wang, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 882 bytes --]

On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> This moves the semantics from net_hub_port_can_receive to receive
> functions, by returning 0 if all receiving ports return 0. Also,
> remember to flush the source port's queue in that case.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
>  1 file changed, 29 insertions(+), 25 deletions(-)

This patch revision doesn't take into account the special case code in
qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
the previous revision of this patch.

The queue is now flushed twice because you've introduced
net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
calls net_hub_flush().

If you want to get rid of net_hub_flush(), that's great.  But please
remove the duplicate code.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-07  8:37 ` Stefan Hajnoczi
@ 2015-07-07  9:41   ` Fam Zheng
  2015-07-20 17:07     ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Fam Zheng @ 2015-07-07  9:41 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Jason Wang, qemu-devel

On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
> On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> > This moves the semantics from net_hub_port_can_receive to receive
> > functions, by returning 0 if all receiving ports return 0. Also,
> > remember to flush the source port's queue in that case.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
> >  1 file changed, 29 insertions(+), 25 deletions(-)
> 
> This patch revision doesn't take into account the special case code in
> qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
> the previous revision of this patch.
> 
> The queue is now flushed twice because you've introduced
> net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
> calls net_hub_flush().
> 
> If you want to get rid of net_hub_flush(), that's great.  But please
> remove the duplicate code.

Right, I missed that. I'll remove the duplicate and send again.

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-07  9:41   ` Fam Zheng
@ 2015-07-20 17:07     ` Stefan Hajnoczi
  2015-07-21  1:27       ` Fam Zheng
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2015-07-20 17:07 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Jason Wang, qemu-devel, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 1149 bytes --]

On Tue, Jul 07, 2015 at 05:41:56PM +0800, Fam Zheng wrote:
> On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
> > On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> > > This moves the semantics from net_hub_port_can_receive to receive
> > > functions, by returning 0 if all receiving ports return 0. Also,
> > > remember to flush the source port's queue in that case.
> > > 
> > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > ---
> > >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
> > >  1 file changed, 29 insertions(+), 25 deletions(-)
> > 
> > This patch revision doesn't take into account the special case code in
> > qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
> > the previous revision of this patch.
> > 
> > The queue is now flushed twice because you've introduced
> > net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
> > calls net_hub_flush().
> > 
> > If you want to get rid of net_hub_flush(), that's great.  But please
> > remove the duplicate code.
> 
> Right, I missed that. I'll remove the duplicate and send again.

Ping?

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-20 17:07     ` Stefan Hajnoczi
@ 2015-07-21  1:27       ` Fam Zheng
  2015-07-21  8:36         ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Fam Zheng @ 2015-07-21  1:27 UTC (permalink / raw)
  To: Stefan Hajnoczi, stefanha; +Cc: Jason Wang, qemu-devel

On Mon, 07/20 18:07, Stefan Hajnoczi wrote:
> On Tue, Jul 07, 2015 at 05:41:56PM +0800, Fam Zheng wrote:
> > On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
> > > On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> > > > This moves the semantics from net_hub_port_can_receive to receive
> > > > functions, by returning 0 if all receiving ports return 0. Also,
> > > > remember to flush the source port's queue in that case.
> > > > 
> > > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > > ---
> > > >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
> > > >  1 file changed, 29 insertions(+), 25 deletions(-)
> > > 
> > > This patch revision doesn't take into account the special case code in
> > > qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
> > > the previous revision of this patch.
> > > 
> > > The queue is now flushed twice because you've introduced
> > > net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
> > > calls net_hub_flush().
> > > 
> > > If you want to get rid of net_hub_flush(), that's great.  But please
> > > remove the duplicate code.
> > 
> > Right, I missed that. I'll remove the duplicate and send again.
> 
> Ping?

I thought the net_hub_flush in qemu_flush_or_purge_queued_packets already makes
sure net-hub is working, so it's just about cleaning up. That's why I deferred
this to 2.5.  Am I wrong?

Fam

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-21  1:27       ` Fam Zheng
@ 2015-07-21  8:36         ` Stefan Hajnoczi
  2015-07-21  8:54           ` Fam Zheng
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2015-07-21  8:36 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Stefan Hajnoczi, Jason Wang, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

On Tue, Jul 21, 2015 at 09:27:56AM +0800, Fam Zheng wrote:
> On Mon, 07/20 18:07, Stefan Hajnoczi wrote:
> > On Tue, Jul 07, 2015 at 05:41:56PM +0800, Fam Zheng wrote:
> > > On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
> > > > On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> > > > > This moves the semantics from net_hub_port_can_receive to receive
> > > > > functions, by returning 0 if all receiving ports return 0. Also,
> > > > > remember to flush the source port's queue in that case.
> > > > > 
> > > > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > > > ---
> > > > >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
> > > > >  1 file changed, 29 insertions(+), 25 deletions(-)
> > > > 
> > > > This patch revision doesn't take into account the special case code in
> > > > qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
> > > > the previous revision of this patch.
> > > > 
> > > > The queue is now flushed twice because you've introduced
> > > > net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
> > > > calls net_hub_flush().
> > > > 
> > > > If you want to get rid of net_hub_flush(), that's great.  But please
> > > > remove the duplicate code.
> > > 
> > > Right, I missed that. I'll remove the duplicate and send again.
> > 
> > Ping?
> 
> I thought the net_hub_flush in qemu_flush_or_purge_queued_packets already makes
> sure net-hub is working, so it's just about cleaning up. That's why I deferred
> this to 2.5.  Am I wrong?

My concern was that your NIC patches remove .can_receive() functions but
net/hub.c still relies on them via qemu_can_send_packet().

After thinking about it more, the code should still work the same even
though net_hub_can_receive() is now mostly useless and should be removed
in QEMU 2.5.

We can leave this patch for now.

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-21  8:36         ` Stefan Hajnoczi
@ 2015-07-21  8:54           ` Fam Zheng
  2015-07-21 11:54             ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Fam Zheng @ 2015-07-21  8:54 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Stefan Hajnoczi, Jason Wang, qemu-devel

On Tue, 07/21 09:36, Stefan Hajnoczi wrote:
> On Tue, Jul 21, 2015 at 09:27:56AM +0800, Fam Zheng wrote:
> > On Mon, 07/20 18:07, Stefan Hajnoczi wrote:
> > > On Tue, Jul 07, 2015 at 05:41:56PM +0800, Fam Zheng wrote:
> > > > On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
> > > > > On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
> > > > > > This moves the semantics from net_hub_port_can_receive to receive
> > > > > > functions, by returning 0 if all receiving ports return 0. Also,
> > > > > > remember to flush the source port's queue in that case.
> > > > > > 
> > > > > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > > > > ---
> > > > > >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
> > > > > >  1 file changed, 29 insertions(+), 25 deletions(-)
> > > > > 
> > > > > This patch revision doesn't take into account the special case code in
> > > > > qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
> > > > > the previous revision of this patch.
> > > > > 
> > > > > The queue is now flushed twice because you've introduced
> > > > > net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
> > > > > calls net_hub_flush().
> > > > > 
> > > > > If you want to get rid of net_hub_flush(), that's great.  But please
> > > > > remove the duplicate code.
> > > > 
> > > > Right, I missed that. I'll remove the duplicate and send again.
> > > 
> > > Ping?
> > 
> > I thought the net_hub_flush in qemu_flush_or_purge_queued_packets already makes
> > sure net-hub is working, so it's just about cleaning up. That's why I deferred
> > this to 2.5.  Am I wrong?
> 
> My concern was that your NIC patches remove .can_receive() functions but
> net/hub.c still relies on them via qemu_can_send_packet().
> 
> After thinking about it more, the code should still work the same even
> though net_hub_can_receive() is now mostly useless and should be removed
> in QEMU 2.5.

Yes. Completely removing .can_receive from the code base for 2.5 is trivial if
the proposed fixes are correct, but it doesn't matter much now.

> 
> We can leave this patch for now.

OK, so net-hub is cleared, please proceed with merging the bulk .can_receive
series, or if there are other issues, revert the qemu_set_fd_handler .can_send
patches and I'll redo it in 2.5.

Fam

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

* Re: [Qemu-devel] [PATCH v2] net-hub: Drop can_receive
  2015-07-21  8:54           ` Fam Zheng
@ 2015-07-21 11:54             ` Stefan Hajnoczi
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2015-07-21 11:54 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Jason Wang, qemu-devel, Stefan Hajnoczi

On Tue, Jul 21, 2015 at 9:54 AM, Fam Zheng <famz@redhat.com> wrote:
> On Tue, 07/21 09:36, Stefan Hajnoczi wrote:
>> On Tue, Jul 21, 2015 at 09:27:56AM +0800, Fam Zheng wrote:
>> > On Mon, 07/20 18:07, Stefan Hajnoczi wrote:
>> > > On Tue, Jul 07, 2015 at 05:41:56PM +0800, Fam Zheng wrote:
>> > > > On Tue, 07/07 09:37, Stefan Hajnoczi wrote:
>> > > > > On Tue, Jul 07, 2015 at 02:30:30PM +0800, Fam Zheng wrote:
>> > > > > > This moves the semantics from net_hub_port_can_receive to receive
>> > > > > > functions, by returning 0 if all receiving ports return 0. Also,
>> > > > > > remember to flush the source port's queue in that case.
>> > > > > >
>> > > > > > Signed-off-by: Fam Zheng <famz@redhat.com>
>> > > > > > ---
>> > > > > >  net/hub.c | 54 +++++++++++++++++++++++++++++-------------------------
>> > > > > >  1 file changed, 29 insertions(+), 25 deletions(-)
>> > > > >
>> > > > > This patch revision doesn't take into account the special case code in
>> > > > > qemu_flush_or_purge_queued_packets(), which I mentioned in my reply to
>> > > > > the previous revision of this patch.
>> > > > >
>> > > > > The queue is now flushed twice because you've introduced
>> > > > > net_hub_port_send_cb() but qemu_flush_or_purge_queued_packets() already
>> > > > > calls net_hub_flush().
>> > > > >
>> > > > > If you want to get rid of net_hub_flush(), that's great.  But please
>> > > > > remove the duplicate code.
>> > > >
>> > > > Right, I missed that. I'll remove the duplicate and send again.
>> > >
>> > > Ping?
>> >
>> > I thought the net_hub_flush in qemu_flush_or_purge_queued_packets already makes
>> > sure net-hub is working, so it's just about cleaning up. That's why I deferred
>> > this to 2.5.  Am I wrong?
>>
>> My concern was that your NIC patches remove .can_receive() functions but
>> net/hub.c still relies on them via qemu_can_send_packet().
>>
>> After thinking about it more, the code should still work the same even
>> though net_hub_can_receive() is now mostly useless and should be removed
>> in QEMU 2.5.
>
> Yes. Completely removing .can_receive from the code base for 2.5 is trivial if
> the proposed fixes are correct, but it doesn't matter much now.
>
>>
>> We can leave this patch for now.
>
> OK, so net-hub is cleared, please proceed with merging the bulk .can_receive
> series, or if there are other issues, revert the qemu_set_fd_handler .can_send
> patches and I'll redo it in 2.5.

By the way, as part of getting rid of qemu_can_send_packet() it would
be good to simplify things so all logic whether to queue or deliver is
in one place.  Right now it's spread across qemu_deliver_packet(),
qemu_can_send_packet(), and qemu_send_packet_async_with_flags().

We didn't notice buggy NICs without flush calls previously because
net/net.c uses a mixture of "polling" (checking conditions for each
packet) and "blocking" (setting receive_disabled and only clearing it
upon flush).  Things seemed to work due to the polling code paths.

When we started hitting the blocking code path it became apparent that
flushes were missing.

Stefan

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

end of thread, other threads:[~2015-07-21 11:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07  6:30 [Qemu-devel] [PATCH v2] net-hub: Drop can_receive Fam Zheng
2015-07-07  8:37 ` Stefan Hajnoczi
2015-07-07  9:41   ` Fam Zheng
2015-07-20 17:07     ` Stefan Hajnoczi
2015-07-21  1:27       ` Fam Zheng
2015-07-21  8:36         ` Stefan Hajnoczi
2015-07-21  8:54           ` Fam Zheng
2015-07-21 11:54             ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.