aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2022-03-31 15:42:17 -0700
committerDamjan Marion <dmarion@me.com>2022-04-01 15:40:34 +0000
commitd3915dc1b5201956578eb900a2d936d94fc09b90 (patch)
tree85f1a2e31158c1825946f0b238ad546a26033784 /src/vnet/session
parent691c630b79ec2230b67944c8a9f77f95b49d95ad (diff)
session: leverage new pool functions in safe realloc
Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I2c264c31d2470b11b94d68411fa8266387319146
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/session.c15
-rw-r--r--src/vnet/session/session.h80
-rw-r--r--src/vnet/session/transport.c9
3 files changed, 50 insertions, 54 deletions
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index f1d1a4e2cfe..256760079ee 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -197,26 +197,13 @@ session_program_transport_ctrl_evt (session_t * s, session_evt_type_t evt)
session_send_ctrl_evt_to_thread (s, evt);
}
-static void
-session_pool_realloc_rpc (void *rpc_args)
-{
- session_worker_t *wrk;
- u32 thread_index;
-
- thread_index = pointer_to_uword (rpc_args);
- wrk = &session_main.wrk[thread_index];
-
- pool_realloc_safe_aligned (wrk->sessions, CLIB_CACHE_LINE_BYTES);
-}
-
session_t *
session_alloc (u32 thread_index)
{
session_worker_t *wrk = &session_main.wrk[thread_index];
session_t *s;
- pool_get_aligned_safe (wrk->sessions, s, thread_index,
- session_pool_realloc_rpc, CLIB_CACHE_LINE_BYTES);
+ pool_get_aligned_safe (wrk->sessions, s, CLIB_CACHE_LINE_BYTES);
clib_memset (s, 0, sizeof (*s));
s->session_index = s - wrk->sessions;
s->thread_index = thread_index;
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index 0cf6cd084fe..68ed8431605 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -769,38 +769,56 @@ STATIC_ASSERT_SIZEOF (pool_safe_realloc_header_t, sizeof (pool_header_t));
#define pool_realloc_flag(PH) \
((pool_safe_realloc_header_t *) pool_header (PH))->flag
-#define pool_realloc_safe_aligned(P, align) \
- do \
- { \
- vlib_main_t *vm = vlib_get_main (); \
- u32 free_elts, max_elts, n_alloc; \
- ASSERT (vlib_get_thread_index () == 0); \
- vlib_worker_thread_barrier_sync (vm); \
- free_elts = pool_free_elts (P); \
- if (free_elts < POOL_REALLOC_SAFE_ELT_THRESH) \
- { \
- max_elts = pool_max_len (P); \
- n_alloc = clib_max (2 * max_elts, POOL_REALLOC_SAFE_ELT_THRESH); \
- pool_alloc_aligned (P, free_elts + n_alloc, align); \
- clib_bitmap_validate (pool_header (P)->free_bitmap, \
- max_elts + n_alloc); \
- } \
- pool_realloc_flag (P) = 0; \
- vlib_worker_thread_barrier_release (vm); \
- } \
- while (0)
+typedef struct pool_realloc_rpc_args_
+{
+ void **pool;
+ uword elt_size;
+ uword align;
+} pool_realloc_rpc_args_t;
+
+always_inline void
+pool_program_safe_realloc_rpc (void *args)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ u32 free_elts, max_elts, n_alloc;
+ pool_realloc_rpc_args_t *pra;
+
+ ASSERT (vlib_get_thread_index () == 0);
+ pra = (pool_realloc_rpc_args_t *) args;
+
+ vlib_worker_thread_barrier_sync (vm);
+
+ free_elts = _pool_free_elts (*pra->pool, pra->elt_size);
+ if (free_elts < POOL_REALLOC_SAFE_ELT_THRESH)
+ {
+ max_elts = _vec_max_len (*pra->pool, pra->elt_size);
+ n_alloc = clib_max (2 * max_elts, POOL_REALLOC_SAFE_ELT_THRESH);
+ _pool_alloc (pra->pool, free_elts + n_alloc, pra->align, 0,
+ pra->elt_size);
+ }
+ pool_realloc_flag (*pra->pool) = 0;
+ clib_mem_free (args);
+
+ vlib_worker_thread_barrier_release (vm);
+}
always_inline void
-pool_program_safe_realloc (void *p, u32 thread_index,
- pool_safe_realloc_rpc_fn *rpc_fn)
+pool_program_safe_realloc (void **p, u32 elt_size, u32 align)
{
+ pool_realloc_rpc_args_t *pra;
+
/* Reuse pad as a realloc flag */
- if (pool_realloc_flag (p))
+ if (pool_realloc_flag (*p))
return;
- pool_realloc_flag (p) = 1;
- session_send_rpc_evt_to_thread (0 /* thread index */, rpc_fn,
- uword_to_pointer (thread_index, void *));
+ pra = clib_mem_alloc (sizeof (*pra));
+ pra->pool = p;
+ pra->elt_size = elt_size;
+ pra->align = align;
+ pool_realloc_flag (*p) = 1;
+
+ session_send_rpc_evt_to_thread (0 /* thread index */,
+ pool_program_safe_realloc_rpc, pra);
}
#define pool_needs_realloc(P) \
@@ -808,17 +826,14 @@ pool_program_safe_realloc (void *p, u32 thread_index,
(vec_len (pool_header (P)->free_indices) < POOL_REALLOC_SAFE_ELT_THRESH && \
pool_free_elts (P) < POOL_REALLOC_SAFE_ELT_THRESH))
-#define pool_get_aligned_safe(P, E, thread_index, rpc_fn, align) \
+#define pool_get_aligned_safe(P, E, align) \
do \
{ \
- ASSERT (vlib_get_thread_index () == thread_index || \
- vlib_thread_is_main_w_barrier ()); \
if (PREDICT_FALSE (pool_needs_realloc (P))) \
{ \
if (PREDICT_FALSE (!(P))) \
{ \
- pool_alloc_aligned (P, 2 * POOL_REALLOC_SAFE_ELT_THRESH, \
- align); \
+ pool_alloc_aligned (P, POOL_REALLOC_SAFE_ELT_THRESH, align); \
} \
else if (PREDICT_FALSE (!pool_free_elts (P))) \
{ \
@@ -829,7 +844,8 @@ pool_program_safe_realloc (void *p, u32 thread_index,
} \
else \
{ \
- pool_program_safe_realloc (P, thread_index, rpc_fn); \
+ pool_program_safe_realloc ((void **) &(P), sizeof ((P)[0]), \
+ _vec_align (P, align)); \
} \
} \
pool_get_aligned (P, E, align); \
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index 0473f198e15..54ce9176666 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -425,20 +425,13 @@ transport_endpoint_free (u32 tepi)
pool_put_index (local_endpoints, tepi);
}
-static void
-transport_endpoint_pool_realloc_rpc (void *rpc_args)
-{
- pool_realloc_safe_aligned (local_endpoints, 0);
-}
-
always_inline local_endpoint_t *
transport_endpoint_alloc (void)
{
local_endpoint_t *lep;
ASSERT (vlib_get_thread_index () <= transport_cl_thread ());
- pool_get_aligned_safe (local_endpoints, lep, transport_cl_thread (),
- transport_endpoint_pool_realloc_rpc, 0);
+ pool_get_aligned_safe (local_endpoints, lep, 0);
return lep;
}