41 s =
format (s,
"SESSION_QUEUE: session index %d, server thread index %d",
48 #define foreach_session_queue_error \ 49 _(TX, "Packets transmitted") \ 50 _(TIMER, "Timer events") \ 51 _(NO_BUFFER, "Out of buffers") 55 #define _(sym,str) SESSION_QUEUE_ERROR_##sym, 62 #define _(sym,string) string, 78 u32 left_from_seg,
u32 * left_to_snd0,
79 u16 * n_bufs,
u32 * tx_offset,
u16 deq_per_buf,
83 u32 chain_bi0, to_deq;
84 u16 len_to_deq0, n_bytes_read;
92 to_deq = left_from_seg;
93 for (j = 1; j < n_bufs_per_seg; j++)
96 len_to_deq0 =
clib_min (to_deq, deq_per_buf);
99 chain_bi0 = smm->tx_buffers[thread_index][*n_bufs];
100 _vec_len (smm->tx_buffers[thread_index]) = *n_bufs;
107 n_bytes_read =
svm_fifo_peek (fifo, *tx_offset, len_to_deq0, data0);
108 *tx_offset += n_bytes_read;
114 ASSERT (n_bytes_read == len_to_deq0);
125 to_deq -= n_bytes_read;
131 *left_to_snd0 -= left_from_seg;
137 session_fifo_event_t * e0,
139 int *n_tx_packets,
u8 peek_data)
142 u32 left_to_snd0, max_len_to_snd0, len_to_deq0, snd_space0;
143 u32 n_bufs_per_evt, n_frames_per_evt, n_bufs_per_frame;
146 u32 next_index, next0, *to_next, n_left_to_next, bi0;
148 u32 tx_offset = 0, max_dequeue0, n_bytes_per_seg, left_for_seg;
149 u16 snd_mss0, n_bufs_per_seg, n_bufs;
152 u32 n_bytes_per_buf, deq_per_buf, deq_per_first_buf;
153 u32 buffers_allocated, buffers_allocated_this_call;
158 tc0 = transport_vft->get_connection (s0->connection_index, thread_index);
161 snd_mss0 = transport_vft->send_mss (tc0);
162 snd_space0 = transport_vft->send_space (tc0);
165 if (snd_space0 == 0 || snd_mss0 == 0)
167 vec_add1 (smm->pending_event_vector[thread_index], *e0);
177 tx_offset = transport_vft->tx_fifo_offset (tc0);
181 max_dequeue0 -= tx_offset;
185 if (max_dequeue0 == 0)
192 if (max_dequeue0 < snd_space0)
195 max_len_to_snd0 = (max_dequeue0 > snd_mss0) ?
196 max_dequeue0 - max_dequeue0 % snd_mss0 : max_dequeue0;
202 max_len_to_snd0 = snd_space0;
209 n_bufs_per_seg = ceil ((
double) n_bytes_per_seg / n_bytes_per_buf);
210 n_bufs_per_evt = ceil ((
double) max_len_to_snd0 / n_bytes_per_seg);
214 deq_per_buf =
clib_min (snd_mss0, n_bytes_per_buf);
217 n_bufs =
vec_len (smm->tx_buffers[thread_index]);
218 left_to_snd0 = max_len_to_snd0;
219 for (i = 0; i < n_frames_per_evt; i++)
225 n_bufs + n_bufs_per_frame - 1);
226 buffers_allocated = 0;
237 buffers_allocated += buffers_allocated_this_call;
239 while (buffers_allocated_this_call > 0
240 && ((buffers_allocated + n_bufs < n_bufs_per_frame)));
242 n_bufs += buffers_allocated;
243 _vec_len (smm->tx_buffers[thread_index]) = n_bufs;
247 vec_add1 (smm->pending_event_vector[thread_index], *e0);
250 ASSERT (n_bufs >= n_bufs_per_frame);
256 while (left_to_snd0 && n_left_to_next)
264 bi0 = smm->tx_buffers[thread_index][--n_bufs];
265 _vec_len (smm->tx_buffers[thread_index]) = n_bufs;
274 b0->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
278 len_to_deq0 =
clib_min (left_to_snd0, deq_per_first_buf);
284 if (n_bytes_read <= 0)
288 tx_offset += n_bytes_read;
294 if (n_bytes_read <= 0)
300 left_to_snd0 -= n_bytes_read;
301 *n_tx_packets = *n_tx_packets + 1;
308 left_for_seg =
clib_min (snd_mss0 - n_bytes_read, left_to_snd0);
310 s0->server_tx_fifo, b0, bi0,
311 n_bufs_per_seg, left_for_seg,
312 &left_to_snd0, &n_bufs, &tx_offset,
313 deq_per_buf, peek_data);
318 transport_vft->push_header (tc0, b0);
322 ed->data[0] = e0->event_id;
323 ed->data[1] = max_dequeue0;
324 ed->data[2] = len_to_deq0;
325 ed->data[3] = left_to_snd0;
345 to_next, n_left_to_next,
352 if (max_len_to_snd0 < max_dequeue0)
357 vec_add1 (smm->pending_event_vector[thread_index], *e0);
371 vec_add1 (smm->pending_event_vector[thread_index], *e0);
374 _vec_len (smm->tx_buffers[thread_index]) += 1;
382 session_fifo_event_t * e0,
393 session_fifo_event_t * e0,
414 session_fifo_event_t _e, *e = &_e;
420 q = smm->vpp_event_queues[my_thread_index];
424 for (i = 0; i < q->cursize; i++)
426 headp = (
i8 *) (&q->data[0] + q->elsize * index);
429 switch (e->event_type)
433 fformat (stdout,
"[%04d] TX session %d\n", i, s0->session_index);
438 fformat (stdout,
"[%04d] disconnect session %d\n", i,
444 fformat (stdout,
"[%04d] builtin_rx %d\n", i, s0->session_index);
448 fformat (stdout,
"[%04d] RPC call %llx with %llx\n",
449 i, (
u64) (e->rpc_args.fp), (
u64) (e->rpc_args.arg));
453 fformat (stdout,
"[%04d] unhandled event type %d\n",
460 if (index == q->maxsize)
469 switch (e->event_type)
486 if (s->server_rx_fifo == f || s->server_tx_fifo == f)
500 session_fifo_event_t *pending_event_vector, *evt;
501 int i, index, found = 0;
506 thread_index = f->master_thread_index;
510 q = smm->vpp_event_queues[thread_index];
512 for (i = 0; i < q->cursize; i++)
514 headp = (
i8 *) (&q->data[0] + q->elsize * index);
519 if (++index == q->maxsize)
525 pending_event_vector = smm->pending_event_vector[thread_index];
543 session_fifo_event_t *my_pending_event_vector, *e;
544 session_fifo_event_t *my_fifo_events;
545 u32 n_to_dequeue, n_events;
548 int n_tx_packets = 0;
564 q = smm->vpp_event_queues[my_thread_index];
568 my_fifo_events = smm->free_event_vector[my_thread_index];
571 n_to_dequeue = q->cursize;
572 my_pending_event_vector = smm->pending_event_vector[my_thread_index];
574 if (n_to_dequeue == 0 &&
vec_len (my_pending_event_vector) == 0)
584 if (0 &&
vec_len (my_pending_event_vector) >= 100)
591 if (pthread_mutex_trylock (&q->mutex))
594 for (i = 0; i < n_to_dequeue; i++)
601 if (q->cursize < (q->maxsize / 8))
602 (void) pthread_cond_broadcast (&q->condvar);
603 pthread_mutex_unlock (&q->mutex);
605 vec_append (my_fifo_events, my_pending_event_vector);
607 _vec_len (my_pending_event_vector) = 0;
608 smm->pending_event_vector[my_thread_index] = my_pending_event_vector;
611 n_events =
vec_len (my_fifo_events);
612 for (i = 0; i < n_events; i++)
615 session_fifo_event_t *e0;
617 e0 = &my_fifo_events[
i];
619 switch (e0->event_type)
635 rv = (smm->session_tx_fns[s0->session_type]) (vm, node, smm, e0, s0,
642 SESSION_QUEUE_ERROR_NO_BUFFER, 1);
656 app->cb_fns.builtin_server_rx_callback (s0);
659 fp = e0->rpc_args.fp;
660 (*fp) (e0->rpc_args.arg);
664 clib_warning (
"unhandled event type %d", e0->event_type);
668 _vec_len (my_fifo_events) = 0;
669 smm->free_event_vector[my_thread_index] = my_fifo_events;
672 SESSION_QUEUE_ERROR_TX, n_tx_packets);
683 .name =
"session-queue",
689 .state = VLIB_NODE_STATE_DISABLED,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
vlib_main_t vlib_global_main
sll srl srl sll sra u16x4 i
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
struct _transport_connection transport_connection_t
static f64 vlib_time_now(vlib_main_t *vm)
struct _transport_proto_vft transport_proto_vft_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct _vlib_node_registration vlib_node_registration_t
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static uword session_queue_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
struct _svm_fifo svm_fifo_t
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
static int session_tx_fifo_read_and_snd_i(vlib_main_t *vm, vlib_node_runtime_t *node, session_manager_main_t *smm, session_fifo_event_t *e0, stream_session_t *s0, u32 thread_index, int *n_tx_packets, u8 peek_data)
void dump_thread_0_event_queue(void)
#define VLIB_BUFFER_NEXT_PRESENT
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
struct _stream_session_t stream_session_t
static char * session_queue_error_strings[]
static session_manager_main_t * vnet_get_session_manager_main()
u16 current_length
Nbytes between current data and the end of this buffer.
static void * vlib_buffer_make_headroom(vlib_buffer_t *b, u8 size)
Make head room, typically for packet headers.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
int session_tx_fifo_peek_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_manager_main_t *smm, session_fifo_event_t *e0, stream_session_t *s0, u32 thread_index, int *n_tx_pkts)
static u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, u32 free_list_index)
static void svm_fifo_unset_event(svm_fifo_t *f)
Unsets fifo event flag.
int unix_shared_memory_queue_sub_raw(unix_shared_memory_queue_t *q, u8 *elem)
u32 node_index
Node index.
struct _session_manager_main session_manager_main_t
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static u8 svm_fifo_set_event(svm_fifo_t *f)
Sets fifo event flag.
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define SESSION_EVT_DBG(_evt, _args...)
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
#define VLIB_BUFFER_TRACE_TRAJECTORY
Compile time buffer trajectory tracing option Turn this on if you run into "bad monkey" contexts...
struct _application application_t
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
static stream_session_t * stream_session_get_if_valid(u64 si, u32 thread_index)
#define foreach_session_queue_error
static u8 session_node_cmp_event(session_fifo_event_t *e, svm_fifo_t *f)
u32 next_buffer
Next buffer for this linked-list of buffers.
#define vec_append(v1, v2)
Append v2 after v1.
void stream_session_disconnect(stream_session_t *s)
Disconnect session and propagate to transport.
static stream_session_t * session_event_get_session(session_fifo_event_t *e, u8 thread_index)
static u8 * format_session_queue_trace(u8 *s, va_list *args)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
int session_tx_fifo_dequeue_and_snd(vlib_main_t *vm, vlib_node_runtime_t *node, session_manager_main_t *smm, session_fifo_event_t *e0, stream_session_t *s0, u32 thread_index, int *n_tx_pkts)
static u32 session_type_to_next[]
static void tcp_update_time(f64 now, u32 thread_index)
transport_proto_vft_t * session_get_transport_vft(u8 session_type)
Get transport virtual function table.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
application_t * application_get(u32 index)
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
#define VLIB_REGISTER_NODE(x,...)
#define vec_foreach(var, vec)
Vector iterator.
static void session_tx_fifo_chain_tail(session_manager_main_t *smm, vlib_main_t *vm, u8 thread_index, svm_fifo_t *fifo, vlib_buffer_t *b0, u32 bi0, u8 n_bufs_per_seg, u32 left_from_seg, u32 *left_to_snd0, u16 *n_bufs, u32 *tx_offset, u16 deq_per_buf, u8 peek_data)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
u8 session_node_lookup_fifo_event(svm_fifo_t *f, session_fifo_event_t *e)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static stream_session_t * stream_session_get_from_handle(u64 handle)
struct _unix_shared_memory_queue unix_shared_memory_queue_t