From patchwork Mon Nov 10 13:33:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 1238 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 27A8B7E1C; Mon, 10 Nov 2014 14:24:31 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 8EA8058F1 for ; Mon, 10 Nov 2014 14:24:28 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 10 Nov 2014 05:34:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="414268567" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by FMSMGA003.fm.intel.com with ESMTP; 10 Nov 2014 05:25:22 -0800 Received: from irsmsx154.ger.corp.intel.com (163.33.192.96) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 10 Nov 2014 13:33:13 +0000 Received: from irsmsx109.ger.corp.intel.com ([169.254.13.101]) by IRSMSX154.ger.corp.intel.com ([169.254.12.116]) with mapi id 14.03.0195.001; Mon, 10 Nov 2014 13:33:12 +0000 From: "Burakov, Anatoly" To: "Burakov, Anatoly" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v7] eal: map PCI memory resources after hugepages Thread-Index: AQHP/NpxQ/zDj7SqH0Gr3BztFsuwDpxZ26uA Date: Mon, 10 Nov 2014 13:33:12 +0000 Message-ID: References: <1415347284-15468-1-git-send-email-liang.xu@cinfotech.cn> <1415619272-8281-1-git-send-email-anatoly.burakov@intel.com> In-Reply-To: <1415619272-8281-1-git-send-email-anatoly.burakov@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v7] eal: map PCI memory resources after hugepages 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Nak, there are issues with the patch. There is another patch already, but I'll submit it whenever Liang verifies it works with his setup. Thanks, Anatoly -----Original Message----- From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Anatoly Burakov Sent: Monday, November 10, 2014 11:35 AM To: dev@dpdk.org Subject: [dpdk-dev] [PATCH v7] eal: map PCI memory resources after hugepages Multi-process DPDK application must mmap hugepages and pci resources into the same virtual address space. By default the virtual addresses are chosen by the primary process automatically when calling the mmap. But sometimes the chosen virtual addresses aren't usable in secondary process - for example, secondary process is linked with more libraries than primary process, and the library occupies the same address space that the primary process has requested for PCI mappings. This patch makes EAL map PCI BARs right after the hugepages (instead of location chosen by mmap) in virtual memory. Signed-off-by: Anatoly Burakov Signed-off-by: Liang Xu --- lib/librte_eal/linuxapp/eal/eal_pci.c | 19 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 9 ++++++++- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 13 +++++++++++-- lib/librte_eal/linuxapp/eal/include/eal_pci_init.h | 6 ++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 5fe3961..dae8739 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -97,6 +97,25 @@ error: return -1; } +void * +pci_find_max_end_va(void) +{ + const struct rte_memseg *seg = rte_eal_get_physmem_layout(); + const struct rte_memseg *last = seg; + unsigned i = 0; + + for (i = 0; i < RTE_MAX_MEMSEG; i++, seg++) { + if (seg->addr == NULL) + break; + + if (seg->addr > last->addr) + last = seg; + + } + return RTE_PTR_ADD(last->addr, last->len); +} + + /* map a particular resource from a file */ void * pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 7e62266..5090bf1 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -48,6 +48,8 @@ static int pci_parse_sysfs_value(const char *filename, uint64_t *val); +void *pci_map_addr = NULL; + #define OFF_MAX ((uint64_t)(off_t)-1) static int @@ -371,10 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev) if (maps[j].addr != NULL) fail = 1; else { - mapaddr = pci_map_resource(NULL, fd, (off_t)offset, + if (pci_map_addr == NULL) + pci_map_addr = pci_find_max_end_va(); + + mapaddr = pci_map_resource(pci_map_addr, fd, (off_t)offset, (size_t)maps[j].size); if (mapaddr == NULL) fail = 1; + + pci_map_addr = RTE_PTR_ADD(pci_map_addr, maps[j].size); } if (fail) { diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index c776ddc..fb6ee7a 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -720,8 +720,17 @@ pci_vfio_map_resource(struct rte_pci_device *dev) if (i == msix_bar) continue; - bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, - reg.size); + if (internal_config.process_type == RTE_PROC_PRIMARY) { + if (pci_map_addr == NULL) + pci_map_addr = pci_find_max_end_va(); + + bar_addr = pci_map_resource(pci_map_addr, vfio_dev_fd, reg.offset, + reg.size); + pci_map_addr = RTE_PTR_ADD(pci_map_addr, reg.size); + } else { + bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, + reg.size); + } if (bar_addr == NULL) { RTE_LOG(ERR, EAL, " %s mapping BAR%i failed: %s\n", pci_addr, i, diff --git a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h index d758bee..1070eb8 100644 --- a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h @@ -59,6 +59,12 @@ struct mapped_pci_resource { TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource); extern struct mapped_pci_res_list *pci_res_list; +/* + * Helper function to map PCI resources right after hugepages in virtual memory + */ +extern void *pci_map_addr; +void *pci_find_max_end_va(void); + void *pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size);