]> git.droids-corp.org - dpdk.git/commitdiff
mempool: rename functions with confusing names
authorBruce Richardson <bruce.richardson@intel.com>
Thu, 30 Jun 2016 12:49:25 +0000 (13:49 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 1 Jul 2016 10:35:57 +0000 (12:35 +0200)
The mempool_count and mempool_free_count behaved contrary to what their
names suggested. The free_count function actually returned the number of
elements that were allocated from the pool, not the number unallocated as
the name implied.

Fix this by introducing two new functions to replace the old ones,
* rte_mempool_avail_count to replace rte_mempool_count
* rte_mempool_in_use_count to replace rte_mempool_free_count

In this patch, the new functions are added, and the old ones are marked
as deprecated. All apps and examples that use the old functions are
updated to use the new functions.

Fixes: af75078fece3 ("first public release")
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
13 files changed:
app/test/test_cryptodev.c
app/test/test_cryptodev_perf.c
app/test/test_mbuf.c
app/test/test_mempool.c
app/test/test_mempool_perf.c
doc/guides/rel_notes/deprecation.rst
drivers/net/qede/qede_rxtx.c
drivers/net/thunderx/nicvf_ethdev.c
examples/multi_process/l2fwd_fork/main.c
examples/qos_sched/main.c
lib/librte_mempool/rte_mempool.c
lib/librte_mempool/rte_mempool.h
lib/librte_mempool/rte_mempool_version.map

index 9dfe34f8c1b3c68e291d450d96703ca472fb446b..fbfe1d0d2104a4c2cc464f214a573489ea2aafaa 100644 (file)
@@ -316,12 +316,12 @@ testsuite_teardown(void)
 
        if (ts_params->mbuf_pool != NULL) {
                RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
-               rte_mempool_count(ts_params->mbuf_pool));
+               rte_mempool_avail_count(ts_params->mbuf_pool));
        }
 
        if (ts_params->op_mpool != NULL) {
                RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
-               rte_mempool_count(ts_params->op_mpool));
+               rte_mempool_avail_count(ts_params->op_mpool));
        }
 
 }
@@ -412,7 +412,7 @@ ut_teardown(void)
 
        if (ts_params->mbuf_pool != NULL)
                RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
-                               rte_mempool_count(ts_params->mbuf_pool));
+                       rte_mempool_avail_count(ts_params->mbuf_pool));
 
        rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
 
index e484cbb53afd2d4e9204a688b3af9fabc610d2e7..d72821121bc405bce1a08044b3a96c529eecb122 100644 (file)
@@ -343,10 +343,10 @@ testsuite_teardown(void)
 
        if (ts_params->mbuf_mp != NULL)
                RTE_LOG(DEBUG, USER1, "CRYPTO_PERF_MBUFPOOL count %u\n",
-               rte_mempool_count(ts_params->mbuf_mp));
+               rte_mempool_avail_count(ts_params->mbuf_mp));
        if (ts_params->op_mpool != NULL)
                RTE_LOG(DEBUG, USER1, "CRYPTO_PERF_OP POOL count %u\n",
-               rte_mempool_count(ts_params->op_mpool));
+               rte_mempool_avail_count(ts_params->op_mpool));
 }
 
 static int
@@ -395,7 +395,7 @@ ut_teardown(void)
 
        if (ts_params->mbuf_mp != NULL)
                RTE_LOG(DEBUG, USER1, "CRYPTO_PERF_MBUFPOOL count %u\n",
-                       rte_mempool_count(ts_params->mbuf_mp));
+                       rte_mempool_avail_count(ts_params->mbuf_mp));
 
        rte_cryptodev_stats_get(ts_params->dev_id, &stats);
 
index 1835acc73a932b4313873e0c570d7755388b9ff2..8664885dd9d4cf2d5173cea562f7e74f9ad4619d 100644 (file)
@@ -717,7 +717,7 @@ test_refcnt_iter(unsigned lcore, unsigned iter)
         * - increment it's reference up to N+1,
         * - enqueue it N times into the ring for slave cores to free.
         */
