-
Notifications
You must be signed in to change notification settings - Fork 15
/
dpdk_eal.c
169 lines (156 loc) · 5.83 KB
/
dpdk_eal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* BSD LICENSE
*
* Copyright(c) 2016-2017 Netronome.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Netronome nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dpdk_eal.h"
#include "argv.h"
#define __MODULE__ "dpdk_eal"
#include "log.h"
#include "rte_errno.h"
#include "rte_mbuf.h"
#include "cpuinfo.h"
#include <getopt.h>
#include <rte_eal.h>
#include <rte_version.h>
int dpdk_eal_initialize(const struct dpdk_conf *conf)
{
int argc = 0;
char **argv = NULL;
int ret;
char buf[32];
unsigned i;
int len = 0;
cpuinfo_t *cpu = get_cpuinfo();
uint32_t socket_bitmap = 0;
uint32_t numa_bitmap = 0;
if (!cpu)
return -1;
if ((conf->core_bitmap & cpu->cpubitmap) != conf->core_bitmap) {
log_error("Specified CPU bitmap 0x%"PRIx64" contains CPUs outside of currently connected CPUs (0x%"PRIx64")",
conf->core_bitmap, cpu->cpubitmap);
return -1;
}
if (!((1<<conf->master_lcore) & cpu->cpubitmap)) {
log_error("Master lcore is not a valid CPU: %u not in (0x%"PRIx64")",
conf->master_lcore, cpu->cpubitmap);
return -1;
}
if (conf->core_bitmap & (1<<conf->master_lcore)) {
log_error("Worker CPU bitmap 0x%"PRIx64" may not contain the master lcore %u",
conf->core_bitmap, conf->master_lcore);
return -1;
}
for (i=0; i<MAX_CPUS; ++i) {
if ((1ULL<<i) & conf->core_bitmap) {
socket_bitmap |= (1<<cpu->cpus[i].socket);
numa_bitmap |= (1<<cpu->cpus[i].numanode);
}
}
add_arg(&argv, &argc, "virtio-forwarder");
#if RTE_VERSION_NUM(20, 11, 0, 0) > RTE_VERSION
add_arg(&argv, &argc, "--master-lcore");
#else
add_arg(&argv, &argc, "--main-lcore");
#endif
snprintf(buf, 32, "%u", conf->master_lcore);
add_arg(&argv, &argc, buf);
add_arg(&argv, &argc, "--log-level");
snprintf(buf, 32, "%u", conf->log_level);
add_arg(&argv, &argc, buf);
add_arg(&argv, &argc, "--huge-dir");
add_arg(&argv, &argc, conf->huge_dir);
add_arg(&argv, &argc, "--file-prefix");
add_arg(&argv, &argc, "virtio-forwarder_");
#if RTE_VERSION_NUM(20, 8, 0, 0) <= RTE_VERSION
if (conf->enable_vfio_vf_token) {
add_arg(&argv, &argc, "--vfio-vf-token");
add_arg(&argv, &argc, conf->vfio_vf_token);
}
#endif
/* Unlink the hugepages after mapping to ensure they're gone when app exits. */
add_arg(&argv, &argc, "--huge-unlink");
#if RTE_VERSION_NUM(17, 2, 0, 0) > RTE_VERSION
/* Prevent scanning all PCI devices at startup, instead only use hotplug API. */
add_arg(&argv, &argc, "--no-pci");
#elif RTE_VERSION_NUM(20, 11, 0, 0) > RTE_VERSION
/* DPDK's --no-pci behaviour changed in 17.2.x With the flag passed, the
* EAL never populates its device lists which causes subsequent hotplugs
* to fail. When it is not passed, EAL attaches to all uio devices,
* which we do not want that either. The 'solution' is to omit the flag
* in order for DPDK to discover devices and to also add a bogus
* whitelist address such that DPDK will only auto-attach to it.
*/
add_arg(&argv, &argc, "-w");
add_arg(&argv, &argc, "ffff:ff:ff.f");
#else
add_arg(&argv, &argc, "-a");
add_arg(&argv, &argc, "ffff:ff:ff.f");
#endif
add_arg(&argv, &argc, "-c"); /* Core mask. */
snprintf(buf, 32, "%llx", (long long)conf->core_bitmap | (1<<conf->master_lcore));
add_arg(&argv, &argc, buf);
add_arg(&argv, &argc, "-n"); /* Mem channels. */
add_arg(&argv, &argc, "4");
add_arg(&argv, &argc, "--socket-mem"); /* Memory to allocate per NUMA node (MiB). */
/* By default, XVIO reserve at least 1 MiB hugepage memory on each numa,
* as error will occur while use NIC on that numa node but not assign
* hugepage.
* In order to reduce memory use, ensure used NIC and CPUs are on the same
* numa, then set 'conf->enable_same_numa', XVIO will only reserve hugepages
* on the active numa node.
*/
for (i = 0; i < cpu->numnodes; i++) {
if (i >= 1)
len += snprintf(buf + len, 32 - len, ",");
if ((1 << i) & numa_bitmap)
len += snprintf(buf + len, 32 - len,
(conf->use_jumbo || conf->enable_tso) ?
"2750" : "768");
else
len += snprintf(buf + len, 32 - len,
conf->enable_same_numa ? "0" : "1");
}
add_arg(&argv, &argc, buf);
optind = 0;
/* Output eal param into log */
for (i = 0; i < argc; i++)
log_info("dpdk eal param %d: %s", i, argv[i]);
log_info("DPDK version: %s", rte_version());
ret = rte_eal_init(argc, argv);
if (ret < 0) {
return ret;
}
log_info("Maximum relays is %u, increase RTE_MAX_ETHPORTS in DPDK if more are required",
RTE_MAX_ETHPORTS);
return 0;
}
void dpdk_eal_finalize(void)
{}