env_dpdk: Add function to iterate memory chunks in a pool

This allows to get start address and length of each
memory chunk in order to create app-specific
resources.
Since we don't want to expose rte structure in the
callback, we have to remap rte data types to SPDK.

Signed-off-by: Alexey Marchuk <alexeymar@nvidia.com>
Change-Id: I3865c4cfe532c6a99a5a3c6c983ded8b9a338de1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16324
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Alexey Marchuk 2023-01-17 14:20:48 +01:00 committed by Tomasz Zawadzki
parent ce37c9e65f
commit 8c8cd12e1d
3 changed files with 50 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2015 Intel Corporation.
* Copyright (c) NetApp, Inc.
* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES.
* All rights reserved.
*/
@ -322,6 +323,14 @@ struct spdk_mempool *spdk_mempool_create(const char *name, size_t count,
typedef void (spdk_mempool_obj_cb_t)(struct spdk_mempool *mp,
void *opaque, void *obj, unsigned obj_idx);
/**
* A memory chunk callback function for memory pool.
*
* Used by spdk_mempool_mem_iter().
*/
typedef void (spdk_mempool_mem_cb_t)(struct spdk_mempool *mp, void *opaque, void *addr,
uint64_t iova, size_t len, unsigned mem_idx);
/**
* Create a thread-safe memory pool with user provided initialization function
* and argument.
@ -414,6 +423,18 @@ size_t spdk_mempool_count(const struct spdk_mempool *pool);
uint32_t spdk_mempool_obj_iter(struct spdk_mempool *mp, spdk_mempool_obj_cb_t obj_cb,
void *obj_cb_arg);
/**
* Iterate through all memory chunks of the pool and call a function on each one.
*
* \param mp Memory pool to iterate on.
* \param mem_cb Function to call on each memory chunk.
* \param mem_cb_arg Opaque pointer passed to the callback function.
*
* \return Number of memory chunks iterated.
*/
uint32_t spdk_mempool_mem_iter(struct spdk_mempool *mp, spdk_mempool_mem_cb_t mem_cb,
void *mem_cb_arg);
/**
* Lookup the memory pool identified by the given name.
*

View File

@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2016 Intel Corporation.
* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES.
* All rights reserved.
*/
@ -283,6 +284,33 @@ spdk_mempool_obj_iter(struct spdk_mempool *mp, spdk_mempool_obj_cb_t obj_cb,
obj_cb_arg);
}
struct env_mempool_mem_iter_ctx {
spdk_mempool_mem_cb_t *user_cb;
void *user_arg;
};
static void
mempool_mem_iter_remap(struct rte_mempool *mp, void *opaque, struct rte_mempool_memhdr *memhdr,
unsigned mem_idx)
{
struct env_mempool_mem_iter_ctx *ctx = opaque;
ctx->user_cb((struct spdk_mempool *)mp, ctx->user_arg, memhdr->addr, memhdr->iova, memhdr->len,
mem_idx);
}
uint32_t
spdk_mempool_mem_iter(struct spdk_mempool *mp, spdk_mempool_mem_cb_t mem_cb,
void *mem_cb_arg)
{
struct env_mempool_mem_iter_ctx ctx = {
.user_cb = mem_cb,
.user_arg = mem_cb_arg
};
return rte_mempool_mem_iter((struct rte_mempool *)mp, mempool_mem_iter_remap, &ctx);
}
struct spdk_mempool *
spdk_mempool_lookup(const char *name)
{

View File

@ -30,6 +30,7 @@
spdk_mempool_put_bulk;
spdk_mempool_count;
spdk_mempool_obj_iter;
spdk_mempool_mem_iter;
spdk_mempool_lookup;
spdk_env_get_core_count;
spdk_env_get_current_core;