summaryrefslogtreecommitdiffstats
path: root/src/vnet/session/segment_manager.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-04-24 14:44:46 -0700
committerDamjan Marion <dmarion@me.com>2019-04-25 18:05:16 +0000
commit88001c64e9e5d0dc08e303857ca34687454ebf10 (patch)
treef747dabb08b764514c3465ca854ebed87031e8bb /src/vnet/session/segment_manager.c
parent1ccbbfbf972eefc87491dd7c260bc0c4dcef8ac9 (diff)
session: cleanup segment manager and fifo segment
Change-Id: I984f347fb465c0c405cef668d8690457e81788e2 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/session/segment_manager.c')
-rw-r--r--src/vnet/session/segment_manager.c547
1 files changed, 321 insertions, 226 deletions
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
*