mempool: use bit flags for multi consumers and producers
[dpdk.git] / lib / librte_mempool / rte_mempool.h
index 0a1777c..178867f 100644 (file)
@@ -953,12 +953,13 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
  * @param n
  *   The number of objects to store back in the mempool, must be strictly
  *   positive.
- * @param is_mp
- *   Mono-producer (0) or multi-producers (1).
+ * @param flags
+ *   The flags used for the mempool creation.
+ *   Single-producer (MEMPOOL_F_SP_PUT flag) or multi-producers.
  */
 static inline void __attribute__((always_inline))
-__mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
-                   unsigned n, int is_mp)
+__mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
+                     unsigned n, int flags)
 {
        struct rte_mempool_cache *cache;
        uint32_t index;
@@ -971,7 +972,7 @@ __mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
        __MEMPOOL_STAT_ADD(mp, put, n);
 
        /* cache is not enabled or single producer or non-EAL thread */
-       if (unlikely(cache_size == 0 || is_mp == 0 ||
+       if (unlikely(cache_size == 0 || flags & MEMPOOL_F_SP_PUT ||
                     lcore_id >= RTE_MAX_LCORE))
                goto ring_enqueue;
 
@@ -1016,6 +1017,28 @@ ring_enqueue:
 
 
 /**
+ * Put several objects back in the mempool.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @param obj_table
+ *   A pointer to a table of void * pointers (objects).
+ * @param n
+ *   The number of objects to add in the mempool from the obj_table.
+ * @param flags
+ *   The flags used for the mempool creation.
+ *   Single-producer (MEMPOOL_F_SP_PUT flag) or multi-producers.
+ */
+static inline void __attribute__((always_inline))
+rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
+                       unsigned n, int flags)
+{
+       __mempool_check_cookies(mp, obj_table, n, 0);
+       __mempool_generic_put(mp, obj_table, n, flags);
+}
+
+/**
+ * @deprecated
  * Put several objects back in the mempool (multi-producers safe).
  *
  * @param mp
@@ -1025,15 +1048,16 @@ ring_enqueue:
  * @param n
  *   The number of objects to add in the mempool from the obj_table.
  */
+__rte_deprecated
 static inline void __attribute__((always_inline))
 rte_mempool_mp_put_bulk(struct rte_mempool *mp, void * const *obj_table,
                        unsigned n)
 {
-       __mempool_check_cookies(mp, obj_table, n, 0);
-       __mempool_put_bulk(mp, obj_table, n, 1);
+       rte_mempool_generic_put(mp, obj_table, n, 0);
 }
 
 /**
+ * @deprecated
  * Put several objects back in the mempool (NOT multi-producers safe).
  *
  * @param mp
@@ -1043,12 +1067,12 @@ rte_mempool_mp_put_bulk(struct rte_mempool *mp, void * const *obj_table,
  * @param n
  *   The number of objects to add in the mempool from obj_table.
  */
-static inline void
+__rte_deprecated
+static inline void __attribute__((always_inline))
 rte_mempool_sp_put_bulk(struct rte_mempool *mp, void * const *obj_table,
                        unsigned n)
 {
-       __mempool_check_cookies(mp, obj_table, n, 0);
-       __mempool_put_bulk(mp, obj_table, n, 0);
+       rte_mempool_generic_put(mp, obj_table, n, MEMPOOL_F_SP_PUT);
 }
 
 /**
@@ -1069,11 +1093,11 @@ static inline void __attribute__((always_inline))
 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
                     unsigned n)
 {
-       __mempool_check_cookies(mp, obj_table, n, 0);
-       __mempool_put_bulk(mp, obj_table, n, !(mp->flags & MEMPOOL_F_SP_PUT));
+       rte_mempool_generic_put(mp, obj_table, n, mp->flags);
 }
 
 /**
+ * @deprecated
  * Put one object in the mempool (multi-producers safe).
  *
  * @param mp
@@ -1081,13 +1105,15 @@ rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
  * @param obj
  *   A pointer to the object to be added.
  */
+__rte_deprecated
 static inline void __attribute__((always_inline))
 rte_mempool_mp_put(struct rte_mempool *mp, void *obj)
 {
-       rte_mempool_mp_put_bulk(mp, &obj, 1);
+       rte_mempool_generic_put(mp, &obj, 1, 0);
 }
 
 /**
+ * @deprecated
  * Put one object back in the mempool (NOT multi-producers safe).
  *
  * @param mp
@@ -1095,10 +1121,11 @@ rte_mempool_mp_put(struct rte_mempool *mp, void *obj)
  * @param obj
  *   A pointer to the object to be added.
  */
+__rte_deprecated
 static inline void __attribute__((always_inline))
 rte_mempool_sp_put(struct rte_mempool *mp, void *obj)
 {
-       rte_mempool_sp_put_bulk(mp, &obj, 1);
+       rte_mempool_generic_put(mp, &obj, 1, MEMPOOL_F_SP_PUT);
 }
 
 /**
@@ -1127,15 +1154,16 @@ rte_mempool_put(struct rte_mempool *mp, void *obj)
  *   A pointer to a table of void * pointers (objects).
  * @param n
  *   The number of objects to get, must be strictly positive.
- * @param is_mc
- *   Mono-consumer (0) or multi-consumers (1).
+ * @param flags
+ *   The flags used for the mempool creation.
+ *   Single-consumer (MEMPOOL_F_SC_GET flag) or multi-consumers.
  * @return
  *   - >=0: Success; number of objects supplied.
  *   - <0: Error; code of ring dequeue function.
  */
 static inline int __attribute__((always_inline))
-__mempool_get_bulk(struct rte_mempool *mp, void **obj_table,
-                  unsigned n, int is_mc)
+__mempool_generic_get(struct rte_mempool *mp, void **obj_table,
+                     unsigned n, int flags)
 {
        int ret;
        struct rte_mempool_cache *cache;
@@ -1145,7 +1173,7 @@ __mempool_get_bulk(struct rte_mempool *mp, void **obj_table,
        uint32_t cache_size = mp->cache_size;
 
        /* cache is not enabled or single consumer */
-       if (unlikely(cache_size == 0 || is_mc == 0 ||
+       if (unlikely(cache_size == 0 || flags & MEMPOOL_F_SC_GET ||
                     n >= cache_size || lcore_id >= RTE_MAX_LCORE))
                goto ring_dequeue;
 
@@ -1197,7 +1225,7 @@ ring_dequeue:
 }
 
 /**
- * Get several objects from the mempool (multi-consumers safe).
+ * Get several objects from the mempool.
  *
  * If cache is enabled, objects will be retrieved first from cache,
  * subsequently from the common pool. Note that it can return -ENOENT when
@@ -1210,21 +1238,52 @@ ring_dequeue:
  *   A pointer to a table of void * pointers (objects) that will be filled.
  * @param n
  *   The number of objects to get from mempool to obj_table.
+ * @param flags
+ *   The flags used for the mempool creation.
+ *   Single-consumer (MEMPOOL_F_SC_GET flag) or multi-consumers.
  * @return
  *   - 0: Success; objects taken.
  *   - -ENOENT: Not enough entries in the mempool; no object is retrieved.
  */
 static inline int __attribute__((always_inline))
-rte_mempool_mc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
+rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned n,
+                       int flags)
 {
        int ret;
-       ret = __mempool_get_bulk(mp, obj_table, n, 1);
+       ret = __mempool_generic_get(mp, obj_table, n, flags);
        if (ret == 0)
                __mempool_check_cookies(mp, obj_table, n, 1);
        return ret;
 }
 
 /**
+ * @deprecated
+ * Get several objects from the mempool (multi-consumers safe).
+ *
+ * If cache is enabled, objects will be retrieved first from cache,
+ * subsequently from the common pool. Note that it can return -ENOENT when
+ * the local cache and common pool are empty, even if cache from other
+ * lcores are full.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @param obj_table
+ *   A pointer to a table of void * pointers (objects) that will be filled.
+ * @param n
+ *   The number of objects to get from mempool to obj_table.
+ * @return
+ *   - 0: Success; objects taken.
+ *   - -ENOENT: Not enough entries in the mempool; no object is retrieved.
+ */
+__rte_deprecated
+static inline int __attribute__((always_inline))
+rte_mempool_mc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
+{
+       return rte_mempool_generic_get(mp, obj_table, n, 0);
+}
+
+/**
+ * @deprecated
  * Get several objects from the mempool (NOT multi-consumers safe).
  *
  * If cache is enabled, objects will be retrieved first from cache,
@@ -1243,14 +1302,11 @@ rte_mempool_mc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
  *   - -ENOENT: Not enough entries in the mempool; no object is
  *     retrieved.
  */
+__rte_deprecated
 static inline int __attribute__((always_inline))
 rte_mempool_sc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
 {
-       int ret;
-       ret = __mempool_get_bulk(mp, obj_table, n, 0);
-       if (ret == 0)
-               __mempool_check_cookies(mp, obj_table, n, 1);
-       return ret;
+       return rte_mempool_generic_get(mp, obj_table, n, MEMPOOL_F_SC_GET);
 }
 
 /**
@@ -1278,15 +1334,11 @@ rte_mempool_sc_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
 static inline int __attribute__((always_inline))
 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
 {
-       int ret;
-       ret = __mempool_get_bulk(mp, obj_table, n,
-                                !(mp->flags & MEMPOOL_F_SC_GET));
-       if (ret == 0)
-               __mempool_check_cookies(mp, obj_table, n, 1);
-       return ret;
+       return rte_mempool_generic_get(mp, obj_table, n, mp->flags);
 }
 
 /**
+ * @deprecated
  * Get one object from the mempool (multi-consumers safe).
  *
  * If cache is enabled, objects will be retrieved first from cache,
@@ -1302,13 +1354,15 @@ rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
  *   - 0: Success; objects taken.
  *   - -ENOENT: Not enough entries in the mempool; no object is retrieved.
  */
+__rte_deprecated
 static inline int __attribute__((always_inline))
 rte_mempool_mc_get(struct rte_mempool *mp, void **obj_p)
 {
-       return rte_mempool_mc_get_bulk(mp, obj_p, 1);
+       return rte_mempool_generic_get(mp, obj_p, 1, 0);
 }
 
 /**
+ * @deprecated
  * Get one object from the mempool (NOT multi-consumers safe).
  *
  * If cache is enabled, objects will be retrieved first from cache,
@@ -1324,10 +1378,11 @@ rte_mempool_mc_get(struct rte_mempool *mp, void **obj_p)
  *   - 0: Success; objects taken.
  *   - -ENOENT: Not enough entries in the mempool; no object is retrieved.
  */
+__rte_deprecated
 static inline int __attribute__((always_inline))
 rte_mempool_sc_get(struct rte_mempool *mp, void **obj_p)
 {
-       return rte_mempool_sc_get_bulk(mp, obj_p, 1);
+       return rte_mempool_generic_get(mp, obj_p, 1, MEMPOOL_F_SC_GET);
 }
 
 /**