summaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-10-12 13:09:26 +0200
committerDave Barach <openvpp@barachs.net>2017-10-25 19:04:06 +0000
commit149ba779cff4ffc48d87ca67a2a8d4afd49b05f5 (patch)
treebc0467669b33b745fe4f44d4d0c787cf53900536 /src/vlib
parenta19d7b822ae9584cde522aefba36915e2af58846 (diff)
vlib: add support for multiple buffer pools
Change-Id: Icaf7d7ad47284aea7a56e8006b69f45874d64202 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/buffer.c36
-rw-r--r--src/vlib/buffer.h18
-rw-r--r--src/vlib/buffer_funcs.h5
-rw-r--r--src/vlib/linux/physmem.c5
-rw-r--r--src/vlib/physmem.h1
5 files changed, 42 insertions, 23 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index d0d8f604528..f00e8854ac1 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -462,7 +462,7 @@ del_free_list (vlib_main_t * vm, vlib_buffer_free_list_t * f)
u32 i;
for (i = 0; i < vec_len (f->buffer_memory_allocated); i++)
- vm->os_physmem_free (vm, vm->buffer_main->physmem_region,
+ vm->os_physmem_free (vm, vm->buffer_main->buffer_pools[0].physmem_region,
f->buffer_memory_allocated[i]);
vec_free (f->name);
vec_free (f->buffer_memory_allocated);
@@ -555,8 +555,10 @@ fill_free_list (vlib_main_t * vm,
/* drb: removed power-of-2 ASSERT */
buffers =
- vm->os_physmem_alloc_aligned (vm, vm->buffer_main->physmem_region,
- n_bytes, sizeof (vlib_buffer_t));
+ vm->os_physmem_alloc_aligned (vm,
+ vm->buffer_main->
+ buffer_pools[0].physmem_region, n_bytes,
+ sizeof (vlib_buffer_t));
if (!buffers)
return n_alloc;
@@ -960,10 +962,15 @@ vlib_buffer_chain_append_data_with_alloc (vlib_main_t * vm,
return copied;
}
-void
-vlib_buffer_add_mem_range (vlib_main_t * vm, uword start, uword size)
+u8
+vlib_buffer_add_physmem_region (vlib_main_t * vm,
+ vlib_physmem_region_index_t pri)
{
vlib_buffer_main_t *bm = vm->buffer_main;
+ vlib_physmem_region_t *pr = vlib_physmem_get_region (vm, pri);
+ vlib_buffer_pool_t *p;
+ uword start = pointer_to_uword (pr->mem);
+ uword size = pr->size;
if (bm->buffer_mem_size == 0)
{
@@ -989,6 +996,12 @@ vlib_buffer_add_mem_range (vlib_main_t * vm, uword start, uword size)
{
clib_panic ("buffer memory size out of range!");
}
+
+ vec_add2 (bm->buffer_pools, p, 1);
+ p->start = start;
+ p->size = size;
+ p->physmem_region = pri;
+ return p - bm->buffer_pools;
}
static u8 *
@@ -1057,6 +1070,7 @@ clib_error_t *
vlib_buffer_main_init (struct vlib_main_t * vm)
{
vlib_buffer_main_t *bm;
+ vlib_physmem_region_index_t pri;
clib_error_t *error;
vec_validate (vm->buffer_main, 0);
@@ -1085,12 +1099,10 @@ vlib_buffer_main_init (struct vlib_main_t * vm)
/* allocate default region */
error = vlib_physmem_region_alloc (vm, "buffers",
vlib_buffer_physmem_sz, 0,
- VLIB_PHYSMEM_F_INIT_MHEAP |
- VLIB_PHYSMEM_F_HAVE_BUFFERS,
- &bm->physmem_region);
+ VLIB_PHYSMEM_F_INIT_MHEAP, &pri);
if (error == 0)
- return 0;
+ goto done;
clib_error_free (error);
@@ -1098,9 +1110,9 @@ vlib_buffer_main_init (struct vlib_main_t * vm)
error = vlib_physmem_region_alloc (vm, "buffers (fake)",
vlib_buffer_physmem_sz, 0,
VLIB_PHYSMEM_F_FAKE |
- VLIB_PHYSMEM_F_INIT_MHEAP |
- VLIB_PHYSMEM_F_HAVE_BUFFERS,
- &bm->physmem_region);
+ VLIB_PHYSMEM_F_INIT_MHEAP, &pri);
+done:
+ vlib_buffer_add_physmem_region (vm, pri);
return error;
}
diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h
index e5c1d21397b..6170323c815 100644
--- a/src/vlib/buffer.h
+++ b/src/vlib/buffer.h
@@ -123,7 +123,8 @@ typedef struct
u8 n_add_refs; /**< Number of additional references to this buffer. */
- u8 dont_waste_me[2]; /**< Available space in the (precious)
+ u8 buffer_pool_index; /**< index of buffer pool this buffer belongs. */
+ u8 dont_waste_me[1]; /**< Available space in the (precious)
first 32 octets of buffer metadata
Before allocating any of it, discussion required!
*/
@@ -405,11 +406,19 @@ extern vlib_buffer_callbacks_t *vlib_buffer_callbacks;
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+ uword start;
+ uword size;
+ vlib_physmem_region_index_t physmem_region;
+} vlib_buffer_pool_t;
+
+typedef struct
+{
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
/* Virtual memory address and size of buffer memory, used for calculating
buffer index */
uword buffer_mem_start;
uword buffer_mem_size;
- vlib_physmem_region_index_t physmem_region;
+ vlib_buffer_pool_t *buffer_pools;
/* Buffer free callback, for subversive activities */
u32 (*buffer_free_callback) (struct vlib_main_t * vm,
@@ -442,8 +451,9 @@ typedef struct
int callbacks_registered;
} vlib_buffer_main_t;
-void vlib_buffer_add_mem_range (struct vlib_main_t *vm, uword start,
- uword size);
+u8 vlib_buffer_add_physmem_region (struct vlib_main_t *vm,
+ vlib_physmem_region_index_t region);
+
clib_error_t *vlib_buffer_main_init (struct vlib_main_t *vm);
typedef struct
diff --git a/src/vlib/buffer_funcs.h b/src/vlib/buffer_funcs.h
index d51de6bedf3..7224e08013e 100644
--- a/src/vlib/buffer_funcs.h
+++ b/src/vlib/buffer_funcs.h
@@ -162,7 +162,10 @@ vlib_buffer_contents (vlib_main_t * vm, u32 buffer_index, u8 * contents)
always_inline u64
vlib_get_buffer_data_physical_address (vlib_main_t * vm, u32 buffer_index)
{
- return vlib_physmem_offset_to_physical (vm, vm->buffer_main->physmem_region,
+ vlib_physmem_region_index_t pri;
+ vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index);
+ pri = vm->buffer_main->buffer_pools[b->buffer_pool_index].physmem_region;
+ return vlib_physmem_offset_to_physical (vm, pri,
(((uword) buffer_index) <<
CLIB_LOG2_CACHE_LINE_BYTES) +
STRUCT_OFFSET_OF (vlib_buffer_t,
diff --git a/src/vlib/linux/physmem.c b/src/vlib/linux/physmem.c
index 6d3f7c55d32..dad4ef064b4 100644
--- a/src/vlib/linux/physmem.c
+++ b/src/vlib/linux/physmem.c
@@ -190,11 +190,6 @@ unix_physmem_region_alloc (vlib_main_t * vm, char *name, u32 size,
MHEAP_FLAG_THREAD_SAFE);
}
- if (flags & VLIB_PHYSMEM_F_HAVE_BUFFERS)
- {
- vlib_buffer_add_mem_range (vm, pointer_to_uword (pr->mem), pr->size);
- }
-
*idx = pr->index;
goto done;
diff --git a/src/vlib/physmem.h b/src/vlib/physmem.h
index a7fed124e27..1e053d65c0f 100644
--- a/src/vlib/physmem.h
+++ b/src/vlib/physmem.h
@@ -55,7 +55,6 @@ typedef struct
void *heap;
u32 flags;
#define VLIB_PHYSMEM_F_INIT_MHEAP (1<<0)
-#define VLIB_PHYSMEM_F_HAVE_BUFFERS (1<<1)
#define VLIB_PHYSMEM_F_FAKE (1<<2)
u8 numa_node;