From: Paolo Bonzini <pbonzini@redhat.com>
To: zwu.kernel@gmail.com
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
stefanha@linux.vnet.ibm.com, jan.kiszka@siemens.com,
wuzhy@linux.vnet.ibm.com
Subject: Re: [PATCH v3 16/16] hub: add the support for hub own flow control
Date: Fri, 25 May 2012 09:04:12 +0200 [thread overview]
Message-ID: <4FBF2EEC.5090202@redhat.com> (raw)
In-Reply-To: <1337882362-20100-17-git-send-email-zwu.kernel@gmail.com>
Il 24/05/2012 19:59, zwu.kernel@gmail.com ha scritto:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>
> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> ---
> net/hub.c | 35 ++++++++++++++++++++++++++++++++---
> net/hub.h | 2 ++
> net/queue.c | 5 +++++
> 3 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/net/hub.c b/net/hub.c
> index 8a583ab..d27c52a 100644
> --- a/net/hub.c
> +++ b/net/hub.c
> @@ -28,6 +28,7 @@ typedef struct NetHubPort {
> QLIST_ENTRY(NetHubPort) next;
> NetHub *hub;
> unsigned int id;
> + uint64_t nr_packets;
> } NetHubPort;
>
> struct NetHub {
> @@ -39,19 +40,37 @@ struct NetHub {
>
> static QLIST_HEAD(, NetHub) hubs = QLIST_HEAD_INITIALIZER(&hubs);
>
> +static void net_hub_receive_completed(NetClientState *nc, ssize_t len)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> + port->nr_packets--;
> + if (!port->nr_packets) {
> + qemu_net_queue_flush(nc->peer->send_queue);
> + }
> +}
> +
> +void net_hub_port_packet_stats(NetClientState *nc)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> +
> + port->nr_packets++;
> +}
Isn't this being called also for non-hubport clients?
> static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port,
> const uint8_t *buf, size_t len)
> {
> NetHubPort *port;
> + ssize_t ret = 0;
>
> QLIST_FOREACH(port, &hub->ports, next) {
> if (port == source_port) {
> continue;
> }
>
> - qemu_send_packet(&port->nc, buf, len);
> + ret = qemu_send_packet_async(&port->nc, buf, len,
> + net_hub_receive_completed);
Just increment nr_packets here:
ret = qemu_send_packet_async
if (ret == 0) {
port->nr_packets++;
}
> }
> - return len;
> + return ret;
You can return len here. In fact returning ret is wrong because the
value comes from a random port (the last one).
> }
>
> static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
> @@ -65,7 +84,8 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
> continue;
> }
>
> - ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
> + ret = qemu_sendv_packet_async(&port->nc, iov, iovcnt,
> + net_hub_receive_completed);
Same here (increment nr_packets)
> }
> return ret;
Same here (return len).
> }
> @@ -84,6 +104,13 @@ static NetHub *net_hub_new(unsigned int id)
> return hub;
> }
>
> +static int net_hub_port_can_receive(NetClientState *nc)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> +
> + return port->nr_packets ? 0 : 1;
> +}
This is "return port->nr_packets == 0;".
But I think you need to implement this on the hub rather than on the
port, and return true only if port->nr_packets == 0 for all ports.
Probably you can move nr_packets to the hub itself rather than the port?
> static ssize_t net_hub_port_receive(NetClientState *nc,
> const uint8_t *buf, size_t len)
> {
> @@ -110,6 +137,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,
> @@ -128,6 +156,7 @@ static NetHubPort *net_hub_port_new(NetHub *hub)
> port = DO_UPCAST(NetHubPort, nc, nc);
> port->id = id;
> port->hub = hub;
> + port->nr_packets = 0;
>
> QLIST_INSERT_HEAD(&hub->ports, port, next);
>
Everything below this has to go away (sender is not necessarily a hub
port!).
> diff --git a/net/hub.h b/net/hub.h
> index d04f1b1..542e657 100644
> --- a/net/hub.h
> +++ b/net/hub.h
> @@ -23,4 +23,6 @@ void net_hub_info(Monitor *mon);
> int net_hub_id_for_client(NetClientState *nc, unsigned int *id);
> void net_hub_check_clients(void);
>
> +void net_hub_port_packet_stats(NetClientState *nc);
> +
> #endif /* NET_HUB_H */
> diff --git a/net/queue.c b/net/queue.c
> index 7484d2a..ebf18aa 100644
> --- a/net/queue.c
> +++ b/net/queue.c
> @@ -22,6 +22,7 @@
> */
>
> #include "net/queue.h"
> +#include "net/hub.h"
> #include "qemu-queue.h"
> #include "net.h"
>
> @@ -101,6 +102,8 @@ static ssize_t qemu_net_queue_append(NetQueue *queue,
>
> QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
>
> + net_hub_port_packet_stats(sender);
> +
> return size;
> }
>
> @@ -134,6 +137,8 @@ static ssize_t qemu_net_queue_append_iov(NetQueue *queue,
>
> QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
>
> + net_hub_port_packet_stats(sender);
> +
> return packet->size;
> }
>
WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: zwu.kernel@gmail.com
Cc: jan.kiszka@siemens.com, wuzhy@linux.vnet.ibm.com,
qemu-devel@nongnu.org, kvm@vger.kernel.org,
stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v3 16/16] hub: add the support for hub own flow control
Date: Fri, 25 May 2012 09:04:12 +0200 [thread overview]
Message-ID: <4FBF2EEC.5090202@redhat.com> (raw)
In-Reply-To: <1337882362-20100-17-git-send-email-zwu.kernel@gmail.com>
Il 24/05/2012 19:59, zwu.kernel@gmail.com ha scritto:
> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
>
> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> ---
> net/hub.c | 35 ++++++++++++++++++++++++++++++++---
> net/hub.h | 2 ++
> net/queue.c | 5 +++++
> 3 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/net/hub.c b/net/hub.c
> index 8a583ab..d27c52a 100644
> --- a/net/hub.c
> +++ b/net/hub.c
> @@ -28,6 +28,7 @@ typedef struct NetHubPort {
> QLIST_ENTRY(NetHubPort) next;
> NetHub *hub;
> unsigned int id;
> + uint64_t nr_packets;
> } NetHubPort;
>
> struct NetHub {
> @@ -39,19 +40,37 @@ struct NetHub {
>
> static QLIST_HEAD(, NetHub) hubs = QLIST_HEAD_INITIALIZER(&hubs);
>
> +static void net_hub_receive_completed(NetClientState *nc, ssize_t len)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> + port->nr_packets--;
> + if (!port->nr_packets) {
> + qemu_net_queue_flush(nc->peer->send_queue);
> + }
> +}
> +
> +void net_hub_port_packet_stats(NetClientState *nc)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> +
> + port->nr_packets++;
> +}
Isn't this being called also for non-hubport clients?
> static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port,
> const uint8_t *buf, size_t len)
> {
> NetHubPort *port;
> + ssize_t ret = 0;
>
> QLIST_FOREACH(port, &hub->ports, next) {
> if (port == source_port) {
> continue;
> }
>
> - qemu_send_packet(&port->nc, buf, len);
> + ret = qemu_send_packet_async(&port->nc, buf, len,
> + net_hub_receive_completed);
Just increment nr_packets here:
ret = qemu_send_packet_async
if (ret == 0) {
port->nr_packets++;
}
> }
> - return len;
> + return ret;
You can return len here. In fact returning ret is wrong because the
value comes from a random port (the last one).
> }
>
> static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
> @@ -65,7 +84,8 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port,
> continue;
> }
>
> - ret = qemu_sendv_packet(&port->nc, iov, iovcnt);
> + ret = qemu_sendv_packet_async(&port->nc, iov, iovcnt,
> + net_hub_receive_completed);
Same here (increment nr_packets)
> }
> return ret;
Same here (return len).
> }
> @@ -84,6 +104,13 @@ static NetHub *net_hub_new(unsigned int id)
> return hub;
> }
>
> +static int net_hub_port_can_receive(NetClientState *nc)
> +{
> + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
> +
> + return port->nr_packets ? 0 : 1;
> +}
This is "return port->nr_packets == 0;".
But I think you need to implement this on the hub rather than on the
port, and return true only if port->nr_packets == 0 for all ports.
Probably you can move nr_packets to the hub itself rather than the port?
> static ssize_t net_hub_port_receive(NetClientState *nc,
> const uint8_t *buf, size_t len)
> {
> @@ -110,6 +137,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,
> @@ -128,6 +156,7 @@ static NetHubPort *net_hub_port_new(NetHub *hub)
> port = DO_UPCAST(NetHubPort, nc, nc);
> port->id = id;
> port->hub = hub;
> + port->nr_packets = 0;
>
> QLIST_INSERT_HEAD(&hub->ports, port, next);
>
Everything below this has to go away (sender is not necessarily a hub
port!).
> diff --git a/net/hub.h b/net/hub.h
> index d04f1b1..542e657 100644
> --- a/net/hub.h
> +++ b/net/hub.h
> @@ -23,4 +23,6 @@ void net_hub_info(Monitor *mon);
> int net_hub_id_for_client(NetClientState *nc, unsigned int *id);
> void net_hub_check_clients(void);
>
> +void net_hub_port_packet_stats(NetClientState *nc);
> +
> #endif /* NET_HUB_H */
> diff --git a/net/queue.c b/net/queue.c
> index 7484d2a..ebf18aa 100644
> --- a/net/queue.c
> +++ b/net/queue.c
> @@ -22,6 +22,7 @@
> */
>
> #include "net/queue.h"
> +#include "net/hub.h"
> #include "qemu-queue.h"
> #include "net.h"
>
> @@ -101,6 +102,8 @@ static ssize_t qemu_net_queue_append(NetQueue *queue,
>
> QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
>
> + net_hub_port_packet_stats(sender);
> +
> return size;
> }
>
> @@ -134,6 +137,8 @@ static ssize_t qemu_net_queue_append_iov(NetQueue *queue,
>
> QTAILQ_INSERT_TAIL(&queue->packets, packet, entry);
>
> + net_hub_port_packet_stats(sender);
> +
> return packet->size;
> }
>
next prev parent reply other threads:[~2012-05-25 7:04 UTC|newest]
Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-24 17:59 [PATCH v3 00/16] net: hub-based networking zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 01/16] net: Add a hub net client zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 02/16] net: Use hubs for the vlan feature zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 03/16] net: Look up 'vlan' net clients using hubs zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 04/16] hub: Check that hubs are configured correctly zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 05/16] net: Drop vlan argument to qemu_new_net_client() zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 06/16] net: Remove vlan qdev property zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 07/16] net: Remove vlan code from net.c zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 08/16] net: Remove VLANState zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 09/16] net: Rename non_vlan_clients to net_clients zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 10/16] net: Rename VLANClientState to NetClientState zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 11/16] net: Rename vc local variables to nc zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 12/16] net: Rename qemu_del_vlan_client() to qemu_del_net_client() zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 13/16] net: Make the monitor output more reasonable hub info zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 20:34 ` Jan Kiszka
2012-05-24 20:34 ` [Qemu-devel] " Jan Kiszka
2012-05-25 0:48 ` Zhi Yong Wu
2012-05-25 0:48 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 12:00 ` Zhi Yong Wu
2012-05-25 12:00 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 13:49 ` Jan Kiszka
2012-05-25 13:49 ` [Qemu-devel] " Jan Kiszka
2012-05-25 13:58 ` Zhi Yong Wu
2012-05-25 13:58 ` [Qemu-devel] " Zhi Yong Wu
2012-05-24 17:59 ` [PATCH v3 14/16] net: cleanup deliver/deliver_iov func pointers zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 15/16] net: determine if packets can be sent before net queue deliver packets zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-24 17:59 ` [PATCH v3 16/16] hub: add the support for hub own flow control zwu.kernel
2012-05-24 17:59 ` [Qemu-devel] " zwu.kernel
2012-05-25 7:04 ` Paolo Bonzini [this message]
2012-05-25 7:04 ` Paolo Bonzini
2012-05-25 7:48 ` Zhi Yong Wu
2012-05-25 7:48 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 10:08 ` Paolo Bonzini
2012-05-25 10:08 ` [Qemu-devel] " Paolo Bonzini
2012-05-25 10:54 ` Zhi Yong Wu
2012-05-25 10:54 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 8:04 ` Zhi Yong Wu
2012-05-25 8:04 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 8:18 ` Zhi Yong Wu
2012-05-25 8:18 ` [Qemu-devel] " Zhi Yong Wu
2012-05-24 20:53 ` [Qemu-devel] [PATCH v3 00/16] net: hub-based networking Luiz Capitulino
2012-05-24 20:53 ` Luiz Capitulino
2012-05-25 0:47 ` Zhi Yong Wu
2012-05-25 0:47 ` [Qemu-devel] " Zhi Yong Wu
2012-05-25 12:49 ` Luiz Capitulino
2012-05-25 12:49 ` Luiz Capitulino
2012-05-25 10:07 ` Stefan Hajnoczi
2012-05-25 10:07 ` [Qemu-devel] " Stefan Hajnoczi
2012-05-25 11:18 ` Markus Armbruster
2012-05-25 11:18 ` [Qemu-devel] " Markus Armbruster
2012-05-25 12:01 ` Stefan Hajnoczi
2012-05-25 12:01 ` Stefan Hajnoczi
2012-05-25 12:30 ` Markus Armbruster
2012-05-25 12:53 ` Luiz Capitulino
2012-05-25 12:53 ` Luiz Capitulino
2012-05-25 12:59 ` Paolo Bonzini
2012-05-25 12:59 ` Paolo Bonzini
2012-05-25 13:07 ` Luiz Capitulino
2012-05-25 13:07 ` [Qemu-devel] " Luiz Capitulino
2012-05-25 13:14 ` Paolo Bonzini
2012-05-25 13:14 ` Paolo Bonzini
2012-05-25 13:18 ` Luiz Capitulino
2012-05-25 13:18 ` Luiz Capitulino
2012-05-25 13:19 ` Paolo Bonzini
2012-05-25 13:19 ` Paolo Bonzini
2012-05-25 13:30 ` Luiz Capitulino
2012-05-25 13:30 ` Luiz Capitulino
2012-05-25 13:37 ` Paolo Bonzini
2012-05-25 13:37 ` Paolo Bonzini
2012-05-25 13:43 ` Luiz Capitulino
2012-05-25 13:43 ` Luiz Capitulino
2012-05-25 13:47 ` Paolo Bonzini
2012-05-25 13:47 ` [Qemu-devel] " Paolo Bonzini
2012-05-25 13:56 ` Luiz Capitulino
2012-05-25 13:56 ` Luiz Capitulino
2012-05-28 11:17 ` Stefan Hajnoczi
2012-05-28 11:17 ` Stefan Hajnoczi
2012-05-28 13:25 ` Luiz Capitulino
2012-05-28 13:25 ` Luiz Capitulino
2012-05-29 8:14 ` Markus Armbruster
2012-06-04 4:48 ` Anthony Liguori
2012-06-04 4:48 ` Anthony Liguori
2012-06-04 7:24 ` Markus Armbruster
2012-06-04 4:56 ` Anthony Liguori
2012-06-04 4:56 ` [Qemu-devel] " Anthony Liguori
2012-06-04 13:09 ` Luiz Capitulino
2012-06-04 13:09 ` Luiz Capitulino
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=4FBF2EEC.5090202@redhat.com \
--to=pbonzini@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=wuzhy@linux.vnet.ibm.com \
--cc=zwu.kernel@gmail.com \
/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 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.