From patchwork Mon Jun 25 10:04:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 167026 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 E9A13B6FFF for ; Mon, 25 Jun 2012 20:11:11 +1000 (EST) Received: from localhost ([::1]:43276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6GD-00046j-LZ for incoming@patchwork.ozlabs.org; Mon, 25 Jun 2012 06:11:09 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6Fx-0003iv-6u for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sj6Fr-0003Au-9H for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sj6Fq-0003Am-SI for qemu-devel@nongnu.org; Mon, 25 Jun 2012 06:10:47 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5PAAb77010628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jun 2012 06:10:37 -0400 Received: from amd-6168-8-1.englab.nay.redhat.com (amd-6168-8-1.englab.nay.redhat.com [10.66.104.52]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5PAAW5B027140; Mon, 25 Jun 2012 06:10:33 -0400 To: krkumar2@in.ibm.com, habanero@linux.vnet.ibm.com, aliguori@us.ibm.com, rusty@rustcorp.com.au, mst@redhat.com, mashirle@us.ibm.com, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, tahm@linux.vnet.ibm.com, jwhan@filewood.snu.ac.kr, akong@redhat.com From: Jason Wang Date: Mon, 25 Jun 2012 18:04:37 +0800 Message-ID: <20120625100437.8096.89752.stgit@amd-6168-8-1.englab.nay.redhat.com> In-Reply-To: <20120625095059.8096.49429.stgit@amd-6168-8-1.englab.nay.redhat.com> References: <20120625095059.8096.49429.stgit@amd-6168-8-1.englab.nay.redhat.com> User-Agent: StGit/0.16-1-g60c4 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC V2 PATCH 3/4] net: multiqueue support 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 This patch adds the multiqueues support for emulated nics. Each VLANClientState pairs are now abstract as a queue instead of a nic, and multiple VLANClientState pointers were stored in the NICState. A queue_index were also introduced to let the emulated nics know which queue the packet were came from or sent out. Virtio-net would be the first user. Signed-off-by: Jason Wang --- hw/dp8393x.c | 2 +- hw/mcf_fec.c | 2 +- hw/qdev-properties.c | 33 +++++++++++++++++++++++----- hw/qdev.h | 3 ++- net.c | 58 +++++++++++++++++++++++++++++++++++++++++++------- net.h | 16 ++++++++++---- 6 files changed, 93 insertions(+), 21 deletions(-) diff --git a/hw/dp8393x.c b/hw/dp8393x.c index 017d074..483a868 100644 --- a/hw/dp8393x.c +++ b/hw/dp8393x.c @@ -900,7 +900,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, s->conf.macaddr = nd->macaddr; s->conf.vlan = nd->vlan; - s->conf.peer = nd->netdev; + s->conf.peers[0] = nd->netdev; s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s); diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c index ae37bef..69f508d 100644 --- a/hw/mcf_fec.c +++ b/hw/mcf_fec.c @@ -473,7 +473,7 @@ void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, s->conf.macaddr = nd->macaddr; s->conf.vlan = nd->vlan; - s->conf.peer = nd->netdev; + s->conf.peers[0] = nd->netdev; s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s); diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 9ae3187..d45fcef 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -554,16 +554,37 @@ PropertyInfo qdev_prop_chr = { static int parse_netdev(DeviceState *dev, const char *str, void **ptr) { - VLANClientState *netdev = qemu_find_netdev(str); + VLANClientState ***nc = (VLANClientState ***)ptr; + VLANClientState *vcs[MAX_QUEUE_NUM]; + int queues, i = 0; + int ret; - if (netdev == NULL) { - return -ENOENT; + *nc = g_malloc(MAX_QUEUE_NUM * sizeof(VLANClientState *)); + queues = qemu_find_netdev_all(str, vcs, MAX_QUEUE_NUM); + if (queues == 0) { + ret = -ENOENT; + goto err; } - if (netdev->peer) { - return -EEXIST; + + for (i = 0; i < queues; i++) { + if (vcs[i] == NULL) { + ret = -ENOENT; + goto err; + } + + if (vcs[i]->peer) { + ret = -EEXIST; + goto err; + } + + (*nc)[i] = vcs[i]; } - *ptr = netdev; + return 0; + +err: + g_free(*nc); + return ret; } static const char *print_netdev(void *ptr) diff --git a/hw/qdev.h b/hw/qdev.h index 5386b16..1c023b4 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -248,6 +248,7 @@ extern PropertyInfo qdev_prop_blocksize; .defval = (bool)_defval, \ } + #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ @@ -274,7 +275,7 @@ extern PropertyInfo qdev_prop_blocksize; #define DEFINE_PROP_STRING(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) #define DEFINE_PROP_NETDEV(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) + DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState**) #define DEFINE_PROP_VLAN(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*) #define DEFINE_PROP_DRIVE(_n, _s, _f) \ diff --git a/net.c b/net.c index eabe830..026a03a 100644 --- a/net.c +++ b/net.c @@ -238,16 +238,40 @@ NICState *qemu_new_nic(NetClientInfo *info, { VLANClientState *nc; NICState *nic; + int i; assert(info->type == NET_CLIENT_TYPE_NIC); assert(info->size >= sizeof(NICState)); - nc = qemu_new_net_client(info, conf->vlan, conf->peer, model, name); + if (conf->peers) { + nc = qemu_new_net_client(info, NULL, conf->peers[0], model, name); + } else { + nc = qemu_new_net_client(info, conf->vlan, NULL, model, name); + } nic = DO_UPCAST(NICState, nc, nc); nic->conf = conf; nic->opaque = opaque; + /* For compatiablity with single queue nic */ + nic->ncs[0] = nc; + nc->opaque = nic; + + for (i = 1 ; i < conf->queues; i++) { + VLANClientState *vc = g_malloc0(sizeof(*vc)); + vc->opaque = nic; + nic->ncs[i] = vc; + vc->peer = conf->peers[i]; + vc->info = info; + vc->queue_index = i; + vc->peer->peer = vc; + QTAILQ_INSERT_TAIL(&non_vlan_clients, vc, next); + + vc->send_queue = qemu_new_net_queue(qemu_deliver_packet, + qemu_deliver_packet_iov, + vc); + } + return nic; } @@ -283,11 +307,10 @@ void qemu_del_vlan_client(VLANClientState *vc) { /* If there is a peer NIC, delete and cleanup client, but do not free. */ if (!vc->vlan && vc->peer && vc->peer->info->type == NET_CLIENT_TYPE_NIC) { - NICState *nic = DO_UPCAST(NICState, nc, vc->peer); - if (nic->peer_deleted) { + if (vc->peer_deleted) { return; } - nic->peer_deleted = true; + vc->peer_deleted = true; /* Let NIC know peer is gone. */ vc->peer->link_down = true; if (vc->peer->info->link_status_changed) { @@ -299,8 +322,7 @@ void qemu_del_vlan_client(VLANClientState *vc) /* If this is a peer NIC and peer has already been deleted, free it now. */ if (!vc->vlan && vc->peer && vc->info->type == NET_CLIENT_TYPE_NIC) { - NICState *nic = DO_UPCAST(NICState, nc, vc); - if (nic->peer_deleted) { + if (vc->peer_deleted) { qemu_free_vlan_client(vc->peer); } } @@ -342,14 +364,14 @@ void qemu_foreach_nic(qemu_nic_foreach func, void *opaque) QTAILQ_FOREACH(nc, &non_vlan_clients, next) { if (nc->info->type == NET_CLIENT_TYPE_NIC) { - func(DO_UPCAST(NICState, nc, nc), opaque); + func((NICState *)nc->opaque, opaque); } } QTAILQ_FOREACH(vlan, &vlans, next) { QTAILQ_FOREACH(nc, &vlan->clients, next) { if (nc->info->type == NET_CLIENT_TYPE_NIC) { - func(DO_UPCAST(NICState, nc, nc), opaque); + func((NICState *)nc->opaque, opaque); } } } @@ -674,6 +696,26 @@ VLANClientState *qemu_find_netdev(const char *id) return NULL; } +int qemu_find_netdev_all(const char *id, VLANClientState **vcs, int max) +{ + VLANClientState *vc; + int ret = 0; + + QTAILQ_FOREACH(vc, &non_vlan_clients, next) { + if (vc->info->type == NET_CLIENT_TYPE_NIC) { + continue; + } + if (!strcmp(vc->name, id) && ret < max) { + vcs[ret++] = vc; + } + if (ret >= max) { + break; + } + } + + return ret; +} + static int nic_get_free_idx(void) { int index; diff --git a/net.h b/net.h index bdc2a06..40378ce 100644 --- a/net.h +++ b/net.h @@ -12,20 +12,24 @@ struct MACAddr { uint8_t a[6]; }; +#define MAX_QUEUE_NUM 32 + /* qdev nic properties */ typedef struct NICConf { MACAddr macaddr; VLANState *vlan; - VLANClientState *peer; + VLANClientState **peers; int32_t bootindex; + int32_t queues; } NICConf; #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ - DEFINE_PROP_NETDEV("netdev", _state, _conf.peer), \ - DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) + DEFINE_PROP_NETDEV("netdev", _state, _conf.peers), \ + DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ + DEFINE_PROP_INT32("queues", _state, _conf.queues, 1) /* VLANs support */ @@ -72,13 +76,16 @@ struct VLANClientState { char *name; char info_str[256]; unsigned receive_disabled : 1; + unsigned int queue_index; + bool peer_deleted; + void *opaque; }; typedef struct NICState { VLANClientState nc; + VLANClientState *ncs[MAX_QUEUE_NUM]; NICConf *conf; void *opaque; - bool peer_deleted; } NICState; struct VLANState { @@ -90,6 +97,7 @@ struct VLANState { VLANState *qemu_find_vlan(int id, int allocate); VLANClientState *qemu_find_netdev(const char *id); +int qemu_find_netdev_all(const char *id, VLANClientState **vcs, int max); VLANClientState *qemu_new_net_client(NetClientInfo *info, VLANState *vlan, VLANClientState *peer,