env: introduce spdk_memzone_reserve_aligned

This is an spdk_memzone_reserve variant with additional
alignment parameter. Now that memzones must be used for
physically contiguous memory, it will become extremely useful.

Change-Id: Ie48d682217e0e2f5c859a1603bb8a81fd2a7d7df
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/416978
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-06-27 11:25:36 +02:00 committed by Jim Harris
parent 2044690e6a
commit 8681eecd9a
3 changed files with 40 additions and 2 deletions

View File

@ -255,6 +255,22 @@ void spdk_dma_free(void *buf);
*/
void *spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags);
/**
* Reserve a named, process shared memory zone with the given size, socket_id,
* flags and alignment.
*
* \param name Name to set for this memory zone.
* \param len Length in bytes.
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
* for any socket.
* \param flags Flags to set for this memory zone.
* \param align Alignment for resulting memzone. Must be a power of 2.
*
* \return a pointer to the allocated memory address on success, or NULL on failure.
*/
void *spdk_memzone_reserve_aligned(const char *name, size_t len, int socket_id,
unsigned flags, unsigned align);
/**
* Lookup the memory zone identified by the given name.
*

View File

@ -133,7 +133,8 @@ spdk_dma_free(void *buf)
}
void *
spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
spdk_memzone_reserve_aligned(const char *name, size_t len, int socket_id,
unsigned flags, unsigned align)
{
const struct rte_memzone *mz;
unsigned dpdk_flags = 0;
@ -151,7 +152,7 @@ spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags
socket_id = SOCKET_ID_ANY;
}
mz = rte_memzone_reserve(name, len, socket_id, dpdk_flags);
mz = rte_memzone_reserve_aligned(name, len, socket_id, dpdk_flags, align);
if (mz != NULL) {
memset(mz->addr, 0, len);
@ -161,6 +162,13 @@ spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags
}
}
void *
spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
{
return spdk_memzone_reserve_aligned(name, len, socket_id, flags,
RTE_CACHE_LINE_SIZE);
}
void *
spdk_memzone_lookup(const char *name)
{

View File

@ -75,6 +75,20 @@ spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags
}
}
/* setup the mock control to pass thru by default */
void *ut_p_spdk_memzone_reserve_aligned = MOCK_PASS_THRU_P;
void *
spdk_memzone_reserve_aligned(const char *name, size_t len, int socket_id,
unsigned flags, unsigned align)
{
if (ut_p_spdk_memzone_reserve_aligned &&
ut_p_spdk_memzone_reserve_aligned == MOCK_PASS_THRU_P) {
return malloc(len);
} else {
return ut_p_spdk_memzone_reserve_aligned;
}
}
void *
spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr)
{