[v5,3/9] eal: add new API to lock/unlock mempool list
Checks
Commit Message
Currently, in order to lock access to the mempool list, a direct
access to the shared memory structure is needed. Add an API to do
the same, and search-and-replace all usages.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: David Marchand <david.marchand@redhat.com>
---
lib/librte_eal/common/eal_common_mcfg.c | 28 +++++++++++++++++++
lib/librte_eal/common/include/rte_eal.h | 5 ----
.../common/include/rte_eal_memconfig.h | 24 ++++++++++++++++
lib/librte_eal/rte_eal_version.map | 4 +++
lib/librte_mempool/rte_mempool.c | 18 ++++++------
5 files changed, 65 insertions(+), 14 deletions(-)
@@ -60,3 +60,31 @@ rte_mcfg_tailq_write_unlock(void)
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
rte_rwlock_write_unlock(&mcfg->qlock);
}
+
+void
+rte_mcfg_mempool_read_lock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_rwlock_read_lock(&mcfg->mplock);
+}
+
+void
+rte_mcfg_mempool_read_unlock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_rwlock_read_unlock(&mcfg->mplock);
+}
+
+void
+rte_mcfg_mempool_write_lock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_rwlock_write_lock(&mcfg->mplock);
+}
+
+void
+rte_mcfg_mempool_write_unlock(void)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ rte_rwlock_write_unlock(&mcfg->mplock);
+}
@@ -446,11 +446,6 @@ typedef void (*rte_usage_hook_t)(const char * prgname);
rte_usage_hook_t
rte_set_application_usage_hook(rte_usage_hook_t usage_func);
-/**
- * macro to get the multiple lock of mempool shared by multiple-instance
- */
-#define RTE_EAL_MEMPOOL_RWLOCK (&rte_eal_get_configuration()->mem_config->mplock)
-
/**
* Whether EAL is using huge pages (disabled by --no-huge option).
* The no-huge mode cannot be used with UIO poll-mode drivers like igb/ixgbe.
@@ -148,6 +148,30 @@ rte_mcfg_tailq_write_lock(void);
void
rte_mcfg_tailq_write_unlock(void);
+/**
+ * Lock the internal EAL Mempool list for shared access.
+ */
+void
+rte_mcfg_mempool_read_lock(void);
+
+/**
+ * Unlock the internal EAL Mempool list for shared access.
+ */
+void
+rte_mcfg_mempool_read_unlock(void);
+
+/**
+ * Lock the internal EAL Mempool list for exclusive access.
+ */
+void
+rte_mcfg_mempool_write_lock(void);
+
+/**
+ * Unlock the internal EAL Mempool list for exclusive access.
+ */
+void
+rte_mcfg_mempool_write_unlock(void);
+
#ifdef __cplusplus
}
#endif
@@ -296,6 +296,10 @@ DPDK_19.08 {
rte_mcfg_mem_read_unlock;
rte_mcfg_mem_write_lock;
rte_mcfg_mem_write_unlock;
+ rte_mcfg_mempool_read_lock;
+ rte_mcfg_mempool_read_unlock;
+ rte_mcfg_mempool_write_lock;
+ rte_mcfg_mempool_write_unlock;
rte_mcfg_tailq_read_lock;
rte_mcfg_tailq_read_unlock;
rte_mcfg_tailq_write_lock;
@@ -830,7 +830,7 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
return NULL;
}
- rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_write_lock();
/*
* reserve a memory zone for this mempool: private data is
@@ -901,12 +901,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
rte_mcfg_tailq_write_lock();
TAILQ_INSERT_TAIL(mempool_list, te, next);
rte_mcfg_tailq_write_unlock();
- rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_write_unlock();
return mp;
exit_unlock:
- rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_write_unlock();
rte_free(te);
rte_mempool_free(mp);
return NULL;
@@ -1268,14 +1268,14 @@ rte_mempool_list_dump(FILE *f)
mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
- rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_lock();
TAILQ_FOREACH(te, mempool_list, next) {
mp = (struct rte_mempool *) te->data;
rte_mempool_dump(f, mp);
}
- rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_unlock();
}
/* search a mempool from its name */
@@ -1288,7 +1288,7 @@ rte_mempool_lookup(const char *name)
mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
- rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_lock();
TAILQ_FOREACH(te, mempool_list, next) {
mp = (struct rte_mempool *) te->data;
@@ -1296,7 +1296,7 @@ rte_mempool_lookup(const char *name)
break;
}
- rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_unlock();
if (te == NULL) {
rte_errno = ENOENT;
@@ -1315,11 +1315,11 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),
mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head, rte_mempool_list);
- rte_rwlock_read_lock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_lock();
TAILQ_FOREACH_SAFE(te, mempool_list, next, tmp_te) {
(*func)((struct rte_mempool *) te->data, arg);
}
- rte_rwlock_read_unlock(RTE_EAL_MEMPOOL_RWLOCK);
+ rte_mcfg_mempool_read_unlock();
}