From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, Thomas Monjalon <thomas.monjalon@6wind.com>,
Panu Matilainen <pmatilai@redhat.com>,
Traynor Kevin <kevin.traynor@intel.com>,
Rich Lane <rich.lane@bigswitch.com>,
Tetsuya Mukawa <mukawa@igel.co.jp>,
Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id
Date: Tue, 7 Jun 2016 11:51:54 +0800 [thread overview]
Message-ID: <1465271530-27878-5-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com>
Make a copy of virtio device id (device_fh) from the virtio_net struct,
so that we could have less dependency on the virtio_net struct.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
examples/vhost/main.c | 59 ++++++++++++++++++++++++---------------------------
examples/vhost/main.h | 1 +
2 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 564e3f9..04a7f52 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -708,7 +708,6 @@ static int
link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
{
struct ether_hdr *pkt_hdr;
- struct virtio_net *dev = vdev->dev;
int i, ret;
/* Learn MAC address of guest device from packet */
@@ -717,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
if (find_vhost_dev(&pkt_hdr->s_addr)) {
RTE_LOG(ERR, VHOST_DATA,
"(%d) device is using a registered MAC!\n",
- dev->device_fh);
+ vdev->device_fh);
return -1;
}
@@ -725,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];
/* vlan_tag currently uses the device_id. */
- vdev->vlan_tag = vlan_tags[dev->device_fh];
+ vdev->vlan_tag = vlan_tags[vdev->device_fh];
/* Print out VMDQ registration info. */
RTE_LOG(INFO, VHOST_DATA,
"(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n",
- dev->device_fh,
+ vdev->device_fh,
vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1],
vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)
/* Register the MAC address. */
ret = rte_eth_dev_mac_addr_add(ports[0], &vdev->mac_address,
- (uint32_t)dev->device_fh + vmdq_pool_base);
+ (uint32_t)vdev->device_fh + vmdq_pool_base);
if (ret)
RTE_LOG(ERR, VHOST_DATA,
"(%d) failed to add device MAC address to VMDQ\n",
- dev->device_fh);
+ vdev->device_fh);
/* Enable stripping of the vlan tag as we handle routing. */
if (vlan_strip)
@@ -814,7 +813,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
{
struct ether_hdr *pkt_hdr;
struct vhost_dev *dst_vdev;
- int fh;
pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -822,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
if (!dst_vdev)
return -1;
- fh = dst_vdev->dev->device_fh;
- if (fh == vdev->dev->device_fh) {
+ if (vdev->device_fh == dst_vdev->device_fh) {
RTE_LOG(DEBUG, VHOST_DATA,
"(%d) TX: src and dst MAC is same. Dropping packet.\n",
- fh);
+ vdev->device_fh);
return 0;
}
- RTE_LOG(DEBUG, VHOST_DATA, "(%d) TX: MAC address is local\n", fh);
+ RTE_LOG(DEBUG, VHOST_DATA,
+ "(%d) TX: MAC address is local\n", dst_vdev->device_fh);
if (unlikely(dst_vdev->remove)) {
RTE_LOG(DEBUG, VHOST_DATA,
- "(%d) device is marked for removal\n", fh);
+ "(%d) device is marked for removal\n", dst_vdev->device_fh);
return 0;
}
@@ -847,7 +845,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
* and get its vlan tag, and offset if it is.
*/
static inline int __attribute__((always_inline))
-find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,
uint32_t *offset, uint16_t *vlan_tag)
{
struct vhost_dev *dst_vdev;
@@ -857,10 +855,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
if (!dst_vdev)
return 0;
- if (dst_vdev->dev->device_fh == dev->device_fh) {
+ if (vdev->device_fh == dst_vdev->device_fh) {
RTE_LOG(DEBUG, VHOST_DATA,
"(%d) TX: src and dst MAC is same. Dropping packet.\n",
- dst_vdev->dev->device_fh);
+ vdev->device_fh);
return -1;
}
@@ -870,11 +868,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
* the packet length by plus it.
*/
*offset = VLAN_HLEN;
- *vlan_tag = vlan_tags[(uint16_t)dst_vdev->dev->device_fh];
+ *vlan_tag = vlan_tags[vdev->device_fh];
RTE_LOG(DEBUG, VHOST_DATA,
- "(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n",
- dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);
+ "(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n",
+ vdev->device_fh, dst_vdev->device_fh, *vlan_tag);
return 0;
}
@@ -937,7 +935,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
struct mbuf_table *tx_q;
unsigned offset = 0;
const uint16_t lcore_id = rte_lcore_id();
- struct virtio_net *dev = vdev->dev;
struct ether_hdr *nh;
@@ -958,14 +955,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
}
if (unlikely(vm2vm_mode == VM2VM_HARDWARE)) {
- if (unlikely(find_local_dest(dev, m, &offset, &vlan_tag) != 0)) {
+ if (unlikely(find_local_dest(vdev, m, &offset,
+ &vlan_tag) != 0)) {
rte_pktmbuf_free(m);
return;
}
}
RTE_LOG(DEBUG, VHOST_DATA,
- "(%d) TX: MAC is external\n", dev->device_fh);
+ "(%d) TX: MAC address is external\n", vdev->device_fh);
queue2nic:
@@ -1095,10 +1093,8 @@ drain_virtio_tx(struct vhost_dev *vdev)
free_pkts(pkts, count);
}
- for (i = 0; i < count; ++i) {
- virtio_tx_route(vdev, pkts[i],
- vlan_tags[(uint16_t)vdev->dev->device_fh]);
- }
+ for (i = 0; i < count; ++i)
+ virtio_tx_route(vdev, pkts[i], vlan_tags[vdev->device_fh]);
}
/*
@@ -1210,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)
RTE_LOG(INFO, VHOST_DATA,
"(%d) device has been removed from data core\n",
- dev->device_fh);
+ vdev->device_fh);
rte_free(vdev);
}
@@ -1225,20 +1221,21 @@ new_device (struct virtio_net *dev)
int lcore, core_add = 0;
uint32_t device_num_min = num_devices;
struct vhost_dev *vdev;
+ int device_fh = dev->device_fh;
vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
if (vdev == NULL) {
RTE_LOG(INFO, VHOST_DATA,
- "(%d) Couldn't allocate memory for vhost dev\n",
- dev->device_fh);
+ "(%d) couldn't allocate memory for vhost dev\n",
+ device_fh);
return -1;
}
vdev->dev = dev;
dev->priv = vdev;
+ vdev->device_fh = device_fh;
TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, global_vdev_entry);
- vdev->vmdq_rx_q
- = dev->device_fh * queues_per_pool + vmdq_queue_base;
+ vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;
/*reset ready flag*/
vdev->ready = DEVICE_MAC_LEARNING;
@@ -1263,7 +1260,7 @@ new_device (struct virtio_net *dev)
RTE_LOG(INFO, VHOST_DATA,
"(%d) device has been added to data core %d\n",
- dev->device_fh, vdev->coreid);
+ device_fh, vdev->coreid);
return 0;
}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index bd7f1a3..11d121b 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -66,6 +66,7 @@ struct vhost_dev {
/**< Device is marked for removal from the data core. */
volatile uint8_t remove;
+ int device_fh;
struct device_statistics stats;
TAILQ_ENTRY(vhost_dev) global_vdev_entry;
TAILQ_ENTRY(vhost_dev) lcore_vdev_entry;
--
1.9.0
next prev parent reply other threads:[~2016-06-07 3:51 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 09/16] vhost: add few more functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-10 16:17 ` Rich Lane
2016-05-10 16:39 ` Yuanhan Liu
2016-05-10 17:13 ` Rich Lane
2016-05-10 17:29 ` Yuanhan Liu
2016-05-10 19:22 ` Thomas Monjalon
2016-05-02 22:25 ` [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-26 17:04 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
2016-05-27 1:36 ` Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
2016-06-07 3:51 ` Yuanhan Liu [this message]
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
2016-06-07 11:42 ` Panu Matilainen
2016-06-07 12:45 ` Yuanhan Liu
2016-06-08 21:51 ` Rich Lane
2016-06-09 4:45 ` Yuanhan Liu
2016-06-13 10:05 ` Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-06-14 12:00 ` [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
2016-06-30 7:39 ` Panu Matilainen
2016-06-30 7:57 ` Yuanhan Liu
2016-06-30 9:05 ` Panu Matilainen
2016-06-30 11:15 ` Mcnamara, John
2016-06-30 11:40 ` Thomas Monjalon
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=1465271530-27878-5-git-send-email-yuanhan.liu@linux.intel.com \
--to=yuanhan.liu@linux.intel.com \
--cc=dev@dpdk.org \
--cc=huawei.xie@intel.com \
--cc=kevin.traynor@intel.com \
--cc=mukawa@igel.co.jp \
--cc=pmatilai@redhat.com \
--cc=rich.lane@bigswitch.com \
--cc=thomas.monjalon@6wind.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).