summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2016-11-11 21:35:18 +0100
committerNeale Ranns <nranns@cisco.com>2016-11-15 10:23:49 +0000
commit409ef615f8389d61df5dbfe7a052d517f194ed33 (patch)
tree775bd468c5a3c38ad2de5922cf5c23f39525710a
parent01b071222d99bea31e2846e95963c475262dd114 (diff)
buffer: clone free_list to each vlib_main on creation
Currently only packet-generator is creating free_lists during runtime. This avoids crash when buffer is freed on different worker thread. Change-Id: If2ae066a12cf7c4b3267d56d8566806f31cf7ffc Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--vlib/vlib/dpdk_buffer.c29
-rw-r--r--vnet/vnet/pg/stream.c9
2 files changed, 31 insertions, 7 deletions
diff --git a/vlib/vlib/dpdk_buffer.c b/vlib/vlib/dpdk_buffer.c
index edb1430d0ca..2f63543ec43 100644
--- a/vlib/vlib/dpdk_buffer.c
+++ b/vlib/vlib/dpdk_buffer.c
@@ -320,6 +320,9 @@ vlib_buffer_create_free_list_helper (vlib_main_t * vm,
{
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *f;
+ int i;
+
+ ASSERT (os_get_cpu_number () == 0);
if (!is_default && pool_elts (bm->buffer_free_list_pool) == 0)
{
@@ -359,6 +362,20 @@ vlib_buffer_create_free_list_helper (vlib_main_t * vm,
hash_set (bm->free_list_by_size, f->n_data_bytes, f->index);
}
+ for (i = 1; i < vec_len (vlib_mains); i++)
+ {
+ vlib_buffer_main_t *wbm = vlib_mains[i]->buffer_main;
+ vlib_buffer_free_list_t *wf;
+ pool_get_aligned (wbm->buffer_free_list_pool,
+ wf, CLIB_CACHE_LINE_BYTES);
+ ASSERT (f - bm->buffer_free_list_pool ==
+ wf - wbm->buffer_free_list_pool);
+ wf[0] = f[0];
+ wf->aligned_buffers = 0;
+ wf->unaligned_buffers = 0;
+ wf->n_alloc = 0;
+ }
+
return f->index;
}
@@ -436,6 +453,9 @@ vlib_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_free_list_t *f;
u32 merge_index;
+ int i;
+
+ ASSERT (os_get_cpu_number () == 0);
f = vlib_buffer_get_free_list (vm, free_list_index);
@@ -452,6 +472,15 @@ vlib_buffer_delete_free_list (vlib_main_t * vm, u32 free_list_index)
memset (f, 0xab, sizeof (f[0]));
pool_put (bm->buffer_free_list_pool, f);
+
+ for (i = 1; i < vec_len (vlib_mains); i++)
+ {
+ bm = vlib_mains[i]->buffer_main;
+ f = vlib_buffer_get_free_list (vlib_mains[i], free_list_index);;
+ memset (f, 0xab, sizeof (f[0]));
+ pool_put (bm->buffer_free_list_pool, f);
+ }
+
}
/* Make sure free list has at least given number of free buffers. */
diff --git a/vnet/vnet/pg/stream.c b/vnet/vnet/pg/stream.c
index 4dd71d91ab2..d0cbab0b68d 100644
--- a/vnet/vnet/pg/stream.c
+++ b/vnet/vnet/pg/stream.c
@@ -434,11 +434,8 @@ pg_stream_add (pg_main_t * pg, pg_stream_t * s_init)
vec_foreach (bi, s->buffer_indices)
{
- vlib_main_t *vmt;
- vmt =
- vlib_num_workers ()? vlib_get_worker_vlib_main (s->worker_index) : vm;
bi->free_list_index =
- vlib_buffer_create_free_list (vmt, s->buffer_bytes,
+ vlib_buffer_create_free_list (vm, s->buffer_bytes,
"pg stream %d buffer #%d",
s - pg->streams,
1 + (bi - s->buffer_indices));
@@ -478,9 +475,7 @@ pg_stream_del (pg_main_t * pg, uword index)
vec_foreach (bi, s->buffer_indices)
{
- vlib_buffer_delete_free_list (vlib_num_workers ()?
- vlib_get_worker_vlib_main (s->worker_index)
- : vm, bi->free_list_index);
+ vlib_buffer_delete_free_list (vm, bi->free_list_index);
clib_fifo_free (bi->buffer_fifo);
}