Skip to contentSkip to conversation

net: move queue number into NICPeers

PATCH Applied Jiri Pirko 4 participants 4 messages May 26, 2014 – Jun 27, 2014 Networking

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 net: move queue number into NICPeers

It indicates the number of elements in ncs field and makes sense to have int inside NICPeers. Also in parse_netdev we do not need to access container and work with NICPeers only.

---
 hw/core/qdev-properties-system.c | 3 +--
 hw/net/virtio-net.c              | 2 +-
 include/net/net.h                | 2 +-
 net/net.c                        | 4 ++--
 4 files changed, 5 insertions(+), 6 deletions(-)
hw/core/qdev-properties-system.c +1 -2
index 404cf18..3fd592c 100644
@@ -180,7 +180,6 @@ PropertyInfo qdev_prop_chr = {
 static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
 {
     NICPeers *peers_ptr = (NICPeers *)ptr;
-    NICConf *conf = container_of(peers_ptr, NICConf, peers);
     NetClientState **ncs = peers_ptr->ncs;
     NetClientState *peers[MAX_QUEUE_NUM];
     int queues, i = 0;
@@ -219,7 +218,7 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
         ncs[i]->queue_index = i;
     }
 
-    conf->queues = queues;
+    peers_ptr->queues = queues;
 
     return 0;
 
hw/net/virtio-net.c +1 -1
index 940a7cf..b4cb277 100644
@@ -1533,7 +1533,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
 
-    n->max_queues = MAX(n->nic_conf.queues, 1);
+    n->max_queues = MAX(n->nic_conf.peers.queues, 1);
     n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
     n->vqs[0].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
     n->curr_queues = 1;
include/net/net.h +1 -1
index 8166345..8a1db8a 100644
@@ -24,13 +24,13 @@ struct MACAddr {
 
 typedef struct NICPeers {
     NetClientState *ncs[MAX_QUEUE_NUM];
+    int32_t queues;
 } NICPeers;
 
 typedef struct NICConf {
     MACAddr macaddr;
     NICPeers peers;
     int32_t bootindex;
-    int32_t queues;
 } NICConf;
 
 #define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
net/net.c +2 -2
index 0ff2e40..0246818 100644
@@ -233,7 +233,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 {
     NetClientState **peers = conf->peers.ncs;
     NICState *nic;
-    int i, queues = MAX(1, conf->queues);
+    int i, queues = MAX(1, conf->peers.queues);
 
     assert(info->type == NET_CLIENT_OPTIONS_KIND_NIC);
     assert(info->size >= sizeof(NICState));
@@ -346,7 +346,7 @@ void qemu_del_net_client(NetClientState *nc)
 
 void qemu_del_nic(NICState *nic)
 {
-    int i, queues = MAX(nic->conf->queues, 1);
+    int i, queues = MAX(nic->conf->peers.queues, 1);
 
     /* If this is a peer NIC and peer has already been deleted, free it now. */
     if (nic->peer_deleted) {
Signature · 1 line
1.9.0
#1 lore raw

Am 26.05.2014 12:04, schrieb Jiri Pirko:

Quoted 11 lines

It indicates the number of elements in ncs field and makes sense to have int inside NICPeers. Also in parse_netdev we do not need to access container and work with NICPeers only.

---
 hw/core/qdev-properties-system.c | 3 +--
 hw/net/virtio-net.c              | 2 +-
 include/net/net.h                | 2 +-
 net/net.c                        | 4 ++--
 4 files changed, 5 insertions(+), 6 deletions(-)

Looks trivial on the qdev side. I'm assuming this will be handled through the net tree.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jiri Pirko
Quoted 5 lines · Jiri Pirko

It indicates the number of elements in ncs field and makes sense to have int inside NICPeers. Also in parse_netdev we do not need to access container and work with NICPeers only.

Please note that at least for virtio these are combined rx/tx queues. We probably should make this clear somewhere.

Quoted 84 lines
---
 hw/core/qdev-properties-system.c | 3 +--
 hw/net/virtio-net.c              | 2 +-
 include/net/net.h                | 2 +-
 net/net.c                        | 4 ++--
 4 files changed, 5 insertions(+), 6 deletions(-)
hw/core/qdev-properties-system.c +1 -2
index 404cf18..3fd592c 100644
@@ -180,7 +180,6 @@ PropertyInfo qdev_prop_chr = {
 static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
 {
     NICPeers *peers_ptr = (NICPeers *)ptr;
-    NICConf *conf = container_of(peers_ptr, NICConf, peers);
     NetClientState **ncs = peers_ptr->ncs;
     NetClientState *peers[MAX_QUEUE_NUM];
     int queues, i = 0;
@@ -219,7 +218,7 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
         ncs[i]->queue_index = i;
     }
 
-    conf->queues = queues;
+    peers_ptr->queues = queues;
 
     return 0;
 
hw/net/virtio-net.c +1 -1
index 940a7cf..b4cb277 100644
@@ -1533,7 +1533,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
 
-    n->max_queues = MAX(n->nic_conf.queues, 1);
+    n->max_queues = MAX(n->nic_conf.peers.queues, 1);
     n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
     n->vqs[0].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
     n->curr_queues = 1;
include/net/net.h +1 -1
index 8166345..8a1db8a 100644
@@ -24,13 +24,13 @@ struct MACAddr {
 
 typedef struct NICPeers {
     NetClientState *ncs[MAX_QUEUE_NUM];
+    int32_t queues;
 } NICPeers;
 
 typedef struct NICConf {
     MACAddr macaddr;
     NICPeers peers;
     int32_t bootindex;
-    int32_t queues;
 } NICConf;
 
 #define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
net/net.c +2 -2
index 0ff2e40..0246818 100644
@@ -233,7 +233,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 {
     NetClientState **peers = conf->peers.ncs;
     NICState *nic;
-    int i, queues = MAX(1, conf->queues);
+    int i, queues = MAX(1, conf->peers.queues);
 
     assert(info->type == NET_CLIENT_OPTIONS_KIND_NIC);
     assert(info->size >= sizeof(NICState));
@@ -346,7 +346,7 @@ void qemu_del_net_client(NetClientState *nc)
 
 void qemu_del_nic(NICState *nic)
 {
-    int i, queues = MAX(nic->conf->queues, 1);
+    int i, queues = MAX(nic->conf->peers.queues, 1);
 
     /* If this is a peer NIC and peer has already been deleted, free it now. */
     if (nic->peer_deleted) {
Signature · 1 line
1.9.0
#3 lore raw
In reply to Jiri Pirko
Quoted 11 lines · Jiri Pirko

It indicates the number of elements in ncs field and makes sense to have int inside NICPeers. Also in parse_netdev we do not need to access container and work with NICPeers only.

---
 hw/core/qdev-properties-system.c | 3 +--
 hw/net/virtio-net.c              | 2 +-
 include/net/net.h                | 2 +-
 net/net.c                        | 4 ++--
 4 files changed, 5 insertions(+), 6 deletions(-)

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan