[PATCH v3 4/6] EAL: Add a new "--align-memsize" option
From: Tetsuya Mukawa <hidden>
Date: 2016-02-22 08:18:27
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
The option will work with "--range-virtaddr", and if the option is specified, mapped address will be align by EAL memory size. Such an alignment is required for using virtio-net PMD extension on container that uses QEMU QTest framework. Signed-off-by: Tetsuya Mukawa <redacted> --- lib/librte_eal/common/eal_common_options.c | 8 ++++++++ lib/librte_eal/common/eal_internal_cfg.h | 1 + lib/librte_eal/common/eal_options.h | 2 ++ lib/librte_eal/linuxapp/eal/eal.c | 4 ++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 9 +++++++++ 5 files changed, 24 insertions(+)
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3b4f789..853420a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c@@ -75,6 +75,7 @@ const struct option eal_long_options[] = { {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM }, {OPT_RANGE_VIRTADDR, 1, NULL, OPT_RANGE_VIRTADDR_NUM }, + {OPT_ALIGN_MEMSIZE, 0, NULL, OPT_ALIGN_MEMSIZE_NUM }, {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM }, {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM }, {OPT_HELP, 0, NULL, OPT_HELP_NUM },
@@ -140,6 +141,7 @@ eal_reset_internal_config(struct internal_config *internal_cfg) internal_cfg->base_virtaddr = 0; internal_cfg->range_virtaddr_start = 0; internal_cfg->range_virtaddr_end = 0; + internal_cfg->align_memsize = 0; internal_cfg->syslog_facility = LOG_DAEMON; /* default value from build option */
@@ -994,6 +996,12 @@ eal_check_common_options(struct internal_config *internal_cfg) return -1; } + if (internal_cfg->range_virtaddr_end == 0 && internal_cfg->align_memsize) { + RTE_LOG(ERR, EAL, "Option --"OPT_RANGE_VIRTADDR" should be " + "specified together with --"OPT_ALIGN_MEMSIZE"\n"); + return -1; + } + return 0; }
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 0734630..df33a9f 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h@@ -80,6 +80,7 @@ struct internal_config { uintptr_t base_virtaddr; /**< base address to try and reserve memory from */ uintptr_t range_virtaddr_start; /**< start address of mappable region */ uintptr_t range_virtaddr_end; /**< end address of mappable region */ + volatile unsigned align_memsize; /**< true to align virtaddr by memory size */ volatile int syslog_facility; /**< facility passed to openlog() */ volatile uint32_t log_level; /**< default log level */ /** default interrupt mode for VFIO */
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index 8e4cf1d..9e36f68 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h@@ -49,6 +49,8 @@ enum { OPT_BASE_VIRTADDR_NUM, #define OPT_RANGE_VIRTADDR "range-virtaddr" OPT_RANGE_VIRTADDR_NUM, +#define OPT_ALIGN_MEMSIZE "align-memsize" + OPT_ALIGN_MEMSIZE_NUM, #define OPT_CREATE_UIO_DEV "create-uio-dev" OPT_CREATE_UIO_DEV_NUM, #define OPT_FILE_PREFIX "file-prefix"
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 80f1995..095e866 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c@@ -643,6 +643,10 @@ eal_parse_args(int argc, char **argv) } break; + case OPT_ALIGN_MEMSIZE_NUM: + internal_config.align_memsize = 1; + break; + case OPT_VFIO_INTR_NUM: if (eal_parse_vfio_intr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --"
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index d608273..221c358 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c@@ -272,6 +272,15 @@ rte_eal_get_free_region(uint64_t pagesz) return NULL; } + if (internal_config.align_memsize) { + /* + * Typically, BAR register of PCI device requiers such + * an alignment. + */ + low_limit = RTE_ALIGN_CEIL(low_limit, alloc_size); + high_limit = RTE_ALIGN_FLOOR(high_limit, alloc_size); + } + fp = fopen("/proc/self/maps", "r"); if (fp == NULL) { rte_panic("Cannot open /proc/self/maps\n");
--
2.1.4