FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
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 <unistd.h>
17
#include <sys/types.h>
18
#include <sys/stat.h>
19
#include <fcntl.h>
20
#include <
linux/vfio.h
>
21
#include <sys/ioctl.h>
22
23
#include <
vnet/vnet.h
>
24
#include <
vnet/plugin/plugin.h
>
25
#include <
dpdk/device/dpdk.h
>
26
#include <vpp/app/version.h>
27
28
/*
29
* Called by the dpdk driver's rte_delay_us() function.
30
* Return 0 to have the dpdk do a regular delay loop.
31
* Return 1 if to skip the delay loop because we are suspending
32
* the calling vlib process instead.
33
*/
34
static
int
35
rte_delay_us_override
(
unsigned
us)
36
{
37
vlib_main_t
*
vm
;
38
39
/* Don't bother intercepting for short delays */
40
if
(us < 10)
41
return
0;
42
43
/*
44
* Only intercept if we are in a vlib process.
45
* If we are called from a vlib worker thread or the vlib main
46
* thread then do not intercept. (Must not be called from an
47
* independent pthread).
48
*/
49
if
(
vlib_get_thread_index
() == 0)
50
{
51
/*
52
* We're in the vlib main thread or a vlib process. Make sure
53
* the process is running and we're not still initializing.
54
*/
55
vm
=
vlib_get_main
();
56
if
(
vlib_in_process_context
(
vm
))
57
{
58
/* Only suspend for the admin_down_process */
59
vlib_process_t
*proc =
vlib_get_current_process
(
vm
);
60
if
(!(proc->
flags
&
VLIB_PROCESS_IS_RUNNING
) ||
61
(proc->
node_runtime
.
node_index
!=
62
admin_up_down_process_node
.index))
63
return
0;
64
65
f64
delay = 1e-6 * us;
66
vlib_process_suspend
(
vm
, delay);
67
return
1;
68
}
69
}
70
return
0;
// no override
71
}
72
73
static
void
74
rte_delay_us_override_cb
(
unsigned
us)
75
{
76
if
(
rte_delay_us_override
(us) == 0)
77
rte_delay_us_block (us);
78
}
79
80
static
clib_error_t
*
dpdk_main_init
(
vlib_main_t
*
vm
)
81
{
82
dpdk_main_t
* dm = &
dpdk_main
;
83
clib_error_t
*
error
= 0;
84
85
dm->
vlib_main
=
vm
;
86
dm->
vnet_main
=
vnet_get_main
();
87
88
/* register custom delay function */
89
rte_delay_us_callback_register (
rte_delay_us_override_cb
);
90
91
return
error
;
92
}
93
94
/* *INDENT-OFF* */
95
VLIB_INIT_FUNCTION
(
dpdk_main_init
) =
96
{
97
.runs_after =
VLIB_INITS
(
"dpdk_init"
),
98
};
99
100
VLIB_PLUGIN_REGISTER
() = {
101
.version = VPP_BUILD_VER,
102
.description =
"Data Plane Development Kit (DPDK)"
,
103
};
104
/* *INDENT-ON* */
vlib_process_t::flags
u16 flags
Definition:
node.h:550
vlib_in_process_context
static uword vlib_in_process_context(vlib_main_t *vm)
Definition:
node_funcs.h:442
dpdk.h
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
dpdk_main_t::vnet_main
vnet_main_t * vnet_main
Definition:
dpdk.h:379
admin_up_down_process_node
vlib_node_registration_t admin_up_down_process_node
(constructor) VLIB_REGISTER_NODE (admin_up_down_process_node)
Definition:
device.c:819
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition:
nat44_ei.c:3047
vlib_process_t::node_runtime
vlib_node_runtime_t node_runtime
Definition:
node.h:537
error
Definition:
cJSON.c:88
rte_delay_us_override_cb
static void rte_delay_us_override_cb(unsigned us)
Definition:
main.c:74
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition:
pnat_test_stubs.h:56
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition:
threads.h:187
dpdk_main
dpdk_main_t dpdk_main
Definition:
init.c:48
dpdk_main_t
Definition:
dpdk.h:357
f64
double f64
Definition:
types.h:142
plugin.h
vlib_node_runtime_t::node_index
u32 node_index
Node index.
Definition:
node.h:478
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:486
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition:
init.h:172
vlib_get_current_process
static vlib_process_t * vlib_get_current_process(vlib_main_t *vm)
Definition:
node_funcs.h:448
rte_delay_us_override
static int rte_delay_us_override(unsigned us)
Definition:
main.c:35
dpdk_main_t::vlib_main
vlib_main_t * vlib_main
Definition:
dpdk.h:378
vlib_main_t
Definition:
main.h:102
VLIB_INITS
#define VLIB_INITS(...)
Definition:
init.h:352
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition:
global_funcs.h:38
clib_error_t
Definition:
clib_error.h:21
vfio.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition:
init.h:51
vlib_process_t
Definition:
node.h:533
vnet.h
VLIB_PROCESS_IS_RUNNING
#define VLIB_PROCESS_IS_RUNNING
Definition:
node.h:557
dpdk_main_init
static clib_error_t * dpdk_main_init(vlib_main_t *vm)
Definition:
main.c:80
src
plugins
dpdk
main.c
Generated on Sat Jan 8 2022 10:36:01 for FD.io VPP by
1.8.17