X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsession_node.c;h=04a5622c835d522a072d0dc999893ebf5386da7e;hb=5a7ca7bde104b12f8dc4a751fd911819d4bd6c8e;hp=f5aed7490eabb34a2aaf4b9ead9321f049c5163c;hpb=2179513b71963a0b42ca6f1f2b641e79ce89447b;p=vpp.git diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c index f5aed7490ea..04a5622c835 100644 --- a/src/vnet/session/session_node.c +++ b/src/vnet/session/session_node.c @@ -159,7 +159,7 @@ session_mq_disconnected_handler (void *data) SVM_Q_WAIT, msg); svm_msg_q_unlock (app_wrk->event_queue); evt = svm_msg_q_msg_data (app_wrk->event_queue, msg); - memset (evt, 0, sizeof (*evt)); + clib_memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; rmp = (session_disconnected_reply_msg_t *) evt->data; rmp->handle = mp->handle; @@ -265,12 +265,13 @@ always_inline void session_tx_fifo_chain_tail (vlib_main_t * vm, session_tx_context_t * ctx, vlib_buffer_t * b, u16 * n_bufs, u8 peek_data) { - session_manager_main_t *smm = &session_manager_main; vlib_buffer_t *chain_b, *prev_b; u32 chain_bi0, to_deq, left_from_seg; + session_manager_worker_t *wrk; u16 len_to_deq, n_bytes_read; u8 *data, j; + wrk = session_manager_get_worker (ctx->s->thread_index); b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID; b->total_length_not_including_first_buffer = 0; @@ -284,8 +285,8 @@ session_tx_fifo_chain_tail (vlib_main_t * vm, session_tx_context_t * ctx, len_to_deq = clib_min (to_deq, ctx->deq_per_buf); *n_bufs -= 1; - chain_bi0 = smm->tx_buffers[ctx->s->thread_index][*n_bufs]; - _vec_len (smm->tx_buffers[ctx->s->thread_index]) = *n_bufs; + chain_bi0 = wrk->tx_buffers[*n_bufs]; + _vec_len (wrk->tx_buffers) = *n_bufs; chain_b = vlib_get_buffer (vm, chain_bi0); chain_b->current_data = 0; @@ -342,16 +343,15 @@ session_tx_fifo_chain_tail (vlib_main_t * vm, session_tx_context_t * ctx, always_inline int session_output_try_get_buffers (vlib_main_t * vm, - session_manager_main_t * smm, + session_manager_worker_t * wrk, u32 thread_index, u16 * n_bufs, u32 wanted) { u32 n_alloc; - vec_validate_aligned (smm->tx_buffers[thread_index], wanted - 1, - CLIB_CACHE_LINE_BYTES); - n_alloc = vlib_buffer_alloc (vm, &smm->tx_buffers[thread_index][*n_bufs], + vec_validate_aligned (wrk->tx_buffers, wanted - 1, CLIB_CACHE_LINE_BYTES); + n_alloc = vlib_buffer_alloc (vm, &wrk->tx_buffers[*n_bufs], wanted - *n_bufs); *n_bufs += n_alloc; - _vec_len (smm->tx_buffers[thread_index]) = *n_bufs; + _vec_len (wrk->tx_buffers) = *n_bufs; return n_alloc; } @@ -548,7 +548,8 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, u32 n_trace = vlib_get_trace_count (vm, node), n_bufs_needed = 0; u32 thread_index = s->thread_index, n_left, pbi; session_manager_main_t *smm = &session_manager_main; - session_tx_context_t *ctx = &smm->ctx[thread_index]; + session_manager_worker_t *wrk = &smm->wrk[thread_index]; + session_tx_context_t *ctx = &wrk->ctx; transport_proto_t tp; vlib_buffer_t *pb; u16 n_bufs, rv; @@ -556,7 +557,7 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, if (PREDICT_FALSE ((rv = session_tx_not_ready (s, peek_data)))) { if (rv < 2) - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); return SESSION_TX_NO_DATA; } @@ -568,10 +569,11 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, ctx->transport_vft = transport_protocol_get_vft (tp); ctx->tc = session_tx_get_transport (ctx, peek_data); ctx->snd_mss = ctx->transport_vft->send_mss (ctx->tc); - ctx->snd_space = ctx->transport_vft->send_space (ctx->tc); + ctx->snd_space = + transport_connection_max_tx_burst (ctx->tc, vm->clib_time.last_cpu_time); if (ctx->snd_space == 0 || ctx->snd_mss == 0) { - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); return SESSION_TX_NO_DATA; } @@ -585,7 +587,7 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, if (PREDICT_FALSE (!ctx->max_len_to_snd)) return SESSION_TX_NO_DATA; - n_bufs = vec_len (smm->tx_buffers[thread_index]); + n_bufs = vec_len (wrk->tx_buffers); n_bufs_needed = ctx->n_segs_per_evt * ctx->n_bufs_per_seg; /* @@ -593,11 +595,11 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, */ if (n_bufs < n_bufs_needed) { - session_output_try_get_buffers (vm, smm, thread_index, &n_bufs, + session_output_try_get_buffers (vm, wrk, thread_index, &n_bufs, ctx->n_bufs_per_seg * VLIB_FRAME_SIZE); if (PREDICT_FALSE (n_bufs < n_bufs_needed)) { - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); return SESSION_TX_NO_BUFFERS; } } @@ -619,15 +621,15 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_buffer_t *b0, *b1; u32 bi0, bi1; - pbi = smm->tx_buffers[thread_index][n_bufs - 3]; + pbi = wrk->tx_buffers[n_bufs - 3]; pb = vlib_get_buffer (vm, pbi); vlib_prefetch_buffer_header (pb, STORE); - pbi = smm->tx_buffers[thread_index][n_bufs - 4]; + pbi = wrk->tx_buffers[n_bufs - 4]; pb = vlib_get_buffer (vm, pbi); vlib_prefetch_buffer_header (pb, STORE); - to_next[0] = bi0 = smm->tx_buffers[thread_index][--n_bufs]; - to_next[1] = bi1 = smm->tx_buffers[thread_index][--n_bufs]; + to_next[0] = bi0 = wrk->tx_buffers[--n_bufs]; + to_next[1] = bi1 = wrk->tx_buffers[--n_bufs]; b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); @@ -656,12 +658,12 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, if (n_left > 1) { - pbi = smm->tx_buffers[thread_index][n_bufs - 2]; + pbi = wrk->tx_buffers[n_bufs - 2]; pb = vlib_get_buffer (vm, pbi); vlib_prefetch_buffer_header (pb, STORE); } - to_next[0] = bi0 = smm->tx_buffers[thread_index][--n_bufs]; + to_next[0] = bi0 = wrk->tx_buffers[--n_bufs]; b0 = vlib_get_buffer (vm, bi0); session_tx_fill_buffer (vm, ctx, b0, &n_bufs, peek_data); @@ -683,15 +685,16 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, session_tx_trace_frame (vm, node, next_index, to_next, ctx->n_segs_per_evt, s, n_trace); - _vec_len (smm->tx_buffers[thread_index]) = n_bufs; + _vec_len (wrk->tx_buffers) = n_bufs; *n_tx_packets += ctx->n_segs_per_evt; + transport_connection_update_tx_stats (ctx->tc, ctx->max_len_to_snd); vlib_put_next_frame (vm, node, next_index, n_left_to_next); /* If we couldn't dequeue all bytes mark as partially read */ ASSERT (ctx->left_to_snd == 0); if (ctx->max_len_to_snd < ctx->max_dequeue) if (svm_fifo_set_event (s->server_tx_fifo)) - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM) { @@ -702,7 +705,7 @@ session_tx_fifo_read_and_snd_i (vlib_main_t * vm, vlib_node_runtime_t * node, /* More data needs to be read */ else if (svm_fifo_max_dequeue (s->server_tx_fifo) > 0) if (svm_fifo_set_event (s->server_tx_fifo)) - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); } return SESSION_TX_OK; } @@ -730,6 +733,8 @@ session_tx_fifo_dequeue_internal (vlib_main_t * vm, stream_session_t * s, int *n_tx_pkts) { application_t *app; + if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED)) + return 0; app = application_get (s->t_app_index); svm_fifo_unset_event (s->server_tx_fifo); return app->cb_fns.builtin_app_tx_callback (s); @@ -741,12 +746,24 @@ session_event_get_session (session_event_t * e, u8 thread_index) return session_get_if_valid (e->fifo->master_session_index, thread_index); } +static void +session_update_dispatch_period (session_manager_worker_t * wrk, f64 now, + u32 thread_index) +{ + f64 sample, prev_period = wrk->dispatch_period, a = 0.8; + + sample = now - wrk->last_vlib_time; + wrk->dispatch_period = a * sample + (1 - a) * prev_period; + wrk->last_vlib_time = now; +} + static uword session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { session_manager_main_t *smm = vnet_get_session_manager_main (); u32 thread_index = vm->thread_index, n_to_dequeue, n_events; + session_manager_worker_t *wrk = &smm->wrk[thread_index]; session_event_t *pending_events, *e; session_event_t *fifo_events; svm_msg_q_msg_t _msg, *msg = &_msg; @@ -762,18 +779,19 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* * Update transport time */ + session_update_dispatch_period (wrk, now, thread_index); transport_update_time (now, thread_index); /* * Get vpp queue events that we can dequeue without blocking */ - mq = smm->vpp_event_queues[thread_index]; - fifo_events = smm->free_event_vector[thread_index]; + mq = wrk->vpp_event_queue; + fifo_events = wrk->free_event_vector; n_to_dequeue = svm_msg_q_size (mq); - pending_events = smm->pending_event_vector[thread_index]; + pending_events = wrk->pending_event_vector; if (!n_to_dequeue && !vec_len (pending_events) - && !vec_len (smm->pending_disconnects[thread_index])) + && !vec_len (wrk->pending_disconnects)) return 0; SESSION_EVT_DBG (SESSION_EVT_DEQ_NODE, 0); @@ -805,11 +823,11 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, svm_msg_q_unlock (mq); vec_append (fifo_events, pending_events); - vec_append (fifo_events, smm->pending_disconnects[thread_index]); + vec_append (fifo_events, wrk->pending_disconnects); _vec_len (pending_events) = 0; - smm->pending_event_vector[thread_index] = pending_events; - _vec_len (smm->pending_disconnects[thread_index]) = 0; + wrk->pending_event_vector = pending_events; + _vec_len (wrk->pending_disconnects) = 0; skip_dequeue: n_events = vec_len (fifo_events); @@ -817,7 +835,7 @@ skip_dequeue: { stream_session_t *s; /* $$$ prefetch 1 ahead maybe */ session_event_t *e; - u8 is_full; + u8 want_tx_evt; e = &fifo_events[i]; switch (e->event_type) @@ -826,28 +844,29 @@ skip_dequeue: /* Don't try to send more that one frame per dispatch cycle */ if (n_tx_packets == VLIB_FRAME_SIZE) { - vec_add1 (smm->pending_event_vector[thread_index], *e); + vec_add1 (wrk->pending_event_vector, *e); break; } s = session_event_get_session (e, thread_index); if (PREDICT_FALSE (!s)) { - clib_warning ("It's dead, Jim!"); + clib_warning ("session was freed!"); continue; } - is_full = svm_fifo_is_full (s->server_tx_fifo); + want_tx_evt = svm_fifo_want_tx_evt (s->server_tx_fifo); /* Spray packets in per session type frames, since they go to * different nodes */ rv = (smm->session_tx_fns[s->session_type]) (vm, node, e, s, &n_tx_packets); if (PREDICT_TRUE (rv == SESSION_TX_OK)) { - /* Notify app there's tx space if not polling */ - if (PREDICT_FALSE (is_full - && !svm_fifo_has_event (s->server_tx_fifo))) - session_dequeue_notify (s); + if (PREDICT_FALSE (want_tx_evt)) + { + svm_fifo_set_want_tx_evt (s->server_tx_fifo, 0); + session_dequeue_notify (s); + } } else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS)) { @@ -863,13 +882,13 @@ skip_dequeue: if (!e->postponed) { e->postponed = 1; - vec_add1 (smm->pending_disconnects[thread_index], *e); + vec_add1 (wrk->pending_disconnects, *e); continue; } /* If tx queue is still not empty, wait */ if (svm_fifo_max_dequeue (s->server_tx_fifo)) { - vec_add1 (smm->pending_disconnects[thread_index], *e); + vec_add1 (wrk->pending_disconnects, *e); continue; } @@ -877,13 +896,18 @@ skip_dequeue: break; case FIFO_EVENT_BUILTIN_RX: s = session_event_get_session (e, thread_index); - if (PREDICT_FALSE (!s)) + if (PREDICT_FALSE (!s || s->session_state >= SESSION_STATE_CLOSING)) continue; svm_fifo_unset_event (s->server_rx_fifo); app_wrk = app_worker_get (s->app_wrk_index); app = application_get (app_wrk->app_index); app->cb_fns.builtin_app_rx_callback (s); break; + case FIFO_EVENT_BUILTIN_TX: + s = session_get_from_handle_if_valid (e->session_handle); + if (PREDICT_TRUE (s != 0)) + session_tx_fifo_dequeue_internal (vm, node, e, s, &n_tx_packets); + break; case FIFO_EVENT_RPC: fp = e->rpc_args.fp; (*fp) (e->rpc_args.arg); @@ -908,7 +932,7 @@ skip_dequeue: } _vec_len (fifo_events) = 0; - smm->free_event_vector[thread_index] = fifo_events; + wrk->free_event_vector = fifo_events; vlib_node_increment_counter (vm, session_queue_node.index, SESSION_QUEUE_ERROR_TX, n_tx_packets); @@ -944,7 +968,7 @@ dump_thread_0_event_queue (void) svm_msg_q_t *mq; int i, index; - mq = smm->vpp_event_queues[my_thread_index]; + mq = smm->wrk[my_thread_index].vpp_event_queue; index = mq->q->head; for (i = 0; i < mq->q->cursize; i++) @@ -1022,20 +1046,22 @@ session_node_cmp_event (session_event_t * e, svm_fifo_t * f) u8 session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e) { - session_manager_main_t *smm = vnet_get_session_manager_main (); - svm_msg_q_t *mq; session_event_t *pending_event_vector, *evt; + session_manager_worker_t *wrk; int i, index, found = 0; svm_msg_q_msg_t *msg; svm_msg_q_ring_t *ring; + svm_msg_q_t *mq; u8 thread_index; ASSERT (e); thread_index = f->master_thread_index; + wrk = session_manager_get_worker (thread_index); + /* * Search evt queue */ - mq = smm->vpp_event_queues[thread_index]; + mq = wrk->vpp_event_queue; index = mq->q->head; for (i = 0; i < mq->q->cursize; i++) { @@ -1051,7 +1077,7 @@ session_node_lookup_fifo_event (svm_fifo_t * f, session_event_t * e) /* * Search pending events vector */ - pending_event_vector = smm->pending_event_vector[thread_index]; + pending_event_vector = wrk->pending_event_vector; vec_foreach (evt, pending_event_vector) { found = session_node_cmp_event (evt, f);