From patchwork Sun Mar 3 13:21:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 224550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 316ED2C030A for ; Mon, 4 Mar 2013 00:22:23 +1100 (EST) Received: from localhost ([::1]:37059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC8rt-0004Y1-AA for incoming@patchwork.ozlabs.org; Sun, 03 Mar 2013 08:22:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC8rT-0004UU-Mx for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:21:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UC8rS-000499-7E for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:21:55 -0500 Received: from mail-da0-f48.google.com ([209.85.210.48]:61920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UC8rR-00048z-UD for qemu-devel@nongnu.org; Sun, 03 Mar 2013 08:21:54 -0500 Received: by mail-da0-f48.google.com with SMTP id w4so2094715dam.7 for ; Sun, 03 Mar 2013 05:21:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=p89Cyfx6g87xW3H+Hh2FUwt0/7MZ28bCDuELPXjEgZw=; b=G3P/tdARAJkWPdYmAlc/Im+YwRF4Molh/VxzS/3tuOtROIIZqG1VyHXKTBmJ8oFyC4 6hhOk1V72hvP2Y4L2poqtkeKDBcvcSFJbUfsVkwszHD9zc9YOTLQ9JClZnxmZONBKwyq 816oaFdp+3rWt170+11O0Ee1OMIGgSDTzEj11jnDmwGDEcav/SvGDMRggB5sVbANp4bg MHB7O2CEyasLdGk0NslfqRIthJtCQyYZ/5FyjFaZu80D2ecAgMr2G17iR2piQNoqoSsx 8Nvl1MUR3hP3Bkr0lzJK37zm5RvHpRle0n7yw2JlAtqRo4Gpq2Ozp/BVlxp/idkAdt1d /ooQ== X-Received: by 10.66.162.133 with SMTP id ya5mr27413601pab.104.1362316913229; Sun, 03 Mar 2013 05:21:53 -0800 (PST) Received: from localhost ([222.128.136.55]) by mx.google.com with ESMTPS id mz8sm16140111pbc.9.2013.03.03.05.21.45 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Sun, 03 Mar 2013 05:21:52 -0800 (PST) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Sun, 3 Mar 2013 21:21:20 +0800 Message-Id: <1362316883-7948-2-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1362316883-7948-1-git-send-email-qemulist@gmail.com> References: <1362316883-7948-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.48 Cc: Stefan Hajnoczi , Paolo Bonzini , mdroth , Anthony Liguori , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 1/3] net: spread hub on AioContexts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Liu Ping Fan Forward packet to other hub ports by their AioContext. Signed-off-by: Liu Ping Fan --- hw/qdev-properties-system.c | 1 + include/block/aio.h | 1 + include/net/net.h | 5 +++++ include/net/queue.h | 14 ++++++++++++++ main-loop.c | 5 +++++ net/hub.c | 33 ++++++++++++++++++++++++++++++--- net/net.c | 1 + net/queue.c | 4 ++-- 8 files changed, 59 insertions(+), 5 deletions(-) diff --git a/hw/qdev-properties-system.c b/hw/qdev-properties-system.c index ce3af22..88f0acf 100644 --- a/hw/qdev-properties-system.c +++ b/hw/qdev-properties-system.c @@ -307,6 +307,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, name, prop->info->name); return; } + hubport->info->reside(hubport, qemu_get_aio_context()); *ptr = hubport; } diff --git a/include/block/aio.h b/include/block/aio.h index 5b54d38..bcb5126 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -229,6 +229,7 @@ bool qemu_aio_wait(void); void qemu_aio_set_event_notifier(EventNotifier *notifier, EventNotifierHandler *io_read, AioFlushEventNotifierHandler *io_flush); +AioContext *qemu_get_aio_context(void); #ifdef CONFIG_POSIX void qemu_aio_set_fd_handler(int fd, diff --git a/include/net/net.h b/include/net/net.h index 43a045e..24563ef 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -8,6 +8,9 @@ #include "net/queue.h" #include "migration/vmstate.h" #include "qapi-types.h" +#include "qemu/thread.h" +#include "block/aio.h" + #define MAX_QUEUE_NUM 1024 @@ -44,6 +47,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); typedef void (NetCleanup) (NetClientState *); typedef void (LinkStatusChanged)(NetClientState *); typedef void (NetClientDestructor)(NetClientState *); +typedef void (NetClientReside)(NetClientState *, AioContext *); typedef struct NetClientInfo { NetClientOptionsKind type; @@ -55,6 +59,7 @@ typedef struct NetClientInfo { NetCleanup *cleanup; LinkStatusChanged *link_status_changed; NetPoll *poll; + NetClientReside *reside; } NetClientInfo; struct NetClientState { diff --git a/include/net/queue.h b/include/net/queue.h index fc02b33..f60e57f 100644 --- a/include/net/queue.h +++ b/include/net/queue.h @@ -38,6 +38,20 @@ NetQueue *qemu_new_net_queue(void *opaque); void qemu_del_net_queue(NetQueue *queue); +void qemu_net_queue_append(NetQueue *queue, + NetClientState *sender, + unsigned flags, + const uint8_t *buf, + size_t size, + NetPacketSent *sent_cb); + +void qemu_net_queue_append_iov(NetQueue *queue, + NetClientState *sender, + unsigned flags, + const struct iovec *iov, + int iovcnt, + NetPacketSent *sent_cb); + ssize_t qemu_net_queue_send(NetQueue *queue, NetClientState *sender, unsigned flags, diff --git a/main-loop.c b/main-loop.c index 8c9b58c..eb80ff3 100644 --- a/main-loop.c +++ b/main-loop.c @@ -109,6 +109,11 @@ static int qemu_signal_init(void) static AioContext *qemu_aio_context; +AioContext *qemu_get_aio_context(void) +{ + return qemu_aio_context; +} + void qemu_notify_event(void) { if (!qemu_aio_context) { diff --git a/net/hub.c b/net/hub.c index a24c9d1..81d2a04 100644 --- a/net/hub.c +++ b/net/hub.c @@ -31,6 +31,8 @@ typedef struct NetHubPort { QLIST_ENTRY(NetHubPort) next; NetHub *hub; int id; + EventNotifier e; + AioContext *ctx; } NetHubPort; struct NetHub { @@ -52,11 +54,20 @@ static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port, continue; } - qemu_send_packet(&port->nc, buf, len); + qemu_net_queue_append(port->nc.peer->send_queue, &port->nc, + QEMU_NET_PACKET_FLAG_NONE, buf, len, NULL); + event_notifier_set(&port->e); } return len; } +static void hub_port_deliver_packet(void *opaque) +{ + NetHubPort *port = (NetHubPort *)opaque; + + qemu_net_queue_flush(port->nc.peer->send_queue); +} + static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, const struct iovec *iov, int iovcnt) { @@ -68,7 +79,9 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, continue; } - qemu_sendv_packet(&port->nc, iov, iovcnt); + qemu_net_queue_append_iov(port->nc.peer->send_queue, &port->nc, + QEMU_NET_PACKET_FLAG_NONE, iov, iovcnt, NULL); + event_notifier_set(&port->e); } return len; } @@ -126,9 +139,22 @@ static void net_hub_port_cleanup(NetClientState *nc) { NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc); + if (port->ctx) { + aio_set_fd_handler(port->ctx, event_notifier_get_fd(&port->e), + NULL, NULL, NULL, NULL); + } QLIST_REMOVE(port, next); } +static void net_hub_port_reside(NetClientState *nc, AioContext *ctx) +{ + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc); + + port->ctx = ctx; + aio_set_fd_handler(ctx, event_notifier_get_fd(&port->e), + hub_port_deliver_packet, NULL, NULL, port); +} + static NetClientInfo net_hub_port_info = { .type = NET_CLIENT_OPTIONS_KIND_HUBPORT, .size = sizeof(NetHubPort), @@ -136,6 +162,7 @@ static NetClientInfo net_hub_port_info = { .receive = net_hub_port_receive, .receive_iov = net_hub_port_receive_iov, .cleanup = net_hub_port_cleanup, + .reside = net_hub_port_reside, }; static NetHubPort *net_hub_port_new(NetHub *hub, const char *name) @@ -155,7 +182,7 @@ static NetHubPort *net_hub_port_new(NetHub *hub, const char *name) port = DO_UPCAST(NetHubPort, nc, nc); port->id = id; port->hub = hub; - + event_notifier_init(&port->e, 0); QLIST_INSERT_HEAD(&hub->ports, port, next); return port; diff --git a/net/net.c b/net/net.c index be03a8d..544542b 100644 --- a/net/net.c +++ b/net/net.c @@ -776,6 +776,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC || !opts->nic->has_netdev)) { peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL); + peer->info->reside(peer, qemu_get_aio_context()); } if (net_client_init_fun[opts->kind](opts, name, peer) < 0) { diff --git a/net/queue.c b/net/queue.c index 6eaf5b6..d4fb965 100644 --- a/net/queue.c +++ b/net/queue.c @@ -83,7 +83,7 @@ void qemu_del_net_queue(NetQueue *queue) g_free(queue); } -static void qemu_net_queue_append(NetQueue *queue, +void qemu_net_queue_append(NetQueue *queue, NetClientState *sender, unsigned flags, const uint8_t *buf, @@ -102,7 +102,7 @@ static void qemu_net_queue_append(NetQueue *queue, QTAILQ_INSERT_TAIL(&queue->packets, packet, entry); } -static void qemu_net_queue_append_iov(NetQueue *queue, +void qemu_net_queue_append_iov(NetQueue *queue, NetClientState *sender, unsigned flags, const struct iovec *iov,