From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id E015D8D8E for ; Sun, 10 Jan 2016 19:43:19 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 10 Jan 2016 10:43:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,548,1444719600"; d="scan'208";a="26927879" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by fmsmga004.fm.intel.com with ESMTP; 10 Jan 2016 10:43:17 -0800 From: Jianfeng Tan To: dev@dpdk.org Date: Sun, 10 Jan 2016 19:43:00 +0800 Message-Id: <1452426182-86851-3-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452426182-86851-1-git-send-email-jianfeng.tan@intel.com> References: <1446748276-132087-1-git-send-email-jianfeng.tan@intel.com> <1452426182-86851-1-git-send-email-jianfeng.tan@intel.com> Cc: nakajima.yoshihiro@lab.ntt.co.jp, mst@redhat.com, ann.zhuangyanying@huawei.com Subject: [dpdk-dev] [PATCH 2/4] mem: add API to obstain memory-backed file info 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: Sun, 10 Jan 2016 18:43:20 -0000 A new API named rte_eal_get_backfile_info() and a new data struct back_file is added to obstain information of memory- backed file info. Signed-off-by: Huawei Xie Signed-off-by: Jianfeng Tan --- lib/librte_eal/common/include/rte_memory.h | 16 +++++++++++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 37 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index 9c9e40f..75ef8db 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -109,6 +109,22 @@ struct rte_memseg { } __rte_packed; /** + * This struct is used to store information about memory-backed file that + * we mapped in memory initialization. + */ +struct back_file { + void *addr; /**< virtual addr */ + size_t size; /**< the page size */ + char filepath[PATH_MAX]; /**< path to backing file on filesystem */ +}; + +/** + * Get the hugepage file information. Caller to free. + * Return number of hugepage files used. + */ +int rte_eal_get_backfile_info(struct back_file **); + +/** * Lock page in physical memory and prevent from swapping. * * @param virt diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 2bb1163..6ca1404 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -758,6 +758,9 @@ sort_by_physaddr(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi) return 0; } +static struct hugepage_file *hugepage_files; +static int num_hugepage_files; + /* * Uses mmap to create a shared memory area for storage of data * Used in this file to store the hugepage file map on disk @@ -776,9 +779,29 @@ create_shared_memory(const char *filename, const size_t mem_size) retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); + hugepage_files = retval; + num_hugepage_files = mem_size / (sizeof(struct hugepage_file)); + return retval; } +int +rte_eal_get_backfile_info(struct back_file **p) +{ + struct back_file *backfiles; + int i, num_backfiles = num_hugepage_files; + + backfiles = malloc(sizeof(struct back_file) * num_backfiles); + for (i = 0; i < num_backfiles; ++i) { + backfiles[i].addr = hugepage_files[i].final_va; + backfiles[i].size = hugepage_files[i].size; + strcpy(backfiles[i].filepath, hugepage_files[i].filepath); + } + + *p = backfiles; + return num_backfiles; +} + /* * this copies *active* hugepages from one hugepage table to another. * destination is typically the shared memory. @@ -1157,6 +1180,20 @@ rte_eal_hugepage_init(void) mcfg->memseg[0].len = internal_config.memory; mcfg->memseg[0].socket_id = socket_id; + hugepage = create_shared_memory(eal_hugepage_info_path(), + sizeof(struct hugepage_file)); + hugepage->orig_va = addr; + hugepage->final_va = addr; + hugepage->physaddr = rte_mem_virt2phy(addr); + hugepage->size = pagesize; + hugepage->socket_id = socket_id; + hugepage->file_id = 0; + hugepage->memseg_id = 0; +#ifdef RTE_EAL_SINGLE_FILE_SEGMENTS + hugepage->repeated = internal_config.memory / pagesize; +#endif + strncpy(hugepage->filepath, filepath, MAX_HUGEPAGE_PATH); + close(fd); return 0; -- 2.1.4