aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/unittest/svm_fifo_test.c146
-rw-r--r--src/svm/CMakeLists.txt12
-rw-r--r--src/svm/fifo_segment.c (renamed from src/svm/svm_fifo_segment.c)679
-rw-r--r--src/svm/fifo_segment.h139
-rw-r--r--src/svm/svm_fifo.c4
-rw-r--r--src/svm/svm_fifo.h9
-rw-r--r--src/svm/svm_fifo_segment.h136
-rw-r--r--src/tests/vnet/session/quic_echo.c20
-rw-r--r--src/tests/vnet/session/tcp_echo.c20
-rw-r--r--src/tests/vnet/session/udp_echo.c34
-rw-r--r--src/vcl/vcl_bapi.c12
-rw-r--r--src/vcl/vcl_private.h2
-rw-r--r--src/vcl/vppcom.c10
-rw-r--r--src/vnet/session-apps/echo_client.h1
-rw-r--r--src/vnet/session-apps/proxy.h1
-rw-r--r--src/vnet/session/application.c16
-rw-r--r--src/vnet/session/application.h8
-rw-r--r--src/vnet/session/application_interface.h2
-rw-r--r--src/vnet/session/application_local.c6
-rw-r--r--src/vnet/session/application_worker.c55
-rw-r--r--src/vnet/session/segment_manager.c547
-rw-r--r--src/vnet/session/segment_manager.h145
-rwxr-xr-xsrc/vnet/session/session_api.c2
23 files changed, 1001 insertions, 1005 deletions
diff --git a/src/plugins/unittest/svm_fifo_test.c b/src/plugins/unittest/svm_fifo_test.c
index af806e4782f..163a8e42c68 100644
--- a/src/plugins/unittest/svm_fifo_test.c
+++ b/src/plugins/unittest/svm_fifo_test.c
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#include <svm/svm_fifo.h>
-#include <svm/svm_fifo_segment.h>
#include <vlib/vlib.h>
+#include <svm/fifo_segment.h>
#define SFIFO_TEST_I(_cond, _comment, _args...) \
({ \
@@ -186,7 +186,7 @@ compare_data (u8 * data1, u8 * data2, u32 start, u32 len, u32 * index)
}
int
-tcp_test_fifo1 (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo1 (vlib_main_t * vm, unformat_input_t * input)
{
svm_fifo_t *f;
u32 fifo_size = 1 << 20;
@@ -423,7 +423,7 @@ err:
}
static int
-tcp_test_fifo2 (vlib_main_t * vm)
+sfifo_test_fifo2 (vlib_main_t * vm)
{
svm_fifo_t *f;
u32 fifo_size = 1 << 20;
@@ -505,7 +505,7 @@ tcp_test_fifo2 (vlib_main_t * vm)
}
static int
-tcp_test_fifo3 (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo3 (vlib_main_t * vm, unformat_input_t * input)
{
svm_fifo_t *f;
u32 fifo_size = 4 << 10;
@@ -730,7 +730,7 @@ tcp_test_fifo3 (vlib_main_t * vm, unformat_input_t * input)
}
static int
-tcp_test_fifo4 (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo4 (vlib_main_t * vm, unformat_input_t * input)
{
svm_fifo_t *f;
u32 fifo_size = 6 << 10;
@@ -803,7 +803,7 @@ fifo_pos (svm_fifo_t * f, u32 pos)
}
static int
-tcp_test_fifo5 (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo5 (vlib_main_t * vm, unformat_input_t * input)
{
svm_fifo_t *f;
u32 fifo_size = 401, j = 0, offset = 200;
@@ -932,7 +932,7 @@ tcp_test_fifo5 (vlib_main_t * vm, unformat_input_t * input)
}
static int
-tcp_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo_grow (vlib_main_t * vm, unformat_input_t * input)
{
int verbose = 0, fifo_size = 201, start_offset = 100, i, j, rv;
int test_n_bytes, deq_bytes, enq_bytes, n_deqs, n_enqs;
@@ -1206,7 +1206,7 @@ svm_fifo_trace_elem_t fifo_trace[] = {};
/* *INDENT-ON* */
static int
-tcp_test_fifo_replay (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo_replay (vlib_main_t * vm, unformat_input_t * input)
{
svm_fifo_t f;
int verbose = 0;
@@ -1236,15 +1236,15 @@ tcp_test_fifo_replay (vlib_main_t * vm, unformat_input_t * input)
return 0;
}
-static svm_fifo_segment_main_t segment_main;
+static fifo_segment_main_t segment_main;
static int
-tcp_test_fifo_segment_hello_world (int verbose)
+sfifo_test_fifo_segment_hello_world (int verbose)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &segment_main;
u8 *test_data, *retrieved_data = 0;
- svm_fifo_segment_private_t *sp;
+ fifo_segment_t *sp;
svm_fifo_t *f;
int rv;
@@ -1252,12 +1252,12 @@ tcp_test_fifo_segment_hello_world (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (sm, a);
+ rv = fifo_segment_create (sm, a);
SFIFO_TEST (!rv, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
- f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
+ sp = fifo_segment_get_segment (sm, a->new_segment_indices[0]);
+ f = fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FIFO);
SFIFO_TEST (f != 0, "svm_fifo_segment_alloc_fifo");
@@ -1281,19 +1281,19 @@ tcp_test_fifo_segment_hello_world (int verbose)
vec_free (test_data);
vec_free (retrieved_data);
- svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST);
- svm_fifo_segment_delete (sm, sp);
+ fifo_segment_free_fifo (sp, f);
+ fifo_segment_delete (sm, sp);
return 0;
}
static int
-tcp_test_fifo_segment_slave (int verbose)
+sfifo_test_fifo_segment_slave (int verbose)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &segment_main;
u8 *test_data, *retrieved_data = 0;
- svm_fifo_segment_private_t *sp;
- svm_fifo_segment_header_t *fsh;
+ fifo_segment_t *sp;
+ fifo_segment_header_t *fsh;
ssvm_shared_header_t *sh;
svm_fifo_t *f;
u32 *result;
@@ -1305,13 +1305,13 @@ tcp_test_fifo_segment_slave (int verbose)
clib_memset (a, 0, sizeof (*a));
a->segment_name = "fifo-test1";
- rv = svm_fifo_segment_attach (sm, a);
+ rv = fifo_segment_attach (sm, a);
SFIFO_TEST (!rv, "svm_fifo_segment_attach returned %d", rv);
- sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
+ sp = fifo_segment_get_segment (sm, a->new_segment_indices[0]);
sh = sp->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
+ fsh = (fifo_segment_header_t *) sh->opaque[0];
/* might wanna wait.. */
f = fsh->fifos;
@@ -1340,11 +1340,11 @@ tcp_test_fifo_segment_slave (int verbose)
}
static int
-tcp_test_fifo_segment_master_slave (int verbose)
+sfifo_test_fifo_segment_master_slave (int verbose)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &segment_main;
- svm_fifo_segment_private_t *sp;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &segment_main;
+ fifo_segment_t *sp;
svm_fifo_t *f;
u8 *test_data;
u32 *result;
@@ -1356,18 +1356,18 @@ tcp_test_fifo_segment_master_slave (int verbose)
SFIFO_TEST (0, "fork failed");
if (!pid)
- tcp_test_fifo_segment_slave (verbose);
+ sfifo_test_fifo_segment_slave (verbose);
clib_memset (a, 0, sizeof (*a));
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (sm, a);
+ rv = fifo_segment_create (sm, a);
SFIFO_TEST (!rv, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
- f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
+ sp = fifo_segment_get_segment (sm, a->new_segment_indices[0]);
+ f = fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FIFO);
SFIFO_TEST (f != 0, "svm_fifo_segment_alloc_fifo alloc");
@@ -1389,17 +1389,17 @@ tcp_test_fifo_segment_master_slave (int verbose)
SFIFO_TEST (*result == 0, "slave reported no error");
vec_free (test_data);
- svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST);
- svm_fifo_segment_delete (sm, sp);
+ fifo_segment_free_fifo (sp, f);
+ fifo_segment_delete (sm, sp);
return 0;
}
static int
-tcp_test_fifo_segment_mempig (int verbose)
+sfifo_test_fifo_segment_mempig (int verbose)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &segment_main;
- svm_fifo_segment_private_t *sp;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &segment_main;
+ fifo_segment_t *sp;
svm_fifo_t *f;
svm_fifo_t **flist = 0;
int rv;
@@ -1410,15 +1410,15 @@ tcp_test_fifo_segment_mempig (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (sm, a);
+ rv = fifo_segment_create (sm, a);
SFIFO_TEST (!rv, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
+ sp = fifo_segment_get_segment (sm, a->new_segment_indices[0]);
for (i = 0; i < 1000; i++)
{
- f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
+ f = fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FIFO);
if (f == 0)
break;
vec_add1 (flist, f);
@@ -1429,14 +1429,14 @@ tcp_test_fifo_segment_mempig (int verbose)
for (i = 0; i < vec_len (flist); i++)
{
f = flist[i];
- svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST);
+ fifo_segment_free_fifo (sp, f);
}
_vec_len (flist) = 0;
for (i = 0; i < 1000; i++)
{
- f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
+ f = fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FIFO);
if (f == 0)
break;
vec_add1 (flist, f);
@@ -1447,15 +1447,15 @@ tcp_test_fifo_segment_mempig (int verbose)
for (i = 0; i < vec_len (flist); i++)
{
f = flist[i];
- svm_fifo_segment_free_fifo (sp, f, FIFO_SEGMENT_RX_FREELIST);
+ fifo_segment_free_fifo (sp, f);
}
- svm_fifo_segment_delete (sm, sp);
+ fifo_segment_delete (sm, sp);
return 0;
}
static int
-tcp_test_fifo_segment (vlib_main_t * vm, unformat_input_t * input)
+sfifo_test_fifo_segment (vlib_main_t * vm, unformat_input_t * input)
{
int rv, verbose = 0;
@@ -1465,27 +1465,27 @@ tcp_test_fifo_segment (vlib_main_t * vm, unformat_input_t * input)
verbose = 1;
else if (unformat (input, "masterslave"))
{
- if ((rv = tcp_test_fifo_segment_master_slave (verbose)))
+ if ((rv = sfifo_test_fifo_segment_master_slave (verbose)))
return -1;
}
else if (unformat (input, "basic"))
{
- if ((rv = tcp_test_fifo_segment_hello_world (verbose)))
+ if ((rv = sfifo_test_fifo_segment_hello_world (verbose)))
return -1;
}
else if (unformat (input, "mempig"))
{
- if ((rv = tcp_test_fifo_segment_mempig (verbose)))
+ if ((rv = sfifo_test_fifo_segment_mempig (verbose)))
return -1;
}
else if (unformat (input, "all"))
{
- if ((rv = tcp_test_fifo_segment_hello_world (verbose)))
+ if ((rv = sfifo_test_fifo_segment_hello_world (verbose)))
return -1;
- if ((rv = tcp_test_fifo_segment_mempig (verbose)))
+ if ((rv = sfifo_test_fifo_segment_mempig (verbose)))
return -1;
/* Pretty slow so avoid running it always
- if ((rv = tcp_test_fifo_segment_master_slave (verbose)))
+ if ((rv = sfifo_test_fifo_segment_master_slave (verbose)))
return -1;
*/
}
@@ -1509,27 +1509,27 @@ svm_fifo_test (vlib_main_t * vm, unformat_input_t * input,
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "fifo1"))
- res = tcp_test_fifo1 (vm, input);
+ res = sfifo_test_fifo1 (vm, input);
else if (unformat (input, "fifo2"))
- res = tcp_test_fifo2 (vm);
+ res = sfifo_test_fifo2 (vm);
else if (unformat (input, "fifo3"))
- res = tcp_test_fifo3 (vm, input);
+ res = sfifo_test_fifo3 (vm, input);
else if (unformat (input, "fifo4"))
- res = tcp_test_fifo4 (vm, input);
+ res = sfifo_test_fifo4 (vm, input);
else if (unformat (input, "fifo5"))
- res = tcp_test_fifo5 (vm, input);
+ res = sfifo_test_fifo5 (vm, input);
else if (unformat (input, "replay"))
- res = tcp_test_fifo_replay (vm, input);
+ res = sfifo_test_fifo_replay (vm, input);
else if (unformat (input, "grow"))
- res = tcp_test_fifo_grow (vm, input);
+ res = sfifo_test_fifo_grow (vm, input);
else if (unformat (input, "segment"))
- res = tcp_test_fifo_segment (vm, input);
+ res = sfifo_test_fifo_segment (vm, input);
else if (unformat (input, "all"))
{
- if ((res = tcp_test_fifo1 (vm, input)))
+ if ((res = sfifo_test_fifo1 (vm, input)))
goto done;
- if ((res = tcp_test_fifo2 (vm)))
+ if ((res = sfifo_test_fifo2 (vm)))
goto done;
/*
@@ -1537,46 +1537,46 @@ svm_fifo_test (vlib_main_t * vm, unformat_input_t * input,
*/
str = "nsegs 10 overlap seed 123";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo3 (vm, input)))
+ if ((res = sfifo_test_fifo3 (vm, input)))
goto done;
unformat_free (input);
str = "nsegs 10 overlap seed 123 in-seq-all";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo3 (vm, input)))
+ if ((res = sfifo_test_fifo3 (vm, input)))
goto done;
unformat_free (input);
str = "nsegs 10 overlap seed 123 initial-offset 3917";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo3 (vm, input)))
+ if ((res = sfifo_test_fifo3 (vm, input)))
goto done;
unformat_free (input);
str = "nsegs 10 overlap seed 123 initial-offset 3917 drop";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo3 (vm, input)))
+ if ((res = sfifo_test_fifo3 (vm, input)))
goto done;
unformat_free (input);
str = "nsegs 10 seed 123 initial-offset 3917 drop no-randomize";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo3 (vm, input)))
+ if ((res = sfifo_test_fifo3 (vm, input)))
goto done;
unformat_free (input);
- if ((res = tcp_test_fifo4 (vm, input)))
+ if ((res = sfifo_test_fifo4 (vm, input)))
goto done;
- if ((res = tcp_test_fifo5 (vm, input)))
+ if ((res = sfifo_test_fifo5 (vm, input)))
goto done;
- if ((res = tcp_test_fifo_grow (vm, input)))
+ if ((res = sfifo_test_fifo_grow (vm, input)))
goto done;
str = "all";
unformat_init_cstring (input, str);
- if ((res = tcp_test_fifo_segment (vm, input)))
+ if ((res = sfifo_test_fifo_segment (vm, input)))
goto done;
}
else
diff --git a/src/svm/CMakeLists.txt b/src/svm/CMakeLists.txt
index ab6f7f71954..7664014153a 100644
--- a/src/svm/CMakeLists.txt
+++ b/src/svm/CMakeLists.txt
@@ -16,23 +16,23 @@
##############################################################################
add_vpp_library(svm
SOURCES
+ fifo_segment.c
+ message_queue.c
+ queue.c
svm.c
ssvm.c
svm_fifo.c
- svm_fifo_segment.c
- queue.c
- message_queue.c
MULTIARCH_SOURCES
svm_fifo.c
INSTALL_HEADERS
+ fifo_segment.h
+ message_queue.h
+ queue.h
ssvm.h
svm_common.h
svm_fifo.h
- svm_fifo_segment.h
- queue.h
- message_queue.h
svm.h
svmdb.h
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/fifo_segment.c
index 8a8bd4aa7ff..6bf2634a290 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -13,190 +13,24 @@
* limitations under the License.
*/
-#include <svm/svm_fifo_segment.h>
-
-static void
-fifo_init_for_segment (svm_fifo_segment_header_t * fsh, u8 * fifo_space,
- u32 size, u32 freelist_index)
-{
- svm_fifo_t *f;
-
- f = (svm_fifo_t *) fifo_space;
- f->freelist_index = freelist_index;
- f->default_chunk.start_byte = 0;
- f->default_chunk.length = size;
- f->default_chunk.next = f->start_chunk = f->end_chunk = &f->default_chunk;
- f->head_chunk = f->tail_chunk = f->ooo_enq = f->ooo_deq = f->start_chunk;
- f->next = fsh->free_fifos[freelist_index];
- fsh->free_fifos[freelist_index] = f;
-}
-
-static void
-allocate_new_fifo_chunk (svm_fifo_segment_header_t * fsh,
- u32 data_size_in_bytes, int chunk_size)
-{
- int freelist_index;
- u32 size;
- u8 *fifo_space;
- u32 rounded_data_size;
- svm_fifo_t *f;
- int i;
-
- rounded_data_size = (1 << (max_log2 (data_size_in_bytes)));
- freelist_index = max_log2 (rounded_data_size)
- - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
-
- /* Calculate space requirement $$$ round-up data_size_in_bytes */
- size = (sizeof (*f) + rounded_data_size) * chunk_size;
-
- /* Allocate fifo space. May fail. */
- fifo_space = clib_mem_alloc_aligned_at_offset
- (size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
- 0 /* os_out_of_memory */ );
-
- /* Out of space.. */
- if (fifo_space == 0)
- return;
-
- /* Carve fifo space */
- for (i = 0; i < chunk_size; i++)
- {
- fifo_init_for_segment (fsh, fifo_space, rounded_data_size,
- freelist_index);
- fifo_space += sizeof (*f) + rounded_data_size;
- }
-}
-
-/**
- * Pre-allocates fifo pairs in fifo segment
- *
- * The number of fifos pre-allocated is the minimum of the requested number
- * of pairs and the maximum number that fit within the segment. If the maximum
- * is hit, the number of fifo pairs requested is updated by subtracting the
- * number of fifos that have been successfully allocated.
- */
-void
-svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
- u32 rx_fifo_size, u32 tx_fifo_size,
- u32 * n_fifo_pairs)
-{
- u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
- u32 rx_fifos_size, tx_fifos_size, pairs_to_allocate;
- int rx_freelist_index, tx_freelist_index;
- ssvm_shared_header_t *sh = s->ssvm.sh;
- svm_fifo_segment_header_t *fsh = s->h;
- u8 *rx_fifo_space, *tx_fifo_space;
- uword space_available;
- void *oldheap;
- svm_fifo_t *f;
- int i;
-
- /* Parameter check */
- if (rx_fifo_size == 0 || tx_fifo_size == 0 || *n_fifo_pairs == 0)
- return;
-
- if (rx_fifo_size < FIFO_SEGMENT_MIN_FIFO_SIZE ||
- rx_fifo_size > FIFO_SEGMENT_MAX_FIFO_SIZE)
- {
- clib_warning ("rx fifo_size out of range %d", rx_fifo_size);
- return;
- }
-
- if (tx_fifo_size < FIFO_SEGMENT_MIN_FIFO_SIZE ||
- tx_fifo_size > FIFO_SEGMENT_MAX_FIFO_SIZE)
- {
- clib_warning ("tx fifo_size out of range %d", rx_fifo_size);
- return;
- }
-
- rx_rounded_data_size = (1 << (max_log2 (rx_fifo_size)));
- rx_freelist_index = max_log2 (rx_fifo_size)
- - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
- tx_rounded_data_size = (1 << (max_log2 (tx_fifo_size)));
- tx_freelist_index = max_log2 (tx_fifo_size)
- - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
-
- /* Calculate space requirements */
- pair_size = 2 * sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
-#if USE_DLMALLOC == 0
- space_available = s->ssvm.ssvm_size - mheap_bytes (sh->heap);
-#else
- space_available = s->ssvm.ssvm_size - mspace_usable_size (sh->heap);
-#endif
-
- pairs_to_allocate = clib_min (space_available / pair_size, *n_fifo_pairs);
- rx_fifos_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
- tx_fifos_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
-
- vec_validate_init_empty (fsh->free_fifos,
- clib_max (rx_freelist_index, tx_freelist_index),
- 0);
-
- oldheap = ssvm_push_heap (sh);
- /* Allocate rx fifo space. May fail. */
- rx_fifo_space = clib_mem_alloc_aligned_at_offset
- (rx_fifos_size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
- 0 /* os_out_of_memory */ );
-
- /* Same for TX */
- tx_fifo_space = clib_mem_alloc_aligned_at_offset
- (tx_fifos_size, CLIB_CACHE_LINE_BYTES, 0 /* align_offset */ ,
- 0 /* os_out_of_memory */ );
-
- /* Make sure it worked. Clean up if it didn't... */
- if (rx_fifo_space == 0 || tx_fifo_space == 0)
- {
- if (rx_fifo_space)
- clib_mem_free (rx_fifo_space);
- else
- clib_warning ("rx fifo preallocation failure: size %d npairs %d",
- rx_fifo_size, *n_fifo_pairs);
-
- if (tx_fifo_space)
- clib_mem_free (tx_fifo_space);
- else
- clib_warning ("tx fifo preallocation failure: size %d nfifos %d",
- tx_fifo_size, *n_fifo_pairs);
- ssvm_pop_heap (oldheap);
- return;
- }
-
- /* Carve rx fifo space */
- for (i = 0; i < pairs_to_allocate; i++)
- {
- fifo_init_for_segment (fsh, rx_fifo_space, rx_rounded_data_size,
- rx_freelist_index);
- rx_fifo_space += sizeof (*f) + rx_rounded_data_size;
- }
- /* Carve tx fifo space */
- for (i = 0; i < pairs_to_allocate; i++)
- {
- fifo_init_for_segment (fsh, tx_fifo_space, tx_rounded_data_size,
- tx_freelist_index);
- tx_fifo_space += sizeof (*f) + tx_rounded_data_size;
- }
-
- /* Account for the pairs allocated */
- *n_fifo_pairs -= pairs_to_allocate;
- ssvm_pop_heap (oldheap);
-}
+#include <svm/fifo_segment.h>
/**
- * Initialize svm fifo segment shared header
+ * Initialize fifo segment shared header
*/
int
-svm_fifo_segment_init (svm_fifo_segment_private_t * s)
+fifo_segment_init (fifo_segment_t * fs)
{
- svm_fifo_segment_header_t *fsh;
+ fifo_segment_header_t *fsh;
ssvm_shared_header_t *sh;
void *oldheap;
- sh = s->ssvm.sh;
+ sh = fs->ssvm.sh;
oldheap = ssvm_push_heap (sh);
fsh = clib_mem_alloc (sizeof (*fsh));
clib_memset (fsh, 0, sizeof (*fsh));
- s->h = sh->opaque[0] = fsh;
+ fs->h = sh->opaque[0] = fsh;
ssvm_pop_heap (oldheap);
@@ -205,51 +39,17 @@ svm_fifo_segment_init (svm_fifo_segment_private_t * s)
}
/**
- * Create an svm fifo segment and initialize as master
+ * Create a fifo segment in process-private memory
*/
-int
-svm_fifo_segment_create (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t * a)
+static int
+fifo_segment_create_process_private (fifo_segment_main_t * sm,
+ fifo_segment_create_args_t * a)
{
- svm_fifo_segment_private_t *s;
- int rv;
-
- /* Allocate a fresh segment */
- pool_get (sm->segments, s);
- clib_memset (s, 0, sizeof (*s));
-
- s->ssvm.ssvm_size = a->segment_size;
- s->ssvm.i_am_master = 1;
- s->ssvm.my_pid = getpid ();
- s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
- s->ssvm.requested_va = sm->next_baseva;
-
- if ((rv = ssvm_master_init (&s->ssvm, a->segment_type)))
- {
- pool_put (sm->segments, s);
- return (rv);
- }
-
- /* Note: requested_va updated due to seg base addr randomization */
- sm->next_baseva = s->ssvm.sh->ssvm_va + a->segment_size;
-
- svm_fifo_segment_init (s);
- vec_add1 (a->new_segment_indices, s - sm->segments);
- return (0);
-}
-
-/**
- * Create an svm fifo segment in process-private memory
- */
-int
-svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t * a)
-{
- svm_fifo_segment_private_t *s;
+ u32 pagesize = clib_mem_get_page_size ();
ssvm_shared_header_t *sh;
+ fifo_segment_t *s;
u32 rnd_size = 0;
u8 *heap;
- u32 pagesize = clib_mem_get_page_size ();
pool_get (sm->segments, s);
clib_memset (s, 0, sizeof (*s));
@@ -286,27 +86,60 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
clib_memset (sh, 0, sizeof (*sh));
sh->heap = heap;
- svm_fifo_segment_init (s);
+ fifo_segment_init (s);
vec_add1 (a->new_segment_indices, s - sm->segments);
return (0);
}
/**
- * Attach as slave to an svm fifo segment
+ * Create a fifo segment and initialize as master
*/
int
-svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t * a)
+fifo_segment_create (fifo_segment_main_t * sm, fifo_segment_create_args_t * a)
{
- svm_fifo_segment_private_t *s;
+ fifo_segment_t *s;
int rv;
+ if (a->segment_type == SSVM_SEGMENT_PRIVATE)
+ return fifo_segment_create_process_private (sm, a);
+
/* Allocate a fresh segment */
pool_get (sm->segments, s);
clib_memset (s, 0, sizeof (*s));
s->ssvm.ssvm_size = a->segment_size;
+ s->ssvm.i_am_master = 1;
+ s->ssvm.my_pid = getpid ();
+ s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
+ s->ssvm.requested_va = sm->next_baseva;
+
+ if ((rv = ssvm_master_init (&s->ssvm, a->segment_type)))
+ {
+ pool_put (sm->segments, s);
+ return (rv);
+ }
+
+ /* Note: requested_va updated due to seg base addr randomization */
+ sm->next_baseva = s->ssvm.sh->ssvm_va + a->segment_size;
+
+ fifo_segment_init (s);
+ vec_add1 (a->new_segment_indices, s - sm->segments);
+ return (0);
+}
+
+/**
+ * Attach as slave to a fifo segment
+ */
+int
+fifo_segment_attach (fifo_segment_main_t * sm, fifo_segment_create_args_t * a)
+{
+ fifo_segment_t *s;
+ int rv;
+
+ pool_get_zero (sm->segments, s);
+
+ s->ssvm.ssvm_size = a->segment_size;
s->ssvm.my_pid = getpid ();
s->ssvm.name = format (0, "%s%c", a->segment_name, 0);
s->ssvm.requested_va = sm->next_baseva;
@@ -329,92 +162,187 @@ svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
}
void
-svm_fifo_segment_delete (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_private_t * s)
+fifo_segment_delete (fifo_segment_main_t * sm, fifo_segment_t * s)
{
ssvm_delete (&s->ssvm);
clib_memset (s, 0xfe, sizeof (*s));
pool_put (sm->segments, s);
}
+u32
+fifo_segment_index (fifo_segment_main_t * sm, fifo_segment_t * s)
+{
+ return s - sm->segments;
+}
+
+void *
+svm_fifo_segment_heap (fifo_segment_t * seg)
+{
+ return seg->ssvm.sh->heap;
+}
+
+fifo_segment_t *
+fifo_segment_get_segment (fifo_segment_main_t * sm, u32 segment_index)
+{
+ return pool_elt_at_index (sm->segments, segment_index);
+}
+
+void
+fifo_segment_info (fifo_segment_t * seg, char **address, size_t * size)
+{
+ if (ssvm_type (&seg->ssvm) == SSVM_SEGMENT_PRIVATE)
+ {
+#if USE_DLMALLOC == 0
+ mheap_t *heap_header;
+
+ *address = pointer_to_uword (seg->ssvm.sh->heap);
+ heap_header = mheap_header (seg->ssvm.sh->heap);
+ *size = heap_header->max_size;
+#else
+ mspace_get_address_and_size (seg->ssvm.sh->heap, address, size);
+#endif
+ }
+ else
+ {
+ *address = (char *) seg->ssvm.sh->ssvm_va;
+ *size = seg->ssvm.ssvm_size;
+ }
+}
+
+void
+fifo_segment_main_init (fifo_segment_main_t * sm, u64 baseva,
+ u32 timeout_in_seconds)
+{
+ sm->next_baseva = baseva;
+ sm->timeout_in_seconds = timeout_in_seconds;
+}
+
+static void
+fifo_init_for_segment (fifo_segment_header_t * fsh, svm_fifo_t * f,
+ u32 size, u32 fl_index)
+{
+ f->freelist_index = fl_index;
+ f->default_chunk.start_byte = 0;
+ f->default_chunk.length = size;
+ f->default_chunk.next = f->start_chunk = f->end_chunk = &f->default_chunk;
+ f->head_chunk = f->tail_chunk = f->ooo_enq = f->ooo_deq = f->start_chunk;
+ f->next = fsh->free_fifos[fl_index];
+ fsh->free_fifos[fl_index] = f;
+}
+
+static inline int
+fs_free_list_for_size (u32 size)
+{
+ return max_log2 (size) - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
+}
+
+static inline int
+fs_fifo_size_is_valid (u32 size)
+{
+ /*
+ * 4K minimum. It's not likely that anything good will happen
+ * with a smaller FIFO.
+ */
+ return size >= FIFO_SEGMENT_MIN_FIFO_SIZE
+ && size <= FIFO_SEGMENT_MAX_FIFO_SIZE;
+}
+
+static void
+allocate_new_fifo_batch (fifo_segment_header_t * fsh,
+ u32 data_size_in_bytes, int chunk_size)
+{
+ u32 size, rounded_data_size;
+ int i, fl_index;
+ u8 *fifos_mem;
+ svm_fifo_t *f;
+
+ rounded_data_size = (1 << (max_log2 (data_size_in_bytes)));
+ fl_index = fs_free_list_for_size (data_size_in_bytes);
+
+ /* Calculate space requirement $$$ round-up data_size_in_bytes */
+ size = (sizeof (*f) + rounded_data_size) * chunk_size;
+
+ /* Allocate fifo space. May fail. */
+ fifos_mem = clib_mem_alloc_aligned_at_offset (size, CLIB_CACHE_LINE_BYTES,
+ 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+
+ /* Out of space.. */
+ if (fifos_mem == 0)
+ return;
+
+ /* Carve fifo space */
+ for (i = 0; i < chunk_size; i++)
+ {
+ f = (svm_fifo_t *) fifos_mem;
+ fifo_init_for_segment (fsh, f, rounded_data_size, fl_index);
+ fifos_mem += sizeof (*f) + rounded_data_size;
+ }
+}
+
/**
- * Allocate fifo in svm segment
+ * Allocate fifo in fifo segment
*/
svm_fifo_t *
-svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * fs,
- u32 data_size_in_bytes,
- svm_fifo_segment_freelist_t list_index)
+fifo_segment_alloc_fifo (fifo_segment_t * fs, u32 data_bytes,
+ fifo_segment_ftype_t ftype)
{
+ fifo_segment_header_t *fsh;
ssvm_shared_header_t *sh;
- svm_fifo_segment_header_t *fsh;
svm_fifo_t *f = 0;
void *oldheap;
- int freelist_index;
+ int fl_index;
- /*
- * 4K minimum. It's not likely that anything good will happen
- * with a smaller FIFO.
- */
- if (data_size_in_bytes < FIFO_SEGMENT_MIN_FIFO_SIZE ||
- data_size_in_bytes > FIFO_SEGMENT_MAX_FIFO_SIZE)
+ if (!fs_fifo_size_is_valid (data_bytes))
{
- clib_warning ("fifo size out of range %d", data_size_in_bytes);
+ clib_warning ("fifo size out of range %d", data_bytes);
return 0;
}
- freelist_index = max_log2 (data_size_in_bytes)
- - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
+ fl_index = fs_free_list_for_size (data_bytes);
sh = fs->ssvm.sh;
ssvm_lock_non_recursive (sh, 1);
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
- switch (list_index)
- {
- case FIFO_SEGMENT_RX_FREELIST:
- case FIFO_SEGMENT_TX_FREELIST:
- vec_validate_init_empty (fsh->free_fifos, freelist_index, 0);
- f = fsh->free_fifos[freelist_index];
- if (PREDICT_FALSE (!f))
- {
- oldheap = ssvm_push_heap (sh);
- allocate_new_fifo_chunk (fsh, data_size_in_bytes,
- FIFO_SEGMENT_ALLOC_CHUNK_SIZE);
- ssvm_pop_heap (oldheap);
- f = fsh->free_fifos[freelist_index];
- }
- if (PREDICT_TRUE (f != 0))
- {
- fsh->free_fifos[freelist_index] = f->next;
- /* (re)initialize the fifo, as in svm_fifo_create */
- clib_memset (f, 0, sizeof (*f));
- svm_fifo_init (f, data_size_in_bytes);
- goto found;
- }
- break;
- case FIFO_SEGMENT_FREELIST_NONE:
- break;
+ fsh = (fifo_segment_header_t *) sh->opaque[0];
+ vec_validate_init_empty (fsh->free_fifos, fl_index, 0);
+ f = fsh->free_fifos[fl_index];
- default:
- clib_warning ("ignore bogus freelist %d", list_index);
- break;
+ /* Try to allocate batch of fifos */
+ if (PREDICT_FALSE (!f))
+ {
+ oldheap = ssvm_push_heap (sh);
+ allocate_new_fifo_batch (fsh, data_bytes,
+ FIFO_SEGMENT_ALLOC_BATCH_SIZE);
+ ssvm_pop_heap (oldheap);
+ f = fsh->free_fifos[fl_index];
+ }
+ if (PREDICT_TRUE (f != 0))
+ {
+ fsh->free_fifos[fl_index] = f->next;
+ /* (re)initialize the fifo, as in svm_fifo_create */
+ memset (f, 0, sizeof (*f));
+ svm_fifo_init (f, data_bytes);
+ goto found;
}
- /* Catch all that allocates just one fifo. Note: this can fail,
- * in which case: create another segment */
+ /* Failed to allocate batch, try just one fifo. This can also fail,
+ * in which case, create another segment */
oldheap = ssvm_push_heap (sh);
- f = svm_fifo_create (data_size_in_bytes);
+ f = svm_fifo_create (data_bytes);
ssvm_pop_heap (oldheap);
+
if (PREDICT_FALSE (f == 0))
goto done;
- f->freelist_index = freelist_index;
+
+ f->freelist_index = fl_index;
found:
- /* If rx_freelist add to active fifos list. When cleaning up segment,
+ /* If rx fifo type add to active fifos list. When cleaning up segment,
* we need a list of active sessions that should be disconnected. Since
* both rx and tx fifos keep pointers to the session, it's enough to track
* only one. */
- if (list_index == FIFO_SEGMENT_RX_FREELIST)
+ if (ftype == FIFO_SEGMENT_RX_FIFO)
{
if (fsh->fifos)
{
@@ -422,6 +350,7 @@ found:
f->next = fsh->fifos;
}
fsh->fifos = f;
+ f->flags |= SVM_FIFO_F_LL_TRACKED;
}
fsh->n_active_fifos++;
@@ -430,13 +359,15 @@ done:
return (f);
}
+/**
+ * Free fifo allocated in fifo segment
+ */
void
-svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, svm_fifo_t * f,
- svm_fifo_segment_freelist_t list_index)
+fifo_segment_free_fifo (fifo_segment_t * s, svm_fifo_t * f)
{
+ fifo_segment_header_t *fsh;
ssvm_shared_header_t *sh;
- svm_fifo_segment_header_t *fsh;
- int freelist_index;
+ int fl_index;
ASSERT (f->refcnt > 0);
@@ -444,39 +375,30 @@ svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, svm_fifo_t * f,
return;
sh = s->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
-
- freelist_index = f->freelist_index;
+ fsh = (fifo_segment_header_t *) sh->opaque[0];
+ fl_index = f->freelist_index;
- ASSERT (freelist_index < vec_len (fsh->free_fifos));
+ ASSERT (fl_index < vec_len (fsh->free_fifos));
ssvm_lock_non_recursive (sh, 2);
- switch (list_index)
+ /* Remove from active list. Only rx fifos are tracked */
+ if (f->flags & SVM_FIFO_F_LL_TRACKED)
{
- case FIFO_SEGMENT_RX_FREELIST:
- /* Remove from active list */
if (f->prev)
f->prev->next = f->next;
else
fsh->fifos = f->next;
if (f->next)
f->next->prev = f->prev;
- /* Fall through: we add only rx fifos to active pool */
- case FIFO_SEGMENT_TX_FREELIST:
- /* Add to free list */
- f->next = fsh->free_fifos[freelist_index];
- f->prev = 0;
- fsh->free_fifos[freelist_index] = f;
- break;
- case FIFO_SEGMENT_FREELIST_NONE:
- break;
-
- default:
- clib_warning ("ignore bogus freelist %d", list_index);
- break;
+ f->flags &= ~SVM_FIFO_F_LL_TRACKED;
}
+ /* Add to free list */
+ f->next = fsh->free_fifos[fl_index];
+ f->prev = 0;
+ fsh->free_fifos[fl_index] = f;
+
if (CLIB_DEBUG)
{
f->master_session_index = ~0;
@@ -487,51 +409,119 @@ svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, svm_fifo_t * f,
ssvm_unlock_non_recursive (sh);
}
+/**
+ * Pre-allocates fifo pairs in fifo segment
+ */
void
-svm_fifo_segment_main_init (svm_fifo_segment_main_t * sm, u64 baseva,
- u32 timeout_in_seconds)
+fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs,
+ u32 rx_fifo_size, u32 tx_fifo_size,
+ u32 * n_fifo_pairs)
{
- sm->next_baseva = baseva;
- sm->timeout_in_seconds = timeout_in_seconds;
-}
+ u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
+ u32 rx_fifos_size, tx_fifos_size, pairs_to_allocate;
+ ssvm_shared_header_t *sh = fs->ssvm.sh;
+ fifo_segment_header_t *fsh = fs->h;
+ int i, rx_fl_index, tx_fl_index;
+ u8 *rx_fifo_mem, *tx_fifo_mem;
+ uword space_available;
+ void *oldheap;
+ svm_fifo_t *f;
-u32
-svm_fifo_segment_index (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_private_t * s)
-{
- return s - sm->segments;
-}
+ /* Parameter check */
+ if (rx_fifo_size == 0 || tx_fifo_size == 0 || *n_fifo_pairs == 0)
+ return;
-/**
- * Retrieve svm segments pool. Used only for debug purposes.
- */
-svm_fifo_segment_private_t *
-svm_fifo_segment_segments_pool (svm_fifo_segment_main_t * sm)
-{
- return sm->segments;
+ if (!fs_fifo_size_is_valid (rx_fifo_size))
+ {
+ clib_warning ("rx fifo_size out of range %d", rx_fifo_size);
+ return;
+ }
+
+ if (!fs_fifo_size_is_valid (tx_fifo_size))
+ {
+ clib_warning ("tx fifo_size out of range %d", tx_fifo_size);
+ return;
+ }
+
+ rx_rounded_data_size = (1 << (max_log2 (rx_fifo_size)));
+ rx_fl_index = fs_free_list_for_size (rx_fifo_size);
+ tx_rounded_data_size = (1 << (max_log2 (tx_fifo_size)));
+ tx_fl_index = fs_free_list_for_size (tx_fifo_size);
+
+ /* Calculate space requirements */
+ pair_size = 2 * sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
+#if USE_DLMALLOC == 0
+ space_available = fs->ssvm.ssvm_size - mheap_bytes (sh->heap);
+#else
+ space_available = fs->ssvm.ssvm_size - mspace_usable_size (sh->heap);
+#endif
+
+ pairs_to_allocate = clib_min (space_available / pair_size, *n_fifo_pairs);
+ rx_fifos_size = (sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
+ tx_fifos_size = (sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
+
+ vec_validate_init_empty (fsh->free_fifos,
+ clib_max (rx_fl_index, tx_fl_index), 0);
+
+ oldheap = ssvm_push_heap (sh);
+
+ /* Allocate rx and tx fifo memory. May fail. */
+ rx_fifo_mem = clib_mem_alloc_aligned_at_offset (rx_fifos_size,
+ CLIB_CACHE_LINE_BYTES,
+ 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+ tx_fifo_mem = clib_mem_alloc_aligned_at_offset (tx_fifos_size,
+ CLIB_CACHE_LINE_BYTES,
+ 0 /* align_offset */ ,
+ 0 /* os_out_of_memory */ );
+
+ /* Make sure it worked. Clean up if it didn't... */
+ if (rx_fifo_mem == 0 || tx_fifo_mem == 0)
+ {
+ rx_fifo_mem ? clib_mem_free (rx_fifo_mem) : clib_mem_free (tx_fifo_mem);
+ clib_warning ("fifo preallocation failure: rx size %d tx size %u "
+ "npairs %d", rx_fifo_size, tx_fifo_size, *n_fifo_pairs);
+ ssvm_pop_heap (oldheap);
+ return;
+ }
+
+ /* Carve rx and tx fifo memory */
+ for (i = 0; i < pairs_to_allocate; i++)
+ {
+ f = (svm_fifo_t *) rx_fifo_mem;
+ fifo_init_for_segment (fsh, f, rx_rounded_data_size, rx_fl_index);
+ rx_fifo_mem += sizeof (*f) + rx_rounded_data_size;
+
+ f = (svm_fifo_t *) tx_fifo_mem;
+ fifo_init_for_segment (fsh, f, tx_rounded_data_size, tx_fl_index);
+ tx_fifo_mem += sizeof (*f) + tx_rounded_data_size;
+ }
+
+ /* Account for the pairs allocated */
+ *n_fifo_pairs -= pairs_to_allocate;
+ ssvm_pop_heap (oldheap);
}
/**
* Get number of active fifos
*/
u32
-svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment)
+fifo_segment_num_fifos (fifo_segment_t * fs)
{
- return fifo_segment->h->n_active_fifos;
+ return fs->h->n_active_fifos;
}
u32
-svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t * fifo_segment,
- u32 fifo_size_in_bytes)
+fifo_segment_num_free_fifos (fifo_segment_t * fs, u32 fifo_size_in_bytes)
{
+ u32 count = 0, rounded_data_size, fl_index;
+ fifo_segment_header_t *fsh;
ssvm_shared_header_t *sh;
- svm_fifo_segment_header_t *fsh;
svm_fifo_t *f;
int i;
- u32 count = 0, rounded_data_size, freelist_index;
- sh = fifo_segment->ssvm.sh;
- fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
+ sh = fs->ssvm.sh;
+ fsh = (fifo_segment_header_t *) sh->opaque[0];
/* Count all free fifos? */
if (fifo_size_in_bytes == ~0)
@@ -552,13 +542,12 @@ svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t * fifo_segment,
}
rounded_data_size = (1 << (max_log2 (fifo_size_in_bytes)));
- freelist_index = max_log2 (rounded_data_size)
- - max_log2 (FIFO_SEGMENT_MIN_FIFO_SIZE);
+ fl_index = fs_free_list_for_size (rounded_data_size);
- if (freelist_index >= vec_len (fsh->free_fifos))
+ if (fl_index >= vec_len (fsh->free_fifos))
return 0;
- f = fsh->free_fifos[freelist_index];
+ f = fsh->free_fifos[fl_index];
if (f == 0)
return 0;
@@ -570,40 +559,23 @@ svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t * fifo_segment,
return count;
}
-void
-svm_fifo_segment_info (svm_fifo_segment_private_t * seg, char **address,
- size_t * size)
+u8
+fifo_segment_has_fifos (fifo_segment_t * fs)
{
- if (ssvm_type (&seg->ssvm) == SSVM_SEGMENT_PRIVATE)
- {
-#if USE_DLMALLOC == 0
- mheap_t *heap_header;
-
- *address = pointer_to_uword (seg->ssvm.sh->heap);
- heap_header = mheap_header (seg->ssvm.sh->heap);
- *size = heap_header->max_size;
-#else
- mspace_get_address_and_size (seg->ssvm.sh->heap, address, size);
-#endif
- }
- else
- {
- *address = (char *) seg->ssvm.sh->ssvm_va;
- *size = seg->ssvm.ssvm_size;
- }
+ return fs->h->fifos != 0;
}
-void *
-svm_fifo_segment_heap (svm_fifo_segment_private_t * seg)
+svm_fifo_t *
+fifo_segment_get_fifo_list (fifo_segment_t * fs)
{
- return seg->ssvm.sh->heap;
+ return fs->h->fifos;
}
u8 *
-format_svm_fifo_segment_type (u8 * s, va_list * args)
+format_fifo_segment_type (u8 * s, va_list * args)
{
- svm_fifo_segment_private_t *sp;
- sp = va_arg (*args, svm_fifo_segment_private_t *);
+ fifo_segment_t *sp;
+ sp = va_arg (*args, fifo_segment_t *);
ssvm_segment_type_t st = ssvm_type (&sp->ssvm);
if (st == SSVM_SEGMENT_PRIVATE)
@@ -621,12 +593,11 @@ format_svm_fifo_segment_type (u8 * s, va_list * args)
* Segment format function
*/
u8 *
-format_svm_fifo_segment (u8 * s, va_list * args)
+format_fifo_segment (u8 * s, va_list * args)
{
- svm_fifo_segment_private_t *sp
- = va_arg (*args, svm_fifo_segment_private_t *);
+ fifo_segment_t *sp = va_arg (*args, fifo_segment_t *);
int verbose __attribute__ ((unused)) = va_arg (*args, int);
- svm_fifo_segment_header_t *fsh = sp->h;
+ fifo_segment_header_t *fsh = sp->h;
u32 count, indent;
svm_fifo_t *f;
int i;
@@ -636,7 +607,7 @@ format_svm_fifo_segment (u8 * s, va_list * args)
s = format (s, "%U segment heap: %U\n", format_white_space, indent,
format_mheap, svm_fifo_segment_heap (sp), verbose);
s = format (s, "%U segment has %u active fifos\n",
- format_white_space, indent, svm_fifo_segment_num_fifos (sp));
+ format_white_space, indent, fifo_segment_num_fifos (sp));
#endif
for (i = 0; i < vec_len (fsh->free_fifos); i++)
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h
new file mode 100644
index 00000000000..cc0ff3adf3a
--- /dev/null
+++ b/src/svm/fifo_segment.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2016-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __included_fifo_segment_h__
+#define __included_fifo_segment_h__
+
+#include <svm/ssvm.h>
+#include <svm/svm_fifo.h>
+
+typedef enum
+{
+ FIFO_SEGMENT_FTYPE_NONE = -1,
+ FIFO_SEGMENT_RX_FIFO = 0,
+ FIFO_SEGMENT_TX_FIFO,
+ FIFO_SEGMENT_N_FTYPES
+} fifo_segment_ftype_t;
+
+#define FIFO_SEGMENT_MIN_FIFO_SIZE 4096 /* 4kB min fifo size */
+#define FIFO_SEGMENT_MAX_FIFO_SIZE (2 << 30) /* 2GB max fifo size */
+#define FIFO_SEGMENT_ALLOC_BATCH_SIZE 32 /* Allocation quantum */
+
+typedef enum fifo_segment_flags_
+{
+ FIFO_SEGMENT_F_IS_PREALLOCATED = 1 << 0,
+ FIFO_SEGMENT_F_WILL_DELETE = 1 << 1,
+} fifo_segment_flags_t;
+
+typedef struct
+{
+ svm_fifo_t *fifos; /**< Linked list of active RX fifos */
+ svm_fifo_t **free_fifos; /**< Freelists, by fifo size */
+ u32 n_active_fifos; /**< Number of active fifos */
+ u8 flags; /**< Segment flags */
+} fifo_segment_header_t;
+
+typedef struct
+{
+ ssvm_private_t ssvm; /**< ssvm segment data */
+ fifo_segment_header_t *h; /**< fifo segment data */
+} fifo_segment_t;
+
+typedef struct
+{
+ fifo_segment_t *segments; /**< pool of fifo segments */
+ u64 next_baseva; /**< Where to put the next one */
+ u32 timeout_in_seconds; /**< Time to wait during attach */
+} fifo_segment_main_t;
+
+typedef struct
+{
+ ssvm_segment_type_t segment_type; /**< type of segment requested */
+ u32 segment_size; /**< size of the segment */
+ int memfd_fd; /**< fd for memfd segments */
+ char *segment_name; /**< segment name */
+ u32 *new_segment_indices; /**< return vec of new seg indices */
+} fifo_segment_create_args_t;
+
+#define fifo_segment_flags(_fs) _fs->h->flags
+
+int fifo_segment_init (fifo_segment_t * fs);
+int fifo_segment_create (fifo_segment_main_t * sm,
+ fifo_segment_create_args_t * a);
+int fifo_segment_attach (fifo_segment_main_t * sm,
+ fifo_segment_create_args_t * a);
+void fifo_segment_delete (fifo_segment_main_t * sm, fifo_segment_t * fs);
+fifo_segment_t *fifo_segment_get_segment (fifo_segment_main_t * sm,
+ u32 fs_index);
+u32 fifo_segment_index (fifo_segment_main_t * sm, fifo_segment_t * fs);
+void fifo_segment_info (fifo_segment_t * seg, char **address, size_t * size);
+
+/**
+ * Allocate fifo in fifo segment
+ *
+ * @param fs fifo segment
+ * @param data_bytes size of default fifo chunk in bytes
+ * @param ftype fifo type @ref fifo_segment_ftype_t
+ * @return new fifo or 0 if alloc failed
+ */
+svm_fifo_t *fifo_segment_alloc_fifo (fifo_segment_t * fs,
+ u32 data_bytes,
+ fifo_segment_ftype_t ftype);
+
+/**
+ * Free fifo allocated in fifo segment
+ *
+ * @param fs fifo segment
+ * @param f fifo to be freed
+ */
+void fifo_segment_free_fifo (fifo_segment_t * fs, svm_fifo_t * f);
+
+/**
+ * Pre-allocates fifo pairs in fifo segment
+ *
+ * The number of fifos pre-allocated is the minimum of the requested number
+ * of pairs and the maximum number that fit within the segment. If the maximum
+ * is hit, the number of fifo pairs requested is updated by subtracting the
+ * number of fifos that have been successfully allocated.
+ *
+ * @param fs fifo segment
+ * @param rx_fifo_size data size of rx fifos
+ * @param tx_fifo_size data size of tx fifos
+ * @param n_fifo_pairs number of pairs requested. Prior to returning, this
+ * is decremented by the the number of pairs allocated.
+ */
+void fifo_segment_preallocate_fifo_pairs (fifo_segment_t * fs,
+ u32 rx_fifo_size,
+ u32 tx_fifo_size,
+ u32 * n_fifo_pairs);
+u8 fifo_segment_has_fifos (fifo_segment_t * fs);
+svm_fifo_t *fifo_segment_get_fifo_list (fifo_segment_t * fs);
+u32 fifo_segment_num_fifos (fifo_segment_t * fs);
+u32 fifo_segment_num_free_fifos (fifo_segment_t * fs, u32 fifo_size_in_bytes);
+
+void fifo_segment_main_init (fifo_segment_main_t * sm, u64 baseva,
+ u32 timeout_in_seconds);
+
+format_function_t format_fifo_segment;
+format_function_t format_fifo_segment_type;
+
+#endif /* __included_fifo_segment_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index a335519d1e4..eafe497eec1 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -882,7 +882,7 @@ svm_fifo_dequeue_drop_all (svm_fifo_t * f)
}
int
-svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs)
+svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs)
{
u32 cursize, head, tail, head_idx;
@@ -914,7 +914,7 @@ svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs)
}
void
-svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs)
+svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs)
{
u32 head, head_idx;
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index 619d6093429..4f2f61939b7 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -67,6 +67,7 @@ typedef enum svm_fifo_flag_
{
SVM_FIFO_F_SIZE_UPDATE = 1 << 0,
SVM_FIFO_F_MULTI_CHUNK = 1 << 1,
+ SVM_FIFO_F_LL_TRACKED = 1 << 2,
} svm_fifo_flag_t;
typedef struct _svm_fifo
@@ -124,11 +125,11 @@ typedef enum
SVM_FIFO_FULL = -2,
} svm_fifo_err_t;
-typedef struct svm_fifo_segment_
+typedef struct svm_fifo_seg_
{
u8 *data;
u32 len;
-} svm_fifo_segment_t;
+} svm_fifo_seg_t;
#if SVM_FIFO_TRACE
#define svm_fifo_trace_add(_f, _s, _l, _t) \
@@ -352,8 +353,8 @@ int svm_fifo_dequeue_nowait (svm_fifo_t * f, u32 max_bytes, u8 * copy_here);
int svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 max_bytes, u8 * copy_here);
int svm_fifo_dequeue_drop (svm_fifo_t * f, u32 max_bytes);
void svm_fifo_dequeue_drop_all (svm_fifo_t * f);
-int svm_fifo_segments (svm_fifo_t * f, svm_fifo_segment_t * fs);
-void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs);
+int svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs);
+void svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs);
void svm_fifo_init_pointers (svm_fifo_t * f, u32 head, u32 tail);
void svm_fifo_clone (svm_fifo_t * df, svm_fifo_t * sf);
void svm_fifo_overwrite_head (svm_fifo_t * f, u8 * data, u32 len);
diff --git a/src/svm/svm_fifo_segment.h b/src/svm/svm_fifo_segment.h
deleted file mode 100644
index d4d48093ae6..00000000000
--- a/src/svm/svm_fifo_segment.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (c) 2016-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __included_ssvm_fifo_segment_h__
-#define __included_ssvm_fifo_segment_h__
-
-#include <svm/ssvm.h>
-#include <svm/svm_fifo.h>
-#include <vppinfra/lock.h>
-
-typedef enum
-{
- FIFO_SEGMENT_FREELIST_NONE = -1,
- FIFO_SEGMENT_RX_FREELIST = 0,
- FIFO_SEGMENT_TX_FREELIST,
- FIFO_SEGMENT_N_FREELISTS
-} svm_fifo_segment_freelist_t;
-
-#define FIFO_SEGMENT_MIN_FIFO_SIZE 4096
-#define FIFO_SEGMENT_MAX_FIFO_SIZE (2 << 30) /* 2GB max fifo size */
-#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE 32 /* Allocation quantum */
-
-#define FIFO_SEGMENT_F_IS_PREALLOCATED (1 << 0)
-#define FIFO_SEGMENT_F_WILL_DELETE (1 << 1)
-
-typedef struct
-{
- svm_fifo_t *fifos; /**< Linked list of active RX fifos */
- svm_fifo_t **free_fifos; /**< Freelists, by fifo size */
- u32 n_active_fifos; /**< Number of active fifos */
- u8 flags; /**< Segment flags */
-} svm_fifo_segment_header_t;
-
-typedef struct
-{
- ssvm_private_t ssvm;
- svm_fifo_segment_header_t *h;
-} svm_fifo_segment_private_t;
-
-typedef struct
-{
- volatile u32 lock;
-
- /** pool of segments */
- svm_fifo_segment_private_t *segments;
- /* Where to put the next one */
- u64 next_baseva;
- u32 timeout_in_seconds;
-} svm_fifo_segment_main_t;
-
-typedef struct
-{
- ssvm_segment_type_t segment_type;
- char *segment_name;
- u32 segment_size;
- u32 *new_segment_indices;
- int memfd_fd;
-} svm_fifo_segment_create_args_t;
-
-#define svm_fifo_segment_flags(_seg) _seg->h->flags
-
-static inline svm_fifo_segment_private_t *
-svm_fifo_segment_get_segment (svm_fifo_segment_main_t * sm, u32 segment_index)
-{
- return pool_elt_at_index (sm->segments, segment_index);
-}
-
-static inline u8
-svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment)
-{
- return fifo_segment->h->fifos != 0;
-}
-
-static inline svm_fifo_t *
-svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment)
-{
- return fifo_segment->h->fifos;
-}
-
-int svm_fifo_segment_init (svm_fifo_segment_private_t * s);
-int svm_fifo_segment_create (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t * a);
-int svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t
- *);
-void svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
- u32 rx_fifo_size,
- u32 tx_fifo_size,
- u32 * n_fifo_pairs);
-int svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_create_args_t * a);
-void svm_fifo_segment_delete (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_private_t * s);
-
-svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
- u32 data_size_in_bytes,
- svm_fifo_segment_freelist_t index);
-void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s,
- svm_fifo_t * f,
- svm_fifo_segment_freelist_t index);
-void svm_fifo_segment_main_init (svm_fifo_segment_main_t * sm, u64 baseva,
- u32 timeout_in_seconds);
-u32 svm_fifo_segment_index (svm_fifo_segment_main_t * sm,
- svm_fifo_segment_private_t * s);
-u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
-u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
- fifo_segment, u32 fifo_size_in_bytes);
-void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, char **address,
- size_t * size);
-
-svm_fifo_segment_private_t
- * svm_fifo_segment_segments_pool (svm_fifo_segment_main_t * sm);
-
-format_function_t format_svm_fifo_segment;
-format_function_t format_svm_fifo_segment_type;
-
-#endif /* __included_ssvm_fifo_segment_h__ */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/tests/vnet/session/quic_echo.c b/src/tests/vnet/session/quic_echo.c
index 4d1288f66d5..7d0cedd1d6b 100644
--- a/src/tests/vnet/session/quic_echo.c
+++ b/src/tests/vnet/session/quic_echo.c
@@ -17,10 +17,10 @@
#include <signal.h>
#include <vnet/session/application_interface.h>
-#include <svm/svm_fifo_segment.h>
#include <vlibmemory/api.h>
#include <vpp/api/vpe_msg_enum.h>
+#include <svm/fifo_segment.h>
#define vl_typedefs /* define message structures */
#include <vpp/api/vpe_all_api_h.h>
@@ -141,7 +141,7 @@ typedef struct
* and all other messages are exchanged using shm IPC. */
u8 use_sock_api;
- svm_fifo_segment_main_t segment_main;
+ fifo_segment_main_t segment_main;
} echo_main_t;
echo_main_t echo_main;
@@ -290,8 +290,8 @@ application_detach (echo_main_t * em)
static int
ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &echo_main.segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &echo_main.segment_main;
int rv;
clib_memset (a, 0, sizeof (*a));
@@ -301,7 +301,7 @@ ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
if (type == SSVM_SEGMENT_MEMFD)
a->memfd_fd = fd;
- if ((rv = svm_fifo_segment_attach (sm, a)))
+ if ((rv = fifo_segment_attach (sm, a)))
{
clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
return rv;
@@ -454,15 +454,15 @@ disconnect_from_vpp (echo_main_t * em)
static void
vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
{
- svm_fifo_segment_main_t *sm = &echo_main.segment_main;
- svm_fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &echo_main.segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
int rv;
clib_memset (a, 0, sizeof (*a));
a->segment_name = (char *) mp->segment_name;
a->segment_size = mp->segment_size;
/* Attach to the segment vpp created */
- rv = svm_fifo_segment_attach (sm, a);
+ rv = fifo_segment_attach (sm, a);
if (rv)
{
clib_warning ("svm_fifo_segment_attach ('%s') failed",
@@ -1286,7 +1286,7 @@ main (int argc, char **argv)
{
int i_am_server = 1, test_return_packets = 0;
echo_main_t *em = &echo_main;
- svm_fifo_segment_main_t *sm = &em->segment_main;
+ fifo_segment_main_t *sm = &em->segment_main;
unformat_input_t _argv, *a = &_argv;
u8 *chroot_prefix;
u8 *uri = 0;
@@ -1309,7 +1309,7 @@ main (int argc, char **argv)
clib_time_init (&em->clib_time);
init_error_string_table (em);
- svm_fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
+ fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
unformat_init_command_line (a, argv);
while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
diff --git a/src/tests/vnet/session/tcp_echo.c b/src/tests/vnet/session/tcp_echo.c
index 3fcc285dc11..6c3ce928490 100644
--- a/src/tests/vnet/session/tcp_echo.c
+++ b/src/tests/vnet/session/tcp_echo.c
@@ -17,10 +17,10 @@
#include <signal.h>
#include <vnet/session/application_interface.h>
-#include <svm/svm_fifo_segment.h>
#include <vlibmemory/api.h>
#include <vpp/api/vpe_msg_enum.h>
+#include <svm/fifo_segment.h>
#define vl_typedefs /* define message structures */
#include <vpp/api/vpe_all_api_h.h>
@@ -141,7 +141,7 @@ typedef struct
* and all other messages are exchanged using shm IPC. */
u8 use_sock_api;
- svm_fifo_segment_main_t segment_main;
+ fifo_segment_main_t segment_main;
} echo_main_t;
echo_main_t echo_main;
@@ -290,8 +290,8 @@ application_detach (echo_main_t * em)
static int
ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
- svm_fifo_segment_main_t *sm = &echo_main.segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &echo_main.segment_main;
int rv;
clib_memset (a, 0, sizeof (*a));
@@ -301,7 +301,7 @@ ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
if (type == SSVM_SEGMENT_MEMFD)
a->memfd_fd = fd;
- if ((rv = svm_fifo_segment_attach (sm, a)))
+ if ((rv = fifo_segment_attach (sm, a)))
{
clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
return rv;
@@ -456,15 +456,15 @@ disconnect_from_vpp (echo_main_t * em)
static void
vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
{
- svm_fifo_segment_main_t *sm = &echo_main.segment_main;
- svm_fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_main_t *sm = &echo_main.segment_main;
+ fifo_segment_create_args_t _a, *a = &_a;
int rv;
clib_memset (a, 0, sizeof (*a));
a->segment_name = (char *) mp->segment_name;
a->segment_size = mp->segment_size;
/* Attach to the segment vpp created */
- rv = svm_fifo_segment_attach (sm, a);
+ rv = fifo_segment_attach (sm, a);
if (rv)
{
clib_warning ("svm_fifo_segment_attach ('%s') failed",
@@ -1291,7 +1291,7 @@ main (int argc, char **argv)
{
int i_am_server = 1, test_return_packets = 0;
echo_main_t *em = &echo_main;
- svm_fifo_segment_main_t *sm = &em->segment_main;
+ fifo_segment_main_t *sm = &em->segment_main;
unformat_input_t _argv, *a = &_argv;
u8 *chroot_prefix;
u8 *uri = 0;
@@ -1314,7 +1314,7 @@ main (int argc, char **argv)
clib_time_init (&em->clib_time);
init_error_string_table (em);
- svm_fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
+ fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
unformat_init_command_line (a, argv);
while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT)
diff --git a/src/tests/vnet/session/udp_echo.c b/src/tests/vnet/session/udp_echo.c
index c949d4cbf6d..f1ecca8e926 100644
--- a/src/tests/vnet/session/udp_echo.c
+++ b/src/tests/vnet/session/udp_echo.c
@@ -27,9 +27,9 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/api/vpe_msg_enum.h>
-#include <svm/svm_fifo_segment.h>
#include <pthread.h>
#include <vnet/session/application_interface.h>
+#include <svm/fifo_segment.h>
#define vl_typedefs /* define message structures */
#include <vpp/api/vpe_all_api_h.h>
@@ -79,7 +79,7 @@ typedef struct
uword *session_index_by_vpp_handles;
/* fifo segment */
- svm_fifo_segment_private_t *seg;
+ fifo_segment_t *seg;
/* intermediate rx buffer */
u8 *rx_buf;
@@ -121,7 +121,7 @@ typedef struct
/* VNET_API_ERROR_FOO -> "Foo" hash table */
uword *error_string_by_error_number;
- svm_fifo_segment_main_t segment_main;
+ fifo_segment_main_t segment_main;
u8 *connect_test_data;
@@ -334,9 +334,9 @@ static void
vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
mp)
{
- svm_fifo_segment_create_args_t _a = { 0 }, *a = &_a;
+ fifo_segment_create_args_t _a = { 0 }, *a = &_a;
udp_echo_main_t *utm = &udp_echo_main;
- svm_fifo_segment_main_t *sm = &utm->segment_main;
+ fifo_segment_main_t *sm = &utm->segment_main;
int rv;
if (mp->retval)
@@ -358,7 +358,7 @@ vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
ASSERT (mp->app_event_queue_address);
/* Attach to the segment vpp created */
- rv = svm_fifo_segment_attach (sm, a);
+ rv = fifo_segment_attach (sm, a);
if (rv)
{
clib_warning ("svm_fifo_segment_attach ('%s') failed",
@@ -841,24 +841,24 @@ client_test (udp_echo_main_t * utm)
static void
vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_create_args_t _a, *a = &_a;
udp_echo_main_t *utm = &udp_echo_main;
- svm_fifo_segment_main_t *sm = &utm->segment_main;
- svm_fifo_segment_private_t *seg;
+ fifo_segment_main_t *sm = &utm->segment_main;
+ fifo_segment_t *seg;
int rv;
clib_memset (a, 0, sizeof (*a));
a->segment_name = (char *) mp->segment_name;
a->segment_size = mp->segment_size;
/* Attach to the segment vpp created */
- rv = svm_fifo_segment_attach (sm, a);
+ rv = fifo_segment_attach (sm, a);
if (rv)
{
clib_warning ("svm_fifo_segment_attach ('%s') failed",
mp->segment_name);
return;
}
- seg = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
+ seg = fifo_segment_get_segment (sm, a->new_segment_indices[0]);
clib_warning ("Mapped new segment '%s' size %d", seg->ssvm.name,
seg->ssvm.ssvm_size);
hash_set (utm->segments_table, clib_net_to_host_u64 (mp->segment_handle),
@@ -869,8 +869,8 @@ static void
vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
{
udp_echo_main_t *utm = &udp_echo_main;
- svm_fifo_segment_main_t *sm = &utm->segment_main;
- svm_fifo_segment_private_t *seg;
+ fifo_segment_main_t *sm = &utm->segment_main;
+ fifo_segment_t *seg;
uword *seg_indexp;
u64 segment_handle;
@@ -882,8 +882,8 @@ vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
return;
}
hash_unset (utm->segments_table, segment_handle);
- seg = svm_fifo_segment_get_segment (sm, (u32) seg_indexp[0]);
- svm_fifo_segment_delete (sm, seg);
+ seg = fifo_segment_get_segment (sm, (u32) seg_indexp[0]);
+ fifo_segment_delete (sm, seg);
clib_warning ("Unmapped segment '%s'", segment_handle);
}
@@ -1127,7 +1127,7 @@ int
main (int argc, char **argv)
{
udp_echo_main_t *utm = &udp_echo_main;
- svm_fifo_segment_main_t *sm = &utm->segment_main;
+ fifo_segment_main_t *sm = &utm->segment_main;
u8 *uri = (u8 *) "udp://6.0.1.1/1234";
unformat_input_t _argv, *a = &_argv;
int i_am_server = 1;
@@ -1139,7 +1139,7 @@ main (int argc, char **argv)
clib_mem_init_thread_safe (0, 256 << 20);
- svm_fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
+ fifo_segment_main_init (sm, HIGH_SEGMENT_BASEVA, 20);
vec_validate (utm->rx_buf, 128 << 10);
utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
diff --git a/src/vcl/vcl_bapi.c b/src/vcl/vcl_bapi.c
index b9f621d356d..b28398101b3 100644
--- a/src/vcl/vcl_bapi.c
+++ b/src/vcl/vcl_bapi.c
@@ -65,7 +65,7 @@ static int
vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
int fd)
{
- svm_fifo_segment_create_args_t _a, *a = &_a;
+ fifo_segment_create_args_t _a, *a = &_a;
int rv;
memset (a, 0, sizeof (*a));
@@ -75,7 +75,7 @@ vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
if (type == SSVM_SEGMENT_MEMFD)
a->memfd_fd = fd;
- if ((rv = svm_fifo_segment_attach (&vcm->segment_main, a)))
+ if ((rv = fifo_segment_attach (&vcm->segment_main, a)))
{
clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
return rv;
@@ -88,15 +88,15 @@ vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
static void
vcl_segment_detach (u64 segment_handle)
{
- svm_fifo_segment_main_t *sm = &vcm->segment_main;
- svm_fifo_segment_private_t *segment;
+ fifo_segment_main_t *sm = &vcm->segment_main;
+ fifo_segment_t *segment;
u32 segment_index;
segment_index = vcl_segment_table_lookup (segment_handle);
if (segment_index == (u32) ~ 0)
return;
- segment = svm_fifo_segment_get_segment (sm, segment_index);
- svm_fifo_segment_delete (sm, segment);
+ segment = fifo_segment_get_segment (sm, segment_index);
+ fifo_segment_delete (sm, segment);
vcl_segment_table_del (segment_handle);
VDBG (0, "detached segment %u handle %u", segment_index, segment_handle);
}
diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h
index 57828cf5b37..8bafa5f74b4 100644
--- a/src/vcl/vcl_private.h
+++ b/src/vcl/vcl_private.h
@@ -325,7 +325,7 @@ typedef struct vppcom_main_t_
/** Mapped segments table */
uword *segment_table;
- svm_fifo_segment_main_t segment_main;
+ fifo_segment_main_t segment_main;
#ifdef VCL_ELOG
/* VPP Event-logger */
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 6668d465fca..1641beee9f6 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -15,10 +15,10 @@
#include <stdio.h>
#include <stdlib.h>
-#include <svm/svm_fifo_segment.h>
#include <vcl/vppcom.h>
#include <vcl/vcl_debug.h>
#include <vcl/vcl_private.h>
+#include <svm/fifo_segment.h>
__thread uword __vcl_worker_index = ~0;
@@ -924,8 +924,8 @@ vppcom_app_create (char *app_name)
vcm->main_pid = getpid ();
vcm->app_name = format (0, "%s", app_name);
vppcom_init_error_string_table ();
- svm_fifo_segment_main_init (&vcm->segment_main, vcl_cfg->segment_baseva,
- 20 /* timeout in secs */ );
+ fifo_segment_main_init (&vcm->segment_main, vcl_cfg->segment_baseva,
+ 20 /* timeout in secs */ );
pool_alloc (vcm->workers, vcl_cfg->max_workers);
clib_spinlock_init (&vcm->workers_lock);
clib_rwlock_init (&vcm->segment_table_lock);
@@ -1611,7 +1611,7 @@ vppcom_session_read_segments (uint32_t session_handle,
}
}
- n_read = svm_fifo_segments (rx_fifo, (svm_fifo_segment_t *) ds);
+ n_read = svm_fifo_segments (rx_fifo, (svm_fifo_seg_t *) ds);
svm_fifo_unset_event (rx_fifo);
return n_read;
@@ -1628,7 +1628,7 @@ vppcom_session_free_segments (uint32_t session_handle,
if (PREDICT_FALSE (!s || s->is_vep))
return;
- svm_fifo_segments_free (s->rx_fifo, (svm_fifo_segment_t *) ds);
+ svm_fifo_segments_free (s->rx_fifo, (svm_fifo_seg_t *) ds);
}
int
diff --git a/src/vnet/session-apps/echo_client.h b/src/vnet/session-apps/echo_client.h
index 81ffcae77dd..68a5921f753 100644
--- a/src/vnet/session-apps/echo_client.h
+++ b/src/vnet/session-apps/echo_client.h
@@ -24,7 +24,6 @@
#include <vppinfra/hash.h>
#include <vppinfra/error.h>
-#include <svm/svm_fifo_segment.h>
#include <vnet/session/session.h>
#include <vnet/session/application_interface.h>
diff --git a/src/vnet/session-apps/proxy.h b/src/vnet/session-apps/proxy.h
index 6a24358ad65..9b80b3d1105 100644
--- a/src/vnet/session-apps/proxy.h
+++ b/src/vnet/session-apps/proxy.h
@@ -23,7 +23,6 @@
#include <vppinfra/hash.h>
#include <vppinfra/error.h>
-#include <svm/svm_fifo_segment.h>
#include <vnet/session/session.h>
#include <vnet/session/application_interface.h>
diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c
index 82b6dfef534..69cc87c9575 100644
--- a/src/vnet/session/application.c
+++ b/src/vnet/session/application.c
@@ -504,7 +504,7 @@ static int
application_alloc_and_init (app_init_args_t * a)
{
ssvm_segment_type_t seg_type = SSVM_SEGMENT_MEMFD;
- segment_manager_properties_t *props;
+ segment_manager_props_t *props;
vl_api_registration_t *reg;
application_t *app;
u64 *options;
@@ -553,7 +553,7 @@ application_alloc_and_init (app_init_args_t * a)
app->flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
props = application_segment_manager_properties (app);
- segment_manager_properties_init (props);
+ segment_manager_props_init (props);
props->segment_size = options[APP_OPTIONS_ADD_SEGMENT_SIZE];
props->prealloc_fifos = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS];
if (options[APP_OPTIONS_ADD_SEGMENT_SIZE])
@@ -719,7 +719,7 @@ application_alloc_worker_and_init (application_t * app, app_worker_t ** wrk)
/*
* Setup first segment manager
*/
- sm = segment_manager_new ();
+ sm = segment_manager_alloc ();
sm->app_wrk_index = app_wrk->wrk_index;
if ((rv = segment_manager_init (sm, app->sm_properties.segment_size,
@@ -746,7 +746,7 @@ application_alloc_worker_and_init (application_t * app, app_worker_t ** wrk)
int
vnet_app_worker_add_del (vnet_app_worker_add_del_args_t * a)
{
- svm_fifo_segment_private_t *fs;
+ fifo_segment_t *fs;
app_worker_map_t *wrk_map;
app_worker_t *app_wrk;
segment_manager_t *sm;
@@ -838,7 +838,7 @@ app_name_from_api_index (u32 api_client_index)
int
vnet_application_attach (vnet_app_attach_args_t * a)
{
- svm_fifo_segment_private_t *fs;
+ fifo_segment_t *fs;
application_t *app = 0;
app_worker_t *app_wrk;
segment_manager_t *sm;
@@ -1313,13 +1313,13 @@ application_remove_proxy (application_t * app)
/* *INDENT-ON* */
}
-segment_manager_properties_t *
+segment_manager_props_t *
application_segment_manager_properties (application_t * app)
{
return &app->sm_properties;
}
-segment_manager_properties_t *
+segment_manager_props_t *
application_get_segment_manager_properties (u32 app_index)
{
application_t *app = application_get (app_index);
@@ -1404,7 +1404,7 @@ format_application (u8 * s, va_list * args)
{
application_t *app = va_arg (*args, application_t *);
CLIB_UNUSED (int verbose) = va_arg (*args, int);
- segment_manager_properties_t *props;
+ segment_manager_props_t *props;
const u8 *app_ns_name, *app_name;
app_worker_map_t *wrk_map;
app_worker_t *app_wrk;
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index 0cf97a75742..4485b743589 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -92,7 +92,7 @@ typedef struct application_
session_cb_vft_t cb_fns;
/** Segment manager properties. Shared by all segment managers */
- segment_manager_properties_t sm_properties;
+ segment_manager_props_t sm_properties;
/** Pool of mappings that keep track of workers associated to this app */
app_worker_map_t *worker_maps;
@@ -197,10 +197,10 @@ u8 application_has_global_scope (application_t * app);
void application_setup_proxy (application_t * app);
void application_remove_proxy (application_t * app);
-segment_manager_properties_t *application_get_segment_manager_properties (u32
- app_index);
+segment_manager_props_t *application_get_segment_manager_properties (u32
+ app_index);
-segment_manager_properties_t
+segment_manager_props_t
* application_segment_manager_properties (application_t * app);
/*
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index 3e6abdbec86..aa1a3f30877 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -17,9 +17,9 @@
#include <vlibmemory/api.h>
#include <svm/message_queue.h>
-#include <svm/svm_fifo_segment.h>
#include <vnet/session/session_types.h>
#include <vnet/tls/tls_test.h>
+#include <svm/fifo_segment.h>
typedef struct _stream_session_cb_vft
{
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index d2edd54512a..f868e1964cc 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -91,10 +91,10 @@ ct_session_endpoint (session_t * ll, session_endpoint_t * sep)
int
ct_session_connect_notify (session_t * ss)
{
- svm_fifo_segment_private_t *seg;
ct_connection_t *sct, *cct;
app_worker_t *client_wrk;
segment_manager_t *sm;
+ fifo_segment_t *seg;
u64 segment_handle;
int is_fail = 0;
session_t *cs;
@@ -167,11 +167,11 @@ ct_init_local_session (app_worker_t * client_wrk, app_worker_t * server_wrk,
ct_connection_t * ct, session_t * ls, session_t * ll)
{
u32 round_rx_fifo_sz, round_tx_fifo_sz, sm_index, seg_size;
- segment_manager_properties_t *props;
- svm_fifo_segment_private_t *seg;
+ segment_manager_props_t *props;
application_t *server;
segment_manager_t *sm;
u32 margin = 16 << 10;
+ fifo_segment_t *seg;
u64 segment_handle;
int seg_index, rv;
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index 3cc84e84f1a..d98c437ec84 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -95,7 +95,7 @@ app_worker_free (app_worker_t * app_wrk)
sm = segment_manager_get (app_wrk->connects_seg_manager);
sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
sm->first_is_protected = 0;
- segment_manager_init_del (sm);
+ segment_manager_init_free (sm);
}
/* If first segment manager is used by a listener */
@@ -108,7 +108,7 @@ app_worker_free (app_worker_t * app_wrk)
/* .. and has no fifos, e.g. it might be used for redirected sessions,
* remove it */
if (!segment_manager_has_fifos (sm))
- segment_manager_del (sm);
+ segment_manager_free (sm);
}
pool_put (app_workers, app_wrk);
@@ -140,7 +140,7 @@ app_worker_alloc_segment_manager (app_worker_t * app_wrk)
return sm;
}
- sm = segment_manager_new ();
+ sm = segment_manager_alloc ();
sm->app_wrk_index = app_wrk->wrk_index;
return sm;
@@ -238,7 +238,7 @@ app_worker_stop_listen_session (app_worker_t * app_wrk, session_t * ls)
}
else
{
- segment_manager_init_del (sm);
+ segment_manager_init_free (sm);
}
hash_unset (app_wrk->listeners_table, handle);
}
@@ -698,63 +698,20 @@ format_app_worker (u8 * s, va_list * args)
void
app_worker_format_connects (app_worker_t * app_wrk, int verbose)
{
- svm_fifo_segment_private_t *fifo_segment;
- vlib_main_t *vm = vlib_get_main ();
segment_manager_t *sm;
- const u8 *app_name;
- u8 *s = 0;
/* Header */
if (!app_wrk)
{
- if (verbose)
- vlib_cli_output (vm, "%-40s%-20s%-15s%-10s", "Connection", "App",
- "API Client", "SegManager");
- else
- vlib_cli_output (vm, "%-40s%-20s", "Connection", "App");
+ segment_manager_format_sessions (0, verbose);
return;
}
if (app_wrk->connects_seg_manager == (u32) ~ 0)
return;
- app_name = application_name_from_index (app_wrk->app_index);
-
- /* Across all fifo segments */
sm = segment_manager_get (app_wrk->connects_seg_manager);
-
- /* *INDENT-OFF* */
- segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
- svm_fifo_t *fifo;
- u8 *str;
-
- fifo = svm_fifo_segment_get_fifo_list (fifo_segment);
- while (fifo)
- {
- u32 session_index, thread_index;
- session_t *session;
-
- session_index = fifo->master_session_index;
- thread_index = fifo->master_thread_index;
-
- session = session_get (session_index, thread_index);
- str = format (0, "%U", format_session, session, verbose);
-
- if (verbose)
- s = format (s, "%-40s%-20s%-15u%-10u", str, app_name,
- app_wrk->api_client_index, app_wrk->connects_seg_manager);
- else
- s = format (s, "%-40s%-20s", str, app_name);
-
- vlib_cli_output (vm, "%v", s);
- vec_reset_length (s);
- vec_free (str);
-
- fifo = fifo->next;
- }
- vec_free (s);
- }));
- /* *INDENT-ON* */
+ segment_manager_format_sessions (sm, verbose);
}
/*
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index 2437f99098b..47c7f563542 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -17,34 +17,43 @@
#include <vnet/session/session.h>
#include <vnet/session/application.h>
-segment_manager_main_t segment_manager_main;
+typedef struct segment_manager_main_
+{
+ segment_manager_t *segment_managers; /**< Pool of segment managers */
+ clib_valloc_main_t va_allocator; /**< Virtual address allocator */
+ u32 seg_name_counter; /**< Counter for segment names */
-/**
- * Counter used to build segment names
- */
-static u32 segment_name_counter = 0;
+ /*
+ * Configuration
+ */
+ u32 default_fifo_size; /**< default rx/tx fifo size */
+ u32 default_segment_size; /**< default fifo segment size */
+ u32 default_app_mq_size; /**< default app msg q size */
+} segment_manager_main_t;
-/**
- * Default fifo and segment size. TODO config.
- */
-static u32 default_fifo_size = 1 << 12;
-static u32 default_segment_size = 1 << 20;
-static u32 default_app_evt_queue_size = 128;
+static segment_manager_main_t sm_main;
-segment_manager_properties_t *
+#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
+do { \
+ clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
+ pool_foreach((VAR), ((SM)->segments), (BODY)); \
+ clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
+} while (0)
+
+static segment_manager_props_t *
segment_manager_properties_get (segment_manager_t * sm)
{
app_worker_t *app_wrk = app_worker_get (sm->app_wrk_index);
return application_get_segment_manager_properties (app_wrk->app_index);
}
-segment_manager_properties_t *
-segment_manager_properties_init (segment_manager_properties_t * props)
+segment_manager_props_t *
+segment_manager_props_init (segment_manager_props_t * props)
{
- props->add_segment_size = default_segment_size;
- props->rx_fifo_size = default_fifo_size;
- props->tx_fifo_size = default_fifo_size;
- props->evt_q_size = default_app_evt_queue_size;
+ props->add_segment_size = sm_main.default_segment_size;
+ props->rx_fifo_size = sm_main.default_fifo_size;
+ props->tx_fifo_size = sm_main.default_fifo_size;
+ props->evt_q_size = sm_main.default_app_mq_size;
return props;
}
@@ -61,20 +70,103 @@ segment_manager_app_detach (segment_manager_t * sm)
}
always_inline u32
-segment_manager_segment_index (segment_manager_t * sm,
- svm_fifo_segment_private_t * seg)
+segment_manager_segment_index (segment_manager_t * sm, fifo_segment_t * seg)
{
return (seg - sm->segments);
}
/**
+ * Adds segment to segment manager's pool
+ *
+ * If needed a writer's lock is acquired before allocating a new segment
+ * to avoid affecting any of the segments pool readers.
+ */
+int
+segment_manager_add_segment (segment_manager_t * sm, u32 segment_size)
+{
+ segment_manager_main_t *smm = &sm_main;
+ u32 rnd_margin = 128 << 10, fs_index = ~0, page_size;
+ uword baseva = (uword) ~ 0ULL, alloc_size;
+ segment_manager_props_t *props;
+ fifo_segment_t *fs;
+ u8 *seg_name;
+ int rv;
+
+ props = segment_manager_properties_get (sm);
+
+ /* Not configured for addition of new segments and not first */
+ if (!props->add_segment && !segment_size)
+ {
+ clib_warning ("cannot allocate new segment");
+ return VNET_API_ERROR_INVALID_VALUE;
+ }
+
+ /*
+ * Allocate fifo segment and lock if needed
+ */
+ if (vlib_num_workers ())
+ clib_rwlock_writer_lock (&sm->segments_rwlock);
+
+ pool_get_zero (sm->segments, fs);
+
+ /*
+ * Initialize ssvm segment and svm fifo private header
+ */
+ segment_size = segment_size ? segment_size : props->add_segment_size;
+ page_size = clib_mem_get_page_size ();
+ segment_size = (segment_size + page_size - 1) & ~(page_size - 1);
+ if (props->segment_type != SSVM_SEGMENT_PRIVATE)
+ {
+ seg_name = format (0, "%d-%d%c", getpid (), smm->seg_name_counter++, 0);
+ alloc_size = (uword) segment_size + rnd_margin;
+ baseva = clib_valloc_alloc (&smm->va_allocator, alloc_size, 0);
+ if (!baseva)
+ {
+ clib_warning ("out of space for segments");
+ pool_put (sm->segments, fs);
+ goto done;
+ }
+ }
+ else
+ seg_name = format (0, "%s%c", "process-private-segment", 0);
+
+ fs->ssvm.ssvm_size = segment_size;
+ fs->ssvm.name = seg_name;
+ fs->ssvm.requested_va = baseva;
+
+ if ((rv = ssvm_master_init (&fs->ssvm, props->segment_type)))
+ {
+ clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
+ segment_size);
+
+ if (props->segment_type != SSVM_SEGMENT_PRIVATE)
+ clib_valloc_free (&smm->va_allocator, baseva);
+ pool_put (sm->segments, fs);
+ goto done;
+ }
+
+ fifo_segment_init (fs);
+
+ /*
+ * Save segment index before dropping lock, if any held
+ */
+ fs_index = fs - sm->segments;
+
+done:
+
+ if (vlib_num_workers ())
+ clib_rwlock_writer_unlock (&sm->segments_rwlock);
+
+ return fs_index;
+}
+
+/**
* Remove segment without lock
*/
void
-segment_manager_del_segment (segment_manager_t * sm,
- svm_fifo_segment_private_t * fs)
+segment_manager_del_segment (segment_manager_t * sm, fifo_segment_t * fs)
{
- segment_manager_main_t *smm = &segment_manager_main;
+ segment_manager_main_t *smm = &sm_main;
if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE)
{
@@ -103,12 +195,12 @@ segment_manager_del_segment (segment_manager_t * sm,
static inline void
segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index)
{
- svm_fifo_segment_private_t *fs;
+ fifo_segment_t *fs;
u8 is_prealloc;
clib_rwlock_writer_lock (&sm->segments_rwlock);
fs = segment_manager_get_segment (sm, fs_index);
- is_prealloc = svm_fifo_segment_flags (fs) & FIFO_SEGMENT_F_IS_PREALLOCATED;
+ is_prealloc = fifo_segment_flags (fs) & FIFO_SEGMENT_F_IS_PREALLOCATED;
if (is_prealloc && !segment_manager_app_detached (sm))
{
clib_rwlock_writer_unlock (&sm->segments_rwlock);
@@ -122,7 +214,7 @@ segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index)
/**
* Reads a segment from the segment manager's pool without lock
*/
-svm_fifo_segment_private_t *
+fifo_segment_t *
segment_manager_get_segment (segment_manager_t * sm, u32 segment_index)
{
return pool_elt_at_index (sm->segments, segment_index);
@@ -130,13 +222,13 @@ segment_manager_get_segment (segment_manager_t * sm, u32 segment_index)
u64
segment_manager_segment_handle (segment_manager_t * sm,
- svm_fifo_segment_private_t * segment)
+ fifo_segment_t * segment)
{
u32 segment_index = segment_manager_segment_index (sm, segment);
return (((u64) segment_manager_index (sm) << 32) | segment_index);
}
-void
+static void
segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
u32 * segment_index)
{
@@ -144,7 +236,14 @@ segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
*segment_index = segment_handle & 0xFFFFFFFF;
}
-svm_fifo_segment_private_t *
+u64
+segment_manager_make_segment_handle (u32 segment_manager_index,
+ u32 segment_index)
+{
+ return (((u64) segment_manager_index << 32) | segment_index);
+}
+
+fifo_segment_t *
segment_manager_get_segment_w_handle (u64 segment_handle)
{
u32 sm_index, segment_index;
@@ -165,7 +264,7 @@ segment_manager_get_segment_w_handle (u64 segment_handle)
* @ref segment_manager_segment_reader_unlock once it finishes working with
* the segment.
*/
-svm_fifo_segment_private_t *
+fifo_segment_t *
segment_manager_get_segment_w_lock (segment_manager_t * sm, u32 segment_index)
{
clib_rwlock_reader_lock (&sm->segments_rwlock);
@@ -185,98 +284,13 @@ segment_manager_segment_writer_unlock (segment_manager_t * sm)
clib_rwlock_writer_unlock (&sm->segments_rwlock);
}
-/**
- * Adds segment to segment manager's pool
- *
- * If needed a writer's lock is acquired before allocating a new segment
- * to avoid affecting any of the segments pool readers.
- */
-int
-segment_manager_add_segment (segment_manager_t * sm, u32 segment_size)
-{
- segment_manager_main_t *smm = &segment_manager_main;
- u32 rnd_margin = 128 << 10, seg_index = ~0, page_size;
- segment_manager_properties_t *props;
- uword baseva = (uword) ~ 0ULL, alloc_size;
- svm_fifo_segment_private_t *seg;
- u8 *seg_name;
- int rv;
-
- props = segment_manager_properties_get (sm);
-
- /* Not configured for addition of new segments and not first */
- if (!props->add_segment && !segment_size)
- {
- clib_warning ("cannot allocate new segment");
- return VNET_API_ERROR_INVALID_VALUE;
- }
-
- /*
- * Allocate fifo segment and lock if needed
- */
- if (vlib_num_workers ())
- clib_rwlock_writer_lock (&sm->segments_rwlock);
-
- pool_get_zero (sm->segments, seg);
-
- /*
- * Initialize ssvm segment and svm fifo private header
- */
- segment_size = segment_size ? segment_size : props->add_segment_size;
- page_size = clib_mem_get_page_size ();
- segment_size = (segment_size + page_size - 1) & ~(page_size - 1);
- if (props->segment_type != SSVM_SEGMENT_PRIVATE)
- {
- seg_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0);
- alloc_size = (uword) segment_size + rnd_margin;
- baseva = clib_valloc_alloc (&smm->va_allocator, alloc_size, 0);
- if (!baseva)
- {
- clib_warning ("out of space for segments");
- pool_put (sm->segments, seg);
- goto done;
- }
- }
- else
- seg_name = format (0, "%s%c", "process-private-segment", 0);
-
- seg->ssvm.ssvm_size = segment_size;
- seg->ssvm.name = seg_name;
- seg->ssvm.requested_va = baseva;
-
- if ((rv = ssvm_master_init (&seg->ssvm, props->segment_type)))
- {
- clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
- segment_size);
-
- if (props->segment_type != SSVM_SEGMENT_PRIVATE)
- clib_valloc_free (&smm->va_allocator, baseva);
- pool_put (sm->segments, seg);
- goto done;
- }
-
- svm_fifo_segment_init (seg);
-
- /*
- * Save segment index before dropping lock, if any held
- */
- seg_index = seg - sm->segments;
-
-done:
-
- if (vlib_num_workers ())
- clib_rwlock_writer_unlock (&sm->segments_rwlock);
-
- return seg_index;
-}
-
segment_manager_t *
-segment_manager_new ()
+segment_manager_alloc (void)
{
- segment_manager_main_t *smm = &segment_manager_main;
+ segment_manager_main_t *smm = &sm_main;
segment_manager_t *sm;
- pool_get (smm->segment_managers, sm);
- clib_memset (sm, 0, sizeof (*sm));
+
+ pool_get_zero (smm->segment_managers, sm);
clib_rwlock_init (&sm->segments_rwlock);
return sm;
}
@@ -292,13 +306,13 @@ segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
u32 rx_fifo_size, tx_fifo_size, pair_size;
u32 rx_rounded_data_size, tx_rounded_data_size;
u64 approx_total_size, max_seg_size = ((u64) 1 << 32) - (128 << 10);
- segment_manager_properties_t *props;
- svm_fifo_segment_private_t *segment;
+ segment_manager_props_t *props;
+ fifo_segment_t *segment;
u32 approx_segment_count;
int seg_index, i;
props = segment_manager_properties_get (sm);
- first_seg_size = clib_max (first_seg_size, default_segment_size);
+ first_seg_size = clib_max (first_seg_size, sm_main.default_segment_size);
if (prealloc_fifo_pairs)
{
@@ -330,11 +344,11 @@ segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
if (i == 0)
sm->event_queue = segment_manager_alloc_queue (segment, props);
- svm_fifo_segment_preallocate_fifo_pairs (segment,
- props->rx_fifo_size,
- props->tx_fifo_size,
- &prealloc_fifo_pairs);
- svm_fifo_segment_flags (segment) = FIFO_SEGMENT_F_IS_PREALLOCATED;
+ fifo_segment_preallocate_fifo_pairs (segment,
+ props->rx_fifo_size,
+ props->tx_fifo_size,
+ &prealloc_fifo_pairs);
+ fifo_segment_flags (segment) = FIFO_SEGMENT_F_IS_PREALLOCATED;
if (prealloc_fifo_pairs == 0)
break;
}
@@ -354,22 +368,87 @@ segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
return 0;
}
+/**
+ * Cleanup segment manager.
+ */
+void
+segment_manager_free (segment_manager_t * sm)
+{
+ segment_manager_main_t *smm = &sm_main;
+ fifo_segment_t *fifo_segment;
+
+ ASSERT (!segment_manager_has_fifos (sm)
+ && segment_manager_app_detached (sm));
+
+ /* If we have empty preallocated segments that haven't been removed, remove
+ * them now. Apart from that, the first segment in the first segment manager
+ * is not removed when all fifos are removed. It can only be removed when
+ * the manager is explicitly deleted/detached by the app. */
+ clib_rwlock_writer_lock (&sm->segments_rwlock);
+
+ /* *INDENT-OFF* */
+ pool_foreach (fifo_segment, sm->segments, ({
+ segment_manager_del_segment (sm, fifo_segment);
+ }));
+ /* *INDENT-ON* */
+
+ clib_rwlock_writer_unlock (&sm->segments_rwlock);
+
+ clib_rwlock_free (&sm->segments_rwlock);
+ if (CLIB_DEBUG)
+ clib_memset (sm, 0xfe, sizeof (*sm));
+ pool_put (smm->segment_managers, sm);
+}
+
+void
+segment_manager_init_free (segment_manager_t * sm)
+{
+ segment_manager_app_detach (sm);
+ if (segment_manager_has_fifos (sm))
+ segment_manager_del_sessions (sm);
+ else
+ {
+ ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm));
+ segment_manager_free (sm);
+ }
+}
+
+segment_manager_t *
+segment_manager_get (u32 index)
+{
+ return pool_elt_at_index (sm_main.segment_managers, index);
+}
+
+segment_manager_t *
+segment_manager_get_if_valid (u32 index)
+{
+ if (pool_is_free_index (sm_main.segment_managers, index))
+ return 0;
+ return pool_elt_at_index (sm_main.segment_managers, index);
+}
+
+u32
+segment_manager_index (segment_manager_t * sm)
+{
+ return sm - sm_main.segment_managers;
+}
+
u8
segment_manager_has_fifos (segment_manager_t * sm)
{
- svm_fifo_segment_private_t *seg;
+ fifo_segment_t *seg;
u8 first = 1;
/* *INDENT-OFF* */
segment_manager_foreach_segment_w_lock (seg, sm, ({
- if (CLIB_DEBUG && !first && !svm_fifo_segment_has_fifos (seg)
- && !(svm_fifo_segment_flags (seg) & FIFO_SEGMENT_F_IS_PREALLOCATED))
+ if (CLIB_DEBUG && !first && !fifo_segment_has_fifos (seg)
+ && !(fifo_segment_flags (seg) & FIFO_SEGMENT_F_IS_PREALLOCATED))
{
clib_warning ("segment %d has no fifos!",
segment_manager_segment_index (sm, seg));
first = 0;
}
- if (svm_fifo_segment_has_fifos (seg))
+ if (fifo_segment_has_fifos (seg))
{
segment_manager_segment_reader_unlock (sm);
return 1;
@@ -386,7 +465,7 @@ segment_manager_has_fifos (segment_manager_t * sm)
void
segment_manager_del_sessions (segment_manager_t * sm)
{
- svm_fifo_segment_private_t *fifo_segment;
+ fifo_segment_t *fifo_segment;
session_handle_t *handles = 0, *handle;
session_t *session;
svm_fifo_t *fifo;
@@ -396,7 +475,7 @@ segment_manager_del_sessions (segment_manager_t * sm)
/* Across all fifo segments used by the server */
/* *INDENT-OFF* */
segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
- fifo = svm_fifo_segment_get_fifo_list (fifo_segment);
+ fifo = fifo_segment_get_fifo_list (fifo_segment);
/*
* Remove any residual sessions from the session lookup table
@@ -422,75 +501,25 @@ segment_manager_del_sessions (segment_manager_t * sm)
session_close (session_get_from_handle (*handle));
}
-/**
- * Removes segment manager.
- *
- * Since the fifos allocated in the segment keep backpointers to the sessions
- * prior to removing the segment, we call session disconnect. This
- * subsequently propagates into transport.
- */
-void
-segment_manager_del (segment_manager_t * sm)
-{
- segment_manager_main_t *smm = &segment_manager_main;
- svm_fifo_segment_private_t *fifo_segment;
-
- ASSERT (!segment_manager_has_fifos (sm)
- && segment_manager_app_detached (sm));
-
- /* If we have empty preallocated segments that haven't been removed, remove
- * them now. Apart from that, the first segment in the first segment manager
- * is not removed when all fifos are removed. It can only be removed when
- * the manager is explicitly deleted/detached by the app. */
- clib_rwlock_writer_lock (&sm->segments_rwlock);
-
- /* *INDENT-OFF* */
- pool_foreach (fifo_segment, sm->segments, ({
- segment_manager_del_segment (sm, fifo_segment);
- }));
- /* *INDENT-ON* */
-
- clib_rwlock_writer_unlock (&sm->segments_rwlock);
-
- clib_rwlock_free (&sm->segments_rwlock);
- if (CLIB_DEBUG)
- clib_memset (sm, 0xfe, sizeof (*sm));
- pool_put (smm->segment_managers, sm);
-}
-
-void
-segment_manager_init_del (segment_manager_t * sm)
-{
- segment_manager_app_detach (sm);
- if (segment_manager_has_fifos (sm))
- segment_manager_del_sessions (sm);
- else
- {
- ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm));
- segment_manager_del (sm);
- }
-}
-
int
-segment_manager_try_alloc_fifos (svm_fifo_segment_private_t * fifo_segment,
+segment_manager_try_alloc_fifos (fifo_segment_t * fifo_segment,
u32 rx_fifo_size, u32 tx_fifo_size,
svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo)
{
- rx_fifo_size = clib_max (rx_fifo_size, default_fifo_size);
- *rx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, rx_fifo_size,
- FIFO_SEGMENT_RX_FREELIST);
+ rx_fifo_size = clib_max (rx_fifo_size, sm_main.default_fifo_size);
+ *rx_fifo = fifo_segment_alloc_fifo (fifo_segment, rx_fifo_size,
+ FIFO_SEGMENT_RX_FIFO);
- tx_fifo_size = clib_max (tx_fifo_size, default_fifo_size);
- *tx_fifo = svm_fifo_segment_alloc_fifo (fifo_segment, tx_fifo_size,
- FIFO_SEGMENT_TX_FREELIST);
+ tx_fifo_size = clib_max (tx_fifo_size, sm_main.default_fifo_size);
+ *tx_fifo = fifo_segment_alloc_fifo (fifo_segment, tx_fifo_size,
+ FIFO_SEGMENT_TX_FIFO);
if (*rx_fifo == 0)
{
/* This would be very odd, but handle it... */
if (*tx_fifo != 0)
{
- svm_fifo_segment_free_fifo (fifo_segment, *tx_fifo,
- FIFO_SEGMENT_TX_FREELIST);
+ fifo_segment_free_fifo (fifo_segment, *tx_fifo);
*tx_fifo = 0;
}
return -1;
@@ -499,8 +528,7 @@ segment_manager_try_alloc_fifos (svm_fifo_segment_private_t * fifo_segment,
{
if (*rx_fifo != 0)
{
- svm_fifo_segment_free_fifo (fifo_segment, *rx_fifo,
- FIFO_SEGMENT_RX_FREELIST);
+ fifo_segment_free_fifo (fifo_segment, *rx_fifo);
*rx_fifo = 0;
}
return -1;
@@ -514,12 +542,12 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
svm_fifo_t ** rx_fifo,
svm_fifo_t ** tx_fifo)
{
- svm_fifo_segment_private_t *fifo_segment = 0;
int alloc_fail = 1, rv = 0, new_fs_index;
- segment_manager_properties_t *props;
- u32 sm_index, fifo_segment_index;
+ segment_manager_props_t *props;
+ fifo_segment_t *fs = 0;
+ u32 sm_index, fs_index;
u8 added_a_segment = 0;
- u64 segment_handle;
+ u64 fs_handle;
props = segment_manager_properties_get (sm);
@@ -528,8 +556,8 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
*/
/* *INDENT-OFF* */
- segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({
- alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
+ segment_manager_foreach_segment_w_lock (fs, sm, ({
+ alloc_fail = segment_manager_try_alloc_fifos (fs,
props->rx_fifo_size,
props->tx_fifo_size,
rx_fifo, tx_fifo);
@@ -548,18 +576,18 @@ alloc_check:
ASSERT (rx_fifo && tx_fifo);
sm_index = segment_manager_index (sm);
- fifo_segment_index = segment_manager_segment_index (sm, fifo_segment);
+ fs_index = segment_manager_segment_index (sm, fs);
(*tx_fifo)->segment_manager = sm_index;
(*rx_fifo)->segment_manager = sm_index;
- (*tx_fifo)->segment_index = fifo_segment_index;
- (*rx_fifo)->segment_index = fifo_segment_index;
+ (*tx_fifo)->segment_index = fs_index;
+ (*rx_fifo)->segment_index = fs_index;
if (added_a_segment)
{
app_worker_t *app_wrk;
- segment_handle = segment_manager_segment_handle (sm, fifo_segment);
+ fs_handle = segment_manager_segment_handle (sm, fs);
app_wrk = app_worker_get (sm->app_wrk_index);
- rv = app_worker_add_segment_notify (app_wrk, segment_handle);
+ rv = app_worker_add_segment_notify (app_wrk, fs_handle);
}
/* Drop the lock after app is notified */
segment_manager_segment_reader_unlock (sm);
@@ -582,9 +610,8 @@ alloc_check:
clib_warning ("Failed to add new segment");
return SESSION_ERROR_SEG_CREATE;
}
- fifo_segment = segment_manager_get_segment_w_lock (sm, new_fs_index);
- alloc_fail = segment_manager_try_alloc_fifos (fifo_segment,
- props->rx_fifo_size,
+ fs = segment_manager_get_segment_w_lock (sm, new_fs_index);
+ alloc_fail = segment_manager_try_alloc_fifos (fs, props->rx_fifo_size,
props->tx_fifo_size,
rx_fifo, tx_fifo);
added_a_segment = 1;
@@ -600,7 +627,7 @@ alloc_check:
void
segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo, svm_fifo_t * tx_fifo)
{
- svm_fifo_segment_private_t *fifo_segment;
+ fifo_segment_t *fs;
segment_manager_t *sm;
u32 segment_index;
@@ -613,11 +640,9 @@ segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo, svm_fifo_t * tx_fifo)
return;
segment_index = rx_fifo->segment_index;
- fifo_segment = segment_manager_get_segment_w_lock (sm, segment_index);
- svm_fifo_segment_free_fifo (fifo_segment, rx_fifo,
- FIFO_SEGMENT_RX_FREELIST);
- svm_fifo_segment_free_fifo (fifo_segment, tx_fifo,
- FIFO_SEGMENT_TX_FREELIST);
+ fs = segment_manager_get_segment_w_lock (sm, segment_index);
+ fifo_segment_free_fifo (fs, rx_fifo);
+ fifo_segment_free_fifo (fs, tx_fifo);
/*
* Try to remove svm segment if it has no fifos. This can be done only if
@@ -625,7 +650,7 @@ segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo, svm_fifo_t * tx_fifo)
* and it is not protected. Moreover, if the segment is first and the app
* has detached from the segment manager, remove the segment manager.
*/
- if (!svm_fifo_segment_has_fifos (fifo_segment))
+ if (!fifo_segment_has_fifos (fs))
{
segment_manager_segment_reader_unlock (sm);
@@ -637,7 +662,7 @@ segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo, svm_fifo_t * tx_fifo)
if (segment_manager_app_detached (sm)
&& !segment_manager_has_fifos (sm))
{
- segment_manager_del (sm);
+ segment_manager_free (sm);
}
}
else
@@ -667,8 +692,8 @@ segment_manager_evt_q_expected_size (u32 q_len)
* Must be called with lock held
*/
svm_msg_q_t *
-segment_manager_alloc_queue (svm_fifo_segment_private_t * segment,
- segment_manager_properties_t * props)
+segment_manager_alloc_queue (fifo_segment_t * segment,
+ segment_manager_props_t * props)
{
u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
@@ -700,13 +725,19 @@ segment_manager_alloc_queue (svm_fifo_segment_private_t * segment,
return q;
}
+svm_msg_q_t *
+segment_manager_event_queue (segment_manager_t * sm)
+{
+ return sm->event_queue;
+}
+
/**
* Frees shm queue allocated in the first segment
*/
void
segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q)
{
- svm_fifo_segment_private_t *segment;
+ fifo_segment_t *segment;
ssvm_shared_header_t *sh;
void *oldheap;
@@ -727,21 +758,25 @@ segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q)
void
segment_manager_main_init (segment_manager_main_init_args_t * a)
{
- segment_manager_main_t *sm = &segment_manager_main;
+ segment_manager_main_t *sm = &sm_main;
clib_valloc_chunk_t _ip, *ip = &_ip;
ip->baseva = a->baseva;
ip->size = a->size;
clib_valloc_init (&sm->va_allocator, ip, 1 /* lock */ );
+
+ sm->default_fifo_size = 1 << 12;
+ sm->default_segment_size = 1 << 20;
+ sm->default_app_mq_size = 128;
}
static clib_error_t *
segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- segment_manager_main_t *smm = &segment_manager_main;
- svm_fifo_segment_private_t *seg;
+ segment_manager_main_t *smm = &sm_main;
+ fifo_segment_t *seg;
segment_manager_t *sm;
u8 show_segments = 0, verbose = 0;
char *address;
@@ -782,15 +817,15 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input,
/* *INDENT-OFF* */
pool_foreach (sm, smm->segment_managers, ({
segment_manager_foreach_segment_w_lock (seg, sm, ({
- svm_fifo_segment_info (seg, &address, &size);
- active_fifos = svm_fifo_segment_num_fifos (seg);
- free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */);
+ fifo_segment_info (seg, &address, &size);
+ active_fifos = fifo_segment_num_fifos (seg);
+ free_fifos = fifo_segment_num_free_fifos (seg, ~0 /* size */);
vlib_cli_output (vm, "%-15v%15U%15llu%15u%15u%15llx",
- ssvm_name (&seg->ssvm), format_svm_fifo_segment_type,
+ ssvm_name (&seg->ssvm), format_fifo_segment_type,
seg, size >> 20ULL, active_fifos, free_fifos,
address);
if (verbose)
- vlib_cli_output (vm, "%U", format_svm_fifo_segment, seg, verbose);
+ vlib_cli_output (vm, "%U", format_fifo_segment, seg, verbose);
}));
}));
/* *INDENT-ON* */
@@ -808,6 +843,66 @@ VLIB_CLI_COMMAND (segment_manager_show_command, static) =
};
/* *INDENT-ON* */
+void
+segment_manager_format_sessions (segment_manager_t * sm, int verbose)
+{
+ fifo_segment_t *fifo_segment;
+ vlib_main_t *vm = vlib_get_main ();
+ app_worker_t *app_wrk;
+ const u8 *app_name;
+ u8 *s = 0;
+
+ if (!sm)
+ {
+ if (verbose)
+ vlib_cli_output (vm, "%-40s%-20s%-15s%-10s", "Connection", "App",
+ "API Client", "SegManager");
+ else
+ vlib_cli_output (vm, "%-40s%-20s", "Connection", "App");
+ return;
+ }
+
+ app_wrk = app_worker_get (sm->app_wrk_index);
+ app_name = application_name_from_index (app_wrk->app_index);
+
+ clib_rwlock_reader_lock (&sm->segments_rwlock);
+
+ /* *INDENT-OFF* */
+ pool_foreach (fifo_segment, sm->segments, ({
+ svm_fifo_t *fifo;
+ u8 *str;
+
+ fifo = fifo_segment_get_fifo_list (fifo_segment);
+ while (fifo)
+ {
+ u32 session_index, thread_index;
+ session_t *session;
+
+ session_index = fifo->master_session_index;
+ thread_index = fifo->master_thread_index;
+
+ session = session_get (session_index, thread_index);
+ str = format (0, "%U", format_session, session, verbose);
+
+ if (verbose)
+ s = format (s, "%-40s%-20s%-15u%-10u", str, app_name,
+ app_wrk->api_client_index, app_wrk->connects_seg_manager);
+ else
+ s = format (s, "%-40s%-20s", str, app_name);
+
+ vlib_cli_output (vm, "%v", s);
+ vec_reset_length (s);
+ vec_free (str);
+
+ fifo = fifo->next;
+ }
+ vec_free (s);
+ }));
+ /* *INDENT-ON* */
+
+ clib_rwlock_reader_unlock (&sm->segments_rwlock);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/session/segment_manager.h b/src/vnet/session/segment_manager.h
index 2b6f43feba7..4f30b7a8d2c 100644
--- a/src/vnet/session/segment_manager.h
+++ b/src/vnet/session/segment_manager.h
@@ -15,14 +15,12 @@
#ifndef SRC_VNET_SESSION_SEGMENT_MANAGER_H_
#define SRC_VNET_SESSION_SEGMENT_MANAGER_H_
-#include <vnet/vnet.h>
-#include <svm/svm_fifo_segment.h>
#include <svm/message_queue.h>
-#include <vlibmemory/api.h>
#include <vppinfra/lock.h>
#include <vppinfra/valloc.h>
+#include <svm/fifo_segment.h>
-typedef struct _segment_manager_properties
+typedef struct _segment_manager_props
{
u32 rx_fifo_size; /**< receive fifo size */
u32 tx_fifo_size; /**< transmit fifo size */
@@ -35,12 +33,12 @@ typedef struct _segment_manager_properties
u8 reserved:6; /**< reserved flags */
ssvm_segment_type_t segment_type; /**< seg type: if set to SSVM_N_TYPES,
private segments are used */
-} segment_manager_properties_t;
+} segment_manager_props_t;
typedef struct _segment_manager
{
/** Pool of segments allocated by this manager */
- svm_fifo_segment_private_t *segments;
+ fifo_segment_t *segments;
/** rwlock that protects the segments pool */
clib_rwlock_t segments_rwlock;
@@ -61,25 +59,6 @@ typedef struct _segment_manager
svm_msg_q_t *event_queue;
} segment_manager_t;
-#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
-do { \
- clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
- pool_foreach((VAR), ((SM)->segments), (BODY)); \
- clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
-} while (0)
-
-typedef struct segment_manager_main_
-{
- /** Pool of segment managers */
- segment_manager_t *segment_managers;
-
- /** Virtual address allocator */
- clib_valloc_main_t va_allocator;
-
-} segment_manager_main_t;
-
-extern segment_manager_main_t segment_manager_main;
-
typedef struct segment_manager_main_init_args_
{
u64 baseva;
@@ -88,86 +67,78 @@ typedef struct segment_manager_main_init_args_
#define SEGMENT_MANAGER_INVALID_APP_INDEX ((u32) ~0)
-/** Pool of segment managers */
-extern segment_manager_t *segment_managers;
-
-always_inline segment_manager_t *
-segment_manager_get (u32 index)
-{
- return pool_elt_at_index (segment_manager_main.segment_managers, index);
-}
-
-always_inline segment_manager_t *
-segment_manager_get_if_valid (u32 index)
-{
- if (pool_is_free_index (segment_manager_main.segment_managers, index))
- return 0;
- return pool_elt_at_index (segment_manager_main.segment_managers, index);
-}
-
-always_inline u32
-segment_manager_index (segment_manager_t * sm)
-{
- return sm - segment_manager_main.segment_managers;
-}
-
-always_inline svm_msg_q_t *
-segment_manager_event_queue (segment_manager_t * sm)
-{
- return sm->event_queue;
-}
-
-always_inline u64
-segment_manager_make_segment_handle (u32 segment_manager_index,
- u32 segment_index)
-{
- return (((u64) segment_manager_index << 32) | segment_index);
-}
-
-u64 segment_manager_segment_handle (segment_manager_t * sm,
- svm_fifo_segment_private_t * segment);
-
-segment_manager_t *segment_manager_new ();
+segment_manager_t *segment_manager_alloc (void);
int segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
u32 prealloc_fifo_pairs);
-svm_fifo_segment_private_t *segment_manager_get_segment (segment_manager_t *,
- u32 segment_index);
-svm_fifo_segment_private_t *segment_manager_get_segment_w_handle (u64);
-svm_fifo_segment_private_t
- * segment_manager_get_segment_w_lock (segment_manager_t * sm,
- u32 segment_index);
+/**
+ * Cleanup segment manager
+ *
+ * @param sm segment manager to be freed
+ */
+void segment_manager_free (segment_manager_t * sm);
+
+/**
+ * Initiate segment manager cleanup
+ *
+ * @param sm segment manager to be freed
+ */
+void segment_manager_init_free (segment_manager_t * sm);
+segment_manager_t *segment_manager_get (u32 index);
+segment_manager_t *segment_manager_get_if_valid (u32 index);
+u32 segment_manager_index (segment_manager_t * sm);
+
int segment_manager_add_segment (segment_manager_t * sm, u32 segment_size);
void segment_manager_del_segment (segment_manager_t * sm,
- svm_fifo_segment_private_t * fs);
+ fifo_segment_t * fs);
+fifo_segment_t *segment_manager_get_segment (segment_manager_t * sm,
+ u32 segment_index);
+fifo_segment_t *segment_manager_get_segment_w_handle (u64 sh);
+fifo_segment_t *segment_manager_get_segment_w_lock (segment_manager_t *,
+ u32 segment_index);
+int segment_manager_add_first_segment (segment_manager_t * sm,
+ u32 segment_size);
+u64 segment_manager_make_segment_handle (u32 segment_manager_index,
+ u32 segment_index);
+u64 segment_manager_segment_handle (segment_manager_t * sm,
+ fifo_segment_t * segment);
void segment_manager_segment_reader_unlock (segment_manager_t * sm);
void segment_manager_segment_writer_unlock (segment_manager_t * sm);
-int segment_manager_add_first_segment (segment_manager_t * sm,
- u32 segment_size);
-void segment_manager_del_sessions (segment_manager_t * sm);
-void segment_manager_del (segment_manager_t * sm);
-void segment_manager_init_del (segment_manager_t * sm);
-u8 segment_manager_has_fifos (segment_manager_t * sm);
int segment_manager_alloc_session_fifos (segment_manager_t * sm,
- svm_fifo_t ** server_rx_fifo,
- svm_fifo_t ** server_tx_fifo);
-int segment_manager_try_alloc_fifos (svm_fifo_segment_private_t * fs,
+ svm_fifo_t ** rx_fifo,
+ svm_fifo_t ** tx_fifo);
+int segment_manager_try_alloc_fifos (fifo_segment_t * fs,
u32 rx_fifo_size, u32 tx_fifo_size,
svm_fifo_t ** rx_fifo,
svm_fifo_t ** tx_fifo);
void segment_manager_dealloc_fifos (svm_fifo_t * rx_fifo,
svm_fifo_t * tx_fifo);
-u32 segment_manager_evt_q_expected_size (u32 q_size);
-svm_msg_q_t *segment_manager_alloc_queue (svm_fifo_segment_private_t * fs,
- segment_manager_properties_t *
- props);
+u8 segment_manager_has_fifos (segment_manager_t * sm);
+
+svm_msg_q_t *segment_manager_alloc_queue (fifo_segment_t * fs,
+ segment_manager_props_t * props);
void segment_manager_dealloc_queue (segment_manager_t * sm, svm_queue_t * q);
+svm_msg_q_t *segment_manager_event_queue (segment_manager_t * sm);
+u32 segment_manager_evt_q_expected_size (u32 q_size);
+
void segment_manager_app_detach (segment_manager_t * sm);
+/**
+ * Cleanup segment manager sessions
+ *
+ * Initiates disconnects for all sessions 'owned' by a segment manager by
+ * leveraging the backpointers that fifos keep.
+ *
+ * @param sm segment manager whose sessions are to be disconnected
+ */
+void segment_manager_del_sessions (segment_manager_t * sm);
+void segment_manager_format_sessions (segment_manager_t * sm, int verbose);
+
void segment_manager_main_init (segment_manager_main_init_args_t * a);
-segment_manager_properties_t
- * segment_manager_properties_init (segment_manager_properties_t * sm);
+
+segment_manager_props_t *segment_manager_props_init (segment_manager_props_t *
+ sm);
#endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
/*
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 0a7781f2876..83af125946e 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -83,8 +83,8 @@ send_add_segment_callback (u32 api_client_index, u64 segment_handle)
{
int fds[SESSION_N_FD_TYPE], n_fds = 0;
vl_api_map_another_segment_t *mp;
- svm_fifo_segment_private_t *fs;
vl_api_registration_t *reg;
+ fifo_segment_t *fs;
ssvm_private_t *sp;
u8 fd_flags = 0;