X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsession.h;h=54740e64cf0c1fbc105e8127583536c692cf0c50;hb=d810a6e218e9af3c3bccd58c9a2d925a7f12242e;hp=2d01eb6a67aad3d0e70fa4cf35e20cb167fdae31;hpb=0046e97eb94cbcf278be2c892e4b686da670a414;p=vpp.git diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h index 2d01eb6a67a..54740e64cf0 100644 --- a/src/vnet/session/session.h +++ b/src/vnet/session/session.h @@ -21,6 +21,7 @@ #include #include #include +#include #define foreach_session_input_error \ _(NO_SESSION, "No session drops") \ @@ -59,6 +60,7 @@ typedef struct session_tx_context_ /** Vector of tx buffer free lists */ u32 *tx_buffers; + vlib_buffer_t **transport_pending_bufs; } session_tx_context_t; typedef struct session_evt_elt @@ -84,6 +86,13 @@ typedef enum session_wrk_flags_ SESSION_WRK_F_ADAPTIVE = 1 << 0, } __clib_packed session_wrk_flag_t; +#define DMA_TRANS_SIZE 1024 +typedef struct +{ + u32 *pending_tx_buffers; + u16 *pending_tx_nexts; +} session_dma_transfer; + typedef struct session_worker_ { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); @@ -133,9 +142,6 @@ typedef struct session_worker_ /** Head of list of pending events */ clib_llist_index_t old_head; - /** Peekers rw lock */ - clib_rwlock_t peekers_rw_locks; - /** Vector of buffers to be sent */ u32 *pending_tx_buffers; @@ -154,6 +160,18 @@ typedef struct session_worker_ /** Main thread loops in poll mode without a connect */ u32 no_connect_loops; + /** List head for first worker evts pending handling on main */ + clib_llist_index_t evts_pending_main; + + int config_index; + u8 dma_enabled; + session_dma_transfer *dma_trans; + u16 trans_head; + u16 trans_tail; + u16 trans_size; + u16 batch_num; + vlib_dma_batch_t *batch; + #if SESSION_DEBUG /** last event poll time by thread */ clib_time_type_t last_event_poll; @@ -170,13 +188,18 @@ extern session_fifo_rx_fn session_tx_fifo_dequeue_internal; u8 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e); +typedef void (*session_update_time_fn) (f64 time_now, u8 thread_index); + typedef struct session_main_ { /** Worker contexts */ session_worker_t *wrk; + /** Vector of transport update time functions */ + session_update_time_fn *update_time_fns; + /** Event queues memfd segment */ - fifo_segment_t evt_qs_segment; + fifo_segment_t wrk_mqs_segment; /** Unique segment name counter */ u32 unique_segment_name_counter; @@ -194,6 +217,15 @@ typedef struct session_main_ transport_proto_t last_transport_proto_type; + /** Number of workers at pool realloc barrier */ + volatile u32 pool_realloc_at_barrier; + + /** Number of workers doing reallocs */ + volatile u32 pool_realloc_doing_work; + + /** Lock to synchronize parallel forced reallocs */ + clib_spinlock_t pool_realloc_lock; + /* * Config parameters */ @@ -217,12 +249,13 @@ typedef struct session_main_ u8 no_adaptive; /** vpp fifo event queue configured length */ - u32 configured_event_queue_length; + u32 configured_wrk_mq_length; /** Session ssvm segment configs*/ - uword session_baseva; - uword session_va_space_size; - uword evt_qs_segment_size; + uword wrk_mqs_segment_size; + + /** Session enable dma*/ + u8 dma_enabled; /** Session table size parameters */ u32 configured_v4_session_table_buckets; @@ -373,37 +406,9 @@ session_get_from_handle_if_valid (session_handle_t handle) u64 session_segment_handle (session_t * s); /** - * Acquires a lock that blocks a session pool from expanding. - * - * This is typically used for safely peeking into other threads' - * pools in order to clone elements. Lock should be dropped as soon - * as possible by calling @ref session_pool_remove_peeker. - * - * NOTE: Avoid using pool_elt_at_index while the lock is held because - * it may lead to free elt bitmap expansion/contraction! - */ -always_inline void -session_pool_add_peeker (u32 thread_index) -{ - session_worker_t *wrk = &session_main.wrk[thread_index]; - if (thread_index == vlib_get_thread_index ()) - return; - clib_rwlock_reader_lock (&wrk->peekers_rw_locks); -} - -always_inline void -session_pool_remove_peeker (u32 thread_index) -{ - session_worker_t *wrk = &session_main.wrk[thread_index]; - if (thread_index == vlib_get_thread_index ()) - return; - clib_rwlock_reader_unlock (&wrk->peekers_rw_locks); -} - -/** - * Get session from handle and 'lock' pool resize if not in same thread + * Get session from handle and avoid pool validation if no same thread * - * Caller should drop the peek 'lock' as soon as possible. + * Peekers are fine because pool grows with barrier (see @ref session_alloc) */ always_inline session_t * session_get_from_handle_safe (u64 handle) @@ -418,36 +423,24 @@ session_get_from_handle_safe (u64 handle) } else { - session_pool_add_peeker (thread_index); - /* Don't use pool_elt_at index. See @ref session_pool_add_peeker */ + /* Don't use pool_elt_at index to avoid pool bitmap reallocs */ return wrk->sessions + session_index_from_handle (handle); } } -always_inline u32 -session_get_index (session_t * s) -{ - return (s - session_main.wrk[s->thread_index].sessions); -} - always_inline session_t * session_clone_safe (u32 session_index, u32 thread_index) { + u32 current_thread_index = vlib_get_thread_index (), new_index; session_t *old_s, *new_s; - u32 current_thread_index = vlib_get_thread_index (); - /* If during the memcpy pool is reallocated AND the memory allocator - * decides to give the old chunk of memory to somebody in a hurry to - * scribble something on it, we have a problem. So add this thread as - * a session pool peeker. - */ - session_pool_add_peeker (thread_index); new_s = session_alloc (current_thread_index); + new_index = new_s->session_index; + /* Session pools are reallocated with barrier (see @ref session_alloc) */ old_s = session_main.wrk[thread_index].sessions + session_index; clib_memcpy_fast (new_s, old_s, sizeof (*new_s)); - session_pool_remove_peeker (thread_index); new_s->thread_index = current_thread_index; - new_s->session_index = session_get_index (new_s); + new_s->session_index = new_index; return new_s; } @@ -529,10 +522,18 @@ void session_register_transport (transport_proto_t transport_proto, const transport_proto_vft_t * vft, u8 is_ip4, u32 output_node); transport_proto_t session_add_transport_proto (void); +void session_register_update_time_fn (session_update_time_fn fn, u8 is_add); int session_tx_fifo_peek_bytes (transport_connection_t * tc, u8 * buffer, u32 offset, u32 max_bytes); u32 session_tx_fifo_dequeue_drop (transport_connection_t * tc, u32 max_bytes); +always_inline void +session_set_state (session_t *s, session_state_t session_state) +{ + s->session_state = session_state; + SESSION_EVT (SESSION_EVT_STATE_CHANGE, s); +} + always_inline u32 transport_max_rx_enqueue (transport_connection_t * tc) { @@ -671,6 +672,17 @@ ho_session_alloc (void) s = session_alloc (0); s->session_state = SESSION_STATE_CONNECTING; s->flags |= SESSION_F_HALF_OPEN; + /* Not ideal. Half-opens are only allocated from main with worker barrier + * but can be cleaned up, i.e., session_half_open_free, from main without + * a barrier. In debug images, the free_bitmap can grow while workers peek + * the sessions pool, e.g., session_half_open_migrate_notify, and as a + * result crash while validating the session. To avoid this, grow the bitmap + * now. */ + if (CLIB_DEBUG) + { + session_t *sp = session_main.wrk[0].sessions; + clib_bitmap_validate (pool_header (sp)->free_bitmap, s->session_index); + } return s; } @@ -761,13 +773,112 @@ session_wrk_update_time (session_worker_t *wrk, f64 now) } void session_wrk_enable_adaptive_mode (session_worker_t *wrk); -fifo_segment_t *session_main_get_evt_q_segment (void); +fifo_segment_t *session_main_get_wrk_mqs_segment (void); void session_node_enable_disable (u8 is_en); clib_error_t *vnet_session_enable_disable (vlib_main_t * vm, u8 is_en); +void session_wrk_handle_evts_main_rpc (void *); session_t *session_alloc_for_connection (transport_connection_t * tc); session_t *session_alloc_for_half_open (transport_connection_t *tc); +typedef void (pool_safe_realloc_rpc_fn) (void *rpc_args); + +typedef struct +{ + u8 ph[STRUCT_OFFSET_OF (pool_header_t, max_elts) + 4]; + u32 flag; +} pool_safe_realloc_header_t; + +STATIC_ASSERT_SIZEOF (pool_safe_realloc_header_t, sizeof (pool_header_t)); + +#define POOL_REALLOC_SAFE_ELT_THRESH 32 + +#define pool_realloc_flag(PH) \ + ((pool_safe_realloc_header_t *) pool_header (PH))->flag + +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 elt_size, u32 align) +{ + pool_realloc_rpc_args_t *pra; + + /* Reuse pad as a realloc flag */ + if (pool_realloc_flag (*p)) + return; + + 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) \ + ((!P) || \ + (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, align) \ + do \ + { \ + if (PREDICT_FALSE (pool_needs_realloc (P))) \ + { \ + if (PREDICT_FALSE (!(P))) \ + { \ + pool_alloc_aligned (P, POOL_REALLOC_SAFE_ELT_THRESH, align); \ + } \ + else if (PREDICT_FALSE (!pool_free_elts (P))) \ + { \ + vlib_workers_sync (); \ + pool_alloc_aligned (P, pool_max_len (P), align); \ + vlib_workers_continue (); \ + ALWAYS_ASSERT (pool_free_elts (P) > 0); \ + } \ + else \ + { \ + pool_program_safe_realloc ((void **) &(P), sizeof ((P)[0]), \ + _vec_align (P, align)); \ + } \ + } \ + pool_get_aligned (P, E, align); \ + } \ + while (0) + #endif /* __included_session_h__ */ /*