summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Gabriel Carrillo <erik.g.carrillo@intel.com>2019-05-09 14:39:36 -0500
committerThomas Monjalon <thomas@monjalon.net>2019-05-10 00:09:29 +0200
commit62e5c38ee4a197e9cf196830324b7fd76c34c022 (patch)
tree15d0e6719d2d8a9c7d1f2c3b6f0713e13eb14f54
parenta55f182b77507f3c7ea65362c759a5a96ddc784b (diff)
downloaddpdk-draft-windows-62e5c38ee4a197e9cf196830324b7fd76c34c022.zip
dpdk-draft-windows-62e5c38ee4a197e9cf196830324b7fd76c34c022.tar.gz
dpdk-draft-windows-62e5c38ee4a197e9cf196830324b7fd76c34c022.tar.xz
timer: allow first subsystem init from secondary
Since memzones can be reserved from secondary processes as well as primary processes, if the first call to the timer subsystem init function occurs in a secondary process, we should allow it to succeed. Fixes: c0749f7096c7 ("timer: allow management in shared memory") Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
-rw-r--r--lib/librte_timer/rte_timer.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c
index 9f2e921..dd79539 100644
--- a/lib/librte_timer/rte_timer.c
+++ b/lib/librte_timer/rte_timer.c
@@ -25,6 +25,7 @@
#include <rte_memzone.h>
#include <rte_malloc.h>
#include <rte_compat.h>
+#include <rte_errno.h>
#include "rte_timer.h"
@@ -155,40 +156,41 @@ rte_timer_subsystem_init_v1905(void)
struct rte_timer_data *data;
int i, lcore_id;
static const char *mz_name = "rte_timer_mz";
+ const size_t data_arr_size =
+ RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);
+ bool do_full_init = true;
if (rte_timer_subsystem_initialized)
return -EALREADY;
- if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
- mz = rte_memzone_lookup(mz_name);
- if (mz == NULL)
- return -EEXIST;
-
- rte_timer_data_arr = mz->addr;
-
- rte_timer_data_arr[default_data_id].internal_flags |=
- FL_ALLOCATED;
-
- rte_timer_subsystem_initialized = 1;
-
- return 0;
+reserve:
+ rte_errno = 0;
+ mz = rte_memzone_reserve_aligned(mz_name, data_arr_size, SOCKET_ID_ANY,
+ 0, RTE_CACHE_LINE_SIZE);
+ if (mz == NULL) {
+ if (rte_errno == EEXIST) {
+ mz = rte_memzone_lookup(mz_name);
+ if (mz == NULL)
+ goto reserve;
+
+ do_full_init = false;
+ } else
+ return -ENOMEM;
}
- mz = rte_memzone_reserve_aligned(mz_name,
- RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr),
- SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
- if (mz == NULL)
- return -ENOMEM;
-
rte_timer_data_arr = mz->addr;
- for (i = 0; i < RTE_MAX_DATA_ELS; i++) {
- data = &rte_timer_data_arr[i];
+ if (do_full_init) {
+ for (i = 0; i < RTE_MAX_DATA_ELS; i++) {
+ data = &rte_timer_data_arr[i];
- for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
- rte_spinlock_init(
- &data->priv_timer[lcore_id].list_lock);
- data->priv_timer[lcore_id].prev_lcore = lcore_id;
+ for (lcore_id = 0; lcore_id < RTE_MAX_LCORE;
+ lcore_id++) {
+ rte_spinlock_init(
+ &data->priv_timer[lcore_id].list_lock);
+ data->priv_timer[lcore_id].prev_lcore =
+ lcore_id;
+ }
}
}
@@ -205,8 +207,8 @@ BIND_DEFAULT_SYMBOL(rte_timer_subsystem_init, _v1905, 19.05);
void __rte_experimental
rte_timer_subsystem_finalize(void)
{
- if (rte_timer_data_arr)
- rte_free(rte_timer_data_arr);
+ if (!rte_timer_subsystem_initialized)
+ return;
rte_timer_subsystem_initialized = 0;
}