Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 15 | #define _GNU_SOURCE |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 16 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 17 | #include <signal.h> |
| 18 | #include <math.h> |
| 19 | #include <vppinfra/format.h> |
| 20 | #include <vlib/vlib.h> |
| 21 | |
| 22 | #include <vlib/threads.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 23 | #include <vlib/unix/cj.h> |
| 24 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | DECLARE_CJ_GLOBAL_LOG; |
| 26 | |
| 27 | #define FRAME_QUEUE_NELTS 32 |
| 28 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 29 | u32 |
| 30 | vl (void *p) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | { |
| 32 | return vec_len (p); |
| 33 | } |
| 34 | |
Damjan Marion | 6a7acc2 | 2016-12-19 16:28:36 +0100 | [diff] [blame] | 35 | vlib_worker_thread_t *vlib_worker_threads; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | vlib_thread_main_t vlib_thread_main; |
| 37 | |
| 38 | uword |
| 39 | os_get_cpu_number (void) |
| 40 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 41 | void *sp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | uword n; |
| 43 | u32 len; |
| 44 | |
| 45 | len = vec_len (vlib_thread_stacks); |
| 46 | if (len == 0) |
| 47 | return 0; |
| 48 | |
| 49 | /* Get any old stack address. */ |
| 50 | sp = &sp; |
| 51 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 52 | n = ((uword) sp - (uword) vlib_thread_stacks[0]) |
| 53 | >> VLIB_LOG2_THREAD_STACK_SIZE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | |
| 55 | /* "processes" have their own stacks, and they always run in thread 0 */ |
| 56 | n = n >= len ? 0 : n; |
| 57 | |
| 58 | return n; |
| 59 | } |
| 60 | |
Dave Barach | 01d86c7 | 2016-08-08 15:13:42 -0400 | [diff] [blame] | 61 | uword |
| 62 | os_get_ncpus (void) |
| 63 | { |
| 64 | u32 len; |
| 65 | |
| 66 | len = vec_len (vlib_thread_stacks); |
| 67 | if (len == 0) |
| 68 | return 1; |
| 69 | else |
| 70 | return len; |
| 71 | } |
| 72 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | void |
| 74 | vlib_set_thread_name (char *name) |
| 75 | { |
| 76 | int pthread_setname_np (pthread_t __target_thread, const char *__name); |
Dave Barach | b2a6e25 | 2016-07-27 10:00:58 -0400 | [diff] [blame] | 77 | int rv; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 78 | pthread_t thread = pthread_self (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 80 | if (thread) |
Dave Barach | b2a6e25 | 2016-07-27 10:00:58 -0400 | [diff] [blame] | 81 | { |
| 82 | rv = pthread_setname_np (thread, name); |
| 83 | if (rv) |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 84 | clib_warning ("pthread_setname_np returned %d", rv); |
Dave Barach | b2a6e25 | 2016-07-27 10:00:58 -0400 | [diff] [blame] | 85 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 88 | static int |
| 89 | sort_registrations_by_no_clone (void *a0, void *a1) |
| 90 | { |
| 91 | vlib_thread_registration_t **tr0 = a0; |
| 92 | vlib_thread_registration_t **tr1 = a1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 94 | return ((i32) ((*tr0)->no_data_structure_clone) |
| 95 | - ((i32) ((*tr1)->no_data_structure_clone))); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static uword * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 99 | vlib_sysfs_list_to_bitmap (char *filename) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | { |
| 101 | FILE *fp; |
| 102 | uword *r = 0; |
| 103 | |
| 104 | fp = fopen (filename, "r"); |
| 105 | |
| 106 | if (fp != NULL) |
| 107 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 108 | u8 *buffer = 0; |
| 109 | vec_validate (buffer, 256 - 1); |
| 110 | if (fgets ((char *) buffer, 256, fp)) |
| 111 | { |
| 112 | unformat_input_t in; |
| 113 | unformat_init_string (&in, (char *) buffer, |
| 114 | strlen ((char *) buffer)); |
Dave Barach | b2a6e25 | 2016-07-27 10:00:58 -0400 | [diff] [blame] | 115 | if (unformat (&in, "%U", unformat_bitmap_list, &r) != 1) |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 116 | clib_warning ("unformat_bitmap_list failed"); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 117 | unformat_free (&in); |
| 118 | } |
| 119 | vec_free (buffer); |
| 120 | fclose (fp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | } |
| 122 | return r; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* Called early in the init sequence */ |
| 127 | |
| 128 | clib_error_t * |
| 129 | vlib_thread_init (vlib_main_t * vm) |
| 130 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 131 | vlib_thread_main_t *tm = &vlib_thread_main; |
| 132 | vlib_worker_thread_t *w; |
| 133 | vlib_thread_registration_t *tr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | u32 n_vlib_mains = 1; |
| 135 | u32 first_index = 1; |
| 136 | u32 i; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 137 | uword *avail_cpu; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | |
| 139 | /* get bitmaps of active cpu cores and sockets */ |
| 140 | tm->cpu_core_bitmap = |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 141 | vlib_sysfs_list_to_bitmap ("/sys/devices/system/cpu/online"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | tm->cpu_socket_bitmap = |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 143 | vlib_sysfs_list_to_bitmap ("/sys/devices/system/node/online"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 145 | avail_cpu = clib_bitmap_dup (tm->cpu_core_bitmap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
| 147 | /* skip cores */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 148 | for (i = 0; i < tm->skip_cores; i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 150 | uword c = clib_bitmap_first_set (avail_cpu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | if (c == ~0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 152 | return clib_error_return (0, "no available cpus to skip"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 154 | avail_cpu = clib_bitmap_set (avail_cpu, c, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* grab cpu for main thread */ |
| 158 | if (!tm->main_lcore) |
| 159 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 160 | tm->main_lcore = clib_bitmap_first_set (avail_cpu); |
| 161 | if (tm->main_lcore == (u8) ~ 0) |
| 162 | return clib_error_return (0, "no available cpus to be used for the" |
| 163 | " main thread"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | } |
| 165 | else |
| 166 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 167 | if (clib_bitmap_get (avail_cpu, tm->main_lcore) == 0) |
| 168 | return clib_error_return (0, "cpu %u is not available to be used" |
| 169 | " for the main thread", tm->main_lcore); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 171 | avail_cpu = clib_bitmap_set (avail_cpu, tm->main_lcore, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | |
| 173 | /* assume that there is socket 0 only if there is no data from sysfs */ |
| 174 | if (!tm->cpu_socket_bitmap) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 175 | tm->cpu_socket_bitmap = clib_bitmap_set (0, 0, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 177 | /* pin main thread to main_lcore */ |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 178 | if (tm->cb.vlib_thread_set_lcore_cb) |
| 179 | { |
| 180 | tm->cb.vlib_thread_set_lcore_cb (0, tm->main_lcore); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | cpu_set_t cpuset; |
| 185 | CPU_ZERO (&cpuset); |
| 186 | CPU_SET (tm->main_lcore, &cpuset); |
| 187 | pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset); |
| 188 | } |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 189 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | /* as many threads as stacks... */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 191 | vec_validate_aligned (vlib_worker_threads, vec_len (vlib_thread_stacks) - 1, |
| 192 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
| 194 | /* Preallocate thread 0 */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 195 | _vec_len (vlib_worker_threads) = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 196 | w = vlib_worker_threads; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 197 | w->thread_mheap = clib_mem_get_heap (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | w->thread_stack = vlib_thread_stacks[0]; |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 199 | w->lcore_id = tm->main_lcore; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 200 | w->lwp = syscall (SYS_gettid); |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 201 | w->thread_id = pthread_self (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | tm->n_vlib_mains = 1; |
| 203 | |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 204 | if (tm->sched_policy != ~0) |
| 205 | { |
| 206 | struct sched_param sched_param; |
| 207 | if (!sched_getparam (w->lwp, &sched_param)) |
| 208 | { |
| 209 | if (tm->sched_priority != ~0) |
| 210 | sched_param.sched_priority = tm->sched_priority; |
| 211 | sched_setscheduler (w->lwp, tm->sched_policy, &sched_param); |
| 212 | } |
| 213 | } |
| 214 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | /* assign threads to cores and set n_vlib_mains */ |
| 216 | tr = tm->next; |
| 217 | |
| 218 | while (tr) |
| 219 | { |
| 220 | vec_add1 (tm->registrations, tr); |
| 221 | tr = tr->next; |
| 222 | } |
| 223 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 224 | vec_sort_with_function (tm->registrations, sort_registrations_by_no_clone); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | |
| 226 | for (i = 0; i < vec_len (tm->registrations); i++) |
| 227 | { |
| 228 | int j; |
| 229 | tr = tm->registrations[i]; |
| 230 | tr->first_index = first_index; |
| 231 | first_index += tr->count; |
| 232 | n_vlib_mains += (tr->no_data_structure_clone == 0) ? tr->count : 0; |
| 233 | |
| 234 | /* construct coremask */ |
| 235 | if (tr->use_pthreads || !tr->count) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 236 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | |
| 238 | if (tr->coremask) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 239 | { |
| 240 | uword c; |
| 241 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | clib_bitmap_foreach (c, tr->coremask, ({ |
| 243 | if (clib_bitmap_get(avail_cpu, c) == 0) |
| 244 | return clib_error_return (0, "cpu %u is not available to be used" |
| 245 | " for the '%s' thread",c, tr->name); |
| 246 | |
| 247 | avail_cpu = clib_bitmap_set(avail_cpu, c, 0); |
| 248 | })); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 249 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 251 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 253 | { |
| 254 | for (j = 0; j < tr->count; j++) |
| 255 | { |
| 256 | uword c = clib_bitmap_first_set (avail_cpu); |
| 257 | if (c == ~0) |
| 258 | return clib_error_return (0, |
| 259 | "no available cpus to be used for" |
| 260 | " the '%s' thread", tr->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 262 | avail_cpu = clib_bitmap_set (avail_cpu, c, 0); |
| 263 | tr->coremask = clib_bitmap_set (tr->coremask, c, 1); |
| 264 | } |
| 265 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 268 | clib_bitmap_free (avail_cpu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | |
| 270 | tm->n_vlib_mains = n_vlib_mains; |
| 271 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 272 | vec_validate_aligned (vlib_worker_threads, first_index - 1, |
| 273 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | vlib_worker_thread_t * |
| 279 | vlib_alloc_thread (vlib_main_t * vm) |
| 280 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 281 | vlib_worker_thread_t *w; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 282 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 283 | if (vec_len (vlib_worker_threads) >= vec_len (vlib_thread_stacks)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | { |
| 285 | clib_warning ("out of worker threads... Quitting..."); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 286 | exit (1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 287 | } |
| 288 | vec_add2 (vlib_worker_threads, w, 1); |
| 289 | w->thread_stack = vlib_thread_stacks[w - vlib_worker_threads]; |
| 290 | return w; |
| 291 | } |
| 292 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 293 | vlib_frame_queue_t * |
| 294 | vlib_frame_queue_alloc (int nelts) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 296 | vlib_frame_queue_t *fq; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 297 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 298 | fq = clib_mem_alloc_aligned (sizeof (*fq), CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 299 | memset (fq, 0, sizeof (*fq)); |
| 300 | fq->nelts = nelts; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 301 | fq->vector_threshold = 128; // packets |
| 302 | vec_validate_aligned (fq->elts, nelts - 1, CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | |
| 304 | if (1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 305 | { |
| 306 | if (((uword) & fq->tail) & (CLIB_CACHE_LINE_BYTES - 1)) |
| 307 | fformat (stderr, "WARNING: fq->tail unaligned\n"); |
| 308 | if (((uword) & fq->head) & (CLIB_CACHE_LINE_BYTES - 1)) |
| 309 | fformat (stderr, "WARNING: fq->head unaligned\n"); |
| 310 | if (((uword) fq->elts) & (CLIB_CACHE_LINE_BYTES - 1)) |
| 311 | fformat (stderr, "WARNING: fq->elts unaligned\n"); |
| 312 | |
| 313 | if (sizeof (fq->elts[0]) % CLIB_CACHE_LINE_BYTES) |
| 314 | fformat (stderr, "WARNING: fq->elts[0] size %d\n", |
| 315 | sizeof (fq->elts[0])); |
| 316 | if (nelts & (nelts - 1)) |
| 317 | { |
| 318 | fformat (stderr, "FATAL: nelts MUST be a power of 2\n"); |
| 319 | abort (); |
| 320 | } |
| 321 | } |
| 322 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 323 | return (fq); |
| 324 | } |
| 325 | |
| 326 | void vl_msg_api_handler_no_free (void *) __attribute__ ((weak)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 327 | void |
| 328 | vl_msg_api_handler_no_free (void *v) |
| 329 | { |
| 330 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 331 | |
| 332 | /* Turned off, save as reference material... */ |
| 333 | #if 0 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 334 | static inline int |
| 335 | vlib_frame_queue_dequeue_internal (int thread_id, |
| 336 | vlib_main_t * vm, vlib_node_main_t * nm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 337 | { |
| 338 | vlib_frame_queue_t *fq = vlib_frame_queues[thread_id]; |
| 339 | vlib_frame_queue_elt_t *elt; |
| 340 | vlib_frame_t *f; |
| 341 | vlib_pending_frame_t *p; |
| 342 | vlib_node_runtime_t *r; |
| 343 | u32 node_runtime_index; |
| 344 | int msg_type; |
| 345 | u64 before; |
| 346 | int processed = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 347 | |
| 348 | ASSERT (vm == vlib_mains[thread_id]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | |
| 350 | while (1) |
| 351 | { |
| 352 | if (fq->head == fq->tail) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 353 | return processed; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 355 | elt = fq->elts + ((fq->head + 1) & (fq->nelts - 1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | |
| 357 | if (!elt->valid) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 358 | return processed; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 360 | before = clib_cpu_time_now (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | |
| 362 | f = elt->frame; |
| 363 | node_runtime_index = elt->node_runtime_index; |
| 364 | msg_type = elt->msg_type; |
| 365 | |
| 366 | switch (msg_type) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 367 | { |
| 368 | case VLIB_FRAME_QUEUE_ELT_FREE_BUFFERS: |
| 369 | vlib_buffer_free (vm, vlib_frame_vector_args (f), f->n_vectors); |
| 370 | /* note fallthrough... */ |
| 371 | case VLIB_FRAME_QUEUE_ELT_FREE_FRAME: |
| 372 | r = vec_elt_at_index (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL], |
| 373 | node_runtime_index); |
| 374 | vlib_frame_free (vm, r, f); |
| 375 | break; |
| 376 | case VLIB_FRAME_QUEUE_ELT_DISPATCH_FRAME: |
| 377 | vec_add2 (vm->node_main.pending_frames, p, 1); |
| 378 | f->flags |= (VLIB_FRAME_PENDING | VLIB_FRAME_FREE_AFTER_DISPATCH); |
| 379 | p->node_runtime_index = elt->node_runtime_index; |
| 380 | p->frame_index = vlib_frame_index (vm, f); |
| 381 | p->next_frame_index = VLIB_PENDING_FRAME_NO_NEXT_FRAME; |
| 382 | fq->dequeue_vectors += (u64) f->n_vectors; |
| 383 | break; |
| 384 | case VLIB_FRAME_QUEUE_ELT_API_MSG: |
| 385 | vl_msg_api_handler_no_free (f); |
| 386 | break; |
| 387 | default: |
| 388 | clib_warning ("bogus frame queue message, type %d", msg_type); |
| 389 | break; |
| 390 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | elt->valid = 0; |
| 392 | fq->dequeues++; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 393 | fq->dequeue_ticks += clib_cpu_time_now () - before; |
| 394 | CLIB_MEMORY_BARRIER (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | fq->head++; |
| 396 | processed++; |
| 397 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 398 | ASSERT (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | return processed; |
| 400 | } |
| 401 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 402 | int |
| 403 | vlib_frame_queue_dequeue (int thread_id, |
| 404 | vlib_main_t * vm, vlib_node_main_t * nm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 405 | { |
| 406 | return vlib_frame_queue_dequeue_internal (thread_id, vm, nm); |
| 407 | } |
| 408 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 409 | int |
| 410 | vlib_frame_queue_enqueue (vlib_main_t * vm, u32 node_runtime_index, |
| 411 | u32 frame_queue_index, vlib_frame_t * frame, |
| 412 | vlib_frame_queue_msg_type_t type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 413 | { |
| 414 | vlib_frame_queue_t *fq = vlib_frame_queues[frame_queue_index]; |
| 415 | vlib_frame_queue_elt_t *elt; |
| 416 | u32 save_count; |
| 417 | u64 new_tail; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 418 | u64 before = clib_cpu_time_now (); |
| 419 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 420 | ASSERT (fq); |
| 421 | |
| 422 | new_tail = __sync_add_and_fetch (&fq->tail, 1); |
| 423 | |
| 424 | /* Wait until a ring slot is available */ |
| 425 | while (new_tail >= fq->head + fq->nelts) |
| 426 | { |
| 427 | f64 b4 = vlib_time_now_ticks (vm, before); |
| 428 | vlib_worker_thread_barrier_check (vm, b4); |
| 429 | /* Bad idea. Dequeue -> enqueue -> dequeue -> trouble */ |
| 430 | // vlib_frame_queue_dequeue (vm->cpu_index, vm, nm); |
| 431 | } |
| 432 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 433 | elt = fq->elts + (new_tail & (fq->nelts - 1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | |
| 435 | /* this would be very bad... */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 436 | while (elt->valid) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | { |
| 438 | } |
| 439 | |
| 440 | /* Once we enqueue the frame, frame->n_vectors is owned elsewhere... */ |
| 441 | save_count = frame->n_vectors; |
| 442 | |
| 443 | elt->frame = frame; |
| 444 | elt->node_runtime_index = node_runtime_index; |
| 445 | elt->msg_type = type; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 446 | CLIB_MEMORY_BARRIER (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | elt->valid = 1; |
| 448 | |
| 449 | return save_count; |
| 450 | } |
| 451 | #endif /* 0 */ |
| 452 | |
| 453 | /* To be called by vlib worker threads upon startup */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 454 | void |
| 455 | vlib_worker_thread_init (vlib_worker_thread_t * w) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 457 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 458 | |
Dave Barach | fdf4944 | 2016-12-20 12:48:14 -0500 | [diff] [blame] | 459 | /* |
| 460 | * Note: disabling signals in worker threads as follows |
| 461 | * prevents the api post-mortem dump scheme from working |
| 462 | * { |
| 463 | * sigset_t s; |
| 464 | * sigfillset (&s); |
| 465 | * pthread_sigmask (SIG_SETMASK, &s, 0); |
| 466 | * } |
| 467 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | |
| 469 | clib_mem_set_heap (w->thread_mheap); |
| 470 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 471 | if (vec_len (tm->thread_prefix) && w->registration->short_name) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 473 | w->name = format (0, "%v_%s_%d%c", tm->thread_prefix, |
| 474 | w->registration->short_name, w->instance_id, '\0'); |
| 475 | vlib_set_thread_name ((char *) w->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | if (!w->registration->use_pthreads) |
| 479 | { |
| 480 | |
| 481 | /* Initial barrier sync, for both worker and i/o threads */ |
| 482 | clib_smp_atomic_add (vlib_worker_threads->workers_at_barrier, 1); |
| 483 | |
| 484 | while (*vlib_worker_threads->wait_at_barrier) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 485 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 486 | |
| 487 | clib_smp_atomic_add (vlib_worker_threads->workers_at_barrier, -1); |
| 488 | } |
| 489 | } |
| 490 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 491 | void * |
| 492 | vlib_worker_thread_bootstrap_fn (void *arg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 493 | { |
| 494 | void *rv; |
| 495 | vlib_worker_thread_t *w = arg; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 496 | |
| 497 | w->lwp = syscall (SYS_gettid); |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 498 | w->thread_id = pthread_self (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 500 | rv = (void *) clib_calljmp |
| 501 | ((uword (*)(uword)) w->thread_function, |
| 502 | (uword) arg, w->thread_stack + VLIB_THREAD_STACK_SIZE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 503 | /* NOTREACHED, we hope */ |
| 504 | return rv; |
| 505 | } |
| 506 | |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 507 | static clib_error_t * |
| 508 | vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned lcore_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 509 | { |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 510 | vlib_thread_main_t *tm = &vlib_thread_main; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 511 | void *(*fp_arg) (void *) = fp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 512 | |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 513 | w->lcore_id = lcore_id; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 514 | if (tm->cb.vlib_launch_thread_cb && !w->registration->use_pthreads) |
| 515 | return tm->cb.vlib_launch_thread_cb (fp, (void *) w, lcore_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 517 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 518 | pthread_t worker; |
| 519 | cpu_set_t cpuset; |
| 520 | CPU_ZERO (&cpuset); |
| 521 | CPU_SET (lcore_id, &cpuset); |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 522 | |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 523 | if (pthread_create (&worker, NULL /* attr */ , fp_arg, (void *) w)) |
| 524 | return clib_error_return_unix (0, "pthread_create"); |
| 525 | |
| 526 | if (pthread_setaffinity_np (worker, sizeof (cpu_set_t), &cpuset)) |
| 527 | return clib_error_return_unix (0, "pthread_setaffinity_np"); |
| 528 | |
| 529 | return 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 530 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 533 | static clib_error_t * |
| 534 | start_workers (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 535 | { |
| 536 | int i, j; |
| 537 | vlib_worker_thread_t *w; |
| 538 | vlib_main_t *vm_clone; |
| 539 | void *oldheap; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 540 | vlib_thread_main_t *tm = &vlib_thread_main; |
| 541 | vlib_thread_registration_t *tr; |
| 542 | vlib_node_runtime_t *rt; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 543 | u32 n_vlib_mains = tm->n_vlib_mains; |
| 544 | u32 worker_thread_index; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 545 | u8 *main_heap = clib_mem_get_per_cpu_heap (); |
| 546 | mheap_t *main_heap_header = mheap_header (main_heap); |
| 547 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 548 | vec_reset_length (vlib_worker_threads); |
| 549 | |
| 550 | /* Set up the main thread */ |
| 551 | vec_add2_aligned (vlib_worker_threads, w, 1, CLIB_CACHE_LINE_BYTES); |
Dave Barach | 3e7deb1 | 2016-02-05 16:29:53 -0500 | [diff] [blame] | 552 | w->elog_track.name = "main thread"; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 553 | elog_track_register (&vm->elog_main, &w->elog_track); |
| 554 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 555 | if (vec_len (tm->thread_prefix)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 556 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 557 | w->name = format (0, "%v_main%c", tm->thread_prefix, '\0'); |
| 558 | vlib_set_thread_name ((char *) w->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 561 | /* |
Dave Barach | 848191d | 2016-04-28 16:24:15 -0400 | [diff] [blame] | 562 | * Truth of the matter: we always use at least two |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 563 | * threads. So, make the main heap thread-safe |
Dave Barach | 848191d | 2016-04-28 16:24:15 -0400 | [diff] [blame] | 564 | * and make the event log thread-safe. |
| 565 | */ |
| 566 | main_heap_header->flags |= MHEAP_FLAG_THREAD_SAFE; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 567 | vm->elog_main.lock = |
| 568 | clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES); |
Dave Barach | 848191d | 2016-04-28 16:24:15 -0400 | [diff] [blame] | 569 | vm->elog_main.lock[0] = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 570 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | if (n_vlib_mains > 1) |
| 572 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 573 | /* Replace hand-crafted length-1 vector with a real vector */ |
| 574 | vlib_mains = 0; |
| 575 | |
| 576 | vec_validate_aligned (vlib_mains, tm->n_vlib_mains - 1, |
| 577 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 578 | _vec_len (vlib_mains) = 0; |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 579 | vec_add1_aligned (vlib_mains, vm, CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 581 | vlib_worker_threads->wait_at_barrier = |
| 582 | clib_mem_alloc_aligned (sizeof (u32), CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 583 | vlib_worker_threads->workers_at_barrier = |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 584 | clib_mem_alloc_aligned (sizeof (u32), CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 585 | |
| 586 | /* Ask for an initial barrier sync */ |
| 587 | *vlib_worker_threads->workers_at_barrier = 0; |
| 588 | *vlib_worker_threads->wait_at_barrier = 1; |
| 589 | |
| 590 | worker_thread_index = 1; |
| 591 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 592 | for (i = 0; i < vec_len (tm->registrations); i++) |
| 593 | { |
| 594 | vlib_node_main_t *nm, *nm_clone; |
| 595 | vlib_buffer_main_t *bm_clone; |
| 596 | vlib_buffer_free_list_t *fl_clone, *fl_orig; |
| 597 | vlib_buffer_free_list_t *orig_freelist_pool; |
| 598 | int k; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 600 | tr = tm->registrations[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 601 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 602 | if (tr->count == 0) |
| 603 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 604 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 605 | for (k = 0; k < tr->count; k++) |
| 606 | { |
| 607 | vec_add2 (vlib_worker_threads, w, 1); |
| 608 | if (tr->mheap_size) |
| 609 | w->thread_mheap = |
| 610 | mheap_alloc (0 /* use VM */ , tr->mheap_size); |
| 611 | else |
| 612 | w->thread_mheap = main_heap; |
| 613 | w->thread_stack = vlib_thread_stacks[w - vlib_worker_threads]; |
| 614 | w->thread_function = tr->function; |
| 615 | w->thread_function_arg = w; |
| 616 | w->instance_id = k; |
| 617 | w->registration = tr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 618 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 619 | w->elog_track.name = |
| 620 | (char *) format (0, "%s %d", tr->name, k + 1); |
| 621 | vec_add1 (w->elog_track.name, 0); |
| 622 | elog_track_register (&vm->elog_main, &w->elog_track); |
Bud Grise | 68adab9 | 2016-02-12 10:36:11 -0500 | [diff] [blame] | 623 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 624 | if (tr->no_data_structure_clone) |
| 625 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 626 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 627 | /* Fork vlib_global_main et al. Look for bugs here */ |
| 628 | oldheap = clib_mem_set_heap (w->thread_mheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 629 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 630 | vm_clone = clib_mem_alloc (sizeof (*vm_clone)); |
| 631 | clib_memcpy (vm_clone, vlib_mains[0], sizeof (*vm_clone)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 632 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 633 | vm_clone->cpu_index = worker_thread_index; |
| 634 | vm_clone->heap_base = w->thread_mheap; |
| 635 | vm_clone->mbuf_alloc_list = 0; |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 636 | vm_clone->init_functions_called = |
| 637 | hash_create (0, /* value bytes */ 0); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 638 | memset (&vm_clone->random_buffer, 0, |
| 639 | sizeof (vm_clone->random_buffer)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 640 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 641 | nm = &vlib_mains[0]->node_main; |
| 642 | nm_clone = &vm_clone->node_main; |
| 643 | /* fork next frames array, preserving node runtime indices */ |
| 644 | nm_clone->next_frames = vec_dup (nm->next_frames); |
| 645 | for (j = 0; j < vec_len (nm_clone->next_frames); j++) |
| 646 | { |
| 647 | vlib_next_frame_t *nf = &nm_clone->next_frames[j]; |
| 648 | u32 save_node_runtime_index; |
| 649 | u32 save_flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 650 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 651 | save_node_runtime_index = nf->node_runtime_index; |
| 652 | save_flags = nf->flags & VLIB_FRAME_NO_FREE_AFTER_DISPATCH; |
| 653 | vlib_next_frame_init (nf); |
| 654 | nf->node_runtime_index = save_node_runtime_index; |
| 655 | nf->flags = save_flags; |
| 656 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 657 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 658 | /* fork the frame dispatch queue */ |
| 659 | nm_clone->pending_frames = 0; |
| 660 | vec_validate (nm_clone->pending_frames, 10); /* $$$$$?????? */ |
| 661 | _vec_len (nm_clone->pending_frames) = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 662 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 663 | /* fork nodes */ |
| 664 | nm_clone->nodes = 0; |
| 665 | for (j = 0; j < vec_len (nm->nodes); j++) |
| 666 | { |
| 667 | vlib_node_t *n; |
| 668 | n = clib_mem_alloc_no_fail (sizeof (*n)); |
| 669 | clib_memcpy (n, nm->nodes[j], sizeof (*n)); |
| 670 | /* none of the copied nodes have enqueue rights given out */ |
| 671 | n->owner_node_index = VLIB_INVALID_NODE_INDEX; |
| 672 | memset (&n->stats_total, 0, sizeof (n->stats_total)); |
| 673 | memset (&n->stats_last_clear, 0, |
| 674 | sizeof (n->stats_last_clear)); |
| 675 | vec_add1 (nm_clone->nodes, n); |
| 676 | } |
| 677 | nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL] = |
| 678 | vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]); |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 679 | vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]) |
| 680 | { |
| 681 | vlib_node_t *n = vlib_get_node (vm, rt->node_index); |
| 682 | rt->cpu_index = vm_clone->cpu_index; |
| 683 | /* copy initial runtime_data from node */ |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 684 | if (n->runtime_data && n->runtime_data_bytes > 0) |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 685 | clib_memcpy (rt->runtime_data, n->runtime_data, |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 686 | clib_min (VLIB_NODE_RUNTIME_DATA_SIZE, |
| 687 | n->runtime_data_bytes)); |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 688 | else if (CLIB_DEBUG > 0) |
| 689 | memset (rt->runtime_data, 0xfe, |
| 690 | VLIB_NODE_RUNTIME_DATA_SIZE); |
| 691 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 692 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 693 | nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT] = |
| 694 | vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT]); |
| 695 | vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]) |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 696 | { |
| 697 | vlib_node_t *n = vlib_get_node (vm, rt->node_index); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 698 | rt->cpu_index = vm_clone->cpu_index; |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 699 | /* copy initial runtime_data from node */ |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 700 | if (n->runtime_data && n->runtime_data_bytes > 0) |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 701 | clib_memcpy (rt->runtime_data, n->runtime_data, |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 702 | clib_min (VLIB_NODE_RUNTIME_DATA_SIZE, |
| 703 | n->runtime_data_bytes)); |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 704 | else if (CLIB_DEBUG > 0) |
| 705 | memset (rt->runtime_data, 0xfe, |
| 706 | VLIB_NODE_RUNTIME_DATA_SIZE); |
| 707 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 708 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 709 | nm_clone->processes = vec_dup (nm->processes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 710 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 711 | /* zap the (per worker) frame freelists, etc */ |
| 712 | nm_clone->frame_sizes = 0; |
| 713 | nm_clone->frame_size_hash = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 714 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 715 | /* Packet trace buffers are guaranteed to be empty, nothing to do here */ |
Damjan Marion | bc20bdf | 2015-12-17 14:28:18 +0100 | [diff] [blame] | 716 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 717 | clib_mem_set_heap (oldheap); |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 718 | vec_add1_aligned (vlib_mains, vm_clone, CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 719 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 720 | vm_clone->error_main.counters = |
| 721 | vec_dup (vlib_mains[0]->error_main.counters); |
| 722 | vm_clone->error_main.counters_last_clear = |
| 723 | vec_dup (vlib_mains[0]->error_main.counters_last_clear); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 724 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 725 | /* Fork the vlib_buffer_main_t free lists, etc. */ |
| 726 | bm_clone = vec_dup (vm_clone->buffer_main); |
| 727 | vm_clone->buffer_main = bm_clone; |
| 728 | |
| 729 | orig_freelist_pool = bm_clone->buffer_free_list_pool; |
| 730 | bm_clone->buffer_free_list_pool = 0; |
| 731 | |
| 732 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | pool_foreach (fl_orig, orig_freelist_pool, |
| 734 | ({ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 735 | pool_get_aligned (bm_clone->buffer_free_list_pool, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 736 | fl_clone, CLIB_CACHE_LINE_BYTES); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 737 | ASSERT (fl_orig - orig_freelist_pool |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 738 | == fl_clone - bm_clone->buffer_free_list_pool); |
| 739 | |
| 740 | fl_clone[0] = fl_orig[0]; |
Damjan Marion | bd69a5f | 2017-02-05 23:44:42 +0100 | [diff] [blame] | 741 | fl_clone->buffers = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 742 | fl_clone->n_alloc = 0; |
| 743 | })); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 744 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 745 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 746 | worker_thread_index++; |
| 747 | } |
| 748 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 749 | } |
| 750 | else |
| 751 | { |
| 752 | /* only have non-data-structure copy threads to create... */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 753 | for (i = 0; i < vec_len (tm->registrations); i++) |
| 754 | { |
| 755 | tr = tm->registrations[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 757 | for (j = 0; j < tr->count; j++) |
| 758 | { |
| 759 | vec_add2 (vlib_worker_threads, w, 1); |
| 760 | if (tr->mheap_size) |
| 761 | w->thread_mheap = |
| 762 | mheap_alloc (0 /* use VM */ , tr->mheap_size); |
| 763 | else |
| 764 | w->thread_mheap = main_heap; |
| 765 | w->thread_stack = vlib_thread_stacks[w - vlib_worker_threads]; |
| 766 | w->thread_function = tr->function; |
| 767 | w->thread_function_arg = w; |
| 768 | w->instance_id = j; |
| 769 | w->elog_track.name = |
| 770 | (char *) format (0, "%s %d", tr->name, j + 1); |
| 771 | w->registration = tr; |
| 772 | vec_add1 (w->elog_track.name, 0); |
| 773 | elog_track_register (&vm->elog_main, &w->elog_track); |
| 774 | } |
| 775 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | worker_thread_index = 1; |
| 779 | |
| 780 | for (i = 0; i < vec_len (tm->registrations); i++) |
| 781 | { |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 782 | clib_error_t *err; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 783 | int j; |
| 784 | |
| 785 | tr = tm->registrations[i]; |
| 786 | |
| 787 | if (tr->use_pthreads || tm->use_pthreads) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 788 | { |
| 789 | for (j = 0; j < tr->count; j++) |
| 790 | { |
| 791 | w = vlib_worker_threads + worker_thread_index++; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 792 | err = vlib_launch_thread_int (vlib_worker_thread_bootstrap_fn, |
| 793 | w, 0); |
| 794 | if (err) |
| 795 | clib_error_report (err); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 796 | } |
| 797 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 798 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 799 | { |
| 800 | uword c; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 801 | /* *INDENT-OFF* */ |
| 802 | clib_bitmap_foreach (c, tr->coremask, ({ |
| 803 | w = vlib_worker_threads + worker_thread_index++; |
| 804 | err = vlib_launch_thread_int (vlib_worker_thread_bootstrap_fn, |
| 805 | w, c); |
| 806 | if (err) |
| 807 | clib_error_report (err); |
| 808 | })); |
| 809 | /* *INDENT-ON* */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 810 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 811 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 812 | vlib_worker_thread_barrier_sync (vm); |
| 813 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | VLIB_MAIN_LOOP_ENTER_FUNCTION (start_workers); |
| 818 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 819 | void |
| 820 | vlib_worker_thread_node_runtime_update (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 821 | { |
| 822 | int i, j; |
| 823 | vlib_worker_thread_t *w; |
| 824 | vlib_main_t *vm; |
| 825 | vlib_node_main_t *nm, *nm_clone; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 826 | vlib_node_t **old_nodes_clone; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 827 | vlib_main_t *vm_clone; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 828 | vlib_node_runtime_t *rt, *old_rt; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 829 | void *oldheap; |
| 830 | never_inline void |
| 831 | vlib_node_runtime_sync_stats (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 832 | vlib_node_runtime_t * r, |
| 833 | uword n_calls, |
| 834 | uword n_vectors, uword n_clocks); |
| 835 | |
| 836 | ASSERT (os_get_cpu_number () == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 837 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 838 | if (vec_len (vlib_mains) == 1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 839 | return; |
| 840 | |
| 841 | vm = vlib_mains[0]; |
| 842 | nm = &vm->node_main; |
| 843 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 844 | ASSERT (os_get_cpu_number () == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 845 | ASSERT (*vlib_worker_threads->wait_at_barrier == 1); |
| 846 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 847 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | * Scrape all runtime stats, so we don't lose node runtime(s) with |
| 849 | * pending counts, or throw away worker / io thread counts. |
| 850 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 851 | for (j = 0; j < vec_len (nm->nodes); j++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 852 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 853 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 854 | n = nm->nodes[j]; |
| 855 | vlib_node_sync_stats (vm, n); |
| 856 | } |
| 857 | |
| 858 | for (i = 1; i < vec_len (vlib_mains); i++) |
| 859 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 860 | vlib_node_t *n; |
| 861 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 862 | vm_clone = vlib_mains[i]; |
| 863 | nm_clone = &vm_clone->node_main; |
| 864 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 865 | for (j = 0; j < vec_len (nm_clone->nodes); j++) |
| 866 | { |
| 867 | n = nm_clone->nodes[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 868 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 869 | rt = vlib_node_get_runtime (vm_clone, n->index); |
| 870 | vlib_node_runtime_sync_stats (vm_clone, rt, 0, 0, 0); |
| 871 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | for (i = 1; i < vec_len (vlib_mains); i++) |
| 875 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 876 | vlib_node_runtime_t *rt; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 877 | w = vlib_worker_threads + i; |
| 878 | oldheap = clib_mem_set_heap (w->thread_mheap); |
Damjan Marion | bc20bdf | 2015-12-17 14:28:18 +0100 | [diff] [blame] | 879 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 880 | vm_clone = vlib_mains[i]; |
| 881 | |
| 882 | /* Re-clone error heap */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 883 | u64 *old_counters = vm_clone->error_main.counters; |
| 884 | u64 *old_counters_all_clear = vm_clone->error_main.counters_last_clear; |
| 885 | clib_memcpy (&vm_clone->error_main, &vm->error_main, |
| 886 | sizeof (vm->error_main)); |
| 887 | j = vec_len (vm->error_main.counters) - 1; |
| 888 | vec_validate_aligned (old_counters, j, CLIB_CACHE_LINE_BYTES); |
| 889 | vec_validate_aligned (old_counters_all_clear, j, CLIB_CACHE_LINE_BYTES); |
Damjan Marion | bc20bdf | 2015-12-17 14:28:18 +0100 | [diff] [blame] | 890 | vm_clone->error_main.counters = old_counters; |
| 891 | vm_clone->error_main.counters_last_clear = old_counters_all_clear; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 892 | |
| 893 | nm_clone = &vm_clone->node_main; |
| 894 | vec_free (nm_clone->next_frames); |
| 895 | nm_clone->next_frames = vec_dup (nm->next_frames); |
Damjan Marion | bc20bdf | 2015-12-17 14:28:18 +0100 | [diff] [blame] | 896 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | for (j = 0; j < vec_len (nm_clone->next_frames); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 898 | { |
| 899 | vlib_next_frame_t *nf = &nm_clone->next_frames[j]; |
| 900 | u32 save_node_runtime_index; |
| 901 | u32 save_flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 902 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 903 | save_node_runtime_index = nf->node_runtime_index; |
| 904 | save_flags = nf->flags & VLIB_FRAME_NO_FREE_AFTER_DISPATCH; |
| 905 | vlib_next_frame_init (nf); |
| 906 | nf->node_runtime_index = save_node_runtime_index; |
| 907 | nf->flags = save_flags; |
| 908 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 909 | |
| 910 | old_nodes_clone = nm_clone->nodes; |
| 911 | nm_clone->nodes = 0; |
| 912 | |
| 913 | /* re-fork nodes */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 914 | for (j = 0; j < vec_len (nm->nodes); j++) |
| 915 | { |
| 916 | vlib_node_t *old_n_clone; |
| 917 | vlib_node_t *new_n, *new_n_clone; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 918 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 919 | new_n = nm->nodes[j]; |
| 920 | old_n_clone = old_nodes_clone[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 921 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 922 | new_n_clone = clib_mem_alloc_no_fail (sizeof (*new_n_clone)); |
| 923 | clib_memcpy (new_n_clone, new_n, sizeof (*new_n)); |
| 924 | /* none of the copied nodes have enqueue rights given out */ |
| 925 | new_n_clone->owner_node_index = VLIB_INVALID_NODE_INDEX; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 926 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 927 | if (j >= vec_len (old_nodes_clone)) |
| 928 | { |
| 929 | /* new node, set to zero */ |
| 930 | memset (&new_n_clone->stats_total, 0, |
| 931 | sizeof (new_n_clone->stats_total)); |
| 932 | memset (&new_n_clone->stats_last_clear, 0, |
| 933 | sizeof (new_n_clone->stats_last_clear)); |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | /* Copy stats if the old data is valid */ |
| 938 | clib_memcpy (&new_n_clone->stats_total, |
| 939 | &old_n_clone->stats_total, |
| 940 | sizeof (new_n_clone->stats_total)); |
| 941 | clib_memcpy (&new_n_clone->stats_last_clear, |
| 942 | &old_n_clone->stats_last_clear, |
| 943 | sizeof (new_n_clone->stats_last_clear)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 944 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 945 | /* keep previous node state */ |
| 946 | new_n_clone->state = old_n_clone->state; |
| 947 | } |
| 948 | vec_add1 (nm_clone->nodes, new_n_clone); |
| 949 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 950 | /* Free the old node clone */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 951 | for (j = 0; j < vec_len (old_nodes_clone); j++) |
| 952 | clib_mem_free (old_nodes_clone[j]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 953 | vec_free (old_nodes_clone); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 954 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 955 | |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 956 | /* re-clone internal nodes */ |
| 957 | old_rt = nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 958 | nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL] = |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 959 | vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 960 | |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 961 | vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 962 | { |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 963 | vlib_node_t *n = vlib_get_node (vm, rt->node_index); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 964 | rt->cpu_index = vm_clone->cpu_index; |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 965 | /* copy runtime_data, will be overwritten later for existing rt */ |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 966 | if (n->runtime_data && n->runtime_data_bytes > 0) |
| 967 | clib_memcpy (rt->runtime_data, n->runtime_data, |
| 968 | clib_min (VLIB_NODE_RUNTIME_DATA_SIZE, |
| 969 | n->runtime_data_bytes)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 970 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 971 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 972 | for (j = 0; j < vec_len (old_rt); j++) |
| 973 | { |
| 974 | rt = vlib_node_get_runtime (vm_clone, old_rt[j].node_index); |
| 975 | rt->state = old_rt[j].state; |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 976 | clib_memcpy (rt->runtime_data, old_rt[j].runtime_data, |
| 977 | VLIB_NODE_RUNTIME_DATA_SIZE); |
| 978 | } |
| 979 | |
| 980 | vec_free (old_rt); |
| 981 | |
| 982 | /* re-clone input nodes */ |
| 983 | old_rt = nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]; |
| 984 | nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT] = |
| 985 | vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT]); |
| 986 | |
| 987 | vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]) |
| 988 | { |
| 989 | vlib_node_t *n = vlib_get_node (vm, rt->node_index); |
| 990 | rt->cpu_index = vm_clone->cpu_index; |
| 991 | /* copy runtime_data, will be overwritten later for existing rt */ |
Damjan Marion | b6f93a1 | 2017-03-16 17:46:41 +0100 | [diff] [blame^] | 992 | if (n->runtime_data && n->runtime_data_bytes > 0) |
| 993 | clib_memcpy (rt->runtime_data, n->runtime_data, |
| 994 | clib_min (VLIB_NODE_RUNTIME_DATA_SIZE, |
| 995 | n->runtime_data_bytes)); |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | for (j = 0; j < vec_len (old_rt); j++) |
| 999 | { |
| 1000 | rt = vlib_node_get_runtime (vm_clone, old_rt[j].node_index); |
| 1001 | rt->state = old_rt[j].state; |
| 1002 | clib_memcpy (rt->runtime_data, old_rt[j].runtime_data, |
| 1003 | VLIB_NODE_RUNTIME_DATA_SIZE); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1004 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1005 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1006 | vec_free (old_rt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1007 | |
| 1008 | nm_clone->processes = vec_dup (nm->processes); |
| 1009 | |
| 1010 | clib_mem_set_heap (oldheap); |
| 1011 | |
| 1012 | // vnet_main_fork_fixup (i); |
| 1013 | } |
| 1014 | } |
| 1015 | |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1016 | u32 |
| 1017 | unformat_sched_policy (unformat_input_t * input, va_list * args) |
| 1018 | { |
| 1019 | u32 *r = va_arg (*args, u32 *); |
| 1020 | |
| 1021 | if (0); |
| 1022 | #define _(v,f,s) else if (unformat (input, s)) *r = SCHED_POLICY_##f; |
| 1023 | foreach_sched_policy |
| 1024 | #undef _ |
| 1025 | else |
| 1026 | return 0; |
| 1027 | return 1; |
| 1028 | } |
| 1029 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1030 | static clib_error_t * |
| 1031 | cpu_config (vlib_main_t * vm, unformat_input_t * input) |
| 1032 | { |
| 1033 | vlib_thread_registration_t *tr; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1034 | uword *p; |
| 1035 | vlib_thread_main_t *tm = &vlib_thread_main; |
| 1036 | u8 *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | u64 coremask; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1038 | uword *bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1039 | u32 count; |
| 1040 | |
| 1041 | tm->thread_registrations_by_name = hash_create_string (0, sizeof (uword)); |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1042 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1043 | tm->n_thread_stacks = 1; /* account for main thread */ |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1044 | tm->sched_policy = ~0; |
| 1045 | tm->sched_priority = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1046 | |
| 1047 | tr = tm->next; |
| 1048 | |
| 1049 | while (tr) |
| 1050 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1051 | hash_set_mem (tm->thread_registrations_by_name, tr->name, (uword) tr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1052 | tr = tr->next; |
| 1053 | } |
| 1054 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1055 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1056 | { |
Damjan Marion | bf74147 | 2016-06-13 22:49:44 +0200 | [diff] [blame] | 1057 | if (unformat (input, "use-pthreads")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1058 | tm->use_pthreads = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1059 | else if (unformat (input, "thread-prefix %v", &tm->thread_prefix)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1060 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1061 | else if (unformat (input, "main-core %u", &tm->main_lcore)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1062 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1063 | else if (unformat (input, "skip-cores %u", &tm->skip_cores)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1064 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1065 | else if (unformat (input, "coremask-%s %llx", &name, &coremask)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1066 | { |
| 1067 | p = hash_get_mem (tm->thread_registrations_by_name, name); |
| 1068 | if (p == 0) |
| 1069 | return clib_error_return (0, "no such thread type '%s'", name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1070 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1071 | tr = (vlib_thread_registration_t *) p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1072 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1073 | if (tr->use_pthreads) |
| 1074 | return clib_error_return (0, |
| 1075 | "coremask cannot be set for '%s' threads", |
| 1076 | name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1077 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1078 | tr->coremask = clib_bitmap_set_multiple |
| 1079 | (tr->coremask, 0, coremask, BITS (coremask)); |
| 1080 | tr->count = clib_bitmap_count_set_bits (tr->coremask); |
| 1081 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1082 | else if (unformat (input, "corelist-%s %U", &name, unformat_bitmap_list, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1083 | &bitmap)) |
| 1084 | { |
| 1085 | p = hash_get_mem (tm->thread_registrations_by_name, name); |
| 1086 | if (p == 0) |
| 1087 | return clib_error_return (0, "no such thread type '%s'", name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1088 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1089 | tr = (vlib_thread_registration_t *) p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1091 | if (tr->use_pthreads) |
| 1092 | return clib_error_return (0, |
| 1093 | "corelist cannot be set for '%s' threads", |
| 1094 | name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1096 | tr->coremask = bitmap; |
| 1097 | tr->count = clib_bitmap_count_set_bits (tr->coremask); |
| 1098 | } |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1099 | else |
| 1100 | if (unformat |
| 1101 | (input, "scheduler-policy %U", unformat_sched_policy, |
| 1102 | &tm->sched_policy)) |
| 1103 | ; |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1104 | else if (unformat (input, "scheduler-priority %u", &tm->sched_priority)) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1105 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1106 | else if (unformat (input, "%s %u", &name, &count)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1107 | { |
| 1108 | p = hash_get_mem (tm->thread_registrations_by_name, name); |
| 1109 | if (p == 0) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1110 | return clib_error_return (0, "no such thread type 3 '%s'", name); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1111 | |
| 1112 | tr = (vlib_thread_registration_t *) p[0]; |
| 1113 | if (tr->fixed_count) |
| 1114 | return clib_error_return |
| 1115 | (0, "number of %s threads not configurable", tr->name); |
| 1116 | tr->count = count; |
| 1117 | } |
| 1118 | else |
| 1119 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1122 | if (tm->sched_priority != ~0) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1123 | { |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1124 | if (tm->sched_policy == SCHED_FIFO || tm->sched_policy == SCHED_RR) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1125 | { |
| 1126 | u32 prio_max = sched_get_priority_max (tm->sched_policy); |
| 1127 | u32 prio_min = sched_get_priority_min (tm->sched_policy); |
| 1128 | if (tm->sched_priority > prio_max) |
| 1129 | tm->sched_priority = prio_max; |
| 1130 | if (tm->sched_priority < prio_min) |
| 1131 | tm->sched_priority = prio_min; |
| 1132 | } |
| 1133 | else |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1134 | { |
| 1135 | return clib_error_return |
| 1136 | (0, |
| 1137 | "scheduling priority (%d) is not allowed for `normal` scheduling policy", |
| 1138 | tm->sched_priority); |
| 1139 | } |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 1140 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1141 | tr = tm->next; |
| 1142 | |
| 1143 | if (!tm->thread_prefix) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1144 | tm->thread_prefix = format (0, "vpp"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1145 | |
| 1146 | while (tr) |
| 1147 | { |
| 1148 | tm->n_thread_stacks += tr->count; |
| 1149 | tm->n_pthreads += tr->count * tr->use_pthreads; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 1150 | tm->n_threads += tr->count * (tr->use_pthreads == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1151 | tr = tr->next; |
| 1152 | } |
| 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | VLIB_EARLY_CONFIG_FUNCTION (cpu_config, "cpu"); |
| 1158 | |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 1159 | #if !defined (__x86_64__) && !defined (__aarch64__) && !defined (__powerpc64__) && !defined(__arm__) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1160 | void |
| 1161 | __sync_fetch_and_add_8 (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1162 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1163 | fformat (stderr, "%s called\n", __FUNCTION__); |
| 1164 | abort (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1165 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1166 | |
| 1167 | void |
| 1168 | __sync_add_and_fetch_8 (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1169 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1170 | fformat (stderr, "%s called\n", __FUNCTION__); |
| 1171 | abort (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1172 | } |
| 1173 | #endif |
| 1174 | |
| 1175 | void vnet_main_fixup (vlib_fork_fixup_t which) __attribute__ ((weak)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1176 | void |
| 1177 | vnet_main_fixup (vlib_fork_fixup_t which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1178 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void |
| 1182 | vlib_worker_thread_fork_fixup (vlib_fork_fixup_t which) |
| 1183 | { |
| 1184 | vlib_main_t *vm = vlib_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1185 | |
| 1186 | if (vlib_mains == 0) |
| 1187 | return; |
| 1188 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1189 | ASSERT (os_get_cpu_number () == 0); |
| 1190 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1191 | |
| 1192 | switch (which) |
| 1193 | { |
| 1194 | case VLIB_WORKER_THREAD_FORK_FIXUP_NEW_SW_IF_INDEX: |
| 1195 | vnet_main_fixup (VLIB_WORKER_THREAD_FORK_FIXUP_NEW_SW_IF_INDEX); |
| 1196 | break; |
| 1197 | |
| 1198 | default: |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1199 | ASSERT (0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1200 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1201 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1204 | void |
| 1205 | vlib_worker_thread_barrier_sync (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1206 | { |
| 1207 | f64 deadline; |
| 1208 | u32 count; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1209 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 1210 | if (vec_len (vlib_mains) < 2) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1211 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1212 | |
| 1213 | count = vec_len (vlib_mains) - 1; |
| 1214 | |
| 1215 | /* Tolerate recursive calls */ |
| 1216 | if (++vlib_worker_threads[0].recursion_level > 1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1217 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1218 | |
Bud Grise | 42f2006 | 2016-03-16 13:09:46 -0400 | [diff] [blame] | 1219 | vlib_worker_threads[0].barrier_sync_count++; |
| 1220 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1221 | ASSERT (os_get_cpu_number () == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1222 | |
| 1223 | deadline = vlib_time_now (vm) + BARRIER_SYNC_TIMEOUT; |
| 1224 | |
| 1225 | *vlib_worker_threads->wait_at_barrier = 1; |
| 1226 | while (*vlib_worker_threads->workers_at_barrier != count) |
| 1227 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1228 | if (vlib_time_now (vm) > deadline) |
| 1229 | { |
| 1230 | fformat (stderr, "%s: worker thread deadlock\n", __FUNCTION__); |
| 1231 | os_panic (); |
| 1232 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1236 | void |
| 1237 | vlib_worker_thread_barrier_release (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1238 | { |
| 1239 | f64 deadline; |
| 1240 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 1241 | if (vec_len (vlib_mains) < 2) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1242 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1243 | |
| 1244 | if (--vlib_worker_threads[0].recursion_level > 0) |
| 1245 | return; |
| 1246 | |
| 1247 | deadline = vlib_time_now (vm) + BARRIER_SYNC_TIMEOUT; |
| 1248 | |
| 1249 | *vlib_worker_threads->wait_at_barrier = 0; |
| 1250 | |
| 1251 | while (*vlib_worker_threads->workers_at_barrier > 0) |
| 1252 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1253 | if (vlib_time_now (vm) > deadline) |
| 1254 | { |
| 1255 | fformat (stderr, "%s: worker thread deadlock\n", __FUNCTION__); |
| 1256 | os_panic (); |
| 1257 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1261 | /* |
| 1262 | * Check the frame queue to see if any frames are available. |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1263 | * If so, pull the packets off the frames and put them to |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1264 | * the handoff node. |
| 1265 | */ |
Damjan Marion | e9d52d5 | 2017-03-09 15:42:26 +0100 | [diff] [blame] | 1266 | int |
| 1267 | vlib_frame_queue_dequeue (vlib_main_t * vm, vlib_frame_queue_main_t * fqm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1268 | { |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1269 | u32 thread_id = vm->cpu_index; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1270 | vlib_frame_queue_t *fq = fqm->vlib_frame_queues[thread_id]; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1271 | vlib_frame_queue_elt_t *elt; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1272 | u32 *from, *to; |
| 1273 | vlib_frame_t *f; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1274 | int msg_type; |
| 1275 | int processed = 0; |
| 1276 | u32 n_left_to_node; |
| 1277 | u32 vectors = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1278 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1279 | ASSERT (fq); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1280 | ASSERT (vm == vlib_mains[thread_id]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1281 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1282 | if (PREDICT_FALSE (fqm->node_index == ~0)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1283 | return 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1284 | /* |
| 1285 | * Gather trace data for frame queues |
| 1286 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1287 | if (PREDICT_FALSE (fq->trace)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1288 | { |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1289 | frame_queue_trace_t *fqt; |
| 1290 | frame_queue_nelt_counter_t *fqh; |
| 1291 | u32 elix; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1292 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1293 | fqt = &fqm->frame_queue_traces[thread_id]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1294 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1295 | fqt->nelts = fq->nelts; |
| 1296 | fqt->head = fq->head; |
| 1297 | fqt->head_hint = fq->head_hint; |
| 1298 | fqt->tail = fq->tail; |
| 1299 | fqt->threshold = fq->vector_threshold; |
| 1300 | fqt->n_in_use = fqt->tail - fqt->head; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1301 | if (fqt->n_in_use >= fqt->nelts) |
| 1302 | { |
| 1303 | // if beyond max then use max |
| 1304 | fqt->n_in_use = fqt->nelts - 1; |
| 1305 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1306 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1307 | /* Record the number of elements in use in the histogram */ |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1308 | fqh = &fqm->frame_queue_histogram[thread_id]; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1309 | fqh->count[fqt->n_in_use]++; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1310 | |
| 1311 | /* Record a snapshot of the elements in use */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1312 | for (elix = 0; elix < fqt->nelts; elix++) |
| 1313 | { |
| 1314 | elt = fq->elts + ((fq->head + 1 + elix) & (fq->nelts - 1)); |
| 1315 | if (1 || elt->valid) |
| 1316 | { |
| 1317 | fqt->n_vectors[elix] = elt->n_vectors; |
| 1318 | } |
| 1319 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1320 | fqt->written = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1321 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1322 | |
| 1323 | while (1) |
| 1324 | { |
| 1325 | if (fq->head == fq->tail) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1326 | { |
| 1327 | fq->head_hint = fq->head; |
| 1328 | return processed; |
| 1329 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1330 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1331 | elt = fq->elts + ((fq->head + 1) & (fq->nelts - 1)); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1332 | |
| 1333 | if (!elt->valid) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1334 | { |
| 1335 | fq->head_hint = fq->head; |
| 1336 | return processed; |
| 1337 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1338 | |
| 1339 | from = elt->buffer_index; |
| 1340 | msg_type = elt->msg_type; |
| 1341 | |
| 1342 | ASSERT (msg_type == VLIB_FRAME_QUEUE_ELT_DISPATCH_FRAME); |
| 1343 | ASSERT (elt->n_vectors <= VLIB_FRAME_SIZE); |
| 1344 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1345 | f = vlib_get_frame_to_node (vm, fqm->node_index); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1346 | |
| 1347 | to = vlib_frame_vector_args (f); |
| 1348 | |
| 1349 | n_left_to_node = elt->n_vectors; |
| 1350 | |
| 1351 | while (n_left_to_node >= 4) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1352 | { |
| 1353 | to[0] = from[0]; |
| 1354 | to[1] = from[1]; |
| 1355 | to[2] = from[2]; |
| 1356 | to[3] = from[3]; |
| 1357 | to += 4; |
| 1358 | from += 4; |
| 1359 | n_left_to_node -= 4; |
| 1360 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1361 | |
| 1362 | while (n_left_to_node > 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1363 | { |
| 1364 | to[0] = from[0]; |
| 1365 | to++; |
| 1366 | from++; |
| 1367 | n_left_to_node--; |
| 1368 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1369 | |
| 1370 | vectors += elt->n_vectors; |
| 1371 | f->n_vectors = elt->n_vectors; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1372 | vlib_put_frame_to_node (vm, fqm->node_index, f); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1373 | |
| 1374 | elt->valid = 0; |
| 1375 | elt->n_vectors = 0; |
| 1376 | elt->msg_type = 0xfefefefe; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1377 | CLIB_MEMORY_BARRIER (); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1378 | fq->head++; |
| 1379 | processed++; |
| 1380 | |
| 1381 | /* |
| 1382 | * Limit the number of packets pushed into the graph |
| 1383 | */ |
| 1384 | if (vectors >= fq->vector_threshold) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1385 | { |
| 1386 | fq->head_hint = fq->head; |
| 1387 | return processed; |
| 1388 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1389 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1390 | ASSERT (0); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1391 | return processed; |
| 1392 | } |
| 1393 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1394 | void |
| 1395 | vlib_worker_thread_fn (void *arg) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1396 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1397 | vlib_worker_thread_t *w = (vlib_worker_thread_t *) arg; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 1398 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1399 | vlib_main_t *vm = vlib_get_main (); |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 1400 | clib_error_t *e; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1401 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1402 | ASSERT (vm->cpu_index == os_get_cpu_number ()); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1403 | |
| 1404 | vlib_worker_thread_init (w); |
| 1405 | clib_time_init (&vm->clib_time); |
| 1406 | clib_mem_set_heap (w->thread_mheap); |
| 1407 | |
Damjan Marion | e9f929b | 2017-03-16 11:32:09 +0100 | [diff] [blame] | 1408 | e = vlib_call_init_exit_functions |
| 1409 | (vm, vm->worker_init_function_registrations, 1 /* call_once */ ); |
| 1410 | if (e) |
| 1411 | clib_error_report (e); |
| 1412 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1413 | /* Wait until the dpdk init sequence is complete */ |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 1414 | while (tm->extern_thread_mgmt && tm->worker_thread_release == 0) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1415 | vlib_worker_thread_barrier_check (); |
| 1416 | |
Damjan Marion | e9d52d5 | 2017-03-09 15:42:26 +0100 | [diff] [blame] | 1417 | vlib_worker_loop (vm); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1420 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1421 | VLIB_REGISTER_THREAD (worker_thread_reg, static) = { |
| 1422 | .name = "workers", |
| 1423 | .short_name = "wk", |
| 1424 | .function = vlib_worker_thread_fn, |
| 1425 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1426 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1427 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 1428 | u32 |
| 1429 | vlib_frame_queue_main_init (u32 node_index, u32 frame_queue_nelts) |
| 1430 | { |
| 1431 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 1432 | vlib_frame_queue_main_t *fqm; |
| 1433 | vlib_frame_queue_t *fq; |
| 1434 | int i; |
| 1435 | |
| 1436 | if (frame_queue_nelts == 0) |
| 1437 | frame_queue_nelts = FRAME_QUEUE_NELTS; |
| 1438 | |
| 1439 | vec_add2 (tm->frame_queue_mains, fqm, 1); |
| 1440 | |
| 1441 | fqm->node_index = node_index; |
| 1442 | |
| 1443 | vec_validate (fqm->vlib_frame_queues, tm->n_vlib_mains - 1); |
| 1444 | _vec_len (fqm->vlib_frame_queues) = 0; |
| 1445 | for (i = 0; i < tm->n_vlib_mains; i++) |
| 1446 | { |
| 1447 | fq = vlib_frame_queue_alloc (frame_queue_nelts); |
| 1448 | vec_add1 (fqm->vlib_frame_queues, fq); |
| 1449 | } |
| 1450 | |
| 1451 | return (fqm - tm->frame_queue_mains); |
| 1452 | } |
| 1453 | |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 1454 | |
| 1455 | int |
| 1456 | vlib_thread_cb_register (struct vlib_main_t *vm, vlib_thread_callbacks_t * cb) |
| 1457 | { |
| 1458 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 1459 | |
| 1460 | if (tm->extern_thread_mgmt) |
| 1461 | return -1; |
| 1462 | |
| 1463 | tm->cb.vlib_launch_thread_cb = cb->vlib_launch_thread_cb; |
| 1464 | tm->extern_thread_mgmt = 1; |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1468 | clib_error_t * |
| 1469 | threads_init (vlib_main_t * vm) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1470 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1471 | return 0; |
| 1472 | } |
| 1473 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1474 | VLIB_INIT_FUNCTION (threads_init); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 1475 | |
| 1476 | /* |
| 1477 | * fd.io coding-style-patch-verification: ON |
| 1478 | * |
| 1479 | * Local Variables: |
| 1480 | * eval: (c-set-style "gnu") |
| 1481 | * End: |
| 1482 | */ |