/* 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;
+ SESSION_DBG ("cannot allocate new segment");
+ return SESSION_E_INVALID;
}
/*
sizeof (fifo_segment_header_t) +
vlib_thread_main.n_vlib_mains * sizeof (fifo_segment_slice_t) +
FIFO_SEGMENT_ALLOC_OVERHEAD;
- segment_size = round_pow2 (segment_size, clib_mem_get_page_size ());
+
+ if (props->huge_page)
+ {
+ uword hugepage_size = clib_mem_get_default_hugepage_size ();
+ segment_size = round_pow2 (segment_size, hugepage_size);
+ fs->ssvm.huge_page = 1;
+ }
+ else
+ segment_size = round_pow2 (segment_size, clib_mem_get_page_size ());
seg_name = format (0, "seg-%u-%u-%u%c", app_wrk->app_index,
app_wrk->wrk_index, smm->seg_name_counter++, 0);
* Save segment index before dropping lock, if any held
*/
fs_index = fs - sm->segments;
+ fs->fs_index = fs_index;
+ fs->sm_index = segment_manager_index (sm);
/*
* Set watermarks in segment
fs_index = segment_manager_add_segment (sm, max_seg_size, 0);
if (fs_index < 0)
{
- clib_warning ("Failed to preallocate segment %d", i);
+ SESSION_DBG ("Failed to preallocate segment %d", i);
return fs_index;
}
fs_index = segment_manager_add_segment (sm, first_seg_size, 0);
if (fs_index < 0)
{
- clib_warning ("Failed to allocate segment");
+ SESSION_DBG ("Failed to allocate segment");
return fs_index;
}
for (; i < fs->n_slices; i++)
{
if (fifo_segment_prealloc_fifo_hdrs (fs, i, hdrs_per_slice))
- return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL;
+ return SESSION_E_SEG_CREATE;
}
}
}
int
-segment_manager_try_alloc_fifos (fifo_segment_t * fifo_segment,
- u32 thread_index,
+segment_manager_try_alloc_fifos (fifo_segment_t *fs, u32 thread_index,
u32 rx_fifo_size, u32 tx_fifo_size,
- svm_fifo_t ** rx_fifo, svm_fifo_t ** tx_fifo)
+ svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
{
rx_fifo_size = clib_max (rx_fifo_size, sm_main.default_fifo_size);
- *rx_fifo = fifo_segment_alloc_fifo_w_slice (fifo_segment, thread_index,
- rx_fifo_size,
+ *rx_fifo = fifo_segment_alloc_fifo_w_slice (fs, thread_index, rx_fifo_size,
FIFO_SEGMENT_RX_FIFO);
tx_fifo_size = clib_max (tx_fifo_size, sm_main.default_fifo_size);
- *tx_fifo = fifo_segment_alloc_fifo_w_slice (fifo_segment, thread_index,
- tx_fifo_size,
+ *tx_fifo = fifo_segment_alloc_fifo_w_slice (fs, thread_index, tx_fifo_size,
FIFO_SEGMENT_TX_FIFO);
if (*rx_fifo == 0)
/* This would be very odd, but handle it... */
if (*tx_fifo != 0)
{
- fifo_segment_free_fifo (fifo_segment, *tx_fifo);
+ fifo_segment_free_fifo (fs, *tx_fifo);
*tx_fifo = 0;
}
- return -1;
+ return SESSION_E_SEG_NO_SPACE;
}
if (*tx_fifo == 0)
{
if (*rx_fifo != 0)
{
- fifo_segment_free_fifo (fifo_segment, *rx_fifo);
+ fifo_segment_free_fifo (fs, *rx_fifo);
*rx_fifo = 0;
}
- return -1;
+ return SESSION_E_SEG_NO_SPACE;
}
return 0;
{
uword free_bytes, max_free_bytes;
fifo_segment_t *cur, *fs = 0;
- u32 fs_index;
- int rv;
max_free_bytes = props->rx_fifo_size + props->tx_fifo_size - 1;
if (PREDICT_FALSE (!fs))
return SESSION_E_SEG_NO_SPACE;
- fs_index = segment_manager_segment_index (sm, fs);
- rv = segment_manager_try_alloc_fifos (fs, thread_index, props->rx_fifo_size,
- props->tx_fifo_size, rx_fifo, tx_fifo);
-
- return rv ? SESSION_E_SEG_NO_SPACE : fs_index;
+ return segment_manager_try_alloc_fifos (
+ fs, thread_index, props->rx_fifo_size, props->tx_fifo_size, rx_fifo,
+ tx_fifo);
}
static int
* some fifos or allocated a segment */
rv = sm_lookup_segment_and_alloc_fifos (sm, props, thread_index, rx_fifo,
tx_fifo);
- if (rv > 0)
+ if (!rv)
goto done;
new_fs_index =
props->tx_fifo_size, rx_fifo, tx_fifo);
if (rv)
{
- clib_warning ("Added a segment, still can't allocate a fifo");
+ SESSION_DBG ("Added a segment, still can't allocate a fifo");
rv = SESSION_E_SEG_NO_SPACE2;
goto done;
}
- rv = new_fs_index;
-
done:
clib_rwlock_writer_unlock (&sm->segments_rwlock);
svm_fifo_t ** tx_fifo)
{
segment_manager_props_t *props;
- u32 sm_index;
- int fs_index;
+ int rv;
props = segment_manager_properties_get (sm);
- sm_index = segment_manager_index (sm);
/*
* Fast path: find the first segment with enough free space and
segment_manager_segment_reader_lock (sm);
- fs_index = sm_lookup_segment_and_alloc_fifos (sm, props, thread_index,
- rx_fifo, tx_fifo);
+ rv = sm_lookup_segment_and_alloc_fifos (sm, props, thread_index, rx_fifo,
+ tx_fifo);
segment_manager_segment_reader_unlock (sm);
* Slow path: if no fifo segment or alloc fail grab writer lock and try
* to allocate new segment
*/
- if (PREDICT_FALSE (fs_index < 0))
- {
- fs_index = sm_lock_and_alloc_segment_and_fifos (sm, props, thread_index,
- rx_fifo, tx_fifo);
- if (fs_index < 0)
- return fs_index;
- }
-
- (*tx_fifo)->segment_manager = sm_index;
- (*rx_fifo)->segment_manager = sm_index;
- (*tx_fifo)->segment_index = fs_index;
- (*rx_fifo)->segment_index = fs_index;
+ if (PREDICT_FALSE (rv < 0))
+ return sm_lock_and_alloc_segment_and_fifos (sm, props, thread_index,
+ rx_fifo, tx_fifo);
return 0;
}
if (!rx_fifo || !tx_fifo)
return;
+ /* Thread that allocated the fifos must be the one to clean them up */
+ ASSERT (rx_fifo->master_thread_index == vlib_get_thread_index () ||
+ rx_fifo->refcnt > 1);
+
/* It's possible to have no segment manager if the session was removed
* as result of a detach. */
if (!(sm = segment_manager_get_if_valid (rx_fifo->segment_manager)))
s = format (s,
"[%u] %v app-wrk: %u segs: %u max-fifo-sz: %U "
"wmarks: %u %u %s flags: 0x%x",
- segment_manager_index (sm), app->name, sm->app_wrk_index,
- pool_elts (sm->segments), format_memory_size, max_fifo_size,
- sm->high_watermark, sm->low_watermark,
+ segment_manager_index (sm), app ? app->name : 0,
+ sm->app_wrk_index, pool_elts (sm->segments), format_memory_size,
+ max_fifo_size, sm->high_watermark, sm->low_watermark,
custom_logic ? "custom-tuning" : "no-tuning", sm->flags);
if (!verbose || !pool_elts (sm->segments))