diff options
author | Matias Elo <matias.elo@nokia.com> | 2018-11-12 14:51:28 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2018-11-14 10:54:25 +0300 |
commit | 33c034c005f686cda95bc21ca4ed1aaf6d7eb539 (patch) | |
tree | 82adff141725b69549109d8b0480747b5d0212cf /platform | |
parent | bfcb5801d210e1535e19e556698dd90337a3d4ac (diff) |
linux-gen: ishm: add internal _ODP_ISHM_USE_HP flag
Add internal shm flag for allocating shm memory always from huge pages.
This is required by zero-copy dpdk packet pool. Internal _odp_shm_reserve()
function is added for passing extra shm flags.
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/include/odp_shm_internal.h | 8 | ||||
-rw-r--r-- | platform/linux-generic/odp_ishm.c | 5 | ||||
-rw-r--r-- | platform/linux-generic/odp_pool.c | 15 | ||||
-rw-r--r-- | platform/linux-generic/odp_shared_memory.c | 27 |
4 files changed, 38 insertions, 17 deletions
diff --git a/platform/linux-generic/include/odp_shm_internal.h b/platform/linux-generic/include/odp_shm_internal.h index 93146a518..a1bd24396 100644 --- a/platform/linux-generic/include/odp_shm_internal.h +++ b/platform/linux-generic/include/odp_shm_internal.h @@ -14,10 +14,13 @@ extern "C" { #include <sys/types.h> #include <inttypes.h> +#include <odp/api/shared_memory.h> + /* flags available at ishm_reserve: */ #define _ODP_ISHM_SINGLE_VA 1 #define _ODP_ISHM_LOCK 2 -#define _ODP_ISHM_EXPORT 4 /*create export descr file in /tmp */ +#define _ODP_ISHM_EXPORT 4 /* create export descr file in /tmp */ +#define _ODP_ISHM_USE_HP 8 /* allocate memory from huge pages */ /** * Shared memory block info @@ -31,6 +34,9 @@ typedef struct _odp_ishm_info_t { uint32_t user_flags;/**< user specific flags */ } _odp_ishm_info_t; +odp_shm_t _odp_shm_reserve(const char *name, uint64_t size, uint32_t align, + uint32_t flags, uint32_t extra_flags); + int _odp_ishm_reserve(const char *name, uint64_t size, int fd, uint32_t align, uint32_t flags, uint32_t user_flags); int _odp_ishm_free_by_index(int block_index); diff --git a/platform/linux-generic/odp_ishm.c b/platform/linux-generic/odp_ishm.c index e03f888f2..054ef6a0f 100644 --- a/platform/linux-generic/odp_ishm.c +++ b/platform/linux-generic/odp_ishm.c @@ -1023,7 +1023,7 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, uint64_t page_sz; /* normal page size. usually 4K*/ uint64_t page_hp_size; /* huge page size */ uint32_t hp_align; - uint64_t len; /* mapped length */ + uint64_t len = 0; /* mapped length */ void *addr = NULL; /* mapping address */ int new_proc_entry; struct stat statbuf; @@ -1091,7 +1091,8 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, } /* Otherwise, Try first huge pages when possible and needed: */ - if ((fd < 0) && page_hp_size && (size > page_sz)) { + if ((fd < 0) && page_hp_size && ((flags & _ODP_ISHM_USE_HP) || + size > page_sz)) { /* at least, alignment in VA should match page size, but user * can request more: If the user requirement exceeds the page * size then we have to make sure the block will be mapped at diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c index 10382c4c8..2262f3558 100644 --- a/platform/linux-generic/odp_pool.c +++ b/platform/linux-generic/odp_pool.c @@ -22,6 +22,7 @@ #include <odp_ring_internal.h> #include <odp_global_data.h> #include <odp_libconfig_internal.h> +#include <odp_shm_internal.h> #include <string.h> #include <stdio.h> @@ -378,6 +379,7 @@ static odp_pool_t pool_create(const char *name, odp_pool_param_t *params, uint32_t max_len; uint32_t ring_size; uint32_t num_extra = 0; + uint32_t extra_shm_flags = 0; int name_len; const char *postfix = "_uarea"; char uarea_name[ODP_POOL_NAME_LEN + sizeof(postfix)]; @@ -487,11 +489,16 @@ static odp_pool_t pool_create(const char *name, odp_pool_param_t *params, * headers. NOP if zero-copy is disabled. */ pool->block_offset = 0; if (params->type == ODP_POOL_PACKET) { - block_size = _odp_dpdk_pool_obj_size(pool, block_size); - if (!block_size) { + uint32_t dpdk_obj_size; + + dpdk_obj_size = _odp_dpdk_pool_obj_size(pool, block_size); + if (!dpdk_obj_size) { ODP_ERR("Calculating DPDK mempool obj size failed\n"); return ODP_POOL_INVALID; } + if (dpdk_obj_size != block_size) + extra_shm_flags |= _ODP_ISHM_USE_HP; + block_size = dpdk_obj_size; } /* Allocate extra memory for skipping packet buffers which cross huge @@ -524,8 +531,8 @@ static odp_pool_t pool_create(const char *name, odp_pool_param_t *params, pool->ext_desc = NULL; pool->ext_destroy = NULL; - shm = odp_shm_reserve(pool->name, pool->shm_size, - ODP_PAGE_SIZE, shmflags); + shm = _odp_shm_reserve(pool->name, pool->shm_size, + ODP_PAGE_SIZE, shmflags, extra_shm_flags); pool->shm = shm; diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 7d405d139..d2f31458e 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -44,6 +44,22 @@ static uint32_t get_ishm_flags(uint32_t flags) return f; } +odp_shm_t _odp_shm_reserve(const char *name, uint64_t size, uint32_t align, + uint32_t flags, uint32_t extra_flags) +{ + int block_index; + uint32_t flgs = 0; /* internal ishm flags */ + + flgs = get_ishm_flags(flags); + flgs |= extra_flags; + + block_index = _odp_ishm_reserve(name, size, -1, align, flgs, flags); + if (block_index >= 0) + return to_handle(block_index); + else + return ODP_SHM_INVALID; +} + int odp_shm_capability(odp_shm_capability_t *capa) { memset(capa, 0, sizeof(odp_shm_capability_t)); @@ -58,16 +74,7 @@ int odp_shm_capability(odp_shm_capability_t *capa) odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags) { - int block_index; - uint32_t flgs = 0; /* internal ishm flags */ - - flgs = get_ishm_flags(flags); - - block_index = _odp_ishm_reserve(name, size, -1, align, flgs, flags); - if (block_index >= 0) - return to_handle(block_index); - else - return ODP_SHM_INVALID; + return _odp_shm_reserve(name, size, align, flags, 0); } odp_shm_t odp_shm_import(const char *remote_name, |