FD.io VPP
v18.01-8-g0eacf49
Vector Packet Processing
Main Page
Related Pages
Modules
Namespaces
Data Structures
Source
Files
Symbols
main.c
Go to the documentation of this file.
1
/*
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:
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
*/
15
16
#include <
vnet/vnet.h
>
17
#include <
vnet/plugin/plugin.h
>
18
#include <
dpdk/device/dpdk.h
>
19
#include <vpp/app/version.h>
20
21
/*
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.
26
*/
27
static
int
28
rte_delay_us_override
(
unsigned
us)
29
{
30
vlib_main_t
*
vm
;
31
32
/* Don't bother intercepting for short delays */
33
if
(us < 10)
34
return
0;
35
36
/*
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).
41
*/
42
if
(
vlib_get_thread_index
() == 0)
43
{
44
/*
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.
47
*/
48
vm =
vlib_get_main
();
49
if
(
vlib_in_process_context
(vm))
50
{
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
))
55
return
0;
56
57
f64
delay = 1e-6 * us;
58
vlib_process_suspend
(vm, delay);
59
return
1;
60
}
61
}
62
return
0;
// no override
63
}
64
65
static
void
66
rte_delay_us_override_cb
(
unsigned
us)
67
{
68
if
(
rte_delay_us_override
(us) == 0)
69
rte_delay_us_block (us);
70
}
71
72
static
clib_error_t
*
dpdk_main_init
(
vlib_main_t
*
vm
)
73
{
74
dpdk_main_t
* dm = &
dpdk_main
;
75
clib_error_t
* error = 0;
76
77
dm->
vlib_main
=
vm
;
78
dm->
vnet_main
=
vnet_get_main
();
79
80
if
((error =
vlib_call_init_function
(vm,
dpdk_init
)))
81
return
error;
82
83
/* register custom delay function */
84
rte_delay_us_callback_register (
rte_delay_us_override_cb
);
85
86
return
error;
87
}
88
89
VLIB_INIT_FUNCTION
(
dpdk_main_init
);
90
91
/* *INDENT-OFF* */
92
VLIB_PLUGIN_REGISTER
() = {
93
.version = VPP_BUILD_VER,
94
.description =
"Data Plane Development Kit (DPDK)"
,
95
};
96
/* *INDENT-ON* */
vlib_process_t::node_runtime
vlib_node_runtime_t node_runtime
Definition:
node.h:495
dpdk_main
dpdk_main_t dpdk_main
Definition:
init.c:39
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition:
misc.c:47
dpdk_main_init
static clib_error_t * dpdk_main_init(vlib_main_t *vm)
Definition:
main.c:72
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
vlib_process_t
Definition:
node.h:492
vlib_process_suspend
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition:
node_funcs.h:448
plugin.h
vlib_node_runtime_t::function
vlib_node_function_t * function
Node function to call.
Definition:
node.h:413
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition:
init.h:111
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition:
init.h:162
dpdk_init
static clib_error_t * dpdk_init(vlib_main_t *vm)
Definition:
init.c:1574
rte_delay_us_override_cb
static void rte_delay_us_override_cb(unsigned us)
Definition:
main.c:66
dpdk.h
vnet.h
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition:
threads.h:221
vlib_get_current_process
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition:
node_funcs.h:417
vm
vlib_main_t * vm
Definition:
buffer.c:283
rte_delay_us_override
static int rte_delay_us_override(unsigned us)
Definition:
main.c:28
admin_up_down_process
uword admin_up_down_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition:
device.c:817
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition:
global_funcs.h:23
clib_error_t
Definition:
clib_error.h:21
f64
double f64
Definition:
types.h:142
vlib_main_t
Definition:
main.h:59
vlib_process_t::flags
u16 flags
Definition:
node.h:508
vlib_in_process_context
static uword vlib_in_process_context(vlib_main_t *vm)
Definition:
node_funcs.h:411
dpdk_main_t::vnet_main
vnet_main_t * vnet_main
Definition:
dpdk.h:394
VLIB_PROCESS_IS_RUNNING
#define VLIB_PROCESS_IS_RUNNING
Definition:
node.h:515
dpdk_main_t
Definition:
dpdk.h:349
dpdk_main_t::vlib_main
vlib_main_t * vlib_main
Definition:
dpdk.h:393
src
plugins
dpdk
main.c
Generated on Wed Feb 7 2018 04:45:40 for FD.io VPP by
1.8.11