From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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: , X-List-Received-Date: Mon, 10 Nov 2014 13:24:29 -0000 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 hugepage= s 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/linuxap= p/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; } =20 +void * +pci_find_max_end_va(void) +{ + const struct rte_memseg *seg =3D rte_eal_get_physmem_layout(); + const struct rte_memseg *last =3D seg; + unsigned i =3D 0; + + for (i =3D 0; i < RTE_MAX_MEMSEG; i++, seg++) { + if (seg->addr =3D=3D NULL) + break; + + if (seg->addr > last->addr) + last =3D 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/lin= uxapp/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 @@ =20 static int pci_parse_sysfs_value(const char *filename, uint64_t *val); =20 +void *pci_map_addr =3D NULL; + =20 #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 !=3D NULL) fail =3D 1; else { - mapaddr =3D pci_map_resource(NULL, fd, (off_t)offset, + if (pci_map_addr =3D=3D NULL) + pci_map_addr =3D pci_find_max_end_va(); + + mapaddr =3D pci_map_resource(pci_map_addr, fd, (off_t)offset, (size_t)maps[j].size); if (mapaddr =3D=3D NULL) fail =3D 1; + + pci_map_addr =3D RTE_PTR_ADD(pci_map_addr, maps[j].size); } =20 if (fail) { diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/li= nuxapp/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 =3D=3D msix_bar) continue; =20 - bar_addr =3D pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, - reg.size); + if (internal_config.process_type =3D=3D RTE_PROC_PRIMARY) { + if (pci_map_addr =3D=3D NULL) + pci_map_addr =3D pci_find_max_end_va(); + + bar_addr =3D pci_map_resource(pci_map_addr, vfio_dev_fd, reg.offset, + reg.size); + pci_map_addr =3D RTE_PTR_ADD(pci_map_addr, reg.size); + } else { + bar_addr =3D pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, + reg.size); + } =20 if (bar_addr =3D=3D 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/librt= e_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; =20 +/* + * Helper function to map PCI resources right after hugepages in virtual m= emory + */ +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); =20 --=20 1.8.1.4