1 Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
3 lib/librte_eal/common/eal_common_options.c | 18 +++++++++++
4 lib/librte_eal/common/eal_internal_cfg.h | 1 +
5 lib/librte_eal/common/eal_options.h | 2 ++
6 lib/librte_eal/linuxapp/eal/eal.c | 4 +--
7 lib/librte_eal/linuxapp/eal/eal_memory.c | 49 +++++++++++++++++++++++++-----
8 5 files changed, 64 insertions(+), 10 deletions(-)
10 diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
11 index f470195..4ad41b3 100644
12 --- a/lib/librte_eal/common/eal_common_options.c
13 +++ b/lib/librte_eal/common/eal_common_options.c
14 @@ -95,6 +95,7 @@ eal_long_options[] = {
15 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
16 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
17 {OPT_XEN_DOM0, 0, NULL, OPT_XEN_DOM0_NUM },
18 + {OPT_SINGLE_FILE, 0, NULL, OPT_SINGLE_FILE_NUM },
22 @@ -933,6 +934,10 @@ eal_parse_common_option(int opt, const char *optarg,
26 + case OPT_SINGLE_FILE_NUM:
27 + conf->single_file = 1;
30 /* don't know what to do, leave this to caller */
33 @@ -1025,6 +1030,17 @@ eal_check_common_options(struct internal_config *internal_cfg)
37 + if (internal_cfg->single_file && internal_cfg->force_sockets == 1) {
38 + RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE" cannot "
39 + "be specified together with --"OPT_SOCKET_MEM"\n");
42 + if (internal_cfg->single_file && internal_cfg->hugepage_unlink) {
43 + RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
44 + "be specified together with --"OPT_SINGLE_FILE"\n");
48 if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 &&
49 rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) {
50 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
51 @@ -1056,6 +1072,8 @@ eal_common_usage(void)
52 " -n CHANNELS Number of memory channels\n"
53 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
54 " -r RANKS Force number of memory ranks (don't detect)\n"
55 + " --"OPT_SINGLE_FILE" Create single file for shared memory, and \n"
56 + " do not promise physical contiguity of memseg\n"
57 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
58 " Prevent EAL from using this PCI device. The argument\n"
59 " format is <domain:bus:devid.func>.\n"
60 diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
61 index 7b7e8c8..82b0f97 100644
62 --- a/lib/librte_eal/common/eal_internal_cfg.h
63 +++ b/lib/librte_eal/common/eal_internal_cfg.h
64 @@ -61,6 +61,7 @@ struct hugepage_info {
66 struct internal_config {
67 volatile size_t memory; /**< amount of asked memory */
68 + volatile unsigned single_file; /**< map all hugepages in single file */
69 volatile unsigned force_nchannel; /**< force number of channels */
70 volatile unsigned force_nrank; /**< force number of ranks */
71 volatile unsigned no_hugetlbfs; /**< true to disable hugetlbfs */
72 diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
73 index a881c62..e5da14a 100644
74 --- a/lib/librte_eal/common/eal_options.h
75 +++ b/lib/librte_eal/common/eal_options.h
76 @@ -83,6 +83,8 @@ enum {
77 OPT_VMWARE_TSC_MAP_NUM,
78 #define OPT_XEN_DOM0 "xen-dom0"
80 +#define OPT_SINGLE_FILE "single-file"
81 + OPT_SINGLE_FILE_NUM,
85 diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
86 index 7c78f2d..b6f2ca2 100644
87 --- a/lib/librte_eal/linuxapp/eal/eal.c
88 +++ b/lib/librte_eal/linuxapp/eal/eal.c
89 @@ -839,6 +839,8 @@ rte_eal_init(int argc, char **argv)
93 + eal_thread_init_master(rte_config.master_lcore);
95 if (rte_eal_memory_init() < 0) {
96 rte_eal_init_alert("Cannot init memory\n");
98 @@ -877,8 +879,6 @@ rte_eal_init(int argc, char **argv)
99 if (eal_plugins_init() < 0)
100 rte_eal_init_alert("Cannot init plugins\n");
102 - eal_thread_init_master(rte_config.master_lcore);
104 ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN);
106 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n", diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
107 index 618a09b..70c6536 100644
108 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
109 +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
110 @@ -982,20 +982,53 @@ rte_eal_hugepage_init(void)
111 /* get pointer to global configuration */
112 mcfg = rte_eal_get_configuration()->mem_config;
114 - /* hugetlbfs can be disabled */
115 - if (internal_config.no_hugetlbfs) {
116 - addr = mmap(NULL, internal_config.memory, PROT_READ | PROT_WRITE,
117 - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
118 + /* when hugetlbfs is disabled or single-file option is specified */
119 + if (internal_config.no_hugetlbfs || internal_config.single_file) {
122 + unsigned socket_id = rte_socket_id();
123 + char filepath[MAX_HUGEPAGE_PATH];
125 + if (internal_config.no_hugetlbfs) {
126 + eal_get_hugefile_path(filepath, sizeof(filepath),
128 + pagesize = RTE_PGSIZE_4K;
130 + struct hugepage_info *hpi;
132 + hpi = &internal_config.hugepage_info[0];
133 + eal_get_hugefile_path(filepath, sizeof(filepath),
135 + pagesize = hpi->hugepage_sz;
137 + fd = open(filepath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
139 + RTE_LOG(ERR, EAL, "%s: open %s failed: %s\n",
140 + __func__, filepath, strerror(errno));
144 + if (ftruncate(fd, internal_config.memory) < 0) {
145 + RTE_LOG(ERR, EAL, "ftuncate %s failed: %s\n",
146 + filepath, strerror(errno));
150 + addr = mmap(NULL, internal_config.memory,
151 + PROT_READ | PROT_WRITE,
152 + MAP_SHARED | MAP_POPULATE, fd, 0);
153 if (addr == MAP_FAILED) {
154 - RTE_LOG(ERR, EAL, "%s: mmap() failed: %s\n", __func__,
156 + RTE_LOG(ERR, EAL, "%s: mmap() failed: %s\n",
157 + __func__, strerror(errno));
160 mcfg->memseg[0].phys_addr = (phys_addr_t)(uintptr_t)addr;
161 mcfg->memseg[0].addr = addr;
162 - mcfg->memseg[0].hugepage_sz = RTE_PGSIZE_4K;
163 + mcfg->memseg[0].hugepage_sz = pagesize;
164 mcfg->memseg[0].len = internal_config.memory;
165 - mcfg->memseg[0].socket_id = 0;
166 + mcfg->memseg[0].socket_id = socket_id;