From patchwork Mon Nov 10 10:04:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: lxu X-Patchwork-Id: 1232 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 A61156828; Mon, 10 Nov 2014 10:54:55 +0100 (CET) Received: from out1134-185.mail.aliyun.com (out1134-185.mail.aliyun.com [42.120.134.185]) by dpdk.org (Postfix) with ESMTP id C72A62E89 for ; Mon, 10 Nov 2014 10:54:51 +0100 (CET) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.0435036|-1; FP=0|0|0|0|0|-1|-1|-1; HT=r46d02009; MF=liang.xu@cinfotech.cn; PH=DW; RN=3; RT=3; SR=0; Received: from WS-web (liang.xu@cinfotech.cn[203.110.175.218]) by r41g06012.xy2.aliyun.com at Mon, 10 Nov 2014 18:04:31 +0800 Date: Mon, 10 Nov 2014 18:04:31 +0800 From: "XU Liang" To: "=?UTF-8?B?QnVyYWtvdiwgQW5hdG9seQ==?=" , "dev@dpdk.org" Message-ID: <0940c02e-7bf7-4019-b400-1bd377bc667d@cinfotech.cn> X-Mailer: Alimail-Mailagent revision 2667797 MIME-Version: 1.0 References: <1415417532-4363-1-git-send-email-liang.xu@cinfotech.cn>, C6ECDF3AB251BE4894318F4E4512369780C07DC0@IRSMSX109.ger.corp.intel.com, dd048730-152d-4922-9edc-985aa3a6a885@cinfotech.cn In-Reply-To: dd048730-152d-4922-9edc-985aa3a6a885@cinfotech.cn x-aliyun-mail-creator: Webmail4_2670074_M3LTW96aWxsYS81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTBfMTBfMSkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzM4LjAuMjEyNS4xMTEgU2FmYXJpLzUzNy4zNg==vN X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] =?utf-8?q?=5BPATCH=5D_eal=3A_map_PCI_memory_resources_?= =?utf-8?q?after_hugepages?= X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: XU Liang 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" Of course you can take this job. Thanks you for your help.------------------------------------------------------------------From:徐亮 Time:2014 Nov 10 (Mon) 18 : 01To:Burakov, Anatoly , dev@dpdk.org Cc:thomas.monjalon@6wind.com Subject:Re: [PATCH] eal: map PCI memory resources after hugepages It is a default value when the requested_addr isn't exist, not an overide. When the pci_map_resource is called at the primary process, the requested_addr is NULL. The default value will be provided by default_map_addr. When the pci_map_resource is called at the secondery process, the requested_addr is exist. Then everything isn't be changed.------------------------------------------------------------------From:Burakov, Anatoly Time:2014 Nov 10 (Mon) 17 : 54To:徐亮 , dev@dpdk.org Cc:thomas.monjalon@6wind.com Subject:RE: [PATCH] eal: map PCI memory resources after hugepages Hi Liang I don't think that overriding the value passed to pci_map_resource as argument is the way to go. While it results in less code, it looks weird, in my opinion at least, as I believe tracking the correctness of address being requested should be the responsibility of the caller, i.e. either UIO or VFIO code. Which is why I keep insisting that you make requested_pci_addr global to linuxapp EAL PCI section and put it into include/eal_pci_init.h. Would you mind if I made a patch for this issue based on your code? Thanks, Anatoly -----Original Message----- From: Liang Xu [mailto:liang.xu@cinfotech.cn] Sent: Saturday, November 8, 2014 3:32 AM To: dev@dpdk.org Cc: Burakov, Anatoly; thomas.monjalon@6wind.com Subject: [PATCH] eal: map PCI memory resources after hugepages A multiple process DPDK application must mmap hugepages and pci resources into same virtual addresses. By default the virtual addresses chosen by the primary process automatically when calling the mmap. But sometime the chosen virtual addresses isn't usable at secondary process. Such as the secondary process linked with more libraries than primary process. The library has been mapped into this virtual address. The command line parameter 'base-virtaddr' has been added for this situation. If it's configured, the hugepages will be mapped into this base address. But the virtual address of pci resources mapped still does not refer to the parameter. In that case "EAL: pci_map_resource(): cannot mmap" will be got. This patch try to map pci resources after hugepages. So the error can be resolved by set base-virtaddr into free virtual address space. Signed-off-by: Liang Xu --- lib/librte_eal/linuxapp/eal/eal_pci.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) + default_map_addr = RTE_PTR_ADD(mapaddr, size); RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); -- 1.9.1 diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index ddb0535..502eef2 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -97,14 +97,42 @@ error: return -1; } +static 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) { void *mapaddr; + /* By default the PCI memory resource will be mapped after hugepages */ + static void *default_map_addr; + if (NULL == requested_addr) { + if (NULL == default_map_addr) + default_map_addr = pci_find_max_end_va(); + mapaddr = default_map_addr; + } else { + mapaddr = requested_addr; + } + /* Map the PCI memory resource of device */ - mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, + mapaddr = mmap(mapaddr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); if (mapaddr == MAP_FAILED || (requested_addr != NULL && mapaddr != requested_addr)) { @@ -114,6 +142,8 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size) strerror(errno), mapaddr); goto fail; } + if (NULL == requested_addr)