summaryrefslogtreecommitdiffstats
path: root/src/plugins/memif
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-09-17 13:41:18 +0200
committerDamjan Marion <damarion@cisco.com>2020-10-02 14:53:53 +0200
commiteb530a24b4ec2b055f5ef40f4b01ca4579dd87b0 (patch)
tree37b6b5f6506b5ddda9bcd3e98995d273f9578ae9 /src/plugins/memif
parente2042e6b7b5f5ecb6ec68e6dac39626e636c51b9 (diff)
memif: map shared memory with clib_mem_vm_map_shared(...)
Type: improvement Change-Id: I91031d56aae884a0a42fca343a2fc24c442b1da8 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/memif')
-rw-r--r--src/plugins/memif/memif.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index 05a7f83b3b1..c1bab0ba15f 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -344,11 +344,11 @@ clib_error_t *
memif_init_regions_and_queues (memif_if_t * mif)
{
vlib_main_t *vm = vlib_get_main ();
+ memif_socket_file_t *msf;
memif_ring_t *ring = NULL;
- int i, j;
+ int fd, i, j;
u64 buffer_offset;
memif_region_t *r;
- clib_mem_vm_alloc_t alloc = { 0 };
clib_error_t *err;
ASSERT (vec_len (mif->regions) == 0);
@@ -364,16 +364,31 @@ memif_init_regions_and_queues (memif_if_t * mif)
r->region_size += mif->run.buffer_size * (1 << mif->run.log2_ring_size) *
(mif->run.num_s2m_rings + mif->run.num_m2s_rings);
- alloc.name = "memif region";
- alloc.size = r->region_size;
- alloc.flags = CLIB_MEM_VM_F_SHARED;
+ if ((fd = clib_mem_vm_create_fd (CLIB_MEM_PAGE_SZ_DEFAULT, "%U region 0",
+ format_memif_device_name,
+ mif->dev_instance)) == -1)
+ {
+ err = clib_mem_get_last_error ();
+ goto error;
+ }
- err = clib_mem_vm_ext_alloc (&alloc);
- if (err)
- goto error;
+ if ((ftruncate (fd, r->region_size)) == -1)
+ {
+ err = clib_error_return_unix (0, "ftruncate");
+ goto error;
+ }
+
+ msf = pool_elt_at_index (memif_main.socket_files, mif->socket_file_index);
+ r->shm = clib_mem_vm_map_shared (0, r->region_size, fd, 0, "memif%lu/%lu:0",
+ msf->socket_id, mif->id);
+
+ if (r->shm == CLIB_MEM_VM_MAP_FAILED)
+ {
+ err = clib_error_return_unix (0, "memif shared region map failed");
+ goto error;
+ }
- r->fd = alloc.fd;
- r->shm = alloc.addr;
+ r->fd = fd;
if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY)
{