X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Flinux%2Feal.c;h=6c34ac89038690b268dfd9847817c45a1095d4d9;hb=378cd4887d6c02bf771eee3a8b56a3af41f37b7c;hp=e7068f198b2d17101d3614a7b0258404c8dfdcb8;hpb=57a2efb304775135e320acde1e0622b1190bffa9;p=dpdk.git diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index e7068f198b..6c34ac8903 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -69,9 +68,6 @@ #define KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups" -/* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook = NULL; - /* 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; @@ -495,6 +491,10 @@ rte_config_init(void) } 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: @@ -532,6 +532,8 @@ eal_hugedirs_unlock(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t hook = eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); printf("EAL Linux options:\n" @@ -541,30 +543,18 @@ eal_usage(const char *prgname) " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n" " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n" " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n" + " --"OPT_VFIO_VF_TOKEN" VF token (UUID) shared between SR-IOV PF and VFs\n" " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n" " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n" " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n" "\n"); /* 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 int eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg) { @@ -634,6 +624,20 @@ eal_parse_vfio_intr(const char *mode) return -1; } +static int +eal_parse_vfio_vf_token(const char *vf_token) +{ + struct internal_config *cfg = eal_get_internal_configuration(); + rte_uuid_t uuid; + + if (!rte_uuid_parse(vf_token, uuid)) { + rte_uuid_copy(cfg->vfio_vf_token, uuid); + return 0; + } + + return -1; +} + /* Parse the arguments for --log-level only */ static void eal_log_level_parse(int argc, char **argv) @@ -776,6 +780,16 @@ eal_parse_args(int argc, char **argv) } break; + case OPT_VFIO_VF_TOKEN_NUM: + if (eal_parse_vfio_vf_token(optarg) < 0) { + RTE_LOG(ERR, EAL, "invalid parameters for --" + OPT_VFIO_VF_TOKEN "\n"); + eal_usage(prgname); + ret = -1; + goto out; + } + break; + case OPT_CREATE_UIO_DEV_NUM: internal_conf->create_uio_dev = 1; break; @@ -869,10 +883,10 @@ 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(config->master_lcore); + socket_id = rte_lcore_to_socket_id(config->main_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"); + RTE_LOG(WARNING, EAL, "WARNING: Main core has no memory on local socket!\n"); } static int @@ -945,7 +959,8 @@ rte_eal_init(int argc, char **argv) { int i, fctret, ret; pthread_t thread_id; - static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); + static uint32_t run_once; + uint32_t has_run = 0; const char *p; static char logid[PATH_MAX]; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; @@ -962,7 +977,8 @@ rte_eal_init(int argc, char **argv) return -1; } - if (!rte_atomic32_test_and_set(&run_once)) { + if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED)) { rte_eal_init_alert("already called initialization."); rte_errno = EALREADY; return -1; @@ -990,14 +1006,14 @@ rte_eal_init(int argc, char **argv) if (fctret < 0) { rte_eal_init_alert("Invalid 'command line' arguments."); rte_errno = EINVAL; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); rte_errno = EINVAL; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } @@ -1009,7 +1025,7 @@ rte_eal_init(int argc, char **argv) if (eal_option_device_parse()) { rte_errno = ENODEV; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } @@ -1049,7 +1065,7 @@ rte_eal_init(int argc, char **argv) if (rte_bus_scan()) { rte_eal_init_alert("Cannot scan the buses for devices"); rte_errno = ENODEV; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } @@ -1069,7 +1085,7 @@ rte_eal_init(int argc, char **argv) */ iova_mode = RTE_IOVA_VA; RTE_LOG(DEBUG, EAL, "Physical addresses are unavailable, selecting IOVA as VA mode.\n"); -#if defined(RTE_LIBRTE_KNI) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) +#if defined(RTE_LIB_KNI) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) } else if (rte_eal_check_module("rte_kni") == 1) { iova_mode = RTE_IOVA_PA; RTE_LOG(DEBUG, EAL, "KNI is loaded, selecting IOVA as PA mode for better KNI performance.\n"); @@ -1086,7 +1102,7 @@ rte_eal_init(int argc, char **argv) RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n"); } } -#if defined(RTE_LIBRTE_KNI) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) +#if defined(RTE_LIB_KNI) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) /* Workaround for KNI which requires physical address to work * in kernels < 4.10 */ @@ -1123,7 +1139,7 @@ rte_eal_init(int argc, char **argv) if (ret < 0) { rte_eal_init_alert("Cannot get hugepage information."); rte_errno = EACCES; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } } @@ -1147,7 +1163,7 @@ rte_eal_init(int argc, char **argv) if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } @@ -1155,7 +1171,7 @@ rte_eal_init(int argc, char **argv) if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); rte_errno = EAGAIN; - rte_atomic32_clear(&run_once); + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); return -1; } #endif @@ -1198,23 +1214,29 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - eal_thread_init_master(config->master_lcore); - - ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset)); + if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t), + &lcore_config[config->main_lcore].cpuset) != 0) { + rte_eal_init_alert("Cannot set affinity"); + rte_errno = EINVAL; + return -1; + } + __rte_thread_init(config->main_lcore, + &lcore_config[config->main_lcore].cpuset); - RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n", - config->master_lcore, (uintptr_t)thread_id, cpuset, + ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset)); + RTE_LOG(DEBUG, EAL, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])\n", + config->main_lcore, (uintptr_t)thread_id, cpuset, ret == 0 ? "" : "..."); - RTE_LCORE_FOREACH_SLAVE(i) { + RTE_LCORE_FOREACH_WORKER(i) { /* - * create communication pipes between master thread + * create communication pipes between main thread * and children */ - if (pipe(lcore_config[i].pipe_master2slave) < 0) + if (pipe(lcore_config[i].pipe_main2worker) < 0) rte_panic("Cannot create pipe\n"); - if (pipe(lcore_config[i].pipe_slave2master) < 0) + if (pipe(lcore_config[i].pipe_worker2main) < 0) rte_panic("Cannot create pipe\n"); lcore_config[i].state = WAIT; @@ -1227,26 +1249,31 @@ rte_eal_init(int argc, char **argv) /* Set thread_name for aid in debugging. */ snprintf(thread_name, sizeof(thread_name), - "lcore-slave-%d", i); + "lcore-worker-%d", i); ret = rte_thread_setname(lcore_config[i].thread_id, thread_name); if (ret != 0) RTE_LOG(DEBUG, EAL, "Cannot set name for lcore thread\n"); + + 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"); } /* - * Launch a dummy function on all slave lcores, so that master lcore + * Launch a dummy function on all worker lcores, so that main lcore * knows they are all ready when this function returns. */ - rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); + rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MAIN); rte_eal_mp_wait_lcore(); /* initialize services so vdevs register service during bus_probe. */ ret = rte_service_init(); if (ret) { rte_eal_init_alert("rte_service_init() failed"); - rte_errno = ENOEXEC; + rte_errno = -ret; return -1; } @@ -1268,7 +1295,7 @@ rte_eal_init(int argc, char **argv) */ ret = rte_service_start_with_defaults(); if (ret < 0 && ret != -ENOTSUP) { - rte_errno = ENOEXEC; + rte_errno = -ret; return -1; } @@ -1333,6 +1360,8 @@ rte_eal_cleanup(void) rte_memseg_walk(mark_freeable, NULL); rte_service_finalize(); rte_mp_channel_cleanup(); + /* after this point, any DPDK pointers will become dangling */ + rte_eal_memory_detach(); rte_trace_save(); eal_trace_fini(); eal_cleanup_config(internal_conf); @@ -1356,6 +1385,14 @@ rte_eal_vfio_intr_mode(void) return internal_conf->vfio_intr_mode; } +void +rte_eal_vfio_get_vf_token(rte_uuid_t vf_token) +{ + struct internal_config *cfg = eal_get_internal_configuration(); + + rte_uuid_copy(vf_token, cfg->vfio_vf_token); +} + int rte_eal_check_module(const char *module_name) {