X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsegment_manager.c;h=cb83d8e53bce26b75094b6193c6389ebfdf7e39e;hb=1c7104514cd40d2377caca36cf40c13b791bc5aa;hp=7cf66ee35b205fd5d603c6e64f5d462b7ec8e000;hpb=c87c91d8b0e85997debaf575f2e30cc2702edf25;p=vpp.git diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c index 7cf66ee35b2..cb83d8e53bc 100644 --- a/src/vnet/session/segment_manager.c +++ b/src/vnet/session/segment_manager.c @@ -74,6 +74,11 @@ session_manager_add_segment_i (segment_manager_t * sm, u32 segment_size, } else { + u32 rx_fifo_size, tx_fifo_size, rx_rounded_data_size, + tx_rounded_data_size; + u32 approx_segment_count; + u64 approx_total_size; + ca->segment_name = "process-private-segment"; ca->segment_size = ~0; ca->rx_fifo_size = sm->properties->rx_fifo_size; @@ -82,6 +87,36 @@ session_manager_add_segment_i (segment_manager_t * sm, u32 segment_size, ca->private_segment_count = sm->properties->private_segment_count; ca->private_segment_size = sm->properties->private_segment_size; + /* Default to a small private segment */ + if (ca->private_segment_size == 0) + ca->private_segment_size = 128 << 20; + + /* Calculate space requirements */ + rx_rounded_data_size = (1 << (max_log2 (ca->rx_fifo_size))); + tx_rounded_data_size = (1 << (max_log2 (ca->tx_fifo_size))); + + rx_fifo_size = sizeof (svm_fifo_t) + rx_rounded_data_size; + tx_fifo_size = sizeof (svm_fifo_t) + tx_rounded_data_size; + + approx_total_size = (u64) ca->preallocated_fifo_pairs + * (rx_fifo_size + tx_fifo_size); + approx_segment_count = + (approx_total_size + + (ca->private_segment_size - 1)) / (u64) ca->private_segment_size; + + /* The user asked us to figure it out... */ + if (ca->private_segment_count == 0) + { + ca->private_segment_count = approx_segment_count; + } + /* Follow directions, but issue a warning */ + else if (approx_segment_count != ca->private_segment_count) + { + clib_warning + ("Honoring segment count %u, but calculated count was %u", + ca->private_segment_count, approx_segment_count); + } + if (svm_fifo_segment_create_process_private (ca)) clib_warning ("Failed to create process private segment"); @@ -162,27 +197,24 @@ u8 segment_manager_has_fifos (segment_manager_t * sm) { svm_fifo_segment_private_t *segment; - /* Weird, but handle it */ - if (vec_len (sm->segment_indices) == 0) - return 0; - if (vec_len (sm->segment_indices) == 1) - { - segment = svm_fifo_segment_get_segment (sm->segment_indices[0]); - if (svm_fifo_segment_num_fifos (segment) == 0) - return 0; - } - if (CLIB_DEBUG) + int i; + + for (i = 0; i < vec_len (sm->segment_indices); i++) { - svm_fifo_segment_private_t *segment; - int i; - for (i = 1; i < vec_len (sm->segment_indices); i++) - { - segment = svm_fifo_segment_get_segment (sm->segment_indices[i]); - if (!svm_fifo_segment_has_fifos (segment)) - clib_warning ("segment has no fifos!"); - } + segment = svm_fifo_segment_get_segment (sm->segment_indices[i]); + if (CLIB_DEBUG && i && !svm_fifo_segment_has_fifos (segment) + && !(segment->h->flags & FIFO_SEGMENT_F_IS_PREALLOCATED)) + clib_warning ("segment %d has no fifos!", sm->segment_indices[i]); + if (svm_fifo_segment_has_fifos (segment)) + return 1; } - return 1; + return 0; +} + +static u8 +segment_manager_app_detached (segment_manager_t * sm) +{ + return (sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX); } static void @@ -193,6 +225,13 @@ segment_manager_del_segment (segment_manager_t * sm, u32 segment_index) clib_spinlock_lock (&sm->lockp); svm_segment_index = sm->segment_indices[segment_index]; fifo_segment = svm_fifo_segment_get_segment (svm_segment_index); + if (!fifo_segment + || ((fifo_segment->h->flags & FIFO_SEGMENT_F_IS_PREALLOCATED) + && !segment_manager_app_detached (sm))) + { + clib_spinlock_unlock (&sm->lockp); + return; + } svm_fifo_segment_delete (fifo_segment); vec_del1 (sm->segment_indices, segment_index); clib_spinlock_unlock (&sm->lockp); @@ -228,13 +267,13 @@ segment_manager_del_sessions (segment_manager_t * sm) session_index = fifo->master_session_index; thread_index = fifo->master_thread_index; - session = stream_session_get (session_index, thread_index); + session = session_get (session_index, thread_index); /* Instead of directly removing the session call disconnect */ if (session->session_state != SESSION_STATE_CLOSED) { session->session_state = SESSION_STATE_CLOSED; - session_send_session_evt_to_thread (stream_session_handle + session_send_session_evt_to_thread (session_handle (session), FIFO_EVENT_DISCONNECT, thread_index); @@ -253,26 +292,29 @@ segment_manager_del_sessions (segment_manager_t * sm) * * Since the fifos allocated in the segment keep backpointers to the sessions * prior to removing the segment, we call session disconnect. This - * subsequently propages into transport. + * subsequently propagates into transport. */ void segment_manager_del (segment_manager_t * sm) { + int i; - ASSERT (vec_len (sm->segment_indices) <= 1); - if (vec_len (sm->segment_indices)) + 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. */ + for (i = vec_len (sm->segment_indices) - 1; i >= 0; i--) { - /* 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. */ if (CLIB_DEBUG) { - svm_fifo_segment_private_t *fifo_segment; - fifo_segment = - svm_fifo_segment_get_segment (sm->segment_indices[0]); - ASSERT (!svm_fifo_segment_has_fifos (fifo_segment)); + svm_fifo_segment_private_t *segment; + segment = svm_fifo_segment_get_segment (sm->segment_indices[i]); + ASSERT (!svm_fifo_segment_has_fifos (segment)); } - segment_manager_del_segment (sm, 0); + segment_manager_del_segment (sm, i); } clib_spinlock_free (&sm->lockp); if (CLIB_DEBUG) @@ -287,8 +329,7 @@ segment_manager_init_del (segment_manager_t * sm) segment_manager_del_sessions (sm); else { - ASSERT (!sm->first_is_protected - || sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX); + ASSERT (!sm->first_is_protected || segment_manager_app_detached (sm)); segment_manager_del (sm); } } @@ -443,7 +484,8 @@ segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo, } /* Remove segment manager if no sessions and detached from app */ - if (sm->app_index == SEGMENT_MANAGER_INVALID_APP_INDEX && is_first) + if (segment_manager_app_detached (sm) + && !segment_manager_has_fifos (sm)) segment_manager_del (sm); } } @@ -503,7 +545,9 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, u8 show_segments = 0, verbose = 0, *name; uword address; u64 size; - u32 fifos; + u32 active_fifos; + u32 free_fifos; + mheap_t *heap_header; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -536,8 +580,8 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, segments = svm_fifo_segment_segments_pool (); vlib_cli_output (vm, "%d svm fifo segments allocated", pool_elts (segments)); - vlib_cli_output (vm, "%-20s%=12s%=12s%=15s", "Name", "Size (M)", - "Fifos", "Address"); + vlib_cli_output (vm, "%-20s%=12s%=16s%=16s%=16s", "Name", + "HeapSize (M)", "ActiveFifos", "FreeFifos", "Address"); /* *INDENT-OFF* */ pool_foreach (seg, segments, ({ @@ -557,9 +601,14 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, size = seg->ssvm.ssvm_size; name = seg->ssvm.sh->name; } - fifos = svm_fifo_segment_num_fifos (seg); - vlib_cli_output (vm, "%-20s%=12u%=12u%=15x", name, size << 20, fifos, + active_fifos = svm_fifo_segment_num_fifos (seg); + free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 /* size */); + vlib_cli_output (vm, "%-20v%=16llu%=16u%=16u%16llx", + name, size >> 20ULL, active_fifos, free_fifos, address); + if (verbose) + vlib_cli_output (vm, "%U", + format_svm_fifo_segment, seg, verbose); if (seg->h->flags & FIFO_SEGMENT_F_IS_PRIVATE) vec_free (name); })); @@ -573,7 +622,7 @@ segment_manager_show_fn (vlib_main_t * vm, unformat_input_t * input, VLIB_CLI_COMMAND (segment_manager_show_command, static) = { .path = "show segment-manager", - .short_help = "show segment-manager [segments]", + .short_help = "show segment-manager [segments][verbose]", .function = segment_manager_show_fn, }; /* *INDENT-ON* */