mempool: return 0 if area is too small on populate
[dpdk.git] / lib / librte_mempool / rte_mempool.h
index c90cf31..652d19f 100644 (file)
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include "rte_mempool_trace_fp.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -736,6 +738,7 @@ rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
 {
        struct rte_mempool_ops *ops;
 
+       rte_mempool_trace_ops_dequeue_bulk(mp, obj_table, n);
        ops = rte_mempool_get_ops(mp->ops_index);
        return ops->dequeue(mp, obj_table, n);
 }
@@ -761,6 +764,7 @@ rte_mempool_ops_dequeue_contig_blocks(struct rte_mempool *mp,
 
        ops = rte_mempool_get_ops(mp->ops_index);
        RTE_ASSERT(ops->dequeue_contig_blocks != NULL);
+       rte_mempool_trace_ops_dequeue_contig_blocks(mp, first_obj_table, n);
        return ops->dequeue_contig_blocks(mp, first_obj_table, n);
 }
 
@@ -783,6 +787,7 @@ rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
 {
        struct rte_mempool_ops *ops;
 
+       rte_mempool_trace_ops_enqueue_bulk(mp, obj_table, n);
        ops = rte_mempool_get_ops(mp->ops_index);
        return ops->enqueue(mp, obj_table, n);
 }
@@ -1107,9 +1112,12 @@ rte_mempool_free(struct rte_mempool *mp);
  * @param opaque
  *   An opaque argument passed to free_cb.
  * @return
- *   The number of objects added on success.
+ *   The number of objects added on success (strictly positive).
  *   On error, the chunk is not added in the memory list of the
- *   mempool and a negative errno is returned.
+ *   mempool the following code is returned:
+ *     (0): not enough room in chunk for one object.
+ *     (-ENOSPC): mempool is already populated.
+ *     (-ENOMEM): allocation failure.
  */
 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
        rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
@@ -1134,9 +1142,12 @@ int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
  * @param opaque
  *   An opaque argument passed to free_cb.
  * @return
- *   The number of objects added on success.
+ *   The number of objects added on success (strictly positive).
  *   On error, the chunk is not added in the memory list of the
- *   mempool and a negative errno is returned.
+ *   mempool the following code is returned:
+ *     (0): not enough room in chunk for one object.
+ *     (-ENOSPC): mempool is already populated.
+ *     (-ENOMEM): allocation failure.
  */
 int
 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
@@ -1264,6 +1275,8 @@ rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
        if (lcore_id >= RTE_MAX_LCORE)
                return NULL;
 
+       rte_mempool_trace_default_cache(mp, lcore_id,
+               &mp->local_cache[lcore_id]);
        return &mp->local_cache[lcore_id];
 }
 
@@ -1283,6 +1296,7 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
                cache = rte_mempool_default_cache(mp, rte_lcore_id());
        if (cache == NULL || cache->len == 0)
                return;
+       rte_mempool_trace_cache_flush(cache, mp);
        rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
        cache->len = 0;
 }
@@ -1362,6 +1376,7 @@ static __rte_always_inline void
 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                        unsigned int n, struct rte_mempool_cache *cache)
 {
+       rte_mempool_trace_generic_put(mp, obj_table, n, cache);
        __mempool_check_cookies(mp, obj_table, n, 0);
        __mempool_generic_put(mp, obj_table, n, cache);
 }
@@ -1386,6 +1401,7 @@ rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
 {
        struct rte_mempool_cache *cache;
        cache = rte_mempool_default_cache(mp, rte_lcore_id());
+       rte_mempool_trace_put_bulk(mp, obj_table, n, cache);
        rte_mempool_generic_put(mp, obj_table, n, cache);
 }
 
@@ -1507,6 +1523,7 @@ rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
        ret = __mempool_generic_get(mp, obj_table, n, cache);
        if (ret == 0)
                __mempool_check_cookies(mp, obj_table, n, 1);
+       rte_mempool_trace_generic_get(mp, obj_table, n, cache);
        return ret;
 }
 
@@ -1537,6 +1554,7 @@ rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
 {
        struct rte_mempool_cache *cache;
        cache = rte_mempool_default_cache(mp, rte_lcore_id());
+       rte_mempool_trace_get_bulk(mp, obj_table, n, cache);
        return rte_mempool_generic_get(mp, obj_table, n, cache);
 }
 
@@ -1606,6 +1624,7 @@ rte_mempool_get_contig_blocks(struct rte_mempool *mp,
                __MEMPOOL_CONTIG_BLOCKS_STAT_ADD(mp, get_fail, n);
        }
 
+       rte_mempool_trace_get_contig_blocks(mp, first_obj_table, n);
        return ret;
 }