diff options
author | Damjan Marion <damarion@cisco.com> | 2018-07-19 17:52:31 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2018-07-19 18:26:01 +0000 |
commit | 4d56e059f78b991cb19ec4e5cf4a07a5607a0642 (patch) | |
tree | be16195b2caf692762cee9d1f7c8c00f53569d79 /src | |
parent | a17158b8723ea9b0e553821dde338969290d33e7 (diff) |
Cleanup of handoff code
- removed handoff-dispatch node
- removed some unused buffer metadata fields
- enqueue to thread logic moved to inline function
Change-Id: I7361e1d88f8cce74cd4fcec90d172eade1855cbd
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vlib/buffer_node.h | 86 | ||||
-rw-r--r-- | src/vnet/buffer.h | 15 | ||||
-rw-r--r-- | src/vnet/feature/feature.h | 14 | ||||
-rw-r--r-- | src/vnet/handoff.c | 322 | ||||
-rw-r--r-- | src/vnet/handoff.h | 11 | ||||
-rw-r--r-- | src/vnet/pg/input.c | 3 |
6 files changed, 110 insertions, 341 deletions
diff --git a/src/vlib/buffer_node.h b/src/vlib/buffer_node.h index c9f4895c739..cfdb0567a0c 100644 --- a/src/vlib/buffer_node.h +++ b/src/vlib/buffer_node.h @@ -443,6 +443,92 @@ vlib_buffer_enqueue_to_next (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_put_next_frame (vm, node, next_index, n_left_to_next); } +static_always_inline void +vlib_buffer_enqueue_to_thread (vlib_main_t * vm, u32 frame_queue_index, + u32 * buffer_indices, u16 * thread_indices, + u32 n_left) +{ + vlib_thread_main_t *tm = vlib_get_thread_main (); + static __thread vlib_frame_queue_elt_t **handoff_queue_elt_by_thread_index = + 0; + static __thread vlib_frame_queue_t **congested_handoff_queue_by_thread_index + = 0; + vlib_frame_queue_elt_t *hf = 0; + u32 n_left_to_next_thread = 0, *to_next_thread = 0; + u32 next_thread_index, current_thread_index = ~0; + int i; + + if (PREDICT_FALSE (handoff_queue_elt_by_thread_index == 0)) + { + vec_validate (handoff_queue_elt_by_thread_index, tm->n_vlib_mains - 1); + vec_validate_init_empty (congested_handoff_queue_by_thread_index, + tm->n_vlib_mains - 1, + (vlib_frame_queue_t *) (~0)); + } + + while (n_left) + { + next_thread_index = thread_indices[0]; + + if (next_thread_index != current_thread_index) + { + if (hf) + hf->n_vectors = VLIB_FRAME_SIZE - n_left_to_next_thread; + + hf = vlib_get_worker_handoff_queue_elt (frame_queue_index, + next_thread_index, + handoff_queue_elt_by_thread_index); + + n_left_to_next_thread = VLIB_FRAME_SIZE - hf->n_vectors; + to_next_thread = &hf->buffer_index[hf->n_vectors]; + current_thread_index = next_thread_index; + } + + to_next_thread[0] = buffer_indices[0]; + to_next_thread++; + n_left_to_next_thread--; + + if (n_left_to_next_thread == 0) + { + hf->n_vectors = VLIB_FRAME_SIZE; + vlib_put_frame_queue_elt (hf); + current_thread_index = ~0; + handoff_queue_elt_by_thread_index[next_thread_index] = 0; + hf = 0; + } + + /* next */ + thread_indices += 1; + buffer_indices += 1; + n_left -= 1; + } + + if (hf) + hf->n_vectors = VLIB_FRAME_SIZE - n_left_to_next_thread; + + /* Ship frames to the thread nodes */ + for (i = 0; i < vec_len (handoff_queue_elt_by_thread_index); i++) + { + if (handoff_queue_elt_by_thread_index[i]) + { + hf = handoff_queue_elt_by_thread_index[i]; + /* + * It works better to let the handoff node + * rate-adapt, always ship the handoff queue element. + */ + if (1 || hf->n_vectors == hf->last_n_vectors) + { + vlib_put_frame_queue_elt (hf); + handoff_queue_elt_by_thread_index[i] = 0; + } + else + hf->last_n_vectors = hf->n_vectors; + } + congested_handoff_queue_by_thread_index[i] = + (vlib_frame_queue_t *) (~0); + } +} + #endif /* included_vlib_buffer_node_h */ /* diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h index 9d45c7ee354..b4ce9c79c87 100644 --- a/src/vnet/buffer.h +++ b/src/vnet/buffer.h @@ -51,7 +51,6 @@ _( 3, VLAN_2_DEEP, "vlan-2-deep") \ _( 4, VLAN_1_DEEP, "vlan-1-deep") \ _( 5, SPAN_CLONE, "span-clone") \ - _( 6, HANDOFF_NEXT_VALID, "handoff-next-valid") \ _( 7, LOCALLY_ORIGINATED, "local") \ _( 8, IS_IP4, "ip4") \ _( 9, IS_IP6, "ip6") \ @@ -88,7 +87,6 @@ _(ip) \ _(l2) \ _(l2t) \ _(l2_classify) \ -_(handoff) \ _(policer) \ _(ipsec) \ _(map) \ @@ -239,12 +237,6 @@ typedef struct u64 hash; } l2_classify; - /* IO - worker thread handoff */ - struct - { - u32 next_index; - } handoff; - /* vnet policer */ struct { @@ -304,13 +296,6 @@ typedef struct u16 overlay_afi; } lisp; - /* Driver rx feature */ - struct - { - u32 saved_next_index; /**< saved by drivers for short-cut */ - u16 buffer_advance; - } device_input_feat; - /* TCP */ struct { diff --git a/src/vnet/feature/feature.h b/src/vnet/feature/feature.h index 81224ebf0e2..66ee97c87d6 100644 --- a/src/vnet/feature/feature.h +++ b/src/vnet/feature/feature.h @@ -265,9 +265,7 @@ vnet_feature_start_device_input_x1 (u32 sw_if_index, u32 * next0, */ u16 adv; - vnet_buffer (b0)->device_input_feat.saved_next_index = *next0; adv = device_input_next_node_advance[*next0]; - vnet_buffer (b0)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b0, -adv); vnet_buffer (b0)->feature_arc_index = feature_arc_index; @@ -299,14 +297,10 @@ vnet_feature_start_device_input_x2 (u32 sw_if_index, */ u16 adv; - vnet_buffer (b0)->device_input_feat.saved_next_index = *next0; adv = device_input_next_node_advance[*next0]; - vnet_buffer (b0)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b0, -adv); - vnet_buffer (b1)->device_input_feat.saved_next_index = *next1; adv = device_input_next_node_advance[*next1]; - vnet_buffer (b1)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b1, -adv); vnet_buffer (b0)->feature_arc_index = feature_arc_index; @@ -346,24 +340,16 @@ vnet_feature_start_device_input_x4 (u32 sw_if_index, */ u16 adv; - vnet_buffer (b0)->device_input_feat.saved_next_index = *next0; adv = device_input_next_node_advance[*next0]; - vnet_buffer (b0)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b0, -adv); - vnet_buffer (b1)->device_input_feat.saved_next_index = *next1; adv = device_input_next_node_advance[*next1]; - vnet_buffer (b1)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b1, -adv); - vnet_buffer (b2)->device_input_feat.saved_next_index = *next2; adv = device_input_next_node_advance[*next2]; - vnet_buffer (b2)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b2, -adv); - vnet_buffer (b3)->device_input_feat.saved_next_index = *next3; adv = device_input_next_node_advance[*next3]; - vnet_buffer (b3)->device_input_feat.buffer_advance = adv; vlib_buffer_advance (b3, -adv); vnet_buffer (b0)->feature_arc_index = feature_arc_index; diff --git a/src/vnet/handoff.c b/src/vnet/handoff.c index 81cb9f55fba..11b877e500d 100644 --- a/src/vnet/handoff.c +++ b/src/vnet/handoff.c @@ -37,15 +37,10 @@ typedef struct /* Worker handoff index */ u32 frame_queue_index; - /* convenience variables */ - vlib_main_t *vlib_main; - vnet_main_t *vnet_main; - u64 (*hash_fn) (ethernet_header_t *); } handoff_main_t; handoff_main_t handoff_main; -vlib_node_registration_t handoff_dispatch_node; typedef struct { @@ -75,145 +70,68 @@ worker_handoff_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { handoff_main_t *hm = &handoff_main; - vlib_thread_main_t *tm = vlib_get_thread_main (); + vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; u32 n_left_from, *from; - static __thread vlib_frame_queue_elt_t **handoff_queue_elt_by_worker_index; - static __thread vlib_frame_queue_t **congested_handoff_queue_by_worker_index - = 0; - vlib_frame_queue_elt_t *hf = 0; - int i; - u32 n_left_to_next_worker = 0, *to_next_worker = 0; - u32 next_worker_index = 0; - u32 current_worker_index = ~0; - - if (PREDICT_FALSE (handoff_queue_elt_by_worker_index == 0)) - { - vec_validate (handoff_queue_elt_by_worker_index, tm->n_vlib_mains - 1); - - vec_validate_init_empty (congested_handoff_queue_by_worker_index, - hm->first_worker_index + hm->num_workers - 1, - (vlib_frame_queue_t *) (~0)); - } + u16 thread_indices[VLIB_FRAME_SIZE], *ti; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; + vlib_get_buffers (vm, from, bufs, n_left_from); + + b = bufs; + ti = thread_indices; while (n_left_from > 0) { - u32 bi0; - vlib_buffer_t *b0; u32 sw_if_index0; u32 hash; u64 hash_key; per_inteface_handoff_data_t *ihd0; u32 index0; - bi0 = from[0]; - from += 1; - n_left_from -= 1; - b0 = vlib_get_buffer (vm, bi0); - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; ASSERT (hm->if_data); ihd0 = vec_elt_at_index (hm->if_data, sw_if_index0); - next_worker_index = hm->first_worker_index; - /* * Force unknown traffic onto worker 0, * and into ethernet-input. $$$$ add more hashes. */ /* Compute ingress LB hash */ - hash_key = hm->hash_fn ((ethernet_header_t *) b0->data); + hash_key = hm->hash_fn ((ethernet_header_t *) + vlib_buffer_get_current (b[0])); hash = (u32) clib_xxhash (hash_key); /* if input node did not specify next index, then packet should go to eternet-input */ - if (PREDICT_FALSE ((b0->flags & VNET_BUFFER_F_HANDOFF_NEXT_VALID) == 0)) - vnet_buffer (b0)->handoff.next_index = - HANDOFF_DISPATCH_NEXT_ETHERNET_INPUT; - else if (vnet_buffer (b0)->handoff.next_index == - HANDOFF_DISPATCH_NEXT_IP4_INPUT - || vnet_buffer (b0)->handoff.next_index == - HANDOFF_DISPATCH_NEXT_IP6_INPUT - || vnet_buffer (b0)->handoff.next_index == - HANDOFF_DISPATCH_NEXT_MPLS_INPUT) - vlib_buffer_advance (b0, (sizeof (ethernet_header_t))); if (PREDICT_TRUE (is_pow2 (vec_len (ihd0->workers)))) index0 = hash & (vec_len (ihd0->workers) - 1); else index0 = hash % vec_len (ihd0->workers); - next_worker_index += ihd0->workers[index0]; - - if (next_worker_index != current_worker_index) - { - if (hf) - hf->n_vectors = VLIB_FRAME_SIZE - n_left_to_next_worker; - - hf = vlib_get_worker_handoff_queue_elt (hm->frame_queue_index, - next_worker_index, - handoff_queue_elt_by_worker_index); - - n_left_to_next_worker = VLIB_FRAME_SIZE - hf->n_vectors; - to_next_worker = &hf->buffer_index[hf->n_vectors]; - current_worker_index = next_worker_index; - } - - /* enqueue to correct worker thread */ - to_next_worker[0] = bi0; - to_next_worker++; - n_left_to_next_worker--; - - if (n_left_to_next_worker == 0) - { - hf->n_vectors = VLIB_FRAME_SIZE; - vlib_put_frame_queue_elt (hf); - current_worker_index = ~0; - handoff_queue_elt_by_worker_index[next_worker_index] = 0; - hf = 0; - } + ti[0] = hm->first_worker_index + ihd0->workers[index0]; if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) - && (b0->flags & VLIB_BUFFER_IS_TRACED))) + && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) { worker_handoff_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); + vlib_add_trace (vm, node, b[0], sizeof (*t)); t->sw_if_index = sw_if_index0; - t->next_worker_index = next_worker_index - hm->first_worker_index; - t->buffer_index = bi0; + t->next_worker_index = ti[0]; + t->buffer_index = vlib_get_buffer_index (vm, b[0]); } + /* next */ + n_left_from -= 1; + ti += 1; + b += 1; } - if (hf) - hf->n_vectors = VLIB_FRAME_SIZE - n_left_to_next_worker; - - /* Ship frames to the worker nodes */ - for (i = 0; i < vec_len (handoff_queue_elt_by_worker_index); i++) - { - if (handoff_queue_elt_by_worker_index[i]) - { - hf = handoff_queue_elt_by_worker_index[i]; - /* - * It works better to let the handoff node - * rate-adapt, always ship the handoff queue element. - */ - if (1 || hf->n_vectors == hf->last_n_vectors) - { - vlib_put_frame_queue_elt (hf); - handoff_queue_elt_by_worker_index[i] = 0; - } - else - hf->last_n_vectors = hf->n_vectors; - } - congested_handoff_queue_by_worker_index[i] = - (vlib_frame_queue_t *) (~0); - } - hf = 0; - current_worker_index = ~0; + vlib_buffer_enqueue_to_thread (vm, hm->frame_queue_index, from, + thread_indices, frame->n_vectors); return frame->n_vectors; } @@ -255,8 +173,10 @@ interface_handoff_enable_disable (vlib_main_t * vm, u32 sw_if_index, return VNET_API_ERROR_INVALID_WORKER; if (hm->frame_queue_index == ~0) - hm->frame_queue_index = - vlib_frame_queue_main_init (handoff_dispatch_node.index, 0); + { + vlib_node_t *n = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); + hm->frame_queue_index = vlib_frame_queue_main_init (n->index, 0); + } vec_validate (hm->if_data, sw_if_index); d = vec_elt_at_index (hm->if_data, sw_if_index); @@ -359,196 +279,6 @@ VLIB_CLI_COMMAND (set_interface_handoff_command, static) = { }; /* *INDENT-ON* */ -typedef struct -{ - u32 buffer_index; - u32 next_index; - u32 sw_if_index; -} handoff_dispatch_trace_t; - -/* packet trace format function */ -static u8 * -format_handoff_dispatch_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - handoff_dispatch_trace_t *t = va_arg (*args, handoff_dispatch_trace_t *); - - s = format (s, "handoff-dispatch: sw_if_index %d next_index %d buffer 0x%x", - t->sw_if_index, t->next_index, t->buffer_index); - return s; -} - -#define foreach_handoff_dispatch_error \ -_(EXAMPLE, "example packets") - -typedef enum -{ -#define _(sym,str) HANDOFF_DISPATCH_ERROR_##sym, - foreach_handoff_dispatch_error -#undef _ - HANDOFF_DISPATCH_N_ERROR, -} handoff_dispatch_error_t; - -static char *handoff_dispatch_error_strings[] = { -#define _(sym,string) string, - foreach_handoff_dispatch_error -#undef _ -}; - -static uword -handoff_dispatch_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next; - handoff_dispatch_next_t next_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - u32 bi0, bi1; - vlib_buffer_t *b0, *b1; - u32 next0, next1; - u32 sw_if_index0, sw_if_index1; - - /* Prefetch next iteration. */ - { - vlib_buffer_t *p2, *p3; - - p2 = vlib_get_buffer (vm, from[2]); - p3 = vlib_get_buffer (vm, from[3]); - - vlib_prefetch_buffer_header (p2, LOAD); - vlib_prefetch_buffer_header (p3, LOAD); - } - - /* speculatively enqueue b0 and b1 to the current next frame */ - to_next[0] = bi0 = from[0]; - to_next[1] = bi1 = from[1]; - from += 2; - to_next += 2; - n_left_from -= 2; - n_left_to_next -= 2; - - b0 = vlib_get_buffer (vm, bi0); - b1 = vlib_get_buffer (vm, bi1); - - next0 = vnet_buffer (b0)->handoff.next_index; - next1 = vnet_buffer (b1)->handoff.next_index; - - if (PREDICT_FALSE (vm->trace_main.trace_active_hint)) - { - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ - 0); - handoff_dispatch_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - t->sw_if_index = sw_if_index0; - t->next_index = next0; - t->buffer_index = bi0; - } - if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) - { - vlib_trace_buffer (vm, node, next1, b1, /* follow_chain */ - 0); - handoff_dispatch_trace_t *t = - vlib_add_trace (vm, node, b1, sizeof (*t)); - sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; - t->sw_if_index = sw_if_index1; - t->next_index = next1; - t->buffer_index = bi1; - } - } - - /* verify speculative enqueues, maybe switch current next frame */ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, - to_next, n_left_to_next, - bi0, bi1, next0, next1); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 bi0; - vlib_buffer_t *b0; - u32 next0; - u32 sw_if_index0; - - /* speculatively enqueue b0 to the current next frame */ - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - - next0 = vnet_buffer (b0)->handoff.next_index; - - if (PREDICT_FALSE (vm->trace_main.trace_active_hint)) - { - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ - 0); - handoff_dispatch_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - t->sw_if_index = sw_if_index0; - t->next_index = next0; - t->buffer_index = bi0; - } - } - - /* verify speculative enqueue, maybe switch current next frame */ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, - to_next, n_left_to_next, - bi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - return frame->n_vectors; -} - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (handoff_dispatch_node) = { - .function = handoff_dispatch_node_fn, - .name = "handoff-dispatch", - .vector_size = sizeof (u32), - .format_trace = format_handoff_dispatch_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .flags = VLIB_NODE_FLAG_IS_HANDOFF, - - .n_errors = ARRAY_LEN(handoff_dispatch_error_strings), - .error_strings = handoff_dispatch_error_strings, - - .n_next_nodes = HANDOFF_DISPATCH_N_NEXT, - - .next_nodes = { - [HANDOFF_DISPATCH_NEXT_DROP] = "error-drop", - [HANDOFF_DISPATCH_NEXT_ETHERNET_INPUT] = "ethernet-input", - [HANDOFF_DISPATCH_NEXT_IP4_INPUT] = "ip4-input-no-checksum", - [HANDOFF_DISPATCH_NEXT_IP6_INPUT] = "ip6-input", - [HANDOFF_DISPATCH_NEXT_MPLS_INPUT] = "mpls-input", - }, -}; - -VLIB_NODE_FUNCTION_MULTIARCH (handoff_dispatch_node, handoff_dispatch_node_fn) -/* *INDENT-ON* */ - clib_error_t * handoff_init (vlib_main_t * vm) { @@ -574,10 +304,6 @@ handoff_init (vlib_main_t * vm) } hm->hash_fn = eth_get_key; - - hm->vlib_main = vm; - hm->vnet_main = &vnet_main; - hm->frame_queue_index = ~0; return 0; diff --git a/src/vnet/handoff.h b/src/vnet/handoff.h index 04ba8bfbc02..f50b86d5c6d 100644 --- a/src/vnet/handoff.h +++ b/src/vnet/handoff.h @@ -22,17 +22,6 @@ #include <vnet/ip/ip6_packet.h> #include <vnet/mpls/packet.h> -typedef enum -{ - HANDOFF_DISPATCH_NEXT_IP4_INPUT, - HANDOFF_DISPATCH_NEXT_IP6_INPUT, - HANDOFF_DISPATCH_NEXT_MPLS_INPUT, - HANDOFF_DISPATCH_NEXT_ETHERNET_INPUT, - HANDOFF_DISPATCH_NEXT_DROP, - HANDOFF_DISPATCH_N_NEXT, -} handoff_dispatch_next_t; - - static inline u64 ipv4_get_key (ip4_header_t * ip) { diff --git a/src/vnet/pg/input.c b/src/vnet/pg/input.c index a9510b7c9c9..82c6c81cf18 100644 --- a/src/vnet/pg/input.c +++ b/src/vnet/pg/input.c @@ -1520,9 +1520,6 @@ pg_generate_packets (vlib_node_runtime_t * node, { vlib_buffer_t *b; b = vlib_get_buffer (vm, to_next[i]); - vnet_buffer (b)->device_input_feat.saved_next_index = - s->next_index; - vnet_buffer (b)->device_input_feat.buffer_advance = 0; b->current_config_index = current_config_index; vnet_buffer (b)->feature_arc_index = feature_arc_index; } |