From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 7C89E7E8C for ; Mon, 20 Oct 2014 06:30:41 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 19 Oct 2014 21:35:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,749,1406617200"; d="scan'208";a="621638324" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga002.jf.intel.com with ESMTP; 19 Oct 2014 21:38:50 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id s9K4cmYg003345; Mon, 20 Oct 2014 12:38:48 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s9K4ckex028183; Mon, 20 Oct 2014 12:38:48 +0800 Received: (from hxie5@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id s9K4ckT9028179; Mon, 20 Oct 2014 12:38:46 +0800 From: Huawei Xie To: dev@dpdk.org Date: Mon, 20 Oct 2014 12:38:17 +0800 Message-Id: <1413779906-28113-6-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1413779906-28113-1-git-send-email-huawei.xie@intel.com> References: <1413779906-28113-1-git-send-email-huawei.xie@intel.com> Subject: [dpdk-dev] [PATCH 05/14] hpa region 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: Mon, 20 Oct 2014 04:30:43 -0000 add hpa(host physical address) region generation/destroy logic. gpa<->hpa memory translation regions are generated at new_device, when a virtio device is ready for packet processing. Signed-off-by: Huawei Xie --- examples/vhost/main.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 03a0f48..e161282 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -2489,6 +2489,7 @@ destroy_device (volatile struct virtio_net *dev) dev->device_fh); mbuf_destroy_zcp(vpool); + rte_free(vdev->regions_hpa); } rte_free(vdev); @@ -2652,7 +2653,7 @@ new_device (struct virtio_net *dev) int lcore, core_add = 0; uint32_t device_num_min = num_devices; struct vhost_dev *vdev; - + uint32_t regionidx; vdev = rte_zmalloc("vhost device", sizeof(*vdev), CACHE_LINE_SIZE); if (vdev == NULL) { @@ -2663,12 +2664,49 @@ new_device (struct virtio_net *dev) vdev->dev = dev; dev->priv = vdev; + if (zero_copy) { + vdev->nregions_hpa = dev->mem->nregions; + for (regionidx = 0; regionidx < dev->mem->nregions; regionidx++) { + vdev->nregions_hpa + += check_hpa_regions( + dev->mem->regions[regionidx].guest_phys_address + + dev->mem->regions[regionidx].address_offset, + dev->mem->regions[regionidx].memory_size); + + } + + vdev->regions_hpa = (struct virtio_memory_regions_hpa *) rte_zmalloc("vhost hpa region", + sizeof(struct virtio_memory_regions_hpa) * vdev->nregions_hpa, + CACHE_LINE_SIZE); + if (vdev->regions_hpa == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, "Cannot allocate memory for hpa region\n"); + rte_free(vdev); + return -1; + } + + + if (fill_hpa_memory_regions( + vdev->regions_hpa, dev->mem + ) != vdev->nregions_hpa) { + + RTE_LOG(ERR, VHOST_CONFIG, + "hpa memory regions number mismatch: " + "[%d]\n", vdev->nregions_hpa); + rte_free(vdev->regions_hpa); + rte_free(vdev); + return -1; + } + } + + /* Add device to main ll */ ll_dev = get_data_ll_free_entry(&ll_root_free); if (ll_dev == NULL) { RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") No free entry found in linked list. Device limit " "of %d devices per core has been reached\n", dev->device_fh, num_devices); + if (vdev->regions_hpa) + rte_free(vdev->regions_hpa); rte_free(vdev); return -1; } @@ -2721,6 +2759,7 @@ new_device (struct virtio_net *dev) dev->device_fh, vdev->vmdq_rx_q); mbuf_destroy_zcp(vpool); + rte_free(vdev->regions_hpa); rte_free(vdev); return -1; } @@ -2743,6 +2782,7 @@ new_device (struct virtio_net *dev) } mbuf_destroy_zcp(vpool); + rte_free(vdev->regions_hpa); rte_free(vdev); return -1; } @@ -2767,6 +2807,8 @@ new_device (struct virtio_net *dev) RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") Failed to add device to data core\n", dev->device_fh); vdev->ready = DEVICE_SAFE_REMOVE; destroy_device(dev); + if (vdev->regions_hpa) + rte_free(vdev->regions_hpa); rte_free(vdev); return -1; } -- 1.8.1.4