X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Flinuxapp%2Feal%2Feal_memory.c;h=38853b753aabbec6069dac3b43342d76d13d0ce3;hb=5c7472135ba8d91d608d89c9311a7d80bda7bee7;hp=284758ac40bd7e6c356c4c7cb867ab820813881b;hpb=7ba49d39f14cef4fbea95521b1224f5539321dd5;p=dpdk.git diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 284758ac40..38853b753a 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -1,35 +1,6 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * Copyright(c) 2013 6WIND. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation. + * Copyright(c) 2013 6WIND S.A. */ #define _FILE_OFFSET_BITS 64 @@ -128,9 +99,6 @@ rte_mem_virt2phy(const void *virtaddr) int page_size; off_t offset; - if (rte_eal_iova_mode() == RTE_IOVA_VA) - return (uintptr_t)virtaddr; - /* Cannot parse /proc/self/pagemap, no need to log errors everywhere */ if (!phys_addrs_available) return RTE_BAD_IOVA; @@ -180,6 +148,14 @@ rte_mem_virt2phy(const void *virtaddr) return physaddr; } +rte_iova_t +rte_mem_virt2iova(const void *virtaddr) +{ + if (rte_eal_iova_mode() == RTE_IOVA_VA) + return (uintptr_t)virtaddr; + return rte_mem_virt2phy(virtaddr); +} + /* * For each hugepage in hugepg_tbl, fill the physaddr value. We find * it by browsing the /proc/self/pagemap special file. @@ -256,33 +232,44 @@ static void * get_virtual_area(size_t *size, size_t hugepage_sz) { void *addr; + void *addr_hint; int fd; long aligned_addr; if (internal_config.base_virtaddr != 0) { - addr = (void*) (uintptr_t) (internal_config.base_virtaddr + - baseaddr_offset); + int page_size = sysconf(_SC_PAGE_SIZE); + addr_hint = (void *) (uintptr_t) + (internal_config.base_virtaddr + baseaddr_offset); + addr_hint = RTE_PTR_ALIGN_FLOOR(addr_hint, page_size); + } else { + addr_hint = NULL; } - else addr = NULL; RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zx bytes\n", *size); + fd = open("/dev/zero", O_RDONLY); if (fd < 0){ RTE_LOG(ERR, EAL, "Cannot open /dev/zero\n"); return NULL; } do { - addr = mmap(addr, - (*size) + hugepage_sz, PROT_READ, + addr = mmap(addr_hint, (*size) + hugepage_sz, PROT_READ, #ifdef RTE_ARCH_PPC_64 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, #else MAP_PRIVATE, #endif fd, 0); - if (addr == MAP_FAILED) + if (addr == MAP_FAILED) { *size -= hugepage_sz; + } else if (addr_hint != NULL && addr != addr_hint) { + RTE_LOG(WARNING, EAL, "WARNING! Base virtual address " + "hint (%p != %p) not respected!\n", + addr_hint, addr); + RTE_LOG(WARNING, EAL, " This may cause issues with " + "mapping memory into secondary processes\n"); + } } while (addr == MAP_FAILED && *size > 0); if (addr == MAP_FAILED) { @@ -339,7 +326,7 @@ void numa_error(char *where) * hugetlbfs, then mmap() hugepage_sz data in it. If orig is set, the * virtual address is stored in hugepg_tbl[i].orig_va, else it is stored * in hugepg_tbl[i].final_va. The second mapping (when orig is 0) tries to - * map continguous physical blocks in contiguous virtual blocks. + * map contiguous physical blocks in contiguous virtual blocks. */ static unsigned map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,