From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 844408D8C for ; Fri, 13 May 2016 07:20:10 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 12 May 2016 22:20:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,612,1455004800"; d="scan'208";a="805314879" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga003.jf.intel.com with ESMTP; 12 May 2016 22:20:08 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: Thomas Monjalon , huawei.xie@intel.com, Panu Matilainen , Tetsuya Mukawa , Traynor Kevin , Rich Lane , Yuanhan Liu Date: Thu, 12 May 2016 22:24:56 -0700 Message-Id: <1463117111-27050-5-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1462227927-22853-1-git-send-email-yuanhan.liu@linux.intel.com> <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2016 05:20:11 -0000 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 --- 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 6c7541a..beb56eb 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]); } /* @@ -1207,7 +1203,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); } @@ -1222,20 +1218,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, next); - 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; @@ -1259,7 +1256,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 c4591b4..aca8904 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) next; } __rte_cache_aligned; -- 1.9.0