Simplifies allocation of fifos as fifo segment and segment manager
indices can be set at alloc time.
Type: improvement
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ibd357b3ff0279d8deefcdcb17010b4068007ccb7
pool_get_zero (sm->segments, fs);
pool_get_zero (sm->segments, fs);
+ fs->fs_index = fs - sm->segments;
+ fs->sm_index = ~0;
fs->ssvm.ssvm_size = a->segment_size;
fs->ssvm.my_pid = getpid ();
fs->ssvm.name = format (0, "%s%c", a->segment_name, 0);
fs->ssvm.ssvm_size = a->segment_size;
fs->ssvm.my_pid = getpid ();
fs->ssvm.name = format (0, "%s%c", a->segment_name, 0);
svm_fifo_init (f, data_bytes);
svm_fifo_init (f, data_bytes);
+ f->segment_manager = fs->sm_index;
+ f->segment_index = fs->fs_index;
+
fss = fsh_slice_get (fsh, slice_index);
pfss = fs_slice_private_get (fs, slice_index);
fss = fsh_slice_get (fsh, slice_index);
pfss = fs_slice_private_get (fs, slice_index);
fifo_slice_private_t *slices; /**< private slice information */
svm_msg_q_t *mqs; /**< private vec of attached mqs */
uword max_byte_index; /**< max byte index for segment */
fifo_slice_private_t *slices; /**< private slice information */
svm_msg_q_t *mqs; /**< private vec of attached mqs */
uword max_byte_index; /**< max byte index for segment */
+ u32 sm_index; /**< owner segment manager index */
+ u32 fs_index; /**< fs index in sm pool */
u8 n_slices; /**< number of fifo segment slices */
u8 flags; /**< private fifo segment flags */
u8 high_watermark; /**< memory pressure watermark high */
u8 n_slices; /**< number of fifo segment slices */
u8 flags; /**< private fifo segment flags */
u8 high_watermark; /**< memory pressure watermark high */
ls->tx_fifo->shr->master_session_index = ls->session_index;
ls->rx_fifo->master_thread_index = ls->thread_index;
ls->tx_fifo->master_thread_index = ls->thread_index;
ls->tx_fifo->shr->master_session_index = ls->session_index;
ls->rx_fifo->master_thread_index = ls->thread_index;
ls->tx_fifo->master_thread_index = ls->thread_index;
- ls->rx_fifo->segment_manager = sm_index;
- ls->tx_fifo->segment_manager = sm_index;
- ls->rx_fifo->segment_index = fs_index;
- ls->tx_fifo->segment_index = fs_index;
seg_handle = segment_manager_segment_handle (sm, fs);
segment_manager_segment_reader_unlock (sm);
seg_handle = segment_manager_segment_handle (sm, fs);
segment_manager_segment_reader_unlock (sm);
* Save segment index before dropping lock, if any held
*/
fs_index = fs - sm->segments;
* 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
/*
* Set watermarks in segment
-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,
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_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);
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)
FIFO_SEGMENT_TX_FIFO);
if (*rx_fifo == 0)
/* This would be very odd, but handle it... */
if (*tx_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);
+ return SESSION_E_SEG_NO_SPACE;
}
if (*tx_fifo == 0)
{
if (*rx_fifo != 0)
{
}
if (*tx_fifo == 0)
{
if (*rx_fifo != 0)
{
- fifo_segment_free_fifo (fifo_segment, *rx_fifo);
+ fifo_segment_free_fifo (fs, *rx_fifo);
+ return SESSION_E_SEG_NO_SPACE;
{
uword free_bytes, max_free_bytes;
fifo_segment_t *cur, *fs = 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;
max_free_bytes = props->rx_fifo_size + props->tx_fifo_size - 1;
if (PREDICT_FALSE (!fs))
return SESSION_E_SEG_NO_SPACE;
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);
* some fifos or allocated a segment */
rv = sm_lookup_segment_and_alloc_fifos (sm, props, thread_index, rx_fifo,
tx_fifo);
* some fifos or allocated a segment */
rv = sm_lookup_segment_and_alloc_fifos (sm, props, thread_index, rx_fifo,
tx_fifo);
goto done;
new_fs_index =
goto done;
new_fs_index =
done:
clib_rwlock_writer_unlock (&sm->segments_rwlock);
done:
clib_rwlock_writer_unlock (&sm->segments_rwlock);
svm_fifo_t ** tx_fifo)
{
segment_manager_props_t *props;
svm_fifo_t ** tx_fifo)
{
segment_manager_props_t *props;
- u32 sm_index;
- int fs_index;
props = segment_manager_properties_get (sm);
props = segment_manager_properties_get (sm);
- sm_index = segment_manager_index (sm);
/*
* Fast path: find the first segment with enough free space and
/*
* Fast path: find the first segment with enough free space and
segment_manager_segment_reader_lock (sm);
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);
segment_manager_segment_reader_unlock (sm);
* Slow path: if no fifo segment or alloc fail grab writer lock and try
* to allocate new segment
*/
* 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);