aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-03-05 19:44:02 +0000
committerFlorin Coras <fcoras@cisco.com>2020-03-05 19:50:15 +0000
commit75ccf7b5c51c170da45fb52bd62a6d621923f245 (patch)
tree09cd03933fd2f237ebe49f750ab795d44ff13504
parentb4e5e50fe898bf905aa7087e17740394b97e5cf9 (diff)
session: fix segment search on fifo alloc
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Iaa4f9b0ec31a58f7406774f73e1a089bfcf4ac30
-rw-r--r--src/svm/fifo_segment.c6
-rw-r--r--src/svm/fifo_segment.h2
-rw-r--r--src/vnet/session/segment_manager.c53
3 files changed, 31 insertions, 30 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index d711c87c88c..39856a1a333 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -1134,6 +1134,12 @@ fifo_segment_cached_bytes (fifo_segment_t * fs)
}
uword
+fifo_segment_available_bytes (fifo_segment_t * fs)
+{
+ return fsh_n_free_bytes (fs->h) + fsh_n_cached_bytes (fs->h);
+}
+
+uword
fifo_segment_fl_chunk_bytes (fifo_segment_t * fs)
{
fifo_segment_header_t *fsh = fs->h;
diff --git a/src/svm/fifo_segment.h b/src/svm/fifo_segment.h
index 00914e6c227..2e193029e85 100644
--- a/src/svm/fifo_segment.h
+++ b/src/svm/fifo_segment.h
@@ -243,6 +243,8 @@ void fifo_segment_update_free_bytes (fifo_segment_t * fs);
*/
uword fifo_segment_cached_bytes (fifo_segment_t * fs);
+uword fifo_segment_available_bytes (fifo_segment_t * fs);
+
/**
* Number of bytes on chunk free lists
*
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index cbd44432e8a..02ac1c081c3 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -294,6 +294,12 @@ segment_manager_get_segment_w_lock (segment_manager_t * sm, u32 segment_index)
}
void
+segment_manager_segment_reader_lock (segment_manager_t * sm)
+{
+ clib_rwlock_reader_lock (&sm->segments_rwlock);
+}
+
+void
segment_manager_segment_reader_unlock (segment_manager_t * sm)
{
clib_rwlock_reader_unlock (&sm->segments_rwlock);
@@ -459,27 +465,6 @@ segment_manager_get_if_valid (u32 index)
return pool_elt_at_index (sm_main.segment_managers, index);
}
-static fifo_segment_t *
-find_max_free_segment (segment_manager_t * sm, u32 thread_index)
-{
- fifo_segment_t *cur, *fs = 0;
- uword free_bytes, max_free_bytes = 0;
-
- clib_rwlock_reader_lock (&sm->segments_rwlock);
- /* *INDENT-OFF* */
- pool_foreach (cur, sm->segments, ({
- if ((free_bytes = fifo_segment_free_bytes (cur)) > max_free_bytes)
- {
- max_free_bytes = free_bytes;
- fs = cur;
- }
- }));
- /* *INDENT-ON* */
- clib_rwlock_reader_unlock (&sm->segments_rwlock);
-
- return fs;
-}
-
u32
segment_manager_index (segment_manager_t * sm)
{
@@ -604,8 +589,9 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
svm_fifo_t ** tx_fifo)
{
int alloc_fail = 1, rv = 0, new_fs_index;
+ uword free_bytes, max_free_bytes = 0;
segment_manager_props_t *props;
- fifo_segment_t *fs = 0;
+ fifo_segment_t *fs = 0, *cur;
u32 sm_index, fs_index;
u8 added_a_segment = 0;
u64 fs_handle;
@@ -615,11 +601,22 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
/*
* Find the first free segment to allocate the fifos in
*/
- fs = find_max_free_segment (sm, thread_index);
+
+ segment_manager_segment_reader_lock (sm);
+
+ /* *INDENT-OFF* */
+ pool_foreach (cur, sm->segments, ({
+ free_bytes = fifo_segment_available_bytes (cur);
+ if (free_bytes > max_free_bytes)
+ {
+ max_free_bytes = free_bytes;
+ fs = cur;
+ }
+ }));
+ /* *INDENT-ON* */
if (fs)
{
- clib_rwlock_reader_lock (&sm->segments_rwlock);
alloc_fail = segment_manager_try_alloc_fifos (fs, thread_index,
props->rx_fifo_size,
props->tx_fifo_size,
@@ -627,14 +624,10 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
/* On success, keep lock until fifos are initialized */
if (!alloc_fail)
goto alloc_success;
-
- segment_manager_segment_reader_unlock (sm);
- }
- else
- {
- alloc_fail = 1;
}
+ segment_manager_segment_reader_unlock (sm);
+
alloc_check:
if (!alloc_fail)