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_to_snd0,
u16 * n_bufs,
u32 * rx_offset,
79 u16 deq_per_buf,
u8 peek_data)
83 u16 len_to_deq0, n_bytes_read;
88 for (j = 1; j < n_bufs_per_seg; j++)
91 len_to_deq0 =
clib_min (*left_to_snd0, deq_per_buf);
94 chain_bi0 = smm->tx_buffers[thread_index][*n_bufs];
95 _vec_len (smm->tx_buffers[thread_index]) = *n_bufs;
102 n_bytes_read =
svm_fifo_peek (fifo, *rx_offset, len_to_deq0, data0);
103 *rx_offset += n_bytes_read;
109 ASSERT (n_bytes_read == len_to_deq0);
120 *left_to_snd0 -= n_bytes_read;
121 if (*left_to_snd0 == 0)
129 session_fifo_event_t * e0,
131 int *n_tx_packets,
u8 peek_data)
134 u32 left_to_snd0, max_len_to_snd0, len_to_deq0, snd_space0;
135 u32 n_bufs_per_evt, n_frames_per_evt;
138 u32 next_index, next0, *to_next, n_left_to_next, bi0;
140 u32 rx_offset = 0, max_dequeue0, n_bytes_per_seg;
141 u16 snd_mss0, n_bufs_per_seg, n_bufs;
144 u32 n_bytes_per_buf, deq_per_buf;
145 u32 buffers_allocated, buffers_allocated_this_call;
150 tc0 = transport_vft->get_connection (s0->connection_index, thread_index);
153 snd_mss0 = transport_vft->send_mss (tc0);
154 snd_space0 = transport_vft->send_space (tc0);
157 if (snd_space0 == 0 || snd_mss0 == 0)
159 vec_add1 (smm->pending_event_vector[thread_index], *e0);
166 rx_offset = transport_vft->tx_fifo_offset (tc0);
173 if (max_dequeue0 == 0)
180 if (max_dequeue0 < snd_space0)
183 max_len_to_snd0 = (max_dequeue0 > snd_mss0) ?
184 max_dequeue0 - max_dequeue0 % snd_mss0 : max_dequeue0;
189 max_len_to_snd0 = snd_space0;
195 n_bufs_per_seg = ceil ((
double) n_bytes_per_seg / n_bytes_per_buf);
196 n_bufs_per_evt = (ceil ((
double) max_len_to_snd0 / n_bytes_per_seg))
200 deq_per_buf =
clib_min (snd_mss0, n_bytes_per_buf);
202 n_bufs =
vec_len (smm->tx_buffers[thread_index]);
203 left_to_snd0 = max_len_to_snd0;
204 for (i = 0; i < n_frames_per_evt; i++)
212 buffers_allocated = 0;
215 buffers_allocated_this_call =
218 &smm->tx_buffers[thread_index][n_bufs + buffers_allocated],
220 buffers_allocated += buffers_allocated_this_call;
222 while (buffers_allocated_this_call > 0
225 n_bufs += buffers_allocated;
227 _vec_len (smm->tx_buffers[thread_index]) = n_bufs;
231 vec_add1 (smm->pending_event_vector[thread_index], *e0);
239 while (left_to_snd0 && n_left_to_next >= n_bufs_per_seg)
247 bi0 = smm->tx_buffers[thread_index][--n_bufs];
249 _vec_len (smm->tx_buffers[thread_index]) = n_bufs;
263 len_to_deq0 =
clib_min (left_to_snd0, deq_per_buf);
272 rx_offset += n_bytes_read;
280 if (n_bytes_read <= 0)
285 left_to_snd0 -= n_bytes_read;
286 *n_tx_packets = *n_tx_packets + 1;
293 s0->server_tx_fifo, b0, bi0,
294 n_bufs_per_seg, &left_to_snd0,
295 &n_bufs, &rx_offset, deq_per_buf,
300 transport_vft->push_header (tc0, b0);
304 ed->data[0] = e0->event_id;
305 ed->data[1] = max_dequeue0;
306 ed->data[2] = len_to_deq0;
307 ed->data[3] = left_to_snd0;
325 to_next, n_left_to_next,
332 if (max_len_to_snd0 < max_dequeue0)
337 vec_add1 (smm->pending_event_vector[thread_index], *e0);
351 vec_add1 (smm->pending_event_vector[thread_index], *e0);
354 _vec_len (smm->tx_buffers[thread_index]) += 1;
362 session_fifo_event_t * e0,
373 session_fifo_event_t * e0,
389 session_index0 = f0->master_session_index;
392 ASSERT (f0->master_thread_index == thread_index);
396 ASSERT (s0 == 0 || s0->thread_index == thread_index);
407 session_fifo_event_t _e, *e = &_e;
413 q = smm->vpp_event_queues[my_thread_index];
417 for (i = 0; i < q->cursize; i++)
419 headp = (
i8 *) (&q->data[0] + q->elsize * index);
422 switch (e->event_type)
426 fformat (stdout,
"[%04d] TX session %d\n", i, s0->session_index);
431 fformat (stdout,
"[%04d] disconnect session %d\n", i,
437 fformat (stdout,
"[%04d] builtin_rx %d\n", i, s0->session_index);
441 fformat (stdout,
"[%04d] RPC call %llx with %llx\n",
442 i, (
u64) (e->rpc_args.fp), (
u64) (e->rpc_args.arg));
446 fformat (stdout,
"[%04d] unhandled event type %d\n",
453 if (index == q->maxsize)
463 session_fifo_event_t *my_pending_event_vector, *e;
464 session_fifo_event_t *my_fifo_events;
465 u32 n_to_dequeue, n_events;
468 int n_tx_packets = 0;
484 q = smm->vpp_event_queues[my_thread_index];
488 my_fifo_events = smm->free_event_vector[my_thread_index];
491 n_to_dequeue = q->cursize;
492 my_pending_event_vector = smm->pending_event_vector[my_thread_index];
494 if (n_to_dequeue == 0 &&
vec_len (my_pending_event_vector) == 0)
504 if (0 &&
vec_len (my_pending_event_vector) >= 100)
511 if (pthread_mutex_trylock (&q->mutex))
514 for (i = 0; i < n_to_dequeue; i++)
521 if (q->cursize < (q->maxsize / 8))
522 (void) pthread_cond_broadcast (&q->condvar);
523 pthread_mutex_unlock (&q->mutex);
525 vec_append (my_fifo_events, my_pending_event_vector);
527 _vec_len (my_pending_event_vector) = 0;
528 smm->pending_event_vector[my_thread_index] = my_pending_event_vector;
531 n_events =
vec_len (my_fifo_events);
532 for (i = 0; i < n_events; i++)
535 session_fifo_event_t *e0;
537 e0 = &my_fifo_events[
i];
539 switch (e0->event_type)
544 if (CLIB_DEBUG && !s0)
554 rv = (smm->session_tx_fns[s0->session_type]) (vm, node, smm, e0, s0,
561 SESSION_QUEUE_ERROR_NO_BUFFER, 1);
574 app->cb_fns.builtin_server_rx_callback (s0);
577 fp = e0->rpc_args.fp;
578 (*fp) (e0->rpc_args.arg);
582 clib_warning (
"unhandled event type %d", e0->event_type);
586 _vec_len (my_fifo_events) = 0;
587 smm->free_event_vector[my_thread_index] = my_fifo_events;
590 SESSION_QUEUE_ERROR_TX, n_tx_packets);
601 .name =
"session-queue",
607 .state = VLIB_NODE_STATE_DISABLED,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
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)
static u32 session_type_to_next[]
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.
#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.
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)
struct _stream_session_t stream_session_t
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)
#define VLIB_BUFFER_NEXT_PRESENT
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
stream_session_t * session_event_get_session(session_fifo_event_t *e0, u8 thread_index)
static char * session_queue_error_strings[]
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
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_to_snd0, u16 *n_bufs, u32 *rx_offset, u16 deq_per_buf, u8 peek_data)
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
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)
struct _transport_proto_vft transport_proto_vft_t
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.
vlib_main_t vlib_global_main
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
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 foreach_session_queue_error
#define VNET_BUFFER_LOCALLY_ORIGINATED
void dump_thread_0_event_queue(void)
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
struct _application application_t
static stream_session_t * stream_session_get_if_valid(u64 si, u32 thread_index)
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.
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
transport_proto_vft_t * session_get_transport_vft(u8 type)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
static void tcp_update_time(f64 now, u32 thread_index)
#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)
#define VLIB_REGISTER_NODE(x,...)
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)
static u8 * format_session_queue_trace(u8 *s, va_list *args)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
u32 flags
buffer flags: 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 uword session_queue_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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