From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 8D77DC386 for ; Fri, 5 Feb 2016 19:21:01 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP; 05 Feb 2016 10:21:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,401,1449561600"; d="scan'208";a="647822687" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by FMSMGA003.fm.intel.com with ESMTP; 05 Feb 2016 10:20:59 -0800 From: Jianfeng Tan To: dev@dpdk.org Date: Fri, 5 Feb 2016 19:20:25 +0800 Message-Id: <1454671228-33284-3-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1454671228-33284-1-git-send-email-jianfeng.tan@intel.com> References: <1446748276-132087-1-git-send-email-jianfeng.tan@intel.com> <1454671228-33284-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 v2 2/5] mem: add API to obtain 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: Fri, 05 Feb 2016 18:21:02 -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 | 40 +++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index 587a25d..b09397e 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 68ef49a..a6b3616 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -743,6 +743,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 @@ -760,9 +763,30 @@ 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. @@ -1148,8 +1172,22 @@ rte_eal_hugepage_init(void) mcfg->memseg[0].len = internal_config.memory; mcfg->memseg[0].socket_id = socket_id; - close(fd); + 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); + /* Suppose we have a very huge hugefile here */ + hugepage->size = internal_config.memory; + 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