-       for (i = 0, n = rte_mempool_count(refcnt_pool);
+       for (i = 0, n = rte_mempool_avail_count(refcnt_pool);
            i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
            i++) {
                ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
@@ -745,7 +745,7 @@ test_refcnt_iter(unsigned lcore, unsigned iter)
 
        /* check that all mbufs are back into mempool by now */
        for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
-               if ((i = rte_mempool_count(refcnt_pool)) == n) {
+               if ((i = rte_mempool_avail_count(refcnt_pool)) == n) {
                        refcnt_lcore[lcore] += tref;
                        printf("%s(lcore=%u, iter=%u) completed, "
                            "%u references processed\n",
index 63c61f35bf13e0df95516e3074dd94f3893b413b..238ff52058a1687811f09b6fedd105c989990baf 100644 (file)
@@ -231,7 +231,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)
        printf("get object count\n");
        /* We have to count the extra caches, one in this case. */
        offset = use_external_cache ? 1 * cache->len : 0;
-       if (rte_mempool_count(mp) + offset != MEMPOOL_SIZE - 1)
+       if (rte_mempool_avail_count(mp) + offset != MEMPOOL_SIZE - 1)
                GOTO_ERR(ret, out);
 
        printf("get private data\n");
@@ -497,7 +497,7 @@ test_mempool_basic_ex(struct rte_mempool *mp)
                return ret;
        }
        printf("test_mempool_basic_ex now mempool (%s) has %u free entries\n",
-               mp->name, rte_mempool_free_count(mp));
+               mp->name, rte_mempool_in_use_count(mp));
        if (rte_mempool_full(mp) != 1) {
                printf("test_mempool_basic_ex the mempool should be full\n");
                goto fail_mp_basic_ex;
index b80a1dd36eb95acc5a1218aa1628ec6954bc81c0..4fac04cd06f761214214ba0a2532c325b32c1d1b 100644 (file)
@@ -240,7 +240,7 @@ launch_cores(unsigned cores)
                   external_cache_size : (unsigned) mp->cache_size,
               cores, n_get_bulk, n_put_bulk, n_keep);
 
-       if (rte_mempool_count(mp) != MEMPOOL_SIZE) {
+       if (rte_mempool_avail_count(mp) != MEMPOOL_SIZE) {
                printf("mempool is not full\n");
                return -1;
        }
index 56cb1d92ddfb1e69d562be122f979caaea7033d8..f502f86375a6bf5f140bfe89e0a1f272fa43fecd 100644 (file)
@@ -32,6 +32,12 @@ Deprecation Notices
   PKT_RX_QINQ_STRIPPED, that are better described. The old flags and
   their behavior will be kept in 16.07 and will be removed in 16.11.
 
+* The APIs rte_mempool_count and rte_mempool_free_count are being deprecated
+  on the basis that they are confusing to use - free_count actually returns
+  the number of allocated entries, not the number of free entries as expected.
+  They are being replaced by rte_mempool_avail_count and
+  rte_mempool_in_use_count respectively.
+
 * The mempool functions for single/multi producer/consumer are deprecated and
   will be removed in 16.11.
   It is replaced by rte_mempool_generic_get/put functions.
index ccce5fdbcd133160a3505d10cf992f2ddfaae786..b5a40fe48e9b5b22509679341dc7996226ae3641 100644 (file)
@@ -23,8 +23,8 @@ static inline int qede_alloc_rx_buffer(struct qede_rx_queue *rxq)
                           "Failed to allocate rx buffer "
                           "sw_rx_prod %u sw_rx_cons %u mp entries %u free %u",
                           idx, rxq->sw_rx_cons & NUM_RX_BDS(rxq),
-                          rte_mempool_count(rxq->mb_pool),
-                          rte_mempool_free_count(rxq->mb_pool));
+                          rte_mempool_avail_count(rxq->mb_pool),
+                          rte_mempool_in_use_count(rxq->mb_pool));
                return -ENOMEM;
        }
        rxq->sw_rx_ring[idx].mbuf = new_mb;
index d534312fa041defba4149c408c2162fc8dec9ad8..48ed3812fe6f04b8183b492aaf53c18744483f3d 100644 (file)
@@ -1158,7 +1158,7 @@ nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
 
        PMD_RX_LOG(DEBUG, "[%d] rxq=%p pool=%s nb_desc=(%d/%d) phy=%" PRIx64,
                        qidx, rxq, mp->name, nb_desc,
-                       rte_mempool_count(mp), rxq->phys);
+                       rte_mempool_avail_count(mp), rxq->phys);
 
        dev->data->rx_queues[qidx] = rxq;
        dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
@@ -1313,10 +1313,10 @@ nicvf_dev_start(struct rte_eth_dev *dev)
                total_rxq_desc += rxq->qlen_mask + 1;
                exp_buffs = RTE_MEMPOOL_CACHE_MAX_SIZE + rxq->rx_free_thresh;
                exp_buffs *= nic->eth_dev->data->nb_rx_queues;
-               if (rte_mempool_count(rxq->pool) < exp_buffs) {
+               if (rte_mempool_avail_count(rxq->pool) < exp_buffs) {
                        PMD_INIT_LOG(ERR, "Buff shortage in pool=%s (%d/%d)",
                                     rxq->pool->name,
-                                    rte_mempool_count(rxq->pool),
+                                    rte_mempool_avail_count(rxq->pool),
                                     exp_buffs);
                        return -ENOENT;
                }
index 368b3099321314a6c7fbc73493bf6203f1e78d68..2d951d93035772d18249fd09a7e241406e5e57c5 100644 (file)
@@ -442,7 +442,8 @@ reset_slave_all_ports(unsigned slaveid)
                pool = rte_mempool_lookup(buf_name);
                if (pool)
                        printf("Port %d mempool free object is %u(%u)\n", slave->port[i],
-                               rte_mempool_count(pool), (unsigned)NB_MBUF);
+                               rte_mempool_avail_count(pool),
+                               (unsigned int)NB_MBUF);
                else
                        printf("Can't find mempool %s\n", buf_name);
 
