aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/svm/fifo_segment.c5
-rw-r--r--src/svm/fifo_segment.h2
-rw-r--r--src/vnet/session/application_local.c4
-rw-r--r--src/vnet/session/segment_manager.c58
4 files changed, 27 insertions, 42 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 8795b46c86a..77177a14a69 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -387,6 +387,8 @@ fifo_segment_attach (fifo_segment_main_t * sm, fifo_segment_create_args_t * a)
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);
@@ -868,6 +870,9 @@ fifo_segment_alloc_fifo_w_slice (fifo_segment_t * fs, u32 slice_index,
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);
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h
index 440f1bb6a02..ec184207269 100644
--- a/src/svm/fifo_segment.h
+++ b/src/svm/fifo_segment.h
@@ -74,6 +74,8 @@ typedef struct
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 */
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index 6d1c9654197..83def8eb730 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -621,10 +621,6 @@ ct_init_accepted_session (app_worker_t *server_wrk, ct_connection_t *ct,
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);
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index cbf6207060c..3b05cd024de 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -154,6 +154,8 @@ segment_manager_add_segment_inline (segment_manager_t *sm, uword segment_size,
* 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
@@ -698,19 +700,16 @@ segment_manager_del_sessions_filter (segment_manager_t *sm,
}
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)
@@ -718,19 +717,19 @@ segment_manager_try_alloc_fifos (fifo_segment_t * fifo_segment,
/* 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;
@@ -744,8 +743,6 @@ sm_lookup_segment_and_alloc_fifos (segment_manager_t *sm,
{
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;
@@ -764,11 +761,9 @@ sm_lookup_segment_and_alloc_fifos (segment_manager_t *sm,
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
@@ -789,7 +784,7 @@ sm_lock_and_alloc_segment_and_fifos (segment_manager_t *sm,
* 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 =
@@ -809,8 +804,6 @@ sm_lock_and_alloc_segment_and_fifos (segment_manager_t *sm,
goto done;
}
- rv = new_fs_index;
-
done:
clib_rwlock_writer_unlock (&sm->segments_rwlock);
@@ -825,11 +818,9 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
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
@@ -838,8 +829,8 @@ segment_manager_alloc_session_fifos (segment_manager_t * 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);
@@ -847,18 +838,9 @@ segment_manager_alloc_session_fifos (segment_manager_t * 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;
}