Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <vnet/vnet.h> |
| 18 | #include <vppinfra/xxhash.h> |
| 19 | #include <vlib/threads.h> |
| 20 | #include <vnet/handoff.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 21 | #include <vnet/feature/feature.h> |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 22 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 23 | typedef struct |
| 24 | { |
| 25 | uword *workers_bitmap; |
| 26 | u32 *workers; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 27 | } per_inteface_handoff_data_t; |
| 28 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 29 | typedef struct |
| 30 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 31 | u32 cached_next_index; |
| 32 | u32 num_workers; |
| 33 | u32 first_worker_index; |
| 34 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 35 | per_inteface_handoff_data_t *if_data; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 36 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 37 | /* Worker handoff index */ |
| 38 | u32 frame_queue_index; |
| 39 | |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 40 | u64 (*hash_fn) (ethernet_header_t *); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 41 | } handoff_main_t; |
| 42 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 43 | extern handoff_main_t handoff_main; |
| 44 | |
| 45 | #ifndef CLIB_MARCH_VARIANT |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 46 | handoff_main_t handoff_main; |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 47 | #endif /* CLIB_MARCH_VARIANT */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 48 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 49 | typedef struct |
| 50 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 51 | u32 sw_if_index; |
| 52 | u32 next_worker_index; |
| 53 | u32 buffer_index; |
| 54 | } worker_handoff_trace_t; |
| 55 | |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 56 | #define foreach_worker_handoff_error \ |
| 57 | _(CONGESTION_DROP, "congestion drop") |
| 58 | |
| 59 | typedef enum |
| 60 | { |
| 61 | #define _(sym,str) WORKER_HANDOFF_ERROR_##sym, |
| 62 | foreach_worker_handoff_error |
| 63 | #undef _ |
| 64 | WORKER_HANDOFF_N_ERROR, |
| 65 | } worker_handoff_error_t; |
| 66 | |
| 67 | static char *worker_handoff_error_strings[] = { |
| 68 | #define _(sym,string) string, |
| 69 | foreach_worker_handoff_error |
| 70 | #undef _ |
| 71 | }; |
| 72 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 73 | /* packet trace format function */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 74 | static u8 * |
| 75 | format_worker_handoff_trace (u8 * s, va_list * args) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 76 | { |
| 77 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 78 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 79 | worker_handoff_trace_t *t = va_arg (*args, worker_handoff_trace_t *); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 80 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 81 | s = |
| 82 | format (s, "worker-handoff: sw_if_index %d, next_worker %d, buffer 0x%x", |
| 83 | t->sw_if_index, t->next_worker_index, t->buffer_index); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 84 | return s; |
| 85 | } |
| 86 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 87 | VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, |
| 88 | vlib_node_runtime_t * node, |
| 89 | vlib_frame_t * frame) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 90 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 91 | handoff_main_t *hm = &handoff_main; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 92 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 93 | u32 n_enq, n_left_from, *from; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 94 | u16 thread_indices[VLIB_FRAME_SIZE], *ti; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 95 | |
| 96 | from = vlib_frame_vector_args (frame); |
| 97 | n_left_from = frame->n_vectors; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 98 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 99 | |
| 100 | b = bufs; |
| 101 | ti = thread_indices; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 102 | |
| 103 | while (n_left_from > 0) |
| 104 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 105 | u32 sw_if_index0; |
| 106 | u32 hash; |
| 107 | u64 hash_key; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 108 | per_inteface_handoff_data_t *ihd0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 109 | u32 index0; |
| 110 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 111 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 112 | sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 113 | ASSERT (hm->if_data); |
| 114 | ihd0 = vec_elt_at_index (hm->if_data, sw_if_index0); |
| 115 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 116 | /* |
| 117 | * Force unknown traffic onto worker 0, |
| 118 | * and into ethernet-input. $$$$ add more hashes. |
| 119 | */ |
| 120 | |
| 121 | /* Compute ingress LB hash */ |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 122 | hash_key = hm->hash_fn ((ethernet_header_t *) |
| 123 | vlib_buffer_get_current (b[0])); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 124 | hash = (u32) clib_xxhash (hash_key); |
| 125 | |
| 126 | /* if input node did not specify next index, then packet |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 127 | should go to ethernet-input */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 128 | |
| 129 | if (PREDICT_TRUE (is_pow2 (vec_len (ihd0->workers)))) |
| 130 | index0 = hash & (vec_len (ihd0->workers) - 1); |
| 131 | else |
| 132 | index0 = hash % vec_len (ihd0->workers); |
| 133 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 134 | ti[0] = hm->first_worker_index + ihd0->workers[index0]; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 135 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 136 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 137 | && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 138 | { |
| 139 | worker_handoff_trace_t *t = |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 140 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 141 | t->sw_if_index = sw_if_index0; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 142 | t->next_worker_index = ti[0]; |
| 143 | t->buffer_index = vlib_get_buffer_index (vm, b[0]); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 146 | /* next */ |
| 147 | n_left_from -= 1; |
| 148 | ti += 1; |
| 149 | b += 1; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Damjan Marion | 9e7a0b4 | 2021-05-14 14:50:01 +0200 | [diff] [blame] | 152 | n_enq = vlib_buffer_enqueue_to_thread (vm, node, hm->frame_queue_index, from, |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 153 | thread_indices, frame->n_vectors, 1); |
| 154 | |
| 155 | if (n_enq < frame->n_vectors) |
| 156 | vlib_node_increment_counter (vm, node->node_index, |
| 157 | WORKER_HANDOFF_ERROR_CONGESTION_DROP, |
| 158 | frame->n_vectors - n_enq); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 159 | return frame->n_vectors; |
| 160 | } |
| 161 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 162 | /* *INDENT-OFF* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 163 | VLIB_REGISTER_NODE (worker_handoff_node) = { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 164 | .name = "worker-handoff", |
| 165 | .vector_size = sizeof (u32), |
| 166 | .format_trace = format_worker_handoff_trace, |
| 167 | .type = VLIB_NODE_TYPE_INTERNAL, |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 168 | .n_errors = ARRAY_LEN(worker_handoff_error_strings), |
| 169 | .error_strings = worker_handoff_error_strings, |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 170 | |
| 171 | .n_next_nodes = 1, |
| 172 | .next_nodes = { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 173 | [0] = "error-drop", |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 174 | }, |
| 175 | }; |
| 176 | |
Damjan Marion | e33b9e0 | 2016-10-17 12:51:18 +0200 | [diff] [blame] | 177 | /* *INDENT-ON* */ |
| 178 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 179 | #ifndef CLIB_MARCH_VARIANT |
Damjan Marion | e33b9e0 | 2016-10-17 12:51:18 +0200 | [diff] [blame] | 180 | int |
| 181 | interface_handoff_enable_disable (vlib_main_t * vm, u32 sw_if_index, |
| 182 | uword * bitmap, int enable_disable) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 183 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 184 | handoff_main_t *hm = &handoff_main; |
| 185 | vnet_sw_interface_t *sw; |
| 186 | vnet_main_t *vnm = vnet_get_main (); |
| 187 | per_inteface_handoff_data_t *d; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 188 | int i, rv = 0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 189 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 190 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 191 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 192 | |
| 193 | sw = vnet_get_sw_interface (vnm, sw_if_index); |
| 194 | if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 195 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 196 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 197 | if (clib_bitmap_last_set (bitmap) >= hm->num_workers) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 198 | return VNET_API_ERROR_INVALID_WORKER; |
| 199 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 200 | if (hm->frame_queue_index == ~0) |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 201 | { |
| 202 | vlib_node_t *n = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); |
| 203 | hm->frame_queue_index = vlib_frame_queue_main_init (n->index, 0); |
| 204 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 205 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 206 | vec_validate (hm->if_data, sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 207 | d = vec_elt_at_index (hm->if_data, sw_if_index); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 208 | |
| 209 | vec_free (d->workers); |
| 210 | vec_free (d->workers_bitmap); |
| 211 | |
| 212 | if (enable_disable) |
| 213 | { |
| 214 | d->workers_bitmap = bitmap; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 215 | /* *INDENT-OFF* */ |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 216 | clib_bitmap_foreach (i, bitmap) |
| 217 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 218 | vec_add1(d->workers, i); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 219 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 220 | /* *INDENT-ON* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 223 | vnet_feature_enable_disable ("device-input", "worker-handoff", |
| 224 | sw_if_index, enable_disable, 0, 0); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 225 | return rv; |
| 226 | } |
| 227 | |
| 228 | static clib_error_t * |
| 229 | set_interface_handoff_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 230 | unformat_input_t * input, |
| 231 | vlib_cli_command_t * cmd) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 232 | { |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 233 | handoff_main_t *hm = &handoff_main; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 234 | u32 sw_if_index = ~0; |
| 235 | int enable_disable = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 236 | uword *bitmap = 0; |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 237 | u32 sym = ~0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 238 | |
| 239 | int rv = 0; |
| 240 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 241 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 242 | { |
| 243 | if (unformat (input, "disable")) |
| 244 | enable_disable = 0; |
| 245 | else if (unformat (input, "workers %U", unformat_bitmap_list, &bitmap)) |
| 246 | ; |
| 247 | else if (unformat (input, "%U", unformat_vnet_sw_interface, |
| 248 | vnet_get_main (), &sw_if_index)) |
| 249 | ; |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 250 | else if (unformat (input, "symmetrical")) |
| 251 | sym = 1; |
| 252 | else if (unformat (input, "asymmetrical")) |
| 253 | sym = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 254 | else |
| 255 | break; |
| 256 | } |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 257 | |
| 258 | if (sw_if_index == ~0) |
| 259 | return clib_error_return (0, "Please specify an interface..."); |
| 260 | |
| 261 | if (bitmap == 0) |
| 262 | return clib_error_return (0, "Please specify list of workers..."); |
| 263 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 264 | rv = |
| 265 | interface_handoff_enable_disable (vm, sw_if_index, bitmap, |
| 266 | enable_disable); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 267 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 268 | switch (rv) |
| 269 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 270 | case 0: |
| 271 | break; |
| 272 | |
| 273 | case VNET_API_ERROR_INVALID_SW_IF_INDEX: |
| 274 | return clib_error_return (0, "Invalid interface"); |
| 275 | break; |
| 276 | |
| 277 | case VNET_API_ERROR_INVALID_WORKER: |
| 278 | return clib_error_return (0, "Invalid worker(s)"); |
| 279 | break; |
| 280 | |
| 281 | case VNET_API_ERROR_UNIMPLEMENTED: |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 282 | return clib_error_return (0, |
| 283 | "Device driver doesn't support redirection"); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 284 | break; |
| 285 | |
| 286 | default: |
| 287 | return clib_error_return (0, "unknown return value %d", rv); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 288 | } |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 289 | |
| 290 | if (sym == 1) |
| 291 | hm->hash_fn = eth_get_sym_key; |
| 292 | else if (sym == 0) |
| 293 | hm->hash_fn = eth_get_key; |
| 294 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 298 | /* *INDENT-OFF* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 299 | VLIB_CLI_COMMAND (set_interface_handoff_command, static) = { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 300 | .path = "set interface handoff", |
| 301 | .short_help = |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 302 | "set interface handoff <interface-name> workers <workers-list> [symmetrical|asymmetrical]", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 303 | .function = set_interface_handoff_command_fn, |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 304 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 305 | /* *INDENT-ON* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 306 | |
Damjan Marion | e33b9e0 | 2016-10-17 12:51:18 +0200 | [diff] [blame] | 307 | clib_error_t * |
| 308 | handoff_init (vlib_main_t * vm) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 309 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 310 | handoff_main_t *hm = &handoff_main; |
| 311 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 312 | clib_error_t *error; |
| 313 | uword *p; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 314 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 315 | if ((error = vlib_call_init_function (vm, threads_init))) |
| 316 | return error; |
| 317 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 318 | vlib_thread_registration_t *tr; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 319 | /* Only the standard vnet worker threads are supported */ |
| 320 | p = hash_get_mem (tm->thread_registrations_by_name, "workers"); |
Dave Barach | 5a9c9b8 | 2016-06-13 18:16:27 -0400 | [diff] [blame] | 321 | if (p) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 322 | { |
Dave Barach | 5a9c9b8 | 2016-06-13 18:16:27 -0400 | [diff] [blame] | 323 | tr = (vlib_thread_registration_t *) p[0]; |
| 324 | if (tr) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 325 | { |
| 326 | hm->num_workers = tr->count; |
| 327 | hm->first_worker_index = tr->first_index; |
| 328 | } |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 329 | } |
| 330 | |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 331 | hm->hash_fn = eth_get_key; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 332 | hm->frame_queue_index = ~0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 333 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | VLIB_INIT_FUNCTION (handoff_init); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 338 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 339 | #endif /* CLIB_MARCH_VARIANT */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 340 | /* |
| 341 | * fd.io coding-style-patch-verification: ON |
| 342 | * |
| 343 | * Local Variables: |
| 344 | * eval: (c-set-style "gnu") |
| 345 | * End: |
| 346 | */ |