#include <rte_devargs.h>
#include <rte_version.h>
#include <rte_vfio.h>
-#include <rte_option.h>
#include <rte_atomic.h>
#include <malloc_heap.h>
+#include <rte_telemetry.h>
#include "eal_private.h"
#include "eal_thread.h"
#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t rte_application_usage_hook = NULL;
-/* early configuration structure, when memory config is not mmapped */
-static struct rte_mem_config early_mem_config;
-
/* define fd variable here, because file needs to be kept open for the
* duration of the program, as we hold a write lock on it in the primary proc */
static int mem_cfg_fd = -1;
.l_type = F_WRLCK,
.l_whence = SEEK_SET,
.l_start = offsetof(struct rte_mem_config, memsegs),
- .l_len = sizeof(early_mem_config.memsegs),
-};
-
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
- .mem_config = &early_mem_config,
+ .l_len = RTE_SIZEOF_FIELD(struct rte_mem_config, memsegs),
};
/* internal configuration (per-core) */
struct lcore_config lcore_config[RTE_MAX_LCORE];
-/* internal configuration */
-struct internal_config internal_config;
-
/* used by rte_rdtsc() */
int rte_cycles_vmware_tsc_map;
-/* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
-
static const char *default_runtime_dir = "/var/run";
int
const char *directory = default_runtime_dir;
const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
const char *fallback = "/tmp";
+ char run_dir[PATH_MAX];
char tmp[PATH_MAX];
int ret;
}
/* create prefix-specific subdirectory under DPDK runtime dir */
- ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
+ ret = snprintf(run_dir, sizeof(run_dir), "%s/%s",
tmp, eal_get_hugefile_prefix());
- if (ret < 0 || ret == sizeof(runtime_dir)) {
+ if (ret < 0 || ret == sizeof(run_dir)) {
RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
return -1;
}
return -1;
}
- ret = mkdir(runtime_dir, 0700);
+ ret = mkdir(run_dir, 0700);
if (ret < 0 && errno != EEXIST) {
RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
- runtime_dir, strerror(errno));
+ run_dir, strerror(errno));
return -1;
}
+ if (eal_set_runtime_dir(run_dir, sizeof(run_dir)))
+ return -1;
+
return 0;
}
return 0;
}
-
-const char *
-rte_eal_get_runtime_dir(void)
-{
- return runtime_dir;
-}
-
-/* Return user provided mbuf pool ops name */
-const char *
-rte_eal_mbuf_user_pool_ops(void)
-{
- return internal_config.user_mbuf_pool_ops_name;
-}
-
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
- return &rte_config;
-}
-
-enum rte_iova_mode
-rte_eal_iova_mode(void)
-{
- return rte_eal_get_configuration()->iova_mode;
-}
-
/* parse a sysfs (or other) file containing one integer value */
int
eal_parse_sysfs_value(const char *filename, unsigned long *val)
static int
rte_eal_config_create(void)
{
+ struct rte_config *config = rte_eal_get_configuration();
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
size_t page_sz = sysconf(_SC_PAGE_SIZE);
- size_t cfg_len = sizeof(*rte_config.mem_config);
+ size_t cfg_len = sizeof(struct rte_mem_config);
size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz);
void *rte_mem_cfg_addr, *mapped_mem_cfg_addr;
int retval;
const char *pathname = eal_runtime_config_path();
- if (internal_config.no_shconf)
+ if (internal_conf->no_shconf)
return 0;
/* map the config before base address so that we don't waste a page */
- if (internal_config.base_virtaddr != 0)
+ if (internal_conf->base_virtaddr != 0)
rte_mem_cfg_addr = (void *)
- RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
+ RTE_ALIGN_FLOOR(internal_conf->base_virtaddr -
sizeof(struct rte_mem_config), page_sz);
else
rte_mem_cfg_addr = NULL;
return -1;
}
- memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
- rte_config.mem_config = rte_mem_cfg_addr;
+ memcpy(rte_mem_cfg_addr, config->mem_config, sizeof(struct rte_mem_config));
+ config->mem_config = rte_mem_cfg_addr;
/* store address of the config in the config itself so that secondary
* processes could later map the config into this exact location
*/
- rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
-
+ config->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
return 0;
}
{
void *rte_mem_cfg_addr;
const char *pathname = eal_runtime_config_path();
+ struct rte_config *config = rte_eal_get_configuration();
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
+
- if (internal_config.no_shconf)
+ if (internal_conf->no_shconf)
return 0;
if (mem_cfg_fd < 0){
}
}
- rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
+ rte_mem_cfg_addr = mmap(NULL, sizeof(*config->mem_config),
PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
/* don't close the fd here, it will be closed on reattach */
if (rte_mem_cfg_addr == MAP_FAILED) {
return -1;
}
- rte_config.mem_config = rte_mem_cfg_addr;
+ config->mem_config = rte_mem_cfg_addr;
return 0;
}
{
struct rte_mem_config *mem_config;
void *rte_mem_cfg_addr;
+ struct rte_config *config = rte_eal_get_configuration();
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
- if (internal_config.no_shconf)
+ if (internal_conf->no_shconf)
return 0;
/* save the address primary process has mapped shared config to */
rte_mem_cfg_addr =
- (void *)(uintptr_t)rte_config.mem_config->mem_cfg_addr;
+ (void *)(uintptr_t)config->mem_config->mem_cfg_addr;
/* unmap original config */
- munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
+ munmap(config->mem_config, sizeof(struct rte_mem_config));
/* remap the config at proper address */
mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
return -1;
}
- rte_config.mem_config = mem_config;
+ config->mem_config = mem_config;
return 0;
}
{
enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
const char *pathname = eal_runtime_config_path();
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
/* if there no shared config, there can be no secondary processes */
- if (!internal_config.no_shconf) {
+ if (!internal_conf->no_shconf) {
/* if we can open the file but not get a write-lock we are a
* secondary process. NOTE: if we get a file handle back, we
* keep that open and don't close it to prevent a race condition
static int
rte_config_init(void)
{
- rte_config.process_type = internal_config.process_type;
+ struct rte_config *config = rte_eal_get_configuration();
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
- switch (rte_config.process_type){
+ config->process_type = internal_conf->process_type;
+
+ switch (config->process_type) {
case RTE_PROC_PRIMARY:
if (rte_eal_config_create() < 0)
return -1;
}
if (rte_eal_config_reattach() < 0)
return -1;
+ if (!__rte_mp_enable()) {
+ RTE_LOG(ERR, EAL, "Primary process refused secondary attachment\n");
+ return -1;
+ }
eal_mcfg_update_internal();
break;
case RTE_PROC_AUTO:
case RTE_PROC_INVALID:
RTE_LOG(ERR, EAL, "Invalid process type %d\n",
- rte_config.process_type);
+ config->process_type);
return -1;
}
static void
eal_usage(const char *prgname)
{
+ rte_usage_hook_t hook = eal_get_application_usage_hook();
+
printf("\nUsage: %s ", prgname);
eal_common_usage();
/* Allow the application to print its usage message too if hook is set */
- if ( rte_application_usage_hook ) {
+ if (hook) {
printf("===== Application Usage =====\n\n");
- rte_application_usage_hook(prgname);
+ (hook)(prgname);
}
}
-/* Set a per-application usage message */
-rte_usage_hook_t
-rte_set_application_usage_hook( rte_usage_hook_t usage_func )
-{
- rte_usage_hook_t old_func;
-
- /* Will be NULL on the first call to denote the last usage routine. */
- old_func = rte_application_usage_hook;
- rte_application_usage_hook = usage_func;
-
- return old_func;
-}
-
static inline size_t
eal_get_hugepage_mem_size(void)
{
uint64_t size = 0;
unsigned i, j;
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
- for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
- struct hugepage_info *hpi = &internal_config.hugepage_info[i];
+ for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
+ struct hugepage_info *hpi = &internal_conf->hugepage_info[i];
if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
size += hpi->hugepage_sz * hpi->num_pages[j];
const int old_optopt = optopt;
const int old_optreset = optreset;
char * const old_optarg = optarg;
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
argvopt = argv;
optind = 1;
break;
ret = (opt == OPT_LOG_LEVEL_NUM) ?
- eal_parse_common_option(opt, optarg, &internal_config) : 0;
+ eal_parse_common_option(opt, optarg, internal_conf) : 0;
/* common parser is not happy */
if (ret < 0)
const int old_optopt = optopt;
const int old_optreset = optreset;
char * const old_optarg = optarg;
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
argvopt = argv;
optind = 1;
optreset = 1;
- opterr = 0;
while ((opt = getopt_long(argc, argvopt, eal_short_options,
eal_long_options, &option_index)) != EOF) {
- /*
- * getopt didn't recognise the option, lets parse the
- * registered options to see if the flag is valid
- */
+ /* getopt didn't recognise the option */
if (opt == '?') {
- ret = rte_option_parse(argv[optind-1]);
- if (ret == 0)
- continue;
-
eal_usage(prgname);
ret = -1;
goto out;
}
- ret = eal_parse_common_option(opt, optarg, &internal_config);
+ ret = eal_parse_common_option(opt, optarg, internal_conf);
/* common parser is not happy */
if (ret < 0) {
eal_usage(prgname);
RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
else {
/* free old ops name */
- if (internal_config.user_mbuf_pool_ops_name !=
+ if (internal_conf->user_mbuf_pool_ops_name !=
NULL)
- free(internal_config.user_mbuf_pool_ops_name);
+ free(internal_conf->user_mbuf_pool_ops_name);
- internal_config.user_mbuf_pool_ops_name =
+ internal_conf->user_mbuf_pool_ops_name =
ops_name;
}
break;
}
/* create runtime data directory */
- if (internal_config.no_shconf == 0 &&
+ if (internal_conf->no_shconf == 0 &&
eal_create_runtime_dir() < 0) {
RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
ret = -1;
goto out;
}
- if (eal_adjust_config(&internal_config) != 0) {
+ if (eal_adjust_config(internal_conf) != 0) {
ret = -1;
goto out;
}
/* sanity checks */
- if (eal_check_common_options(&internal_config) != 0) {
+ if (eal_check_common_options(internal_conf) != 0) {
eal_usage(prgname);
ret = -1;
goto out;
eal_check_mem_on_local_socket(void)
{
int socket_id;
+ const struct rte_config *config = rte_eal_get_configuration();
- socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
+ socket_id = rte_lcore_to_socket_id(config->master_lcore);
if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
{
return 0;
}
-
-/* return non-zero if hugepages are enabled. */
-int rte_eal_has_hugepages(void)
-{
- return !internal_config.no_hugetlbfs;
-}
-
/* Abstraction for port I/0 privilege */
int
rte_eal_iopl_init(void)
static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
char thread_name[RTE_MAX_THREAD_NAME_LEN];
+ const struct rte_config *config = rte_eal_get_configuration();
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
thread_id = pthread_self();
- eal_reset_internal_config(&internal_config);
+ eal_reset_internal_config(internal_conf);
+
+ /* clone argv to report out later in telemetry */
+ eal_save_args(argc, argv);
/* set log level as early as possible */
eal_log_level_parse(argc, argv);
}
/* FreeBSD always uses legacy memory model */
- internal_config.legacy_mem = true;
+ internal_conf->legacy_mem = true;
if (eal_plugins_init() < 0) {
rte_eal_init_alert("Cannot init plugins");
}
/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
- if (internal_config.iova_mode == RTE_IOVA_DC) {
+ if (internal_conf->iova_mode == RTE_IOVA_DC) {
/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */
enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
rte_eal_get_configuration()->iova_mode = iova_mode;
} else {
rte_eal_get_configuration()->iova_mode =
- internal_config.iova_mode;
+ internal_conf->iova_mode;
}
RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
- if (internal_config.no_hugetlbfs == 0) {
+ if (internal_conf->no_hugetlbfs == 0) {
/* rte_config isn't initialized yet */
- ret = internal_config.process_type == RTE_PROC_PRIMARY ?
+ ret = internal_conf->process_type == RTE_PROC_PRIMARY ?
eal_hugepage_info_init() :
eal_hugepage_info_read();
if (ret < 0) {
}
}
- if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
- if (internal_config.no_hugetlbfs)
- internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
+ if (internal_conf->memory == 0 && internal_conf->force_sockets == 0) {
+ if (internal_conf->no_hugetlbfs)
+ internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE;
else
- internal_config.memory = eal_get_hugepage_mem_size();
+ internal_conf->memory = eal_get_hugepage_mem_size();
}
- if (internal_config.vmware_tsc_map == 1) {
+ if (internal_conf->vmware_tsc_map == 1) {
#ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
rte_cycles_vmware_tsc_map = 1;
RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
eal_check_mem_on_local_socket();
- eal_thread_init_master(rte_config.master_lcore);
+ if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
+ &lcore_config[config->master_lcore].cpuset) != 0) {
+ rte_eal_init_alert("Cannot set affinity");
+ rte_errno = EINVAL;
+ return -1;
+ }
+ __rte_thread_init(config->master_lcore,
+ &lcore_config[config->master_lcore].cpuset);
ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
- rte_config.master_lcore, thread_id, cpuset,
+ config->master_lcore, thread_id, cpuset,
ret == 0 ? "" : "...");
RTE_LCORE_FOREACH_SLAVE(i) {
snprintf(thread_name, sizeof(thread_name),
"lcore-slave-%d", i);
rte_thread_setname(lcore_config[i].thread_id, thread_name);
+
+ ret = pthread_setaffinity_np(lcore_config[i].thread_id,
+ sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
+ if (ret != 0)
+ rte_panic("Cannot set affinity\n");
}
/*
* In no_shconf mode, no runtime directory is created in the first
* place, so no cleanup needed.
*/
- if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) {
- rte_eal_init_alert("Cannot clear runtime directory\n");
+ if (!internal_conf->no_shconf && eal_clean_runtime_dir() < 0) {
+ rte_eal_init_alert("Cannot clear runtime directory");
return -1;
}
+ if (!internal_conf->no_telemetry) {
+ const char *error_str = NULL;
+ if (rte_telemetry_init(rte_eal_get_runtime_dir(),
+ &internal_conf->ctrl_cpuset, &error_str)
+ != 0) {
+ rte_eal_init_alert(error_str);
+ return -1;
+ }
+ if (error_str != NULL)
+ RTE_LOG(NOTICE, EAL, "%s\n", error_str);
+ }
eal_mcfg_complete();
- /* Call each registered callback, if enabled */
- rte_option_init();
-
return fctret;
}
int
rte_eal_cleanup(void)
{
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
rte_service_finalize();
rte_mp_channel_cleanup();
rte_trace_save();
eal_trace_fini();
- eal_cleanup_config(&internal_config);
+ eal_cleanup_config(internal_conf);
return 0;
}
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
- return rte_config.process_type;
-}
-
-int rte_eal_has_pci(void)
-{
- return !internal_config.no_pci;
-}
-
int rte_eal_create_uio_dev(void)
{
- return internal_config.create_uio_dev;
+ const struct internal_config *internal_conf =
+ eal_get_internal_configuration();
+ return internal_conf->create_uio_dev;
}
enum rte_intr_mode
return RTE_INTR_MODE_NONE;
}
+void
+rte_eal_vfio_get_vf_token(__rte_unused rte_uuid_t vf_token)
+{
+}
+
int rte_vfio_setup_device(__rte_unused const char *sysfs_base,
__rte_unused const char *dev_addr,
__rte_unused int *vfio_dev_fd,