struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
rte_rwlock_write_unlock(&mcfg->mplock);
}
+
+void
+rte_mcfg_timer_lock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_spinlock_lock(&mcfg->tlock);
+}
+
+void
+rte_mcfg_timer_unlock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_spinlock_unlock(&mcfg->tlock);
+}
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_pause.h>
+#include <rte_spinlock.h>
#include <rte_rwlock.h>
#include <rte_tailq.h>
rte_rwlock_t mlock; /**< used by memzones for thread safety. */
rte_rwlock_t qlock; /**< used by tailqs for thread safety. */
rte_rwlock_t mplock; /**< used by mempool library for thread safety. */
+ rte_spinlock_t tlock; /**< used by timer library for thread safety. */
rte_rwlock_t memory_hotplug_lock;
/**< Indicates whether memory hotplug request is in progress. */
#ifndef _RTE_EAL_MEMCONFIG_H_
#define _RTE_EAL_MEMCONFIG_H_
+#include <rte_compat.h>
+
/**
* @file
*
void
rte_mcfg_mempool_write_unlock(void);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Lock the internal EAL Timer Library lock for exclusive access.
+ */
+__rte_experimental
+void
+rte_mcfg_timer_lock(void);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Unlock the internal EAL Timer Library lock for exclusive access.
+ */
+__rte_experimental
+void
+rte_mcfg_timer_unlock(void);
+
#ifdef __cplusplus
}
#endif
#include <rte_atomic.h>
#include <rte_common.h>
#include <rte_cycles.h>
+#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_memory.h>
#include <rte_launch.h>
};
#define RTE_MAX_DATA_ELS 64
+static const struct rte_memzone *rte_timer_data_mz;
+static int *volatile rte_timer_mz_refcnt;
static struct rte_timer_data *rte_timer_data_arr;
static const uint32_t default_data_id;
static uint32_t rte_timer_subsystem_initialized;
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);
+ RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);
+ const size_t mem_size = data_arr_size + sizeof(*rte_timer_mz_refcnt);
bool do_full_init = true;
if (rte_timer_subsystem_initialized)
return -EALREADY;
-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;
+ rte_mcfg_timer_lock();
- do_full_init = false;
- } else
+ mz = rte_memzone_lookup(mz_name);
+ if (mz == NULL) {
+ mz = rte_memzone_reserve_aligned(mz_name, mem_size,
+ SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
+ if (mz == NULL) {
+ rte_mcfg_timer_unlock();
return -ENOMEM;
- }
+ }
+ do_full_init = true;
+ } else
+ do_full_init = false;
+ rte_timer_data_mz = mz;
rte_timer_data_arr = mz->addr;
+ rte_timer_mz_refcnt = (void *)((char *)mz->addr + data_arr_size);
if (do_full_init) {
for (i = 0; i < RTE_MAX_DATA_ELS; i++) {
}
rte_timer_data_arr[default_data_id].internal_flags |= FL_ALLOCATED;
+ (*rte_timer_mz_refcnt)++;
+
+ rte_mcfg_timer_unlock();
rte_timer_subsystem_initialized = 1;
if (!rte_timer_subsystem_initialized)
return;
+ rte_mcfg_timer_lock();
+
+ if (--(*rte_timer_mz_refcnt) == 0)
+ rte_memzone_free(rte_timer_data_mz);
+
+ rte_mcfg_timer_unlock();
+
rte_timer_subsystem_initialized = 0;
}