summaryrefslogtreecommitdiffstats
path: root/src/vnet/session/segment_manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session/segment_manager.c')
-rw-r--r--src/vnet/session/segment_manager.c134
1 files changed, 113 insertions, 21 deletions
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index 16e5bc56736..e053232001d 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -28,6 +28,11 @@ u32 segment_name_counter = 0;
segment_manager_t *segment_managers = 0;
/**
+ * Process private segment index
+ */
+u32 private_segment_index = ~0;
+
+/**
* Default fifo and segment size. TODO config.
*/
u32 default_fifo_size = 1 << 16;
@@ -100,6 +105,26 @@ session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size)
return rv;
}
+static void
+segment_manager_alloc_process_private_segment ()
+{
+ svm_fifo_segment_create_args_t _a, *a = &_a;
+
+ if (private_segment_index != ~0)
+ return;
+
+ memset (a, 0, sizeof (*a));
+ a->segment_name = "process-private-segment";
+ a->segment_size = ~0;
+ a->new_segment_index = ~0;
+
+ if (svm_fifo_segment_create_process_private (a))
+ clib_warning ("Failed to create process private segment");
+
+ private_segment_index = a->new_segment_index;
+ ASSERT (private_segment_index != ~0);
+}
+
/**
* Initializes segment manager based on options provided.
* Returns error if svm segment allocation fails.
@@ -114,7 +139,9 @@ segment_manager_init (segment_manager_t * sm,
/* app allocates these */
sm->properties = properties;
- if (first_seg_size > 0)
+ first_seg_size = first_seg_size > 0 ? first_seg_size : default_segment_size;
+
+ if (sm->properties->use_private_segment == 0)
{
rv = session_manager_add_first_segment (sm, first_seg_size);
if (rv)
@@ -123,7 +150,15 @@ segment_manager_init (segment_manager_t * sm,
return rv;
}
}
+ else
+ {
+ if (private_segment_index == ~0)
+ segment_manager_alloc_process_private_segment ();
+ ASSERT (private_segment_index != ~0);
+ vec_add1 (sm->segment_indices, private_segment_index);
+ }
+ clib_spinlock_init (&sm->lockp);
return 0;
}
@@ -162,8 +197,8 @@ segment_manager_del (segment_manager_t * sm)
stream_session_t *session;
fifo = fifos[i];
- session_index = fifo->server_session_index;
- thread_index = fifo->server_thread_index;
+ session_index = fifo->master_session_index;
+ thread_index = fifo->master_thread_index;
session = stream_session_get (session_index, thread_index);
@@ -183,7 +218,9 @@ segment_manager_del (segment_manager_t * sm)
deleted_thread_indices[i]);
/* Instead of directly removing the session call disconnect */
- stream_session_disconnect (session);
+ session_send_session_evt_to_thread (stream_session_handle (session),
+ FIFO_EVENT_DISCONNECT,
+ deleted_thread_indices[i]);
/*
stream_session_table_del (smm, session);
@@ -200,6 +237,7 @@ segment_manager_del (segment_manager_t * sm)
/* svm_fifo_segment_delete (fifo_segment); */
}
+ clib_spinlock_free (&sm->lockp);
vec_free (deleted_sessions);
vec_free (deleted_thread_indices);
pool_put (segment_managers, sm);
@@ -232,9 +270,13 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
u8 added_a_segment = 0;
int i;
- /* Allocate svm fifos */
ASSERT (vec_len (sm->segment_indices));
+ /* Make sure we don't have multiple threads trying to allocate segments
+ * at the same time. */
+ clib_spinlock_lock (&sm->lockp);
+
+ /* Allocate svm fifos */
again:
for (i = 0; i < vec_len (sm->segment_indices); i++)
{
@@ -283,7 +325,9 @@ again:
}
if (session_manager_add_segment (sm))
- return VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
+ {
+ return VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
+ }
added_a_segment = 1;
goto again;
@@ -295,14 +339,16 @@ again:
}
}
- if (added_a_segment)
- return segment_manager_notify_app_seg_add (sm, *fifo_segment_index);
-
/* Backpointers to segment manager */
sm_index = segment_manager_index (sm);
(*server_tx_fifo)->segment_manager = sm_index;
(*server_rx_fifo)->segment_manager = sm_index;
+ clib_spinlock_unlock (&sm->lockp);
+
+ if (added_a_segment)
+ return segment_manager_notify_app_seg_add (sm, *fifo_segment_index);
+
return 0;
}
@@ -313,26 +359,72 @@ segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo,
segment_manager_t *sm;
svm_fifo_segment_private_t *fifo_segment;
+ sm = segment_manager_get_if_valid (rx_fifo->segment_manager);
+
+ /* It's possible to have no segment manager if the session was removed
+ * as result of a detach */
+ if (!sm)
+ return;
+
fifo_segment = svm_fifo_get_segment (svm_segment_index);
svm_fifo_segment_free_fifo (fifo_segment, rx_fifo);
svm_fifo_segment_free_fifo (fifo_segment, tx_fifo);
- /* If we have segment manager, try doing some cleanup.
- * It's possible to have no segment manager if the session was removed
- * as result of a detach */
- sm = segment_manager_get_if_valid (rx_fifo->segment_manager);
- if (sm)
+ /* Remove segment only if it holds no fifos and not the first */
+ if (sm->segment_indices[0] != svm_segment_index
+ && !svm_fifo_segment_has_fifos (fifo_segment))
{
- /* Remove segment only if it holds no fifos and not the first */
- if (sm->segment_indices[0] != svm_segment_index
- && !svm_fifo_segment_has_fifos (fifo_segment))
- {
- svm_fifo_segment_delete (fifo_segment);
- vec_del1 (sm->segment_indices, svm_segment_index);
- }
+ svm_fifo_segment_delete (fifo_segment);
+ vec_del1 (sm->segment_indices, svm_segment_index);
}
}
+/**
+ * Allocates shm queue in the first segment
+ */
+unix_shared_memory_queue_t *
+segment_manager_alloc_queue (segment_manager_t * sm, u32 queue_size)
+{
+ ssvm_shared_header_t *sh;
+ svm_fifo_segment_private_t *segment;
+ unix_shared_memory_queue_t *q;
+ void *oldheap;
+
+ ASSERT (sm->segment_indices != 0);
+
+ segment = svm_fifo_get_segment (sm->segment_indices[0]);
+ sh = segment->ssvm.sh;
+
+ oldheap = ssvm_push_heap (sh);
+ q =
+ unix_shared_memory_queue_init (queue_size, sizeof (session_fifo_event_t),
+ 0 /* consumer pid */ , 0
+ /* signal when queue non-empty */ );
+ ssvm_pop_heap (oldheap);
+ return q;
+}
+
+/**
+ * Frees shm queue allocated in the first segment
+ */
+void
+segment_manager_dealloc_queue (segment_manager_t * sm,
+ unix_shared_memory_queue_t * q)
+{
+ ssvm_shared_header_t *sh;
+ svm_fifo_segment_private_t *segment;
+ void *oldheap;
+
+ ASSERT (sm->segment_indices != 0);
+
+ segment = svm_fifo_get_segment (sm->segment_indices[0]);
+ sh = segment->ssvm.sh;
+
+ oldheap = ssvm_push_heap (sh);
+ unix_shared_memory_queue_free (q);
+ ssvm_pop_heap (oldheap);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*