examples: skip build when missing dependencies
[dpdk.git] / drivers / mempool / cnxk / cn10k_mempool_ops.c
index c225c22..4c669b8 100644 (file)
@@ -157,6 +157,102 @@ cn10k_mempool_enq(struct rte_mempool *mp, void *const *obj_table,
        return 0;
 }
 
+static unsigned int
+cn10k_mempool_get_count(const struct rte_mempool *mp)
+{
+       struct batch_op_data *op_data;
+       unsigned int count = 0;
+       int i;
+
+       op_data = batch_op_data_get(mp->pool_id);
+
+       rte_wmb();
+       for (i = 0; i < RTE_MAX_LCORE; i++) {
+               struct batch_op_mem *mem = &op_data->mem[i];
+
+               if (mem->status == BATCH_ALLOC_OP_ISSUED)
+                       count += roc_npa_aura_batch_alloc_count(mem->objs,
+                                                               BATCH_ALLOC_SZ);
+
+               if (mem->status == BATCH_ALLOC_OP_DONE)
+                       count += mem->sz;
+       }
+
+       count += cnxk_mempool_get_count(mp);
+
+       return count;
+}
+
+static int __rte_hot
+cn10k_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n)
+{
+       struct batch_op_data *op_data;
+       struct batch_op_mem *mem;
+       unsigned int count = 0;
+       int tid, rc, retry;
+       bool loop = true;
+
+       op_data = batch_op_data_get(mp->pool_id);
+       tid = rte_lcore_id();
+       mem = &op_data->mem[tid];
+
+       /* Issue batch alloc */
+       if (mem->status == BATCH_ALLOC_OP_NOT_ISSUED) {
+               rc = roc_npa_aura_batch_alloc_issue(mp->pool_id, mem->objs,
+                                                   BATCH_ALLOC_SZ, 0, 1);
+               /* If issue fails, try falling back to default alloc */
+               if (unlikely(rc))
+                       return cn10k_mempool_enq(mp, obj_table, n);
+               mem->status = BATCH_ALLOC_OP_ISSUED;
+       }
+
+       retry = 4;
+       while (loop) {
+               unsigned int cur_sz;
+
+               if (mem->status == BATCH_ALLOC_OP_ISSUED) {
+                       mem->sz = roc_npa_aura_batch_alloc_extract(
+                               mem->objs, mem->objs, BATCH_ALLOC_SZ);
+
+                       /* If partial alloc reduce the retry count */
+                       retry -= (mem->sz != BATCH_ALLOC_SZ);
+                       /* Break the loop if retry count exhausted */
+                       loop = !!retry;
+                       mem->status = BATCH_ALLOC_OP_DONE;
+               }
+
+               cur_sz = n - count;
+               if (cur_sz > mem->sz)
+                       cur_sz = mem->sz;
+
+               /* Dequeue the pointers */
+               memcpy(&obj_table[count], &mem->objs[mem->sz - cur_sz],
+                      cur_sz * sizeof(uintptr_t));
+               mem->sz -= cur_sz;
+               count += cur_sz;
+
+               /* Break loop if the required pointers has been dequeued */
+               loop &= (count != n);
+
+               /* Issue next batch alloc if pointers are exhausted */
+               if (mem->sz == 0) {
+                       rc = roc_npa_aura_batch_alloc_issue(
+                               mp->pool_id, mem->objs, BATCH_ALLOC_SZ, 0, 1);
+                       /* Break loop if issue failed and set status */
+                       loop &= !rc;
+                       mem->status = !rc;
+               }
+       }
+
+       if (unlikely(count != n)) {
+               /* No partial alloc allowed. Free up allocated pointers */
+               cn10k_mempool_enq(mp, obj_table, count);
+               return -ENOENT;
+       }
+
+       return 0;
+}
+
 static int
 cn10k_mempool_alloc(struct rte_mempool *mp)
 {
@@ -214,10 +310,10 @@ static struct rte_mempool_ops cn10k_mempool_ops = {
        .alloc = cn10k_mempool_alloc,
        .free = cn10k_mempool_free,
        .enqueue = cn10k_mempool_enq,
-       .dequeue = cnxk_mempool_deq,
-       .get_count = cnxk_mempool_get_count,
+       .dequeue = cn10k_mempool_deq,
+       .get_count = cn10k_mempool_get_count,
        .calc_mem_size = cnxk_mempool_calc_mem_size,
        .populate = cnxk_mempool_populate,
 };
 
-MEMPOOL_REGISTER_OPS(cn10k_mempool_ops);
+RTE_MEMPOOL_REGISTER_OPS(cn10k_mempool_ops);