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