Skip to content

Commit

Permalink
linux-gen: ishm: add internal _ODP_ISHM_USE_HP flag
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MatiasElo authored and muvarov committed Nov 14, 2018
1 parent bfcb580 commit 33c034c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
8 changes: 7 additions & 1 deletion platform/linux-generic/include/odp_shm_internal.h
Expand Up @@ -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
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions platform/linux-generic/odp_ishm.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions platform/linux-generic/odp_pool.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
27 changes: 17 additions & 10 deletions platform/linux-generic/odp_shared_memory.c
Expand Up @@ -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));
Expand All @@ -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,
Expand Down

0 comments on commit 33c034c

Please sign in to comment.