2 * Copyright (c) 2017 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vnet/plugin/plugin.h>
18 #include <dpdk/device/dpdk.h>
19 #include <vpp/app/version.h>
22 * Called by the dpdk driver's rte_delay_us() function.
23 * Return 0 to have the dpdk do a regular delay loop.
24 * Return 1 if to skip the delay loop because we are suspending
25 * the calling vlib process instead.
28 rte_delay_us_override (unsigned us)
32 /* Don't bother intercepting for short delays */
37 * Only intercept if we are in a vlib process.
38 * If we are called from a vlib worker thread or the vlib main
39 * thread then do not intercept. (Must not be called from an
40 * independent pthread).
42 if (os_get_cpu_number () == 0)
45 * We're in the vlib main thread or a vlib process. Make sure
46 * the process is running and we're not still initializing.
48 vm = vlib_get_main ();
49 if (vlib_in_process_context (vm))
51 /* Only suspend for the admin_down_process */
52 vlib_process_t *proc = vlib_get_current_process (vm);
53 if (!(proc->flags & VLIB_PROCESS_IS_RUNNING) ||
54 (proc->node_runtime.function != admin_up_down_process))
57 f64 delay = 1e-6 * us;
58 vlib_process_suspend (vm, delay);
62 return 0; // no override
66 rte_delay_us_override_cb (unsigned us)
68 if (rte_delay_us_override (us) == 0)
69 rte_delay_us_block (us);
72 static clib_error_t * dpdk_main_init (vlib_main_t * vm)
74 dpdk_main_t * dm = &dpdk_main;
75 clib_error_t * error = 0;
78 dm->vnet_main = vnet_get_main ();
80 if ((error = vlib_call_init_function (vm, dpdk_init)))
83 /* register custom delay function */
84 rte_delay_us_callback_register (rte_delay_us_override_cb);
89 VLIB_INIT_FUNCTION (dpdk_main_init);
92 VLIB_PLUGIN_REGISTER () = {
93 .version = VPP_BUILD_VER,