index e16b164dd260628841d67f6f82794baa5b24c9d7..e10cfd448d29eb552f3b2b141f5512c0f9df7eab 100644 (file)
@@ -201,8 +201,6 @@ app_stat(void)
                                stats.oerrors - tx_stats[i].oerrors);
                memcpy(&tx_stats[i], &stats, sizeof(stats));
 
-               //printf("MP = %d\n", rte_mempool_count(conf->app_pktmbuf_pool));
-
 #if APP_COLLECT_STAT
                printf("-------+------------+------------+\n");
                printf("       |  received  |   dropped  |\n");
index 4f159fce43c1c886931f83ea7a2419d5c276bf57..d78d02b7b8c514cb631d3eee867501c7779ab382 100644 (file)
@@ -960,8 +960,8 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
 }
 
 /* Return the number of entries in the mempool */
-unsigned
-rte_mempool_count(const struct rte_mempool *mp)
+unsigned int
+rte_mempool_avail_count(const struct rte_mempool *mp)
 {
        unsigned count;
        unsigned lcore_id;
@@ -983,6 +983,19 @@ rte_mempool_count(const struct rte_mempool *mp)
        return count;
 }
 
+/* return the number of entries allocated from the mempool */
+unsigned int
+rte_mempool_in_use_count(const struct rte_mempool *mp)
+{
+       return mp->size - rte_mempool_avail_count(mp);
+}
+
+unsigned int
+rte_mempool_count(const struct rte_mempool *mp)
+{
+       return rte_mempool_avail_count(mp);
+}
+
 /* dump the cache status */
 static unsigned
 rte_mempool_dump_cache(FILE *f, const struct rte_mempool *mp)
index c8a81e2da7dc207af19e5350bbabaf787e2e10e0..fb7052e1452313f801d526c826201250e2b29933 100644 (file)
@@ -1498,9 +1498,41 @@ rte_mempool_get(struct rte_mempool *mp, void **obj_p)
  * @return
  *   The number of entries in the mempool.
  */
+unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
+
+/**
+ * @deprecated
+ * Return the number of entries in the mempool.
+ *
+ * When cache is enabled, this function has to browse the length of
+ * all lcores, so it should not be used in a data path, but only for
+ * debug purposes.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @return
+ *   The number of entries in the mempool.
+ */
+__rte_deprecated
 unsigned rte_mempool_count(const struct rte_mempool *mp);
 
 /**
+ * Return the number of elements which have been allocated from the mempool
+ *
+ * When cache is enabled, this function has to browse the length of
+ * all lcores, so it should not be used in a data path, but only for
+ * debug purposes.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @return
+ *   The number of free entries in the mempool.
+ */
+unsigned int
+rte_mempool_in_use_count(const struct rte_mempool *mp);
+
+/**
+ * @deprecated
  * Return the number of free entries in the mempool ring.
  * i.e. how many entries can be freed back to the mempool.
  *
@@ -1517,10 +1549,11 @@ unsigned rte_mempool_count(const struct rte_mempool *mp);
  * @return
  *   The number of free entries in the mempool.
  */
+__rte_deprecated
 static inline unsigned
 rte_mempool_free_count(const struct rte_mempool *mp)
 {
-       return mp->size - rte_mempool_count(mp);
+       return rte_mempool_in_use_count(mp);
 }
 
 /**
@@ -1539,7 +1572,7 @@ rte_mempool_free_count(const struct rte_mempool *mp)
 static inline int
 rte_mempool_full(const struct rte_mempool *mp)
 {
-       return !!(rte_mempool_count(mp) == mp->size);
+       return !!(rte_mempool_avail_count(mp) == mp->size);
 }
 
 /**
@@ -1558,7 +1591,7 @@ rte_mempool_full(const struct rte_mempool *mp)
 static inline int
 rte_mempool_empty(const struct rte_mempool *mp)
 {
-       return !!(rte_mempool_count(mp) == 0);
+       return !!(rte_mempool_avail_count(mp) == 0);
 }
 
 /**
index 729ea9777ba1819252bd098246665358594238c0..dee1c990739bb0decde996f073675f09afe7283d 100644 (file)
@@ -19,6 +19,7 @@ DPDK_2.0 {
 DPDK_16.07 {
        global:
 
+       rte_mempool_avail_count;
        rte_mempool_cache_create;
        rte_mempool_cache_flush;
        rte_mempool_cache_free;
@@ -28,6 +29,7 @@ DPDK_16.07 {
        rte_mempool_free;
        rte_mempool_generic_get;
        rte_mempool_generic_put;
+       rte_mempool_in_use_count;
        rte_mempool_mem_iter;
        rte_mempool_obj_iter;
        rte_mempool_ops_table;