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(-) 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) + default_map_addr = RTE_PTR_ADD(mapaddr, size); RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); -- 1.9.1 From thomas.monjalon@6wind.com Mon Nov 10 10:54:11 2014 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by dpdk.org (Postfix) with ESMTP id C38582E89 for ; Mon, 10 Nov 2014 10:54:11 +0100 (CET) Received: by mail-wi0-f172.google.com with SMTP id bs8so9734150wib.11 for ; Mon, 10 Nov 2014 02:03:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d100.net; s 130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type; bh=boS8myAu9T2LhsGLlflh1gTZs6fn3na8zppnVl5Nkt0=; b=IaJOJUS/JrF4U3PkAUw2VydRtST+peS3IpSMmXPLNsuEZYzxeO43UJso5BOmcI/mMq QzHhckAcg6gVVNbR3zSknV5t95rBtKFzqMOBSZkBNp5zx6lraLSV7cOWsxz69QSTn5aa IJScbNMrzQ4oFhnBddxnewYwgjrbYfZCKkMlb1aXAmD0oowSG9fNpwqPNsiBjfKCdIni r1qNErpwflVOVCJD3Cd8Fg/ZEbkrnS0fgSp4bdJqzIDLIYxnlWX/iRhPQ28Er+mIWKUA WdoZgxmnG7FNDPwINoehsEZy2Jk0gj01APXuEO6fotBAxBcy9cgGjNBS0YFnOgefwHtX WKew=X-Gm-Message-State: ALoCoQlQQ/m8Xk75za5kGhi2XnYX3zSCMpPf7ucHc7ycV0rAJmgo0ezWQbkZpGOT69QBzeeh1O1E X-Received: by 10.180.19.164 with SMTP id g4mr28712962wie.51.1415613836517; Mon, 10 Nov 2014 02:03:56 -0800 (PST) Received: from xps13.localnet (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by mx.google.com with ESMTPSA id hk9sm22516289wjb.46.2014.11.10.02.03.55 for (version=TLSv1.2 cipherDHE-RSA-AES128-GCM-SHA256 bits8/128); Mon, 10 Nov 2014 02:03:55 -0800 (PST) From: Thomas Monjalon To: "Sujith Sankar (ssujith)" Date: Mon, 10 Nov 2014 11:03:37 +0100 Message-ID: <2661634.q9QAmChB5I@xps13> Organization: 6WIND User-Agent: KMail/4.14.2 (Linux/3.17.2-1-ARCH; KDE/4.14.2; x86_64; ; ) In-Reply-To: References: <1415390747-9532-1-git-send-email-ssujith@cisco.com> <1794590.eegJuKmrRB@xps13> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH 0/7] Cisco Systems Inc. VIC Ethernet PMD - ENIC PMD 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 09:54:12 -0000 2014-11-10 09:27, Sujith Sankar: > On 07/11/14 9:17 pm, "Thomas Monjalon" wrote: > >It seems that this PMD is based on DPDK 1.7. > >Could you rebase it on HEAD? > > This patch is based on 1.7.1. Thought that is the latest. And I got the > diff from origin. > What made you feel that the patch is from 1.7? By saying 1.7, I meant 1.7.0 or 1.7.1. In current HEAD (future 1.8.0), there is a lot of changes which make your PMD incompatible. That's why the rule is to base the patches on the latest HEAD. Thanks for your efforts. -- Thomas