@@ -19,7 +19,7 @@ extern "C" {
#endif
void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
- int type);
+ int type, odp_shm_e flag);
uintptr_t _odp_shm_get_paddr(void *vaddr);
#ifdef __cplusplus
@@ -96,7 +96,8 @@ int odp_buffer_pool_init_global(void)
pool_tbl = odp_shm_reserve("odp_buffer_pools",
sizeof(pool_table_t),
- sizeof(pool_entry_t));
+ sizeof(pool_entry_t),
+ ODP_SHM_THREAD);
if (pool_tbl == NULL)
return -1;
@@ -71,7 +71,8 @@ int odp_pktio_init_global(void)
pktio_tbl = odp_shm_reserve("odp_pktio_entries",
sizeof(pktio_table_t),
- sizeof(pktio_entry_t));
+ sizeof(pktio_entry_t),
+ ODP_SHM_THREAD);
if (pktio_tbl == NULL)
return -1;
@@ -99,7 +99,8 @@ int odp_queue_init_global(void)
queue_tbl = odp_shm_reserve("odp_queues",
sizeof(queue_table_t),
- sizeof(queue_entry_t));
+ sizeof(queue_entry_t),
+ ODP_SHM_THREAD);
if (queue_tbl == NULL)
return -1;
@@ -99,9 +99,11 @@ enum {
};
void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
- int type)
+ int type, odp_shm_e flag)
{
- int i;
+ int i, ret, shm_open_flags;
+ int shm = -1;
+ int mmap_flags = MAP_SHARED;
odp_shm_block_t *block;
#ifdef MAP_HUGETLB
uint64_t huge_sz, page_sz;
@@ -144,6 +146,12 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
mem_config.mapping_id = -1;
if (type == ODP_SHM_CMA) {
+ if (flag != ODP_SHM_THREAD) {
+ ODP_ERR("shm_open with ODP_SHM_CMA is not implemented\n");
+ odp_spinlock_unlock(&odp_shm_tbl->lock);
+ return NULL;
+ }
+
ti_em_rh_alloc_map_cma(&mem_config);
if (!mem_config.vaddr) {
@@ -161,18 +169,42 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
void *addr = MAP_FAILED;
block->huge = 0;
+ if (flag != ODP_SHM_THREAD) {
+ shm_open_flags = O_RDWR;
+ if (flag == ODP_SHM_PROC)
+ shm_open_flags |= O_CREAT;
+
+ shm = shm_open(name, shm_open_flags, S_IRUSR | S_IWUSR);
+ if (shm == -1) {
+ odp_spinlock_unlock(&odp_shm_tbl->lock);
+ ODP_ERR("shm_open failed");
+ return NULL;
+ }
+
+ ret = ftruncate(shm, size + align);
+ if (ret == -1) {
+ odp_spinlock_unlock(&odp_shm_tbl->lock);
+ if (flag != ODP_SHM_PROC_NOCREAT)
+ shm_unlink(name);
+ ODP_ERR("ftruncate failed");
+ return NULL;
+ }
+ } else {
+ mmap_flags |= MAP_ANONYMOUS;
+ }
+
#ifdef MAP_HUGETLB
/* Try first huge pages */
if (huge_sz && (size + align) > page_sz) {
addr = mmap(NULL, size + align, PROT_READ | PROT_WRITE,
- SHM_FLAGS | MAP_HUGETLB, -1, 0);
+ mmap_flags | MAP_HUGETLB, shm, 0);
}
#endif
/* Use normal pages for small or failed huge page allocations */
if (addr == MAP_FAILED) {
addr = mmap(NULL, size + align, PROT_READ | PROT_WRITE,
- SHM_FLAGS, -1, 0);
+ mmap_flags, shm, 0);
} else {
block->huge = 1;
}
@@ -208,9 +240,10 @@ void *_odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
return block->addr;
}
-void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align)
+void *odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
+ odp_shm_e flag)
{
- return _odp_shm_reserve(name, size, align, ODP_SHM_CMA);
+ return _odp_shm_reserve(name, size, align, ODP_SHM_CMA, flag);
}
uintptr_t _odp_shm_get_paddr(void *vaddr)
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- .../include/odp_shared_memory_internal.h | 2 +- platform/linux-keystone2/odp_buffer_pool.c | 3 +- platform/linux-keystone2/odp_packet_io.c | 3 +- platform/linux-keystone2/odp_queue.c | 3 +- platform/linux-keystone2/odp_shared_memory.c | 45 +++++++++++++++++++--- 5 files changed, 46 insertions(+), 10 deletions(-)