1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand. |
---|
4 | * All rights reserved. |
---|
5 | * |
---|
6 | * This file is part of libtrace. |
---|
7 | * |
---|
8 | * This code has been developed by the University of Waikato WAND |
---|
9 | * research group. For further information please see http://www.wand.net.nz/ |
---|
10 | * |
---|
11 | * libtrace is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License as published by |
---|
13 | * the Free Software Foundation; either version 3 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * libtrace is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public License |
---|
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * |
---|
25 | * |
---|
26 | * Kit capture format. |
---|
27 | * |
---|
28 | * Intel Data Plane Development Kit is a LIVE capture format. |
---|
29 | * |
---|
30 | * This format also supports writing which will write packets out to the |
---|
31 | * network as a form of packet replay. This should not be confused with the |
---|
32 | * RT protocol which is intended to transfer captured packet records between |
---|
33 | * RT-speaking programs. |
---|
34 | */ |
---|
35 | |
---|
36 | #define _GNU_SOURCE |
---|
37 | |
---|
38 | #include "config.h" |
---|
39 | #include "libtrace.h" |
---|
40 | #include "libtrace_int.h" |
---|
41 | #include "format_helper.h" |
---|
42 | #include "libtrace_arphrd.h" |
---|
43 | #include "hash_toeplitz.h" |
---|
44 | #include "format_dpdk.h" |
---|
45 | |
---|
46 | #ifdef HAVE_INTTYPES_H |
---|
47 | # include <inttypes.h> |
---|
48 | #else |
---|
49 | # error "Can't find inttypes.h" |
---|
50 | #endif |
---|
51 | |
---|
52 | #include <stdlib.h> |
---|
53 | #include <unistd.h> |
---|
54 | #include <endian.h> |
---|
55 | #include <string.h> |
---|
56 | #include <math.h> |
---|
57 | |
---|
58 | #ifdef HAVE_LIBNUMA |
---|
59 | #include <numa.h> |
---|
60 | #endif |
---|
61 | |
---|
62 | #define MBUF(x) ((struct rte_mbuf *) x) |
---|
63 | /* Get the original placement of the packet data */ |
---|
64 | #define MBUF_PKTDATA(x) ((char *) x + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM) |
---|
65 | #define FORMAT(x) ((struct dpdk_format_data_t*)(x->format_data)) |
---|
66 | #define PERPKT_FORMAT(x) ((struct dpdk_per_lcore_t*)(x->format_data)) |
---|
67 | |
---|
68 | #define FORMAT_DATA_HEAD(x) FORMAT(x)->per_stream->head |
---|
69 | #define FORMAT_DATA_FIRST(x) ((dpdk_per_stream_t *)FORMAT_DATA_HEAD(x)->data) |
---|
70 | |
---|
71 | #define TV_TO_NS(tv) ((uint64_t) tv.tv_sec*1000000000ull + \ |
---|
72 | (uint64_t) tv.tv_usec*1000ull) |
---|
73 | #define TS_TO_NS(ts) ((uint64_t) ts.tv_sec*1000000000ull + \ |
---|
74 | (uint64_t) ts.tv_nsec) |
---|
75 | |
---|
76 | #if RTE_PKTMBUF_HEADROOM != 128 |
---|
77 | #warning "RTE_PKT_MBUF_HEADROOM is not set to the default value of 128 - " \ |
---|
78 | "any libtrace instance processing these packet must be have the" \ |
---|
79 | "same RTE_PKTMBUF_HEADROOM set" |
---|
80 | #endif |
---|
81 | |
---|
82 | |
---|
83 | static pthread_mutex_t dpdk_lock = PTHREAD_MUTEX_INITIALIZER; |
---|
84 | /* Memory pools Per NUMA node */ |
---|
85 | static struct rte_mempool * mem_pools[4][RTE_MAX_LCORE] = {{0}}; |
---|
86 | |
---|
87 | /* Used by both input and output however some fields are not used |
---|
88 | * for output */ |
---|
89 | struct dpdk_format_data_t { |
---|
90 | int8_t promisc; /* promiscuous mode - RX only */ |
---|
91 | uint8_t paused; /* See paused_state */ |
---|
92 | portid_t port; /* Always 0 we only whitelist a single port - Shared TX & RX */ |
---|
93 | portid_t nb_ports; /* Total number of usable ports on system should be 1 */ |
---|
94 | uint16_t link_speed; /* Link speed 10,100,1000,10000 etc. */ |
---|
95 | int snaplen; /* The snap length for the capture - RX only */ |
---|
96 | /* We always have to setup both rx and tx queues even if we don't want them */ |
---|
97 | int nb_rx_buf; /* The number of packet buffers in the rx ring */ |
---|
98 | int nb_tx_buf; /* The number of packet buffers in the tx ring */ |
---|
99 | int nic_numa_node; /* The NUMA node that the NIC is attached to */ |
---|
100 | struct rte_mempool * pktmbuf_pool; /* Our packet memory pool */ |
---|
101 | #if DPDK_USE_BLACKLIST |
---|
102 | struct rte_pci_addr blacklist[BLACK_LIST_SIZE]; /* Holds our device blacklist */ |
---|
103 | unsigned int nb_blacklist; /* Number of blacklist items in are valid */ |
---|
104 | #endif |
---|
105 | char mempool_name[MEMPOOL_NAME_LEN]; /* The name of the mempool that we are using */ |
---|
106 | enum hasher_types hasher_type; |
---|
107 | uint8_t *rss_key; |
---|
108 | /* To improve single-threaded performance we always batch reading |
---|
109 | * packets, in a burst, otherwise the parallel library does this for us */ |
---|
110 | struct rte_mbuf* burst_pkts[BURST_SIZE]; |
---|
111 | int burst_size; /* The total number read in the burst */ |
---|
112 | int burst_offset; /* The offset we are into the burst */ |
---|
113 | |
---|
114 | /* Our parallel streams */ |
---|
115 | libtrace_list_t *per_stream; |
---|
116 | }; |
---|
117 | |
---|
118 | enum dpdk_addt_hdr_flags { |
---|
119 | INCLUDES_CHECKSUM = 0x1, |
---|
120 | INCLUDES_HW_TIMESTAMP = 0x2, /* Used with 82580 driver */ |
---|
121 | }; |
---|
122 | |
---|
123 | /** |
---|
124 | * A structure placed in front of the packet where we can store |
---|
125 | * additional information about the given packet. |
---|
126 | * +--------------------------+ |
---|
127 | * | rte_mbuf (pkt) | sizeof(rte_mbuf) |
---|
128 | * +--------------------------+ |
---|
129 | * | dpdk_addt_hdr | sizeof(dpdk_addt_hdr) |
---|
130 | * +--------------------------+ |
---|
131 | * | padding | RTE_PKTMBUF_HEADROOM-sizeof(dpdk_addt_hdr) |
---|
132 | * +--------------------------+ |
---|
133 | * * hw_timestamp_82580 * 16 bytes Optional |
---|
134 | * +--------------------------+ |
---|
135 | * | Packet data | Variable Size |
---|
136 | * | | |
---|
137 | */ |
---|
138 | struct dpdk_addt_hdr { |
---|
139 | uint64_t timestamp; |
---|
140 | uint8_t flags; |
---|
141 | uint8_t direction; |
---|
142 | uint8_t reserved1; |
---|
143 | uint8_t reserved2; |
---|
144 | uint32_t cap_len; /* The size to say the capture is */ |
---|
145 | }; |
---|
146 | |
---|
147 | static bool dpdk_can_write(libtrace_packet_t *packet) { |
---|
148 | return true; |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * We want to blacklist all devices except those on the whitelist |
---|
153 | * (I say list, but yes it is only the one). |
---|
154 | * |
---|
155 | * The default behaviour of rte_pci_probe() will map every possible device |
---|
156 | * to its DPDK driver. The DPDK driver will take the ethernet device |
---|
157 | * out of the kernel (i.e. no longer /dev/ethx) and cannot be used. |
---|
158 | * |
---|
159 | * So blacklist all devices except the one that we wish to use so that |
---|
160 | * the others can still be used as standard ethernet ports. |
---|
161 | * |
---|
162 | * @return 0 if successful, otherwise -1 on error. |
---|
163 | */ |
---|
164 | #if DPDK_USE_BLACKLIST |
---|
165 | static int blacklist_devices(struct dpdk_format_data_t *format_data, struct rte_pci_addr *whitelist) |
---|
166 | { |
---|
167 | struct rte_pci_device *dev = NULL; |
---|
168 | format_data->nb_blacklist = 0; |
---|
169 | |
---|
170 | memset(format_data->blacklist, 0, sizeof (format_data->blacklist)); |
---|
171 | |
---|
172 | TAILQ_FOREACH(dev, &device_list, next) { |
---|
173 | if (whitelist != NULL && whitelist->domain == dev->addr.domain |
---|
174 | && whitelist->bus == dev->addr.bus |
---|
175 | && whitelist->devid == dev->addr.devid |
---|
176 | && whitelist->function == dev->addr.function) |
---|
177 | continue; |
---|
178 | if (format_data->nb_blacklist >= sizeof (format_data->blacklist) |
---|
179 | / sizeof (format_data->blacklist[0])) { |
---|
180 | fprintf(stderr, "Warning: too many devices to blacklist consider" |
---|
181 | " increasing BLACK_LIST_SIZE"); |
---|
182 | break; |
---|
183 | } |
---|
184 | format_data->blacklist[format_data->nb_blacklist] = dev->addr; |
---|
185 | ++format_data->nb_blacklist; |
---|
186 | } |
---|
187 | |
---|
188 | rte_eal_pci_set_blacklist(format_data->blacklist, format_data->nb_blacklist); |
---|
189 | return 0; |
---|
190 | } |
---|
191 | #else /* DPDK_USE_BLACKLIST */ |
---|
192 | #include <rte_devargs.h> |
---|
193 | static int whitelist_device(struct dpdk_format_data_t *format_data UNUSED, struct rte_pci_addr *whitelist) |
---|
194 | { |
---|
195 | char pci_str[20] = {0}; |
---|
196 | snprintf(pci_str, sizeof(pci_str), PCI_PRI_FMT, |
---|
197 | whitelist->domain, |
---|
198 | whitelist->bus, |
---|
199 | whitelist->devid, |
---|
200 | whitelist->function); |
---|
201 | if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, pci_str) < 0) { |
---|
202 | return -1; |
---|
203 | } |
---|
204 | return 0; |
---|
205 | } |
---|
206 | #endif |
---|
207 | |
---|
208 | /** |
---|
209 | * Parse the URI format as a pci address |
---|
210 | * Fills in addr, note core is optional and is unchanged if |
---|
211 | * a value for it is not provided. |
---|
212 | * |
---|
213 | * i.e. ./libtrace dpdk:0:1:0.0 -> 0:1:0.0 |
---|
214 | * or ./libtrace dpdk:0:1:0.1-2 -> 0:1:0.1 (Using CPU core #2) |
---|
215 | */ |
---|
216 | static int parse_pciaddr(char * str, struct rte_pci_addr * addr, long * core) { |
---|
217 | int matches; |
---|
218 | |
---|
219 | if (!str) { |
---|
220 | fprintf(stderr, "NULL str passed into parse_pciaddr()\n"); |
---|
221 | return -1; |
---|
222 | } |
---|
223 | #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) |
---|
224 | matches = sscanf(str, "%8"SCNx32":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld", |
---|
225 | &addr->domain, &addr->bus, &addr->devid, |
---|
226 | &addr->function, core); |
---|
227 | #else |
---|
228 | matches = sscanf(str, "%4"SCNx16":%2"SCNx8":%2"SCNx8".%2"SCNx8"-%ld", |
---|
229 | &addr->domain, &addr->bus, &addr->devid, |
---|
230 | &addr->function, core); |
---|
231 | #endif |
---|
232 | if (matches >= 4) { |
---|
233 | return 0; |
---|
234 | } else { |
---|
235 | return -1; |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | /** |
---|
240 | * Convert a pci address to the numa node it is |
---|
241 | * connected to. |
---|
242 | * |
---|
243 | * This checks /sys/bus/pci/devices/XXXX:XX:XX.X/numa_node |
---|
244 | * so we can call it before DPDK |
---|
245 | * |
---|
246 | * @return -1 if unknown otherwise a number 0 or higher of the numa node |
---|
247 | */ |
---|
248 | static int pci_to_numa(struct rte_pci_addr * dev_addr) { |
---|
249 | char path[50] = {0}; |
---|
250 | FILE *file; |
---|
251 | |
---|
252 | /* Read from the system */ |
---|
253 | snprintf(path, sizeof(path), "/sys/bus/pci/devices/"PCI_PRI_FMT"/numa_node", |
---|
254 | dev_addr->domain, |
---|
255 | dev_addr->bus, |
---|
256 | dev_addr->devid, |
---|
257 | dev_addr->function); |
---|
258 | |
---|
259 | if((file = fopen(path, "r")) != NULL) { |
---|
260 | int numa_node = -1; |
---|
261 | fscanf(file, "%d", &numa_node); |
---|
262 | fclose(file); |
---|
263 | return numa_node; |
---|
264 | } |
---|
265 | return -1; |
---|
266 | } |
---|
267 | |
---|
268 | #if DEBUG |
---|
269 | /* For debugging */ |
---|
270 | static inline void dump_configuration() |
---|
271 | { |
---|
272 | struct rte_config * global_config; |
---|
273 | long nb_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
---|
274 | |
---|
275 | if (nb_cpu <= 0) { |
---|
276 | perror("sysconf(_SC_NPROCESSORS_ONLN) failed." |
---|
277 | " Falling back to the first core."); |
---|
278 | nb_cpu = 1; /* fallback to just 1 core */ |
---|
279 | } |
---|
280 | if (nb_cpu > RTE_MAX_LCORE) |
---|
281 | nb_cpu = RTE_MAX_LCORE; |
---|
282 | |
---|
283 | global_config = rte_eal_get_configuration(); |
---|
284 | |
---|
285 | if (global_config != NULL) { |
---|
286 | int i; |
---|
287 | fprintf(stderr, "Intel DPDK setup\n" |
---|
288 | "---Version : %s\n" |
---|
289 | "---Master LCore : %"PRIu32"\n" |
---|
290 | "---LCore Count : %"PRIu32"\n", |
---|
291 | rte_version(), |
---|
292 | global_config->master_lcore, global_config->lcore_count); |
---|
293 | |
---|
294 | for (i = 0 ; i < nb_cpu; i++) { |
---|
295 | fprintf(stderr, " ---Core %d : %s\n", i, |
---|
296 | global_config->lcore_role[i] == ROLE_RTE ? "on" : "off"); |
---|
297 | } |
---|
298 | |
---|
299 | const char * proc_type; |
---|
300 | switch (global_config->process_type) { |
---|
301 | case RTE_PROC_AUTO: |
---|
302 | proc_type = "auto"; |
---|
303 | break; |
---|
304 | case RTE_PROC_PRIMARY: |
---|
305 | proc_type = "primary"; |
---|
306 | break; |
---|
307 | case RTE_PROC_SECONDARY: |
---|
308 | proc_type = "secondary"; |
---|
309 | break; |
---|
310 | case RTE_PROC_INVALID: |
---|
311 | proc_type = "invalid"; |
---|
312 | break; |
---|
313 | default: |
---|
314 | proc_type = "something worse than invalid!!"; |
---|
315 | } |
---|
316 | fprintf(stderr, "---Process Type : %s\n", proc_type); |
---|
317 | } |
---|
318 | |
---|
319 | } |
---|
320 | #endif |
---|
321 | |
---|
322 | /** |
---|
323 | * Expects to be called from the master lcore and moves it to the given dpdk id |
---|
324 | * @param core (zero indexed) If core is on the physical system affinity is bound otherwise |
---|
325 | * affinity is set to all cores. Must be less than RTE_MAX_LCORE |
---|
326 | * and not already in use. |
---|
327 | * @return 0 is successful otherwise -1 on error. |
---|
328 | */ |
---|
329 | static inline int dpdk_move_master_lcore(libtrace_t *libtrace, size_t core) { |
---|
330 | struct rte_config *cfg = rte_eal_get_configuration(); |
---|
331 | cpu_set_t cpuset; |
---|
332 | int i; |
---|
333 | |
---|
334 | if (core >= RTE_MAX_LCORE) { |
---|
335 | fprintf(stderr, "Core must be a value less than the number of cores " |
---|
336 | "in dpdk_move_master_lcore()\n"); |
---|
337 | return -1; |
---|
338 | } |
---|
339 | if (rte_get_master_lcore() != rte_lcore_id()) { |
---|
340 | fprintf(stderr, "Master core not equal to core id in dpdk_move_master_lcore()\n"); |
---|
341 | return -1; |
---|
342 | } |
---|
343 | |
---|
344 | if (core == rte_lcore_id()) |
---|
345 | return 0; |
---|
346 | |
---|
347 | /* Make sure we are not overwriting someone else */ |
---|
348 | if (rte_lcore_is_enabled(core)) { |
---|
349 | fprintf(stderr, "Cannot override another core in dpdk_move_master_lcore()\n"); |
---|
350 | return -1; |
---|
351 | } |
---|
352 | |
---|
353 | /* Move the core */ |
---|
354 | cfg->lcore_role[rte_lcore_id()] = ROLE_OFF; |
---|
355 | cfg->lcore_role[core] = ROLE_RTE; |
---|
356 | lcore_config[core].thread_id = lcore_config[rte_lcore_id()].thread_id; |
---|
357 | rte_eal_get_configuration()->master_lcore = core; |
---|
358 | RTE_PER_LCORE(_lcore_id) = core; |
---|
359 | |
---|
360 | /* Now change the affinity, either mapped to a single core or all accepted */ |
---|
361 | CPU_ZERO(&cpuset); |
---|
362 | |
---|
363 | if (lcore_config[core].detected) { |
---|
364 | CPU_SET(core, &cpuset); |
---|
365 | } else { |
---|
366 | for (i = 0; i < RTE_MAX_LCORE; ++i) { |
---|
367 | if (lcore_config[i].detected) |
---|
368 | CPU_SET(i, &cpuset); |
---|
369 | } |
---|
370 | } |
---|
371 | |
---|
372 | i = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); |
---|
373 | if (i != 0) { |
---|
374 | trace_set_err(libtrace, errno, "pthread_setaffinity_np failed\n"); |
---|
375 | return -1; |
---|
376 | } |
---|
377 | return 0; |
---|
378 | } |
---|
379 | |
---|
380 | /** |
---|
381 | * XXX This is very bad XXX |
---|
382 | * But we have to do something to allow getopts nesting |
---|
383 | * Luckly normally the format is last so it doesn't matter |
---|
384 | * DPDK only supports modern systems so hopefully this |
---|
385 | * will continue to work |
---|
386 | */ |
---|
387 | struct saved_getopts { |
---|
388 | char *optarg; |
---|
389 | int optind; |
---|
390 | int opterr; |
---|
391 | int optopt; |
---|
392 | }; |
---|
393 | |
---|
394 | static void save_getopts(struct saved_getopts *opts) { |
---|
395 | opts->optarg = optarg; |
---|
396 | opts->optind = optind; |
---|
397 | opts->opterr = opterr; |
---|
398 | opts->optopt = optopt; |
---|
399 | } |
---|
400 | |
---|
401 | static void restore_getopts(struct saved_getopts *opts) { |
---|
402 | optarg = opts->optarg; |
---|
403 | optind = opts->optind; |
---|
404 | opterr = opts->opterr; |
---|
405 | optopt = opts->optopt; |
---|
406 | } |
---|
407 | |
---|
408 | static inline int dpdk_init_environment(char * uridata, struct dpdk_format_data_t * format_data, |
---|
409 | char * err, int errlen) { |
---|
410 | int ret; /* Returned error codes */ |
---|
411 | struct rte_pci_addr use_addr; /* The only address that we don't blacklist */ |
---|
412 | char cpu_number[10] = {0}; /* The CPU mask we want to bind to */ |
---|
413 | char mem_map[20] = {0}; /* The memory name */ |
---|
414 | long nb_cpu; /* The number of CPUs in the system */ |
---|
415 | long my_cpu; /* The CPU number we want to bind to */ |
---|
416 | int i; |
---|
417 | struct rte_config *cfg = rte_eal_get_configuration(); |
---|
418 | struct saved_getopts save_opts; |
---|
419 | |
---|
420 | /* This initialises the Environment Abstraction Layer (EAL) |
---|
421 | * If we had slave workers these are put into WAITING state |
---|
422 | * |
---|
423 | * Basically binds this thread to a fixed core, which we choose as |
---|
424 | * the last core on the machine (assuming fewer interrupts mapped here). |
---|
425 | * "-c" controls the cpu mask 0x1=1st core 0x2=2nd 0x4=3rd and so on |
---|
426 | * "-n" the number of memory channels into the CPU (hardware specific) |
---|
427 | * - Most likely to be half the number of ram slots in your machine. |
---|
428 | * We could count ram slots by "dmidecode -t 17 | grep -c 'Size:'" |
---|
429 | * Controls where in memory packets are stored such that they are spread |
---|
430 | * across the channels. We just use 1 to be safe. |
---|
431 | * |
---|
432 | * Using unique file prefixes mean separate memory is used, unlinking |
---|
433 | * the two processes. However be careful we still cannot access a |
---|
434 | * port that already in use. |
---|
435 | */ |
---|
436 | char* argv[] = {"libtrace", |
---|
437 | "-c", cpu_number, |
---|
438 | "-n", "1", |
---|
439 | "--proc-type", "auto", |
---|
440 | "--file-prefix", mem_map, |
---|
441 | "-m", "512", |
---|
442 | #if DPDK_USE_LOG_LEVEL |
---|
443 | # if DEBUG |
---|
444 | "--log-level", "8", /* RTE_LOG_DEBUG */ |
---|
445 | # else |
---|
446 | "--log-level", "5", /* RTE_LOG_WARNING */ |
---|
447 | # endif |
---|
448 | #endif |
---|
449 | NULL}; |
---|
450 | int argc = sizeof(argv) / sizeof(argv[0]) - 1; |
---|
451 | |
---|
452 | #if DEBUG |
---|
453 | rte_log_set_global_level(RTE_LOG_DEBUG); |
---|
454 | #else |
---|
455 | rte_log_set_global_level(RTE_LOG_WARNING); |
---|
456 | #endif |
---|
457 | |
---|
458 | /* Get the number of cpu cores in the system and use the last core |
---|
459 | * on the correct numa node */ |
---|
460 | nb_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
---|
461 | if (nb_cpu <= 0) { |
---|
462 | perror("sysconf(_SC_NPROCESSORS_ONLN) failed." |
---|
463 | " Falling back to the first core."); |
---|
464 | nb_cpu = 1; /* fallback to the first core */ |
---|
465 | } |
---|
466 | if (nb_cpu > RTE_MAX_LCORE) |
---|
467 | nb_cpu = RTE_MAX_LCORE; |
---|
468 | |
---|
469 | my_cpu = -1; |
---|
470 | /* This allows the user to specify the core - we would try to do this |
---|
471 | * automatically but it's hard to tell that this is secondary |
---|
472 | * before running rte_eal_init(...). Currently we are limited to 1 |
---|
473 | * instance per core due to the way memory is allocated. */ |
---|
474 | if (parse_pciaddr(uridata, &use_addr, &my_cpu) != 0) { |
---|
475 | snprintf(err, errlen, "Failed to parse URI"); |
---|
476 | return -1; |
---|
477 | } |
---|
478 | |
---|
479 | #ifdef HAVE_LIBNUMA |
---|
480 | format_data->nic_numa_node = pci_to_numa(&use_addr); |
---|
481 | if (my_cpu < 0) { |
---|
482 | #if DEBUG |
---|
483 | /* If we can assign to a core on the same numa node */ |
---|
484 | fprintf(stderr, "Using pci card on numa_node%d\n", format_data->nic_numa_node); |
---|
485 | #endif |
---|
486 | if(format_data->nic_numa_node >= 0) { |
---|
487 | int max_node_cpu = -1; |
---|
488 | struct bitmask *mask = numa_allocate_cpumask(); |
---|
489 | if (!mask) { |
---|
490 | fprintf(stderr, "Unable to allocate cpu mask in dpdk_init_environment()\n"); |
---|
491 | return -1; |
---|
492 | } |
---|
493 | numa_node_to_cpus(format_data->nic_numa_node, mask); |
---|
494 | for (i = 0 ; i < nb_cpu; ++i) { |
---|
495 | if (numa_bitmask_isbitset(mask,i)) |
---|
496 | max_node_cpu = i+1; |
---|
497 | } |
---|
498 | my_cpu = max_node_cpu; |
---|
499 | } |
---|
500 | } |
---|
501 | #endif |
---|
502 | if (my_cpu < 0) { |
---|
503 | my_cpu = nb_cpu; |
---|
504 | } |
---|
505 | |
---|
506 | |
---|
507 | snprintf(format_data->mempool_name, MEMPOOL_NAME_LEN, |
---|
508 | "libtrace_pool_%"PRIu32, (uint32_t) nb_cpu); |
---|
509 | |
---|
510 | if (!(my_cpu > 0 && my_cpu <= nb_cpu)) { |
---|
511 | snprintf(err, errlen, |
---|
512 | "Intel DPDK - User defined a bad CPU number %"PRIu32" must be" |
---|
513 | " between 1 and %"PRIu32, (uint32_t) my_cpu, (uint32_t) nb_cpu); |
---|
514 | return -1; |
---|
515 | } |
---|
516 | |
---|
517 | /* Make our mask with all cores turned on this is so that DPDK |
---|
518 | * gets all CPU info in older versions */ |
---|
519 | snprintf(cpu_number, sizeof(cpu_number), "%x", ~(UINT32_MAX<<MIN(31, nb_cpu))); |
---|
520 | //snprintf(cpu_number, sizeof(cpu_number), "%x", 0x1 << (my_cpu - 1)); |
---|
521 | |
---|
522 | #if !DPDK_USE_BLACKLIST |
---|
523 | /* Black list all ports besides the one that we want to use */ |
---|
524 | if ((ret = whitelist_device(format_data, &use_addr)) < 0) { |
---|
525 | snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed," |
---|
526 | " are you sure the address is correct?: %s", strerror(-ret)); |
---|
527 | return -1; |
---|
528 | } |
---|
529 | #endif |
---|
530 | |
---|
531 | /* Give the memory map a unique name */ |
---|
532 | snprintf(mem_map, sizeof(mem_map), "libtrace-%d", (int) getpid()); |
---|
533 | /* rte_eal_init it makes a call to getopt so we need to reset the |
---|
534 | * global optind variable of getopt otherwise this fails */ |
---|
535 | save_getopts(&save_opts); |
---|
536 | optind = 1; |
---|
537 | if ((ret = rte_eal_init(argc, argv)) < 0) { |
---|
538 | snprintf(err, errlen, |
---|
539 | "Intel DPDK - Initialisation of EAL failed: %s", strerror(-ret)); |
---|
540 | return -1; |
---|
541 | } |
---|
542 | restore_getopts(&save_opts); |
---|
543 | // These are still running but will never do anything with DPDK v1.7 we |
---|
544 | // should remove this XXX in the future |
---|
545 | for(i = 0; i < RTE_MAX_LCORE; ++i) { |
---|
546 | if (rte_lcore_is_enabled(i) && i != (int) rte_get_master_lcore()) { |
---|
547 | cfg->lcore_role[i] = ROLE_OFF; |
---|
548 | cfg->lcore_count--; |
---|
549 | } |
---|
550 | } |
---|
551 | // Only the master should be running |
---|
552 | if (cfg->lcore_count != 1) { |
---|
553 | fprintf(stderr, "Expected only the master core to be running in dpdk_init_environment()\n"); |
---|
554 | return -1; |
---|
555 | } |
---|
556 | |
---|
557 | // TODO XXX TODO |
---|
558 | dpdk_move_master_lcore(NULL, my_cpu-1); |
---|
559 | |
---|
560 | #if DEBUG |
---|
561 | dump_configuration(); |
---|
562 | #endif |
---|
563 | |
---|
564 | #if DPDK_USE_PMD_INIT |
---|
565 | /* This registers all available NICs with Intel DPDK |
---|
566 | * These are not loaded until rte_eal_pci_probe() is called. |
---|
567 | */ |
---|
568 | if ((ret = rte_pmd_init_all()) < 0) { |
---|
569 | snprintf(err, errlen, |
---|
570 | "Intel DPDK - rte_pmd_init_all failed: %s", strerror(-ret)); |
---|
571 | return -1; |
---|
572 | } |
---|
573 | #endif |
---|
574 | |
---|
575 | #if DPDK_USE_BLACKLIST |
---|
576 | /* Blacklist all ports besides the one that we want to use */ |
---|
577 | if ((ret = blacklist_devices(format_data, &use_addr)) < 0) { |
---|
578 | snprintf(err, errlen, "Intel DPDK - Whitelisting PCI device failed," |
---|
579 | " are you sure the address is correct?: %s", strerror(-ret)); |
---|
580 | return -1; |
---|
581 | } |
---|
582 | #endif |
---|
583 | |
---|
584 | #if DPDK_USE_PCI_PROBE |
---|
585 | /* This loads DPDK drivers against all ports that are not blacklisted */ |
---|
586 | if ((ret = rte_eal_pci_probe()) < 0) { |
---|
587 | snprintf(err, errlen, |
---|
588 | "Intel DPDK - rte_eal_pci_probe failed: %s", strerror(-ret)); |
---|
589 | return -1; |
---|
590 | } |
---|
591 | #endif |
---|
592 | |
---|
593 | format_data->nb_ports = rte_eth_dev_count(); |
---|
594 | |
---|
595 | if (format_data->nb_ports != 1) { |
---|
596 | snprintf(err, errlen, |
---|
597 | "Intel DPDK - rte_eth_dev_count returned %d but it should be 1", |
---|
598 | format_data->nb_ports); |
---|
599 | return -1; |
---|
600 | } |
---|
601 | |
---|
602 | return 0; |
---|
603 | } |
---|
604 | |
---|
605 | int dpdk_init_input (libtrace_t *libtrace) { |
---|
606 | dpdk_per_stream_t stream = DPDK_EMPTY_STREAM; |
---|
607 | char err[500]; |
---|
608 | err[0] = 0; |
---|
609 | |
---|
610 | libtrace->format_data = (struct dpdk_format_data_t *) |
---|
611 | malloc(sizeof(struct dpdk_format_data_t)); |
---|
612 | |
---|
613 | if (!libtrace->format_data) { |
---|
614 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " |
---|
615 | "format data inside dpdk_init_input()"); |
---|
616 | return 1; |
---|
617 | } |
---|
618 | |
---|
619 | FORMAT(libtrace)->port = 0; /* Always assume 1 port loaded */ |
---|
620 | FORMAT(libtrace)->nb_ports = 0; |
---|
621 | FORMAT(libtrace)->snaplen = 0; /* Use default */ |
---|
622 | FORMAT(libtrace)->nb_rx_buf = NB_RX_MBUF; |
---|
623 | FORMAT(libtrace)->nb_tx_buf = MIN_NB_BUF; |
---|
624 | FORMAT(libtrace)->nic_numa_node = -1; |
---|
625 | FORMAT(libtrace)->promisc = -1; |
---|
626 | FORMAT(libtrace)->pktmbuf_pool = NULL; |
---|
627 | #if DPDK_USE_BLACKLIST |
---|
628 | FORMAT(libtrace)->nb_blacklist = 0; |
---|
629 | #endif |
---|
630 | FORMAT(libtrace)->paused = DPDK_NEVER_STARTED; |
---|
631 | FORMAT(libtrace)->mempool_name[0] = 0; |
---|
632 | memset(FORMAT(libtrace)->burst_pkts, 0, |
---|
633 | sizeof(FORMAT(libtrace)->burst_pkts[0]) * BURST_SIZE); |
---|
634 | FORMAT(libtrace)->burst_size = 0; |
---|
635 | FORMAT(libtrace)->burst_offset = 0; |
---|
636 | FORMAT(libtrace)->hasher_type = HASHER_BALANCE; |
---|
637 | FORMAT(libtrace)->rss_key = NULL; |
---|
638 | |
---|
639 | /* Make our first stream */ |
---|
640 | FORMAT(libtrace)->per_stream = libtrace_list_init(sizeof(struct dpdk_per_stream_t)); |
---|
641 | libtrace_list_push_back(FORMAT(libtrace)->per_stream, &stream); |
---|
642 | |
---|
643 | if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) { |
---|
644 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); |
---|
645 | free(libtrace->format_data); |
---|
646 | libtrace->format_data = NULL; |
---|
647 | return -1; |
---|
648 | } |
---|
649 | return 0; |
---|
650 | } |
---|
651 | |
---|
652 | static int dpdk_init_output(libtrace_out_t *libtrace) |
---|
653 | { |
---|
654 | dpdk_per_stream_t stream = DPDK_EMPTY_STREAM; |
---|
655 | char err[500]; |
---|
656 | err[0] = 0; |
---|
657 | |
---|
658 | libtrace->format_data = (struct dpdk_format_data_t *) |
---|
659 | malloc(sizeof(struct dpdk_format_data_t)); |
---|
660 | |
---|
661 | if (!libtrace->format_data) { |
---|
662 | trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory for " |
---|
663 | "format data inside dpdk_init_output()"); |
---|
664 | return -1; |
---|
665 | } |
---|
666 | FORMAT(libtrace)->port = 0; /* Always assume 1 port loaded */ |
---|
667 | FORMAT(libtrace)->nb_ports = 0; |
---|
668 | FORMAT(libtrace)->snaplen = 0; /* Use default */ |
---|
669 | FORMAT(libtrace)->nb_rx_buf = MIN_NB_BUF; |
---|
670 | FORMAT(libtrace)->nb_tx_buf = NB_TX_MBUF; |
---|
671 | FORMAT(libtrace)->nic_numa_node = -1; |
---|
672 | FORMAT(libtrace)->promisc = -1; |
---|
673 | FORMAT(libtrace)->pktmbuf_pool = NULL; |
---|
674 | #if DPDK_USE_BLACKLIST |
---|
675 | FORMAT(libtrace)->nb_blacklist = 0; |
---|
676 | #endif |
---|
677 | FORMAT(libtrace)->paused = DPDK_NEVER_STARTED; |
---|
678 | FORMAT(libtrace)->mempool_name[0] = 0; |
---|
679 | memset(FORMAT(libtrace)->burst_pkts, 0, sizeof(FORMAT(libtrace)->burst_pkts[0]) * BURST_SIZE); |
---|
680 | FORMAT(libtrace)->burst_size = 0; |
---|
681 | FORMAT(libtrace)->burst_offset = 0; |
---|
682 | |
---|
683 | FORMAT(libtrace)->per_stream = libtrace_list_init(sizeof(struct dpdk_per_stream_t)); |
---|
684 | libtrace_list_push_back(FORMAT(libtrace)->per_stream, &stream); |
---|
685 | |
---|
686 | if (dpdk_init_environment(libtrace->uridata, FORMAT(libtrace), err, sizeof(err)) != 0) { |
---|
687 | trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); |
---|
688 | free(libtrace->format_data); |
---|
689 | libtrace->format_data = NULL; |
---|
690 | return -1; |
---|
691 | } |
---|
692 | return 0; |
---|
693 | } |
---|
694 | |
---|
695 | /** |
---|
696 | * Note here snaplen excludes the MAC checksum. Packets over |
---|
697 | * the requested snaplen will be dropped. (Excluding MAC checksum) |
---|
698 | * |
---|
699 | * I.e the maximum size of a standard ethernet packet is 1518 (Including MAC checksum) |
---|
700 | * So to allow packets upto 1518 this would be set to 1514 and if GET_MAC_CRC_CHECKSUM |
---|
701 | * is set the maximum size of the returned packet would be 1518 otherwise |
---|
702 | * 1514 would be the largest size possibly returned. |
---|
703 | * |
---|
704 | */ |
---|
705 | int dpdk_config_input (libtrace_t *libtrace, |
---|
706 | trace_option_t option, |
---|
707 | void *data) { |
---|
708 | switch (option) { |
---|
709 | case TRACE_OPTION_SNAPLEN: |
---|
710 | /* Only support changing snaplen before a call to start is |
---|
711 | * made */ |
---|
712 | if (FORMAT(libtrace)->paused == DPDK_NEVER_STARTED) |
---|
713 | FORMAT(libtrace)->snaplen=*(int*)data; |
---|
714 | else |
---|
715 | return -1; |
---|
716 | return 0; |
---|
717 | case TRACE_OPTION_PROMISC: |
---|
718 | FORMAT(libtrace)->promisc=*(int*)data; |
---|
719 | return 0; |
---|
720 | case TRACE_OPTION_HASHER: |
---|
721 | switch (*((enum hasher_types *) data)) |
---|
722 | { |
---|
723 | case HASHER_BALANCE: |
---|
724 | case HASHER_UNIDIRECTIONAL: |
---|
725 | case HASHER_BIDIRECTIONAL: |
---|
726 | FORMAT(libtrace)->hasher_type = *(enum hasher_types*)data; |
---|
727 | if (FORMAT(libtrace)->rss_key) |
---|
728 | free(FORMAT(libtrace)->rss_key); |
---|
729 | FORMAT(libtrace)->rss_key = NULL; |
---|
730 | return 0; |
---|
731 | case HASHER_CUSTOM: |
---|
732 | // Let libtrace do this |
---|
733 | return -1; |
---|
734 | } |
---|
735 | break; |
---|
736 | case TRACE_OPTION_FILTER: |
---|
737 | /* TODO filtering */ |
---|
738 | case TRACE_OPTION_META_FREQ: |
---|
739 | case TRACE_OPTION_EVENT_REALTIME: |
---|
740 | case TRACE_OPTION_REPLAY_SPEEDUP: |
---|
741 | case TRACE_OPTION_CONSTANT_ERF_FRAMING: |
---|
742 | break; |
---|
743 | /* Avoid default: so that future options will cause a warning |
---|
744 | * here to remind us to implement it, or flag it as |
---|
745 | * unimplementable |
---|
746 | */ |
---|
747 | } |
---|
748 | |
---|
749 | /* Don't set an error - trace_config will try to deal with the |
---|
750 | * option and will set an error if it fails */ |
---|
751 | return -1; |
---|
752 | } |
---|
753 | |
---|
754 | /* Can set jumbo frames/ or limit the size of a frame by setting both |
---|
755 | * max_rx_pkt_len and jumbo_frame. This can be limited to less than |
---|
756 | * |
---|
757 | */ |
---|
758 | static struct rte_eth_conf port_conf = { |
---|
759 | .rxmode = { |
---|
760 | .mq_mode = ETH_RSS, |
---|
761 | .split_hdr_size = 0, |
---|
762 | .header_split = 0, /**< Header Split disabled */ |
---|
763 | .hw_ip_checksum = 0, /**< IP checksum offload disabled */ |
---|
764 | .hw_vlan_filter = 0, /**< VLAN filtering disabled */ |
---|
765 | .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ |
---|
766 | .max_rx_pkt_len = 0, /**< Max frame Size if Jumbo enabled */ |
---|
767 | #if GET_MAC_CRC_CHECKSUM |
---|
768 | /* So it appears that if hw_strip_crc is turned off the driver will still |
---|
769 | * take this off. See line 955ish in lib/librte_pmd_e1000/igb_rxtx.c. |
---|
770 | * So if .hw_strip_crc=0 a valid CRC exists 4 bytes after the end of the |
---|
771 | * So lets just add it back on when we receive the packet. |
---|
772 | */ |
---|
773 | .hw_strip_crc = 0, /**< CRC stripped by hardware */ |
---|
774 | #else |
---|
775 | /* By default strip the MAC checksum because it's a bit of a hack to |
---|
776 | * actually read these. And don't want to rely on disabling this to actualy |
---|
777 | * always cut off the checksum in the future |
---|
778 | */ |
---|
779 | .hw_strip_crc = 1, /**< CRC stripped by hardware */ |
---|
780 | #endif |
---|
781 | }, |
---|
782 | .txmode = { |
---|
783 | .mq_mode = ETH_DCB_NONE, |
---|
784 | }, |
---|
785 | .rx_adv_conf = { |
---|
786 | .rss_conf = { |
---|
787 | .rss_hf = RX_RSS_FLAGS, |
---|
788 | }, |
---|
789 | }, |
---|
790 | .intr_conf = { |
---|
791 | .lsc = 1 |
---|
792 | } |
---|
793 | }; |
---|
794 | |
---|
795 | static const struct rte_eth_rxconf rx_conf = { |
---|
796 | .rx_thresh = { |
---|
797 | .pthresh = 8,/* RX_PTHRESH prefetch */ |
---|
798 | .hthresh = 8,/* RX_HTHRESH host */ |
---|
799 | .wthresh = 4,/* RX_WTHRESH writeback */ |
---|
800 | }, |
---|
801 | .rx_free_thresh = 0, |
---|
802 | .rx_drop_en = 0, /* Drop packets oldest packets if out of space */ |
---|
803 | }; |
---|
804 | |
---|
805 | static const struct rte_eth_txconf tx_conf = { |
---|
806 | .tx_thresh = { |
---|
807 | /* |
---|
808 | * TX_PTHRESH prefetch |
---|
809 | * Set on the NIC, if the number of unprocessed descriptors to queued on |
---|
810 | * the card fall below this try grab at least hthresh more unprocessed |
---|
811 | * descriptors. |
---|
812 | */ |
---|
813 | .pthresh = 36, |
---|
814 | |
---|
815 | /* TX_HTHRESH host |
---|
816 | * Set on the NIC, the batch size to prefetch unprocessed tx descriptors. |
---|
817 | */ |
---|
818 | .hthresh = 0, |
---|
819 | |
---|
820 | /* TX_WTHRESH writeback |
---|
821 | * Set on the NIC, the number of sent descriptors before writing back |
---|
822 | * status to confirm the transmission. This is done more efficiently as |
---|
823 | * a bulk DMA-transfer rather than writing one at a time. |
---|
824 | * Similar to tx_free_thresh however this is applied to the NIC, where |
---|
825 | * as tx_free_thresh is when DPDK will check these. This is extended |
---|
826 | * upon by tx_rs_thresh (10Gbit cards) which doesn't write all |
---|
827 | * descriptors rather only every n'th item, reducing DMA memory bandwidth. |
---|
828 | */ |
---|
829 | .wthresh = 4, |
---|
830 | }, |
---|
831 | |
---|
832 | /* Used internally by DPDK rather than passed to the NIC. The number of |
---|
833 | * packet descriptors to send before checking for any responses written |
---|
834 | * back (to confirm the transmission). Default = 32 if set to 0) |
---|
835 | */ |
---|
836 | .tx_free_thresh = 0, |
---|
837 | |
---|
838 | /* This is the Report Status threshold, used by 10Gbit cards, |
---|
839 | * This signals the card to only write back status (such as |
---|
840 | * transmission successful) after this minimum number of transmit |
---|
841 | * descriptors are seen. The default is 32 (if set to 0) however if set |
---|
842 | * to greater than 1 TX wthresh must be set to zero, because this is kindof |
---|
843 | * a replacement. See the dpdk programmers guide for more restrictions. |
---|
844 | */ |
---|
845 | .tx_rs_thresh = 1, |
---|
846 | }; |
---|
847 | |
---|
848 | /** |
---|
849 | * A callback for a link state change (LSC). |
---|
850 | * |
---|
851 | * Packets may be received before this notification. In fact the DPDK IGXBE |
---|
852 | * driver likes to put a delay upto 5sec before sending this. |
---|
853 | * |
---|
854 | * We use this to ensure the link speed is correct for our timestamp |
---|
855 | * calculations. Because packets might be received before the link up we still |
---|
856 | * update this when the packet is received. |
---|
857 | * |
---|
858 | * @param port The DPDK port |
---|
859 | * @param event The TYPE of event (expected to be RTE_ETH_EVENT_INTR_LSC) |
---|
860 | * @param cb_arg The dpdk_format_data_t structure associated with the format |
---|
861 | */ |
---|
862 | #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) |
---|
863 | static int dpdk_lsc_callback(portid_t port, enum rte_eth_event_type event, |
---|
864 | void *cb_arg, void *retparam UNUSED) { |
---|
865 | #else |
---|
866 | static void dpdk_lsc_callback(portid_t port, enum rte_eth_event_type event, |
---|
867 | void *cb_arg) { |
---|
868 | #endif |
---|
869 | struct dpdk_format_data_t * format_data = cb_arg; |
---|
870 | struct rte_eth_link link_info; |
---|
871 | if (event != RTE_ETH_EVENT_INTR_LSC) { |
---|
872 | fprintf(stderr, "Received unexpected event in dpdk_lsc_callback()\n"); |
---|
873 | #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) |
---|
874 | return -1; |
---|
875 | #else |
---|
876 | return; |
---|
877 | #endif |
---|
878 | } |
---|
879 | if (port != format_data->port) { |
---|
880 | fprintf(stderr, "Port does not match port in format data in dpdk_lsc_callback()\n"); |
---|
881 | return -1; |
---|
882 | } |
---|
883 | |
---|
884 | rte_eth_link_get_nowait(port, &link_info); |
---|
885 | |
---|
886 | if (link_info.link_status) |
---|
887 | format_data->link_speed = link_info.link_speed; |
---|
888 | else |
---|
889 | format_data->link_speed = 0; |
---|
890 | |
---|
891 | #if DEBUG |
---|
892 | fprintf(stderr, "LSC - link status is %s %s speed=%d\n", |
---|
893 | link_info.link_status ? "up" : "down", |
---|
894 | (link_info.link_duplex == ETH_LINK_FULL_DUPLEX) ? |
---|
895 | "full-duplex" : "half-duplex", |
---|
896 | (int) link_info.link_speed); |
---|
897 | #endif |
---|
898 | |
---|
899 | /* Turns out DPDK drivers might not come back up if the link speed |
---|
900 | * changes. So we reset the autoneg procedure. This is very unsafe |
---|
901 | * we have have threads reading packets and we stop the port. */ |
---|
902 | #if 0 |
---|
903 | if (!link_info.link_status) { |
---|
904 | int ret; |
---|
905 | rte_eth_dev_stop(port); |
---|
906 | ret = rte_eth_dev_start(port); |
---|
907 | if (ret < 0) { |
---|
908 | fprintf(stderr, "Resetting the DPDK port failed : %s\n", |
---|
909 | strerror(-ret)); |
---|
910 | } |
---|
911 | } |
---|
912 | #endif |
---|
913 | #if RTE_VERSION >= RTE_VERSION_NUM(17, 8, 0, 1) |
---|
914 | return 0; |
---|
915 | #endif |
---|
916 | } |
---|
917 | |
---|
918 | /** Reserve a DPDK lcore ID for a thread globally. |
---|
919 | * |
---|
920 | * @param real If true allocate a real lcore, otherwise allocate a core which |
---|
921 | * does not exist on the local machine. |
---|
922 | * @param socket the prefered NUMA socket - only used if a real core is requested |
---|
923 | * @return a valid core, which can later be used with dpdk_register_lcore() or a |
---|
924 | * -1 if have run out of cores. |
---|
925 | * |
---|
926 | * If any thread is reading or freeing packets we need to register it here |
---|
927 | * due to TLS caches in the memory pools. |
---|
928 | */ |
---|
929 | static int dpdk_reserve_lcore(bool real, int socket) { |
---|
930 | int new_id = -1; |
---|
931 | int i; |
---|
932 | struct rte_config *cfg = rte_eal_get_configuration(); |
---|
933 | (void) socket; |
---|
934 | |
---|
935 | pthread_mutex_lock(&dpdk_lock); |
---|
936 | /* If 'reading packets' fill in cores from 0 up and bind affinity |
---|
937 | * otherwise start from the MAX core (which is also the master) and work backwards |
---|
938 | * in this case physical cores on the system will not exist so we don't bind |
---|
939 | * these to any particular physical core */ |
---|
940 | if (real) { |
---|
941 | #ifdef HAVE_LIBNUMA |
---|
942 | for (i = 0; i < RTE_MAX_LCORE; ++i) { |
---|
943 | if (!rte_lcore_is_enabled(i) && numa_node_of_cpu(i) == socket) { |
---|
944 | new_id = i; |
---|
945 | if (!lcore_config[i].detected) |
---|
946 | new_id = -1; |
---|
947 | break; |
---|
948 | } |
---|
949 | } |
---|
950 | #endif |
---|
951 | /* Retry without the the numa restriction */ |
---|
952 | if (new_id == -1) { |
---|
953 | for (i = 0; i < RTE_MAX_LCORE; ++i) { |
---|
954 | if (!rte_lcore_is_enabled(i)) { |
---|
955 | new_id = i; |
---|
956 | if (!lcore_config[i].detected) |
---|
957 | fprintf(stderr, "Warning the" |
---|
958 | " number of 'reading' " |
---|
959 | "threads exceed cores\n"); |
---|
960 | break; |
---|
961 | } |
---|
962 | } |
---|
963 | } |
---|
964 | } else { |
---|
965 | for (i = RTE_MAX_LCORE-1; i >= 0; --i) { |
---|
966 | if (!rte_lcore_is_enabled(i)) { |
---|
967 | new_id = i; |
---|
968 | break; |
---|
969 | } |
---|
970 | } |
---|
971 | } |
---|
972 | |
---|
973 | if (new_id != -1) { |
---|
974 | /* Enable the core in global DPDK structs */ |
---|
975 | cfg->lcore_role[new_id] = ROLE_RTE; |
---|
976 | cfg->lcore_count++; |
---|
977 | } |
---|
978 | |
---|
979 | pthread_mutex_unlock(&dpdk_lock); |
---|
980 | return new_id; |
---|
981 | } |
---|
982 | |
---|
983 | /** Register a thread as a lcore |
---|
984 | * @param libtrace any error is set against libtrace on exit |
---|
985 | * @param real If this is a true lcore we will bind its affinty to the |
---|
986 | * requested core. |
---|
987 | * @param lcore The lcore as retrieved from dpdk_reserve_lcore() |
---|
988 | * @return 0, if successful otherwise -1 if an error occured (details are stored |
---|
989 | * in libtrace) |
---|
990 | * |
---|
991 | * @note This must be called from the thread being registered. |
---|
992 | */ |
---|
993 | static int dpdk_register_lcore(libtrace_t *libtrace, bool real, int lcore) { |
---|
994 | int ret; |
---|
995 | RTE_PER_LCORE(_lcore_id) = lcore; |
---|
996 | |
---|
997 | /* Set affinity bind to corresponding core */ |
---|
998 | if (real) { |
---|
999 | cpu_set_t cpuset; |
---|
1000 | CPU_ZERO(&cpuset); |
---|
1001 | CPU_SET(rte_lcore_id(), &cpuset); |
---|
1002 | ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); |
---|
1003 | if (ret != 0) { |
---|
1004 | trace_set_err(libtrace, errno, "Warning " |
---|
1005 | "pthread_setaffinity_np failed"); |
---|
1006 | return -1; |
---|
1007 | } |
---|
1008 | } |
---|
1009 | |
---|
1010 | return 0; |
---|
1011 | } |
---|
1012 | |
---|
1013 | /** Allocates a new dpdk packet buffer memory pool. |
---|
1014 | * |
---|
1015 | * @param n The number of threads |
---|
1016 | * @param pkt_size The packet size we need ot store |
---|
1017 | * @param socket_id The NUMA socket id |
---|
1018 | * @param A new mempool, if NULL query the DPDK library for the error code |
---|
1019 | * see rte_mempool_create() documentation. |
---|
1020 | * |
---|
1021 | * This allocates a new pool or recycles an existing memory pool. |
---|
1022 | * Call dpdk_free_memory() to free the memory. |
---|
1023 | * We cannot delete memory so instead we store the pools, allowing them to be |
---|
1024 | * re-used. |
---|
1025 | */ |
---|
1026 | static struct rte_mempool *dpdk_alloc_memory(unsigned n, |
---|
1027 | unsigned pkt_size, |
---|
1028 | int socket_id) { |
---|
1029 | struct rte_mempool *ret; |
---|
1030 | size_t j,k; |
---|
1031 | char name[MEMPOOL_NAME_LEN]; |
---|
1032 | |
---|
1033 | /* Add on packet size overheads */ |
---|
1034 | pkt_size += sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM; |
---|
1035 | |
---|
1036 | pthread_mutex_lock(&dpdk_lock); |
---|
1037 | |
---|
1038 | if (socket_id == SOCKET_ID_ANY || socket_id > 4) { |
---|
1039 | /* Best guess go for zero */ |
---|
1040 | socket_id = 0; |
---|
1041 | } |
---|
1042 | |
---|
1043 | /* Find a valid pool */ |
---|
1044 | for (j = 0; j < RTE_MAX_LCORE && mem_pools[socket_id][j]; ++j) { |
---|
1045 | if (mem_pools[socket_id][j]->size >= n && |
---|
1046 | mem_pools[socket_id][j]->elt_size >= pkt_size) { |
---|
1047 | break; |
---|
1048 | } |
---|
1049 | } |
---|
1050 | |
---|
1051 | /* Find the end (+1) of the list */ |
---|
1052 | for (k = j; k < RTE_MAX_LCORE && mem_pools[socket_id][k]; ++k) {} |
---|
1053 | |
---|
1054 | if (mem_pools[socket_id][j]) { |
---|
1055 | ret = mem_pools[socket_id][j]; |
---|
1056 | mem_pools[socket_id][j] = mem_pools[socket_id][k-1]; |
---|
1057 | mem_pools[socket_id][k-1] = NULL; |
---|
1058 | mem_pools[socket_id][j] = NULL; |
---|
1059 | } else { |
---|
1060 | static uint32_t test = 10; |
---|
1061 | test++; |
---|
1062 | snprintf(name, MEMPOOL_NAME_LEN, |
---|
1063 | "libtrace_pool_%"PRIu32, test); |
---|
1064 | |
---|
1065 | ret = rte_mempool_create(name, n, pkt_size, |
---|
1066 | 128, sizeof(struct rte_pktmbuf_pool_private), |
---|
1067 | rte_pktmbuf_pool_init, NULL, |
---|
1068 | rte_pktmbuf_init, NULL, |
---|
1069 | socket_id, 0); |
---|
1070 | } |
---|
1071 | |
---|
1072 | pthread_mutex_unlock(&dpdk_lock); |
---|
1073 | return ret; |
---|
1074 | } |
---|
1075 | |
---|
1076 | /** Stores the memory against the DPDK library. |
---|
1077 | * |
---|
1078 | * @param mempool The mempool to free |
---|
1079 | * @param socket_id The NUMA socket this mempool was allocated upon. |
---|
1080 | * |
---|
1081 | * Because we cannot free a memory pool, we verify it's full (i.e. unused) and |
---|
1082 | * store the memory shared globally against the format. |
---|
1083 | */ |
---|
1084 | static void dpdk_free_memory(struct rte_mempool *mempool, int socket_id) { |
---|
1085 | size_t i; |
---|
1086 | pthread_mutex_lock(&dpdk_lock); |
---|
1087 | |
---|
1088 | /* We should have all entries back in the mempool */ |
---|
1089 | rte_mempool_audit(mempool); |
---|
1090 | if (!rte_mempool_full(mempool)) { |
---|
1091 | fprintf(stderr, "DPDK memory pool not empty %d of %d, please " |
---|
1092 | "free all packets before finishing a trace\n", |
---|
1093 | rte_mempool_avail_count(mempool), mempool->size); |
---|
1094 | } |
---|
1095 | |
---|
1096 | /* Find the end (+1) of the list */ |
---|
1097 | for (i = 0; i < RTE_MAX_LCORE && mem_pools[socket_id][i]; ++i) {} |
---|
1098 | |
---|
1099 | if (i >= RTE_MAX_LCORE) { |
---|
1100 | fprintf(stderr, "Too many memory pools, dropping this one\n"); |
---|
1101 | } else { |
---|
1102 | mem_pools[socket_id][i] = mempool; |
---|
1103 | } |
---|
1104 | |
---|
1105 | pthread_mutex_unlock(&dpdk_lock); |
---|
1106 | } |
---|
1107 | |
---|
1108 | /* Attach memory to the port and start (or restart) the port/s. |
---|
1109 | */ |
---|
1110 | static int dpdk_start_streams(struct dpdk_format_data_t *format_data, |
---|
1111 | char *err, int errlen, uint16_t rx_queues) { |
---|
1112 | int ret, i; |
---|
1113 | struct rte_eth_link link_info; /* Wait for link */ |
---|
1114 | dpdk_per_stream_t empty_stream = DPDK_EMPTY_STREAM; |
---|
1115 | |
---|
1116 | /* Already started */ |
---|
1117 | if (format_data->paused == DPDK_RUNNING) |
---|
1118 | return 0; |
---|
1119 | |
---|
1120 | /* First time started we need to alloc our memory, doing this here |
---|
1121 | * rather than in environment setup because we don't have snaplen then */ |
---|
1122 | if (format_data->paused == DPDK_NEVER_STARTED) { |
---|
1123 | if (format_data->snaplen == 0) { |
---|
1124 | format_data->snaplen = RX_MBUF_SIZE; |
---|
1125 | port_conf.rxmode.jumbo_frame = 0; |
---|
1126 | port_conf.rxmode.max_rx_pkt_len = 0; |
---|
1127 | } else { |
---|
1128 | double expn; |
---|
1129 | |
---|
1130 | /* Use jumbo frames */ |
---|
1131 | port_conf.rxmode.jumbo_frame = 1; |
---|
1132 | port_conf.rxmode.max_rx_pkt_len = format_data->snaplen; |
---|
1133 | |
---|
1134 | /* Use less buffers if we're supporting jumbo frames |
---|
1135 | * otherwise we won't be able to allocate memory. |
---|
1136 | */ |
---|
1137 | if (format_data->snaplen > 1500) { |
---|
1138 | format_data->nb_rx_buf /= 2; |
---|
1139 | } |
---|
1140 | |
---|
1141 | /* snaplen should be rounded up to next power of two |
---|
1142 | * to ensure enough memory is allocated for each |
---|
1143 | * mbuf :( |
---|
1144 | */ |
---|
1145 | expn = ceil(log2((double)(format_data->snaplen))); |
---|
1146 | format_data->snaplen = pow(2, (int)expn); |
---|
1147 | } |
---|
1148 | |
---|
1149 | #if GET_MAC_CRC_CHECKSUM |
---|
1150 | /* This is additional overhead so make sure we allow space for this */ |
---|
1151 | format_data->snaplen += ETHER_CRC_LEN; |
---|
1152 | #endif |
---|
1153 | #if HAS_HW_TIMESTAMPS_82580 |
---|
1154 | format_data->snaplen += sizeof(struct hw_timestamp_82580); |
---|
1155 | #endif |
---|
1156 | |
---|
1157 | /* Create the mbuf pool, which is the place packets are allocated |
---|
1158 | * from - There is no free function (I cannot see one). |
---|
1159 | * NOTE: RX queue requires nb_packets + 1 otherwise it fails to |
---|
1160 | * allocate however that extra 1 packet is not used. |
---|
1161 | * (I assume <= vs < error some where in DPDK code) |
---|
1162 | * TX requires nb_tx_buffers + 1 in the case the queue is full |
---|
1163 | * so that will fill the new buffer and wait until slots in the |
---|
1164 | * ring become available. |
---|
1165 | */ |
---|
1166 | #if DEBUG |
---|
1167 | fprintf(stderr, "Creating mempool named %s\n", format_data->mempool_name); |
---|
1168 | #endif |
---|
1169 | format_data->pktmbuf_pool = dpdk_alloc_memory(format_data->nb_tx_buf*2, |
---|
1170 | format_data->snaplen, |
---|
1171 | format_data->nic_numa_node); |
---|
1172 | |
---|
1173 | if (format_data->pktmbuf_pool == NULL) { |
---|
1174 | snprintf(err, errlen, "Intel DPDK - Initialisation of mbuf " |
---|
1175 | "pool failed: %s", strerror(rte_errno)); |
---|
1176 | return -1; |
---|
1177 | } |
---|
1178 | } |
---|
1179 | |
---|
1180 | /* Generate the hash key, based on the device */ |
---|
1181 | uint8_t rss_size = 52; // 52 for i40e, 40 for others, use the largest by default |
---|
1182 | // In new versions DPDK we can query the size |
---|
1183 | #if RTE_VERSION >= RTE_VERSION_NUM(2, 1, 0, 0) |
---|
1184 | struct rte_eth_dev_info dev_info; |
---|
1185 | rte_eth_dev_info_get(format_data->port, &dev_info); |
---|
1186 | rss_size = dev_info.hash_key_size; |
---|
1187 | #endif |
---|
1188 | if (rss_size != 0) { |
---|
1189 | format_data->rss_key = malloc(rss_size); |
---|
1190 | if (format_data->hasher_type == HASHER_BIDIRECTIONAL) { |
---|
1191 | toeplitz_ncreate_bikey(format_data->rss_key, rss_size); |
---|
1192 | } else { |
---|
1193 | toeplitz_ncreate_unikey(format_data->rss_key, rss_size); |
---|
1194 | } |
---|
1195 | port_conf.rx_adv_conf.rss_conf.rss_key = format_data->rss_key; |
---|
1196 | #if RTE_VERSION >= RTE_VERSION_NUM(1, 7, 0, 1) |
---|
1197 | port_conf.rx_adv_conf.rss_conf.rss_key_len = rss_size; |
---|
1198 | #endif |
---|
1199 | } else { |
---|
1200 | fprintf(stderr, "DPDK couldn't configure RSS hashing!"); |
---|
1201 | } |
---|
1202 | |
---|
1203 | /* ----------- Now do the setup for the port mapping ------------ */ |
---|
1204 | /* Order of calls must be |
---|
1205 | * rte_eth_dev_configure() |
---|
1206 | * rte_eth_tx_queue_setup() |
---|
1207 | * rte_eth_rx_queue_setup() |
---|
1208 | * rte_eth_dev_start() |
---|
1209 | * other rte_eth calls |
---|
1210 | */ |
---|
1211 | |
---|
1212 | /* This must be called first before another *eth* function |
---|
1213 | * 1+ rx, 1 tx queues, port_conf sets checksum stripping etc */ |
---|
1214 | ret = rte_eth_dev_configure(format_data->port, rx_queues, 1, &port_conf); |
---|
1215 | if (ret < 0) { |
---|
1216 | snprintf(err, errlen, "Intel DPDK - Cannot configure device port" |
---|
1217 | " %"PRIu8" : %s", format_data->port, |
---|
1218 | strerror(-ret)); |
---|
1219 | return -1; |
---|
1220 | } |
---|
1221 | #if DEBUG |
---|
1222 | fprintf(stderr, "Doing dev configure\n"); |
---|
1223 | #endif |
---|
1224 | /* Initialise the TX queue a minimum value if using this port for |
---|
1225 | * receiving. Otherwise a larger size if writing packets. |
---|
1226 | */ |
---|
1227 | ret = rte_eth_tx_queue_setup(format_data->port, |
---|
1228 | 0 /* queue XXX */, |
---|
1229 | format_data->nb_tx_buf, |
---|
1230 | SOCKET_ID_ANY, |
---|
1231 | DPDK_USE_NULL_QUEUE_CONFIG ? NULL : &tx_conf); |
---|
1232 | if (ret < 0) { |
---|
1233 | snprintf(err, errlen, "Intel DPDK - Cannot configure TX queue" |
---|
1234 | " on port %d : %s", (int)format_data->port, |
---|
1235 | strerror(-ret)); |
---|
1236 | return -1; |
---|
1237 | } |
---|
1238 | |
---|
1239 | /* Attach memory to our RX queues */ |
---|
1240 | for (i=0; i < rx_queues; i++) { |
---|
1241 | dpdk_per_stream_t *stream; |
---|
1242 | #if DEBUG |
---|
1243 | fprintf(stderr, "Configuring queue %d\n", i); |
---|
1244 | #endif |
---|
1245 | |
---|
1246 | /* Add storage for the stream */ |
---|
1247 | if (libtrace_list_get_size(format_data->per_stream) <= (size_t) i) |
---|
1248 | libtrace_list_push_back(format_data->per_stream, &empty_stream); |
---|
1249 | stream = libtrace_list_get_index(format_data->per_stream, i)->data; |
---|
1250 | stream->queue_id = i; |
---|
1251 | |
---|
1252 | if (stream->lcore == -1) |
---|
1253 | stream->lcore = dpdk_reserve_lcore(true, format_data->nic_numa_node); |
---|
1254 | |
---|
1255 | if (stream->lcore == -1) { |
---|
1256 | snprintf(err, errlen, "Intel DPDK - Failed to reserve a lcore" |
---|
1257 | ". Too many threads?"); |
---|
1258 | return -1; |
---|
1259 | } |
---|
1260 | |
---|
1261 | if (stream->mempool == NULL) { |
---|
1262 | stream->mempool = dpdk_alloc_memory( |
---|
1263 | format_data->nb_rx_buf*2, |
---|
1264 | format_data->snaplen, |
---|
1265 | rte_lcore_to_socket_id(stream->lcore)); |
---|
1266 | |
---|
1267 | if (stream->mempool == NULL) { |
---|
1268 | snprintf(err, errlen, "Intel DPDK - Initialisation of mbuf " |
---|
1269 | "pool failed: %s", strerror(rte_errno)); |
---|
1270 | return -1; |
---|
1271 | } |
---|
1272 | } |
---|
1273 | |
---|
1274 | /* Initialise the RX queue with some packets from memory */ |
---|
1275 | ret = rte_eth_rx_queue_setup(format_data->port, |
---|
1276 | stream->queue_id, |
---|
1277 | format_data->nb_rx_buf, |
---|
1278 | format_data->nic_numa_node, |
---|
1279 | DPDK_USE_NULL_QUEUE_CONFIG ? NULL: &rx_conf, |
---|
1280 | stream->mempool); |
---|
1281 | if (ret < 0) { |
---|
1282 | snprintf(err, errlen, "Intel DPDK - Cannot configure" |
---|
1283 | " RX queue on port %d : %s", |
---|
1284 | (int)format_data->port, |
---|
1285 | strerror(-ret)); |
---|
1286 | return -1; |
---|
1287 | } |
---|
1288 | } |
---|
1289 | |
---|
1290 | #if DEBUG |
---|
1291 | fprintf(stderr, "Doing start device\n"); |
---|
1292 | #endif |
---|
1293 | rte_eth_stats_reset(format_data->port); |
---|
1294 | /* Start device */ |
---|
1295 | ret = rte_eth_dev_start(format_data->port); |
---|
1296 | if (ret < 0) { |
---|
1297 | snprintf(err, errlen, "Intel DPDK - rte_eth_dev_start failed : %s", |
---|
1298 | strerror(-ret)); |
---|
1299 | return -1; |
---|
1300 | } |
---|
1301 | |
---|
1302 | /* Default promiscuous to on */ |
---|
1303 | if (format_data->promisc == -1) |
---|
1304 | format_data->promisc = 1; |
---|
1305 | |
---|
1306 | if (format_data->promisc == 1) |
---|
1307 | rte_eth_promiscuous_enable(format_data->port); |
---|
1308 | else |
---|
1309 | rte_eth_promiscuous_disable(format_data->port); |
---|
1310 | |
---|
1311 | /* We have now successfully started/unpased */ |
---|
1312 | format_data->paused = DPDK_RUNNING; |
---|
1313 | |
---|
1314 | |
---|
1315 | /* Register a callback for link state changes */ |
---|
1316 | ret = rte_eth_dev_callback_register(format_data->port, |
---|
1317 | RTE_ETH_EVENT_INTR_LSC, |
---|
1318 | dpdk_lsc_callback, |
---|
1319 | format_data); |
---|
1320 | #if DEBUG |
---|
1321 | if (ret) |
---|
1322 | fprintf(stderr, "rte_eth_dev_callback_register failed %d : %s\n", |
---|
1323 | ret, strerror(-ret)); |
---|
1324 | #endif |
---|
1325 | |
---|
1326 | /* Get the current link status */ |
---|
1327 | rte_eth_link_get_nowait(format_data->port, &link_info); |
---|
1328 | format_data->link_speed = link_info.link_speed; |
---|
1329 | #if DEBUG |
---|
1330 | fprintf(stderr, "Link status is %d %d %d\n", (int) link_info.link_status, |
---|
1331 | (int) link_info.link_duplex, (int) link_info.link_speed); |
---|
1332 | #endif |
---|
1333 | |
---|
1334 | return 0; |
---|
1335 | } |
---|
1336 | |
---|
1337 | int dpdk_start_input (libtrace_t *libtrace) { |
---|
1338 | char err[500]; |
---|
1339 | err[0] = 0; |
---|
1340 | |
---|
1341 | /* Make sure we don't reserve an extra thread for this */ |
---|
1342 | FORMAT_DATA_FIRST(libtrace)->queue_id = rte_lcore_id(); |
---|
1343 | |
---|
1344 | if (dpdk_start_streams(FORMAT(libtrace), err, sizeof(err), 1) != 0) { |
---|
1345 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); |
---|
1346 | free(libtrace->format_data); |
---|
1347 | libtrace->format_data = NULL; |
---|
1348 | return -1; |
---|
1349 | } |
---|
1350 | return 0; |
---|
1351 | } |
---|
1352 | |
---|
1353 | static inline size_t dpdk_get_max_rx_queues (portid_t port_id) { |
---|
1354 | struct rte_eth_dev_info dev_info; |
---|
1355 | rte_eth_dev_info_get(port_id, &dev_info); |
---|
1356 | return dev_info.max_rx_queues; |
---|
1357 | } |
---|
1358 | |
---|
1359 | static inline size_t dpdk_processor_count () { |
---|
1360 | long nb_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
---|
1361 | if (nb_cpu <= 0) |
---|
1362 | return 1; |
---|
1363 | else |
---|
1364 | return (size_t) nb_cpu; |
---|
1365 | } |
---|
1366 | |
---|
1367 | int dpdk_pstart_input (libtrace_t *libtrace) { |
---|
1368 | char err[500]; |
---|
1369 | int i=0, phys_cores=0; |
---|
1370 | int tot = libtrace->perpkt_thread_count; |
---|
1371 | libtrace_list_node_t *n; |
---|
1372 | err[0] = 0; |
---|
1373 | |
---|
1374 | if (rte_lcore_id() != rte_get_master_lcore()) |
---|
1375 | fprintf(stderr, "Warning dpdk_pstart_input should be called" |
---|
1376 | " from the master DPDK thread!\n"); |
---|
1377 | |
---|
1378 | /* If the master is not on the last thread we move it there */ |
---|
1379 | if (rte_get_master_lcore() != RTE_MAX_LCORE - 1) { |
---|
1380 | if (dpdk_move_master_lcore(libtrace, RTE_MAX_LCORE - 1) != 0) |
---|
1381 | return -1; |
---|
1382 | } |
---|
1383 | |
---|
1384 | /* Don't exceed the number of cores in the system/detected by dpdk |
---|
1385 | * We don't have to force this but performance wont be good if we don't */ |
---|
1386 | for (i = 0; i < RTE_MAX_LCORE; ++i) { |
---|
1387 | if (lcore_config[i].detected) { |
---|
1388 | if (rte_lcore_is_enabled(i)) { |
---|
1389 | #if DEBUG |
---|
1390 | fprintf(stderr, "Found core %d already in use!\n", i); |
---|
1391 | #endif |
---|
1392 | } else { |
---|
1393 | phys_cores++; |
---|
1394 | } |
---|
1395 | } |
---|
1396 | } |
---|
1397 | /* If we are restarting we have already allocated some threads as such |
---|
1398 | * we add these back to the count for this calculation */ |
---|
1399 | for (n = FORMAT_DATA_HEAD(libtrace); n; n = n->next) { |
---|
1400 | dpdk_per_stream_t * stream = n->data; |
---|
1401 | if (stream->lcore != -1) |
---|
1402 | phys_cores++; |
---|
1403 | } |
---|
1404 | |
---|
1405 | tot = MIN(libtrace->perpkt_thread_count, |
---|
1406 | dpdk_get_max_rx_queues(FORMAT(libtrace)->port)); |
---|
1407 | tot = MIN(tot, phys_cores); |
---|
1408 | |
---|
1409 | #if DEBUG |
---|
1410 | fprintf(stderr, "Running pstart DPDK tot=%d req=%d phys=%d\n", tot, |
---|
1411 | libtrace->perpkt_thread_count, phys_cores); |
---|
1412 | #endif |
---|
1413 | |
---|
1414 | if (dpdk_start_streams(FORMAT(libtrace), err, sizeof(err), tot) != 0) { |
---|
1415 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); |
---|
1416 | free(libtrace->format_data); |
---|
1417 | libtrace->format_data = NULL; |
---|
1418 | return -1; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /* Make sure we only start the number that we should */ |
---|
1422 | libtrace->perpkt_thread_count = tot; |
---|
1423 | return 0; |
---|
1424 | } |
---|
1425 | |
---|
1426 | /** |
---|
1427 | * Register a thread with the DPDK system, |
---|
1428 | * When we start DPDK in parallel libtrace we move the 'main thread' to the |
---|
1429 | * MAXIMUM CPU core slot (32) and remove any affinity restrictions DPDK |
---|
1430 | * gives it. |
---|
1431 | * |
---|
1432 | * We then allow a mapper thread to be started on every real core as DPDK would, |
---|
1433 | * we also bind these to the corresponding CPU cores. |
---|
1434 | * |
---|
1435 | * @param libtrace A pointer to the trace |
---|
1436 | * @param reading True if the thread will be used to read packets, i.e. will |
---|
1437 | * call pread_packet(), false if thread used to process packet |
---|
1438 | * in any other manner including statistics functions. |
---|
1439 | */ |
---|
1440 | int dpdk_pregister_thread(libtrace_t *libtrace, libtrace_thread_t *t, bool reading) |
---|
1441 | { |
---|
1442 | #if DEBUG |
---|
1443 | char name[99]; |
---|
1444 | name[0] = 0; |
---|
1445 | #if defined(HAVE_PTHREAD_SETNAME_NP) && defined(__linux__) |
---|
1446 | pthread_getname_np(pthread_self(), |
---|
1447 | name, sizeof(name)); |
---|
1448 | #endif |
---|
1449 | #endif |
---|
1450 | if (reading) { |
---|
1451 | dpdk_per_stream_t *stream; |
---|
1452 | /* Attach our thread */ |
---|
1453 | if(t->type == THREAD_PERPKT) { |
---|
1454 | t->format_data = libtrace_list_get_index(FORMAT(libtrace)->per_stream, t->perpkt_num)->data; |
---|
1455 | if (t->format_data == NULL) { |
---|
1456 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, |
---|
1457 | "Too many threads registered"); |
---|
1458 | return -1; |
---|
1459 | } |
---|
1460 | } else { |
---|
1461 | t->format_data = FORMAT_DATA_FIRST(libtrace); |
---|
1462 | } |
---|
1463 | stream = t->format_data; |
---|
1464 | #if DEBUG |
---|
1465 | fprintf(stderr, "%s new id memory:%s cpu-core:%d\n", name, stream->mempool->name, rte_lcore_id()); |
---|
1466 | #endif |
---|
1467 | return dpdk_register_lcore(libtrace, true, stream->lcore); |
---|
1468 | } else { |
---|
1469 | int lcore = dpdk_reserve_lcore(reading, 0); |
---|
1470 | if (lcore == -1) { |
---|
1471 | trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Too many threads" |
---|
1472 | " for DPDK"); |
---|
1473 | return -1; |
---|
1474 | } |
---|
1475 | #if DEBUG |
---|
1476 | fprintf(stderr, "%s new id cpu-core:%d\n", name, rte_lcore_id()); |
---|
1477 | #endif |
---|
1478 | return dpdk_register_lcore(libtrace, false, lcore); |
---|
1479 | } |
---|
1480 | |
---|
1481 | return 0; |
---|
1482 | } |
---|
1483 | |
---|
1484 | /** |
---|
1485 | * Unregister a thread with the DPDK system. |
---|
1486 | * |
---|
1487 | * Only previously registered threads should be calling this just before |
---|
1488 | * they are destroyed. |
---|
1489 | */ |
---|
1490 | void dpdk_punregister_thread(libtrace_t *libtrace UNUSED, libtrace_thread_t *t UNUSED) |
---|
1491 | { |
---|
1492 | struct rte_config *cfg = rte_eal_get_configuration(); |
---|
1493 | |
---|
1494 | if (rte_lcore_id() >= RTE_MAX_LCORE) { |
---|
1495 | fprintf(stderr, "Expected core id less than or equal to RTE_MAX_LCORE in " |
---|
1496 | "dpdk_punregister_thread()\n"); |
---|
1497 | return; |
---|
1498 | } |
---|
1499 | pthread_mutex_lock(&dpdk_lock); |
---|
1500 | /* Skip if master */ |
---|
1501 | if (rte_lcore_id() == rte_get_master_lcore()) { |
---|
1502 | fprintf(stderr, "INFO: we are skipping unregistering the master lcore\n"); |
---|
1503 | pthread_mutex_unlock(&dpdk_lock); |
---|
1504 | return; |
---|
1505 | } |
---|
1506 | |
---|
1507 | /* Disable this core in global DPDK structs */ |
---|
1508 | cfg->lcore_role[rte_lcore_id()] = ROLE_OFF; |
---|
1509 | cfg->lcore_count--; |
---|
1510 | RTE_PER_LCORE(_lcore_id) = -1; // Might make the world burn if used again |
---|
1511 | if (cfg->lcore_count < 1) { |
---|
1512 | fprintf(stderr, "You cannot unregister the master lcore in dpdk_punregister_thread()\n"); |
---|
1513 | return; |
---|
1514 | } |
---|
1515 | pthread_mutex_unlock(&dpdk_lock); |
---|
1516 | return; |
---|
1517 | } |
---|
1518 | |
---|
1519 | static int dpdk_start_output(libtrace_out_t *libtrace) |
---|
1520 | { |
---|
1521 | char err[500]; |
---|
1522 | err[0] = 0; |
---|
1523 | |
---|
1524 | if (dpdk_start_streams(FORMAT(libtrace), err, sizeof(err), 1) != 0) { |
---|
1525 | trace_set_err_out(libtrace, TRACE_ERR_INIT_FAILED, "%s", err); |
---|
1526 | free(libtrace->format_data); |
---|
1527 | libtrace->format_data = NULL; |
---|
1528 | return -1; |
---|
1529 | } |
---|
1530 | return 0; |
---|
1531 | } |
---|
1532 | |
---|
1533 | int dpdk_pause_input(libtrace_t * libtrace) { |
---|
1534 | libtrace_list_node_t *tmp = FORMAT_DATA_HEAD(libtrace); |
---|
1535 | /* This stops the device, but can be restarted using rte_eth_dev_start() */ |
---|
1536 | if (FORMAT(libtrace)->paused == DPDK_RUNNING) { |
---|
1537 | #if DEBUG |
---|
1538 | fprintf(stderr, "Pausing DPDK port\n"); |
---|
1539 | #endif |
---|
1540 | rte_eth_dev_stop(FORMAT(libtrace)->port); |
---|
1541 | FORMAT(libtrace)->paused = DPDK_PAUSED; |
---|
1542 | /* Empty the queue of packets */ |
---|
1543 | for (; FORMAT(libtrace)->burst_offset < FORMAT(libtrace)->burst_size; ++FORMAT(libtrace)->burst_offset) { |
---|
1544 | rte_pktmbuf_free(FORMAT(libtrace)->burst_pkts[FORMAT(libtrace)->burst_offset]); |
---|
1545 | } |
---|
1546 | FORMAT(libtrace)->burst_offset = 0; |
---|
1547 | FORMAT(libtrace)->burst_size = 0; |
---|
1548 | |
---|
1549 | for (; tmp != NULL; tmp = tmp->next) { |
---|
1550 | dpdk_per_stream_t *stream = tmp->data; |
---|
1551 | stream->ts_last_sys = 0; |
---|
1552 | #if HAS_HW_TIMESTAMPS_82580 |
---|
1553 | stream->ts_first_sys = 0; |
---|
1554 | #endif |
---|
1555 | } |
---|
1556 | |
---|
1557 | } |
---|
1558 | return 0; |
---|
1559 | } |
---|
1560 | |
---|
1561 | static int dpdk_write_packet(libtrace_out_t *trace, |
---|
1562 | libtrace_packet_t *packet){ |
---|
1563 | |
---|
1564 | /* Check dpdk can write this type of packet */ |
---|
1565 | if (!dpdk_can_write(packet)) { |
---|
1566 | return 0; |
---|
1567 | } |
---|
1568 | |
---|
1569 | struct rte_mbuf* m_buff[1]; |
---|
1570 | |
---|
1571 | int wirelen = trace_get_wire_length(packet); |
---|
1572 | int caplen = trace_get_capture_length(packet); |
---|
1573 | |
---|
1574 | /* Check for a checksum and remove it */ |
---|
1575 | if (trace_get_link_type(packet) == TRACE_TYPE_ETH && |
---|
1576 | wirelen == caplen) |
---|
1577 | caplen -= ETHER_CRC_LEN; |
---|
1578 | |
---|
1579 | m_buff[0] = rte_pktmbuf_alloc(FORMAT(trace)->pktmbuf_pool); |
---|
1580 | if (m_buff[0] == NULL) { |
---|
1581 | trace_set_err_out(trace, errno, "Cannot get an empty packet buffer"); |
---|
1582 | return -1; |
---|
1583 | } else { |
---|
1584 | int ret; |
---|
1585 | memcpy(rte_pktmbuf_append(m_buff[0], caplen), packet->payload, caplen); |
---|
1586 | do { |
---|
1587 | ret = rte_eth_tx_burst(FORMAT(trace)->port, 0 /*queue TODO*/, m_buff, 1); |
---|
1588 | } while (ret != 1); |
---|
1589 | } |
---|
1590 | |
---|
1591 | return 0; |
---|
1592 | } |
---|
1593 | |
---|
1594 | int dpdk_fin_input(libtrace_t * libtrace) { |
---|
1595 | libtrace_list_node_t * n; |
---|
1596 | /* Free our memory structures */ |
---|
1597 | if (libtrace->format_data != NULL) { |
---|
1598 | |
---|
1599 | if (FORMAT(libtrace)->port != 0xFF) |
---|
1600 | rte_eth_dev_callback_unregister(FORMAT(libtrace)->port, |
---|
1601 | RTE_ETH_EVENT_INTR_LSC, |
---|
1602 | dpdk_lsc_callback, |
---|
1603 | FORMAT(libtrace)); |
---|
1604 | /* Close the device completely, device cannot be restarted */ |
---|
1605 | rte_eth_dev_close(FORMAT(libtrace)->port); |
---|
1606 | |
---|
1607 | dpdk_free_memory(FORMAT(libtrace)->pktmbuf_pool, |
---|
1608 | FORMAT(libtrace)->nic_numa_node); |
---|
1609 | |
---|
1610 | for (n = FORMAT(libtrace)->per_stream->head; n ; n = n->next) { |
---|
1611 | dpdk_per_stream_t * stream = n->data; |
---|
1612 | if (stream->mempool) |
---|
1613 | dpdk_free_memory(stream->mempool, |
---|
1614 | rte_lcore_to_socket_id(stream->lcore)); |
---|
1615 | } |
---|
1616 | |
---|
1617 | libtrace_list_deinit(FORMAT(libtrace)->per_stream); |
---|
1618 | /* filter here if we used it */ |
---|
1619 | if (FORMAT(libtrace)->rss_key) |
---|
1620 | free(FORMAT(libtrace)->rss_key); |
---|
1621 | free(libtrace->format_data); |
---|
1622 | } |
---|
1623 | |
---|
1624 | return 0; |
---|
1625 | } |
---|
1626 | |
---|
1627 | |
---|
1628 | static int dpdk_fin_output(libtrace_out_t * libtrace) { |
---|
1629 | /* Free our memory structures */ |
---|
1630 | if (libtrace->format_data != NULL) { |
---|
1631 | /* Close the device completely, device cannot be restarted */ |
---|
1632 | if (FORMAT(libtrace)->port != 0xFF) |
---|
1633 | rte_eth_dev_close(FORMAT(libtrace)->port); |
---|
1634 | libtrace_list_deinit(FORMAT(libtrace)->per_stream); |
---|
1635 | /* filter here if we used it */ |
---|
1636 | free(libtrace->format_data); |
---|
1637 | } |
---|
1638 | |
---|
1639 | return 0; |
---|
1640 | } |
---|
1641 | |
---|
1642 | /** |
---|
1643 | * Get the start of the additional header that we added to a packet. |
---|
1644 | */ |
---|
1645 | static inline struct dpdk_addt_hdr * get_addt_hdr (const libtrace_packet_t *packet) { |
---|
1646 | if (!packet) { |
---|
1647 | fprintf(stderr, "NULL packet passed into dpdk_addt_hdr()\n"); |
---|
1648 | return NULL; |
---|
1649 | } |
---|
1650 | if (!packet->buffer) { |
---|
1651 | fprintf(stderr, "NULL packet buffer passed into dpdk_addt_hdr()\n"); |
---|
1652 | return NULL; |
---|
1653 | } |
---|
1654 | /* Our header sits straight after the mbuf header */ |
---|
1655 | return (struct dpdk_addt_hdr *) ((struct rte_mbuf*) packet->buffer + 1); |
---|
1656 | } |
---|
1657 | |
---|
1658 | static int dpdk_get_capture_length (const libtrace_packet_t *packet) { |
---|
1659 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
1660 | return hdr->cap_len; |
---|
1661 | } |
---|
1662 | |
---|
1663 | static size_t dpdk_set_capture_length(libtrace_packet_t *packet, size_t size) { |
---|
1664 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
1665 | if (size > hdr->cap_len) { |
---|
1666 | /* Cannot make a packet bigger */ |
---|
1667 | return trace_get_capture_length(packet); |
---|
1668 | } |
---|
1669 | |
---|
1670 | /* Reset the cached capture length first*/ |
---|
1671 | packet->cached.capture_length = -1; |
---|
1672 | hdr->cap_len = (uint32_t) size; |
---|
1673 | return trace_get_capture_length(packet); |
---|
1674 | } |
---|
1675 | |
---|
1676 | static int dpdk_get_wire_length (const libtrace_packet_t *packet) { |
---|
1677 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
1678 | int org_cap_size; /* The original capture size */ |
---|
1679 | if (hdr->flags & INCLUDES_HW_TIMESTAMP) { |
---|
1680 | org_cap_size = (int) rte_pktmbuf_pkt_len(MBUF(packet->buffer)) - |
---|
1681 | sizeof(struct hw_timestamp_82580); |
---|
1682 | } else { |
---|
1683 | org_cap_size = (int) rte_pktmbuf_pkt_len(MBUF(packet->buffer)); |
---|
1684 | } |
---|
1685 | if (hdr->flags & INCLUDES_CHECKSUM) { |
---|
1686 | return org_cap_size; |
---|
1687 | } else { |
---|
1688 | /* DPDK packets are always TRACE_TYPE_ETH packets */ |
---|
1689 | return org_cap_size + ETHER_CRC_LEN; |
---|
1690 | } |
---|
1691 | } |
---|
1692 | |
---|
1693 | int dpdk_get_framing_length (const libtrace_packet_t *packet) { |
---|
1694 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
1695 | if (hdr->flags & INCLUDES_HW_TIMESTAMP) |
---|
1696 | return sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM + |
---|
1697 | sizeof(struct hw_timestamp_82580); |
---|
1698 | else |
---|
1699 | return sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM; |
---|
1700 | } |
---|
1701 | |
---|
1702 | int dpdk_prepare_packet(libtrace_t *libtrace UNUSED, |
---|
1703 | libtrace_packet_t *packet, void *buffer, |
---|
1704 | libtrace_rt_types_t rt_type, uint32_t flags) { |
---|
1705 | if (!packet) { |
---|
1706 | fprintf(stderr, "NULL packet passed into dpdk_prepare_packet()\n"); |
---|
1707 | return TRACE_ERR_NULL_PACKET; |
---|
1708 | } |
---|
1709 | if (packet->buffer != buffer && |
---|
1710 | packet->buf_control == TRACE_CTRL_PACKET) { |
---|
1711 | free(packet->buffer); |
---|
1712 | } |
---|
1713 | |
---|
1714 | if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) |
---|
1715 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
1716 | else |
---|
1717 | packet->buf_control = TRACE_CTRL_EXTERNAL; |
---|
1718 | |
---|
1719 | packet->buffer = buffer; |
---|
1720 | packet->header = buffer; |
---|
1721 | |
---|
1722 | /* Don't use pktmbuf_mtod will fail if the packet is a copy */ |
---|
1723 | packet->payload = (char *)buffer + dpdk_get_framing_length(packet); |
---|
1724 | packet->type = rt_type; |
---|
1725 | return 0; |
---|
1726 | } |
---|
1727 | |
---|
1728 | /** |
---|
1729 | * Given a packet size and a link speed, computes the |
---|
1730 | * time to transmit in nanoseconds. |
---|
1731 | * |
---|
1732 | * @param format_data The dpdk format data from which we get the link speed |
---|
1733 | * and if unset updates it in a thread safe manner |
---|
1734 | * @param pkt_size The size of the packet in bytes |
---|
1735 | * @return The wire time in nanoseconds |
---|
1736 | */ |
---|
1737 | static inline uint32_t calculate_wire_time(struct dpdk_format_data_t* format_data, uint32_t pkt_size) { |
---|
1738 | uint32_t wire_time; |
---|
1739 | /* 20 extra bytes of interframe gap and preamble */ |
---|
1740 | # if GET_MAC_CRC_CHECKSUM |
---|
1741 | wire_time = ((pkt_size + 20) * 8000); |
---|
1742 | # else |
---|
1743 | wire_time = ((pkt_size + 20 + ETHER_CRC_LEN) * 8000); |
---|
1744 | # endif |
---|
1745 | |
---|
1746 | /* Division is really slow and introduces a pipeline stall |
---|
1747 | * The compiler will optimise this into magical multiplication and shifting |
---|
1748 | * See http://ridiculousfish.com/blog/posts/labor-of-division-episode-i.html |
---|
1749 | */ |
---|
1750 | retry_calc_wiretime: |
---|
1751 | switch (format_data->link_speed) { |
---|
1752 | case ETH_SPEED_NUM_40G: |
---|
1753 | wire_time /= ETH_SPEED_NUM_40G; |
---|
1754 | break; |
---|
1755 | case ETH_SPEED_NUM_20G: |
---|
1756 | wire_time /= ETH_SPEED_NUM_20G; |
---|
1757 | break; |
---|
1758 | case ETH_SPEED_NUM_10G: |
---|
1759 | wire_time /= ETH_SPEED_NUM_10G; |
---|
1760 | break; |
---|
1761 | case ETH_SPEED_NUM_1G: |
---|
1762 | wire_time /= ETH_SPEED_NUM_1G; |
---|
1763 | break; |
---|
1764 | case 0: |
---|
1765 | { |
---|
1766 | /* Maybe the link was down originally, but now it should be up */ |
---|
1767 | struct rte_eth_link link = {0}; |
---|
1768 | rte_eth_link_get_nowait(format_data->port, &link); |
---|
1769 | if (link.link_status && link.link_speed) { |
---|
1770 | format_data->link_speed = link.link_speed; |
---|
1771 | #ifdef DEBUG |
---|
1772 | fprintf(stderr, "Link has come up updated speed=%d\n", (int) link.link_speed); |
---|
1773 | #endif |
---|
1774 | goto retry_calc_wiretime; |
---|
1775 | } |
---|
1776 | /* We don't know the link speed, make sure numbers are counting up */ |
---|
1777 | wire_time = 1; |
---|
1778 | break; |
---|
1779 | } |
---|
1780 | default: |
---|
1781 | wire_time /= format_data->link_speed; |
---|
1782 | } |
---|
1783 | return wire_time; |
---|
1784 | } |
---|
1785 | |
---|
1786 | /** |
---|
1787 | * Does any extra preperation to all captured packets |
---|
1788 | * This includes adding our extra header to it with the timestamp, |
---|
1789 | * and any snapping |
---|
1790 | * |
---|
1791 | * @param format_data The DPDK format data |
---|
1792 | * @param plc The DPDK per lcore format data |
---|
1793 | * @param pkts An array of size nb_pkts of DPDK packets |
---|
1794 | */ |
---|
1795 | static inline void dpdk_ready_pkts(libtrace_t *libtrace, |
---|
1796 | struct dpdk_per_stream_t *plc, |
---|
1797 | struct rte_mbuf **pkts, |
---|
1798 | size_t nb_pkts) { |
---|
1799 | struct dpdk_format_data_t *format_data = FORMAT(libtrace); |
---|
1800 | struct dpdk_addt_hdr *hdr; |
---|
1801 | size_t i; |
---|
1802 | uint64_t cur_sys_time_ns; |
---|
1803 | #if HAS_HW_TIMESTAMPS_82580 |
---|
1804 | struct hw_timestamp_82580 *hw_ts; |
---|
1805 | uint64_t estimated_wraps; |
---|
1806 | #else |
---|
1807 | |
---|
1808 | #endif |
---|
1809 | |
---|
1810 | #if USE_CLOCK_GETTIME |
---|
1811 | struct timespec cur_sys_time = {0}; |
---|
1812 | /* This looks terrible and I feel bad doing it. But it's OK |
---|
1813 | * on new kernels, because this is a fast vsyscall */ |
---|
1814 | clock_gettime(CLOCK_REALTIME, &cur_sys_time); |
---|
1815 | cur_sys_time_ns = TS_TO_NS(cur_sys_time); |
---|
1816 | #else |
---|
1817 | struct timeval cur_sys_time = {0}; |
---|
1818 | /* Also a fast vsyscall */ |
---|
1819 | gettimeofday(&cur_sys_time, NULL); |
---|
1820 | cur_sys_time_ns = TV_TO_NS(cur_sys_time); |
---|
1821 | #endif |
---|
1822 | |
---|
1823 | /* The system clock is not perfect so when running |
---|
1824 | * at linerate we could timestamp a packet in the past. |
---|
1825 | * To avoid this we munge the timestamp to appear 1ns |
---|
1826 | * after the previous packet. We should eventually catch up |
---|
1827 | * to system time since a 64byte packet on a 10G link takes 67ns. |
---|
1828 | * |
---|
1829 | * Note with parallel readers timestamping packets |
---|
1830 | * with duplicate stamps or out of order is unavoidable without |
---|
1831 | * hardware timestamping from the NIC. |
---|
1832 | */ |
---|
1833 | #if !HAS_HW_TIMESTAMPS_82580 |
---|
1834 | if (plc->ts_last_sys >= cur_sys_time_ns) { |
---|
1835 | cur_sys_time_ns = plc->ts_last_sys + 1; |
---|
1836 | } |
---|
1837 | #endif |
---|
1838 | |
---|
1839 | ct_assert(RTE_PKTMBUF_HEADROOM >= sizeof(struct dpdk_addt_hdr)); |
---|
1840 | for (i = 0 ; i < nb_pkts ; ++i) { |
---|
1841 | |
---|
1842 | /* We put our header straight after the dpdk header */ |
---|
1843 | hdr = (struct dpdk_addt_hdr *) (pkts[i] + 1); |
---|
1844 | memset(hdr, 0, sizeof(struct dpdk_addt_hdr)); |
---|
1845 | |
---|
1846 | #if GET_MAC_CRC_CHECKSUM |
---|
1847 | /* Add back in the CRC sum */ |
---|
1848 | rte_pktmbuf_pkt_len(pkt) += ETHER_CRC_LEN; |
---|
1849 | rte_pktmbuf_data_len(pkt) += ETHER_CRC_LEN; |
---|
1850 | hdr->flags |= INCLUDES_CHECKSUM; |
---|
1851 | #endif |
---|
1852 | |
---|
1853 | hdr->cap_len = rte_pktmbuf_pkt_len(pkts[i]); |
---|
1854 | |
---|
1855 | #if HAS_HW_TIMESTAMPS_82580 |
---|
1856 | /* The timestamp is sitting before our packet and is included in pkt_len */ |
---|
1857 | hdr->flags |= INCLUDES_HW_TIMESTAMP; |
---|
1858 | hdr->cap_len -= sizeof(struct hw_timestamp_82580); |
---|
1859 | hw_ts = (struct hw_timestamp_82580 *) MBUF_PKTDATA(pkts[i]); |
---|
1860 | |
---|
1861 | /* Taken from igb_ptp.c part of Intel Linux drivers (Good example code) |
---|
1862 | * |
---|
1863 | * +----------+---+ +--------------+ |
---|
1864 | * 82580 | 24 | 8 | | 32 | |
---|
1865 | * +----------+---+ +--------------+ |
---|
1866 | * reserved \______ 40 bits _____/ |
---|
1867 | * |
---|
1868 | * The 40 bit 82580 SYSTIM overflows every |
---|
1869 | * 2^40 * 10^-9 / 60 = 18.3 minutes. |
---|
1870 | * |
---|
1871 | * NOTE picture is in Big Endian order, in memory it's acutally in Little |
---|
1872 | * Endian (for the full 64 bits) i.e. picture is mirrored |
---|
1873 | */ |
---|
1874 | |
---|
1875 | /* Despite what the documentation says this is in Little |
---|
1876 | * Endian byteorder. Mask the reserved section out. |
---|
1877 | */ |
---|
1878 | hdr->timestamp = le64toh(hw_ts->timestamp) & |
---|
1879 | ~(((~0ull)>>TS_NBITS_82580)<<TS_NBITS_82580); |
---|
1880 | |
---|
1881 | if (unlikely(plc->ts_first_sys == 0)) { |
---|
1882 | plc->ts_first_sys = cur_sys_time_ns - hdr->timestamp; |
---|
1883 | plc->ts_last_sys = plc->ts_first_sys; |
---|
1884 | } |
---|
1885 | |
---|
1886 | /* This will have serious problems if packets aren't read quickly |
---|
1887 | * that is within a couple of seconds because our clock cycles every |
---|
1888 | * 18 seconds */ |
---|
1889 | estimated_wraps = (cur_sys_time_ns - plc->ts_last_sys) |
---|
1890 | / (1ull<<TS_NBITS_82580); |
---|
1891 | |
---|
1892 | /* Estimated_wraps gives the number of times the counter should have |
---|
1893 | * wrapped (however depending on value last time it could have wrapped |
---|
1894 | * twice more (if hw clock is close to its max value) or once less (allowing |
---|
1895 | * for a bit of variance between hw and sys clock). But if the clock |
---|
1896 | * shouldn't have wrapped once then don't allow it to go backwards in time */ |
---|
1897 | if (unlikely(estimated_wraps >= 2)) { |
---|
1898 | /* 2 or more wrap arounds add all but the very last wrap */ |
---|
1899 | plc->wrap_count += estimated_wraps - 1; |
---|
1900 | } |
---|
1901 | |
---|
1902 | /* Set the timestamp to the lowest possible value we're considering */ |
---|
1903 | hdr->timestamp += plc->ts_first_sys + |
---|
1904 | plc->wrap_count * (1ull<<TS_NBITS_82580); |
---|
1905 | |
---|
1906 | /* In most runs only the first if() will need evaluating - i.e our |
---|
1907 | * estimate is correct. */ |
---|
1908 | if (unlikely(!WITHIN_VARIANCE(cur_sys_time_ns, |
---|
1909 | hdr->timestamp, MAXSKEW_82580))) { |
---|
1910 | /* Failed to match estimated_wraps-1 (or estimated_wraps in ==0 case) */ |
---|
1911 | plc->wrap_count++; |
---|
1912 | hdr->timestamp += (1ull<<TS_NBITS_82580); |
---|
1913 | if (!WITHIN_VARIANCE(cur_sys_time_ns, |
---|
1914 | hdr->timestamp, MAXSKEW_82580)) { |
---|
1915 | /* Failed to match estimated_wraps */ |
---|
1916 | plc->wrap_count++; |
---|
1917 | hdr->timestamp += (1ull<<TS_NBITS_82580); |
---|
1918 | if (!WITHIN_VARIANCE(cur_sys_time_ns, |
---|
1919 | hdr->timestamp, MAXSKEW_82580)) { |
---|
1920 | if (estimated_wraps == 0) { |
---|
1921 | /* 0 case Failed to match estimated_wraps+2 */ |
---|
1922 | printf("WARNING - Hardware Timestamp failed to" |
---|
1923 | " match using systemtime!\n"); |
---|
1924 | hdr->timestamp = cur_sys_time_ns; |
---|
1925 | } else { |
---|
1926 | /* Failed to match estimated_wraps+1 */ |
---|
1927 | plc->wrap_count++; |
---|
1928 | hdr->timestamp += (1ull<<TS_NBITS_82580); |
---|
1929 | if (!WITHIN_VARIANCE(cur_sys_time_ns, |
---|
1930 | hdr->timestamp, MAXSKEW_82580)) { |
---|
1931 | /* Failed to match estimated_wraps+2 */ |
---|
1932 | printf("WARNING - Hardware Timestamp failed to" |
---|
1933 | " match using systemtime!!\n"); |
---|
1934 | } |
---|
1935 | } |
---|
1936 | } |
---|
1937 | } |
---|
1938 | } |
---|
1939 | #else |
---|
1940 | |
---|
1941 | hdr->timestamp = cur_sys_time_ns; |
---|
1942 | /* Offset the next packet by the wire time of previous */ |
---|
1943 | calculate_wire_time(format_data, hdr->cap_len); |
---|
1944 | |
---|
1945 | #endif |
---|
1946 | } |
---|
1947 | |
---|
1948 | plc->ts_last_sys = cur_sys_time_ns; |
---|
1949 | return; |
---|
1950 | } |
---|
1951 | |
---|
1952 | |
---|
1953 | static void dpdk_fin_packet(libtrace_packet_t *packet) |
---|
1954 | { |
---|
1955 | if ( packet->buf_control == TRACE_CTRL_EXTERNAL ) { |
---|
1956 | rte_pktmbuf_free(packet->buffer); |
---|
1957 | packet->buffer = NULL; |
---|
1958 | } |
---|
1959 | } |
---|
1960 | |
---|
1961 | /** Reads at least one packet or returns an error |
---|
1962 | */ |
---|
1963 | int dpdk_read_packet_stream (libtrace_t *libtrace, |
---|
1964 | dpdk_per_stream_t *stream, |
---|
1965 | libtrace_message_queue_t *mesg, |
---|
1966 | struct rte_mbuf* pkts_burst[], |
---|
1967 | size_t nb_packets) { |
---|
1968 | size_t nb_rx; /* Number of rx packets we've recevied */ |
---|
1969 | while (1) { |
---|
1970 | /* Poll for a batch of packets */ |
---|
1971 | nb_rx = rte_eth_rx_burst(FORMAT(libtrace)->port, |
---|
1972 | stream->queue_id, pkts_burst, nb_packets); |
---|
1973 | if (nb_rx > 0) { |
---|
1974 | /* Got some packets - otherwise we keep spining */ |
---|
1975 | dpdk_ready_pkts(libtrace, stream, pkts_burst, nb_rx); |
---|
1976 | //fprintf(stderr, "Doing P READ PACKET port=%d q=%d\n", (int) FORMAT(libtrace)->port, (int) get_thread_table_num(libtrace)); |
---|
1977 | return nb_rx; |
---|
1978 | } |
---|
1979 | /* Check the message queue this could be less than 0 */ |
---|
1980 | if (mesg && libtrace_message_queue_count(mesg) > 0) |
---|
1981 | return READ_MESSAGE; |
---|
1982 | if ((nb_rx=is_halted(libtrace)) != (size_t) -1) |
---|
1983 | return nb_rx; |
---|
1984 | /* Wait a while, polling on memory degrades performance |
---|
1985 | * This relieves the pressure on memory allowing the NIC to DMA */ |
---|
1986 | rte_delay_us(10); |
---|
1987 | } |
---|
1988 | |
---|
1989 | /* We'll never get here - but if we did it would be bad */ |
---|
1990 | return READ_ERROR; |
---|
1991 | } |
---|
1992 | |
---|
1993 | static int dpdk_pread_packets (libtrace_t *libtrace, |
---|
1994 | libtrace_thread_t *t, |
---|
1995 | libtrace_packet_t **packets, |
---|
1996 | size_t nb_packets) { |
---|
1997 | int nb_rx; /* Number of rx packets we've recevied */ |
---|
1998 | struct rte_mbuf* pkts_burst[nb_packets]; /* Array of pointer(s) */ |
---|
1999 | int i; |
---|
2000 | dpdk_per_stream_t *stream = t->format_data; |
---|
2001 | struct dpdk_addt_hdr * hdr; |
---|
2002 | |
---|
2003 | nb_rx = dpdk_read_packet_stream (libtrace, stream, &t->messages, |
---|
2004 | pkts_burst, nb_packets); |
---|
2005 | |
---|
2006 | if (nb_rx > 0) { |
---|
2007 | for (i = 0; i < nb_rx; ++i) { |
---|
2008 | if (packets[i]->buffer != NULL) { |
---|
2009 | /* The packet should always be finished */ |
---|
2010 | if (packets[i]->buf_control != TRACE_CTRL_PACKET) { |
---|
2011 | trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Expected packet buffer " |
---|
2012 | "to be empty in dpdk_pread_packets()\n"); |
---|
2013 | return -1; |
---|
2014 | } |
---|
2015 | free(packets[i]->buffer); |
---|
2016 | } |
---|
2017 | packets[i]->buf_control = TRACE_CTRL_EXTERNAL; |
---|
2018 | packets[i]->type = TRACE_RT_DATA_DPDK; |
---|
2019 | packets[i]->buffer = pkts_burst[i]; |
---|
2020 | packets[i]->trace = libtrace; |
---|
2021 | packets[i]->error = 1; |
---|
2022 | hdr = (struct dpdk_addt_hdr *) |
---|
2023 | ((struct rte_mbuf*) pkts_burst[i] + 1); |
---|
2024 | packets[i]->order = hdr->timestamp; |
---|
2025 | dpdk_prepare_packet(libtrace, packets[i], packets[i]->buffer, packets[i]->type, 0); |
---|
2026 | } |
---|
2027 | } |
---|
2028 | |
---|
2029 | return nb_rx; |
---|
2030 | } |
---|
2031 | |
---|
2032 | int dpdk_read_packet (libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
2033 | int nb_rx; /* Number of rx packets we've received */ |
---|
2034 | dpdk_per_stream_t *stream = FORMAT_DATA_FIRST(libtrace); |
---|
2035 | |
---|
2036 | /* Free the last packet buffer */ |
---|
2037 | if (packet->buffer != NULL) { |
---|
2038 | /* The packet should always be finished */ |
---|
2039 | if (packet->buf_control != TRACE_CTRL_PACKET) { |
---|
2040 | trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Expected packet buffer to be " |
---|
2041 | "empty in dpdk_read_packet()\n"); |
---|
2042 | return -1; |
---|
2043 | } |
---|
2044 | free(packet->buffer); |
---|
2045 | packet->buffer = NULL; |
---|
2046 | } |
---|
2047 | |
---|
2048 | packet->buf_control = TRACE_CTRL_EXTERNAL; |
---|
2049 | packet->type = TRACE_RT_DATA_DPDK; |
---|
2050 | |
---|
2051 | /* Check if we already have some packets buffered */ |
---|
2052 | if (FORMAT(libtrace)->burst_size != FORMAT(libtrace)->burst_offset) { |
---|
2053 | packet->buffer = FORMAT(libtrace)->burst_pkts[FORMAT(libtrace)->burst_offset++]; |
---|
2054 | packet->trace = libtrace; |
---|
2055 | dpdk_prepare_packet(libtrace, packet, packet->buffer, packet->type, 0); |
---|
2056 | return 1; // TODO should be bytes read, which essentially useless anyway |
---|
2057 | } |
---|
2058 | |
---|
2059 | nb_rx = dpdk_read_packet_stream (libtrace, stream, NULL, |
---|
2060 | FORMAT(libtrace)->burst_pkts, BURST_SIZE); |
---|
2061 | |
---|
2062 | if (nb_rx > 0) { |
---|
2063 | FORMAT(libtrace)->burst_size = nb_rx; |
---|
2064 | FORMAT(libtrace)->burst_offset = 1; |
---|
2065 | packet->buffer = FORMAT(libtrace)->burst_pkts[0]; |
---|
2066 | packet->trace = libtrace; |
---|
2067 | dpdk_prepare_packet(libtrace, packet, packet->buffer, packet->type, 0); |
---|
2068 | return 1; |
---|
2069 | } |
---|
2070 | return nb_rx; |
---|
2071 | } |
---|
2072 | |
---|
2073 | static struct timeval dpdk_get_timeval (const libtrace_packet_t *packet) { |
---|
2074 | struct timeval tv; |
---|
2075 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
2076 | |
---|
2077 | tv.tv_sec = hdr->timestamp / (uint64_t) 1000000000; |
---|
2078 | tv.tv_usec = (hdr->timestamp % (uint64_t) 1000000000) / 1000; |
---|
2079 | return tv; |
---|
2080 | } |
---|
2081 | |
---|
2082 | static struct timespec dpdk_get_timespec (const libtrace_packet_t *packet) { |
---|
2083 | struct timespec ts; |
---|
2084 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
2085 | |
---|
2086 | ts.tv_sec = hdr->timestamp / (uint64_t) 1000000000; |
---|
2087 | ts.tv_nsec = hdr->timestamp % (uint64_t) 1000000000; |
---|
2088 | return ts; |
---|
2089 | } |
---|
2090 | |
---|
2091 | static libtrace_linktype_t dpdk_get_link_type (const libtrace_packet_t *packet UNUSED) { |
---|
2092 | return TRACE_TYPE_ETH; /* Always ethernet until proven otherwise */ |
---|
2093 | } |
---|
2094 | |
---|
2095 | static libtrace_direction_t dpdk_get_direction (const libtrace_packet_t *packet) { |
---|
2096 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
2097 | return (libtrace_direction_t) hdr->direction; |
---|
2098 | } |
---|
2099 | |
---|
2100 | static libtrace_direction_t dpdk_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction) { |
---|
2101 | struct dpdk_addt_hdr * hdr = get_addt_hdr(packet); |
---|
2102 | hdr->direction = (uint8_t) direction; |
---|
2103 | return (libtrace_direction_t) hdr->direction; |
---|
2104 | } |
---|
2105 | |
---|
2106 | void dpdk_get_stats(libtrace_t *trace, libtrace_stat_t *stats) { |
---|
2107 | struct rte_eth_stats dev_stats = {0}; |
---|
2108 | |
---|
2109 | if (trace->format_data == NULL || FORMAT(trace)->port == 0xFF) |
---|
2110 | return; |
---|
2111 | |
---|
2112 | /* Grab the current stats */ |
---|
2113 | rte_eth_stats_get(FORMAT(trace)->port, &dev_stats); |
---|
2114 | |
---|
2115 | stats->captured_valid = true; |
---|
2116 | stats->captured = dev_stats.ipackets; |
---|
2117 | |
---|
2118 | stats->dropped_valid = true; |
---|
2119 | stats->dropped = dev_stats.imissed; |
---|
2120 | |
---|
2121 | #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 2) |
---|
2122 | /* DPDK commit 86057c fixes ensures missed does not get counted as |
---|
2123 | * errors */ |
---|
2124 | stats->errors_valid = true; |
---|
2125 | stats->errors = dev_stats.ierrors; |
---|
2126 | #else |
---|
2127 | /* DPDK errors includes drops */ |
---|
2128 | stats->errors_valid = true; |
---|
2129 | stats->errors = dev_stats.ierrors - dev_stats.imissed; |
---|
2130 | #endif |
---|
2131 | stats->received_valid = true; |
---|
2132 | stats->received = dev_stats.ipackets + dev_stats.imissed; |
---|
2133 | |
---|
2134 | } |
---|
2135 | |
---|
2136 | /* Attempts to read a packet in a non-blocking fashion. If one is not |
---|
2137 | * available a SLEEP event is returned. We do not have the ability to |
---|
2138 | * create a select()able file descriptor in DPDK. |
---|
2139 | */ |
---|
2140 | libtrace_eventobj_t dpdk_trace_event(libtrace_t *trace, |
---|
2141 | libtrace_packet_t *packet) { |
---|
2142 | libtrace_eventobj_t event = {0,0,0.0,0}; |
---|
2143 | size_t nb_rx; /* Number of received packets we've read */ |
---|
2144 | |
---|
2145 | do { |
---|
2146 | |
---|
2147 | /* No packets waiting in our buffer? Try and read some more */ |
---|
2148 | if (FORMAT(trace)->burst_size == FORMAT(trace)->burst_offset) { |
---|
2149 | nb_rx = rte_eth_rx_burst(FORMAT(trace)->port, |
---|
2150 | FORMAT_DATA_FIRST(trace)->queue_id, |
---|
2151 | FORMAT(trace)->burst_pkts, BURST_SIZE); |
---|
2152 | if (nb_rx > 0) { |
---|
2153 | dpdk_ready_pkts(trace, FORMAT_DATA_FIRST(trace), |
---|
2154 | FORMAT(trace)->burst_pkts, nb_rx); |
---|
2155 | FORMAT(trace)->burst_size = nb_rx; |
---|
2156 | FORMAT(trace)->burst_offset = 0; |
---|
2157 | } |
---|
2158 | } |
---|
2159 | |
---|
2160 | /* Now do we have packets waiting? */ |
---|
2161 | if (FORMAT(trace)->burst_size != FORMAT(trace)->burst_offset) { |
---|
2162 | /* Free the last packet buffer */ |
---|
2163 | if (packet->buffer != NULL) { |
---|
2164 | /* The packet should always be finished */ |
---|
2165 | if (packet->buf_control != TRACE_CTRL_PACKET) { |
---|
2166 | trace_set_err(trace, TRACE_ERR_BAD_PACKET, "Expected packet " |
---|
2167 | "buffer to be empty in dpdk_trace_event()\n"); |
---|
2168 | event.type = TRACE_EVENT_TERMINATE; |
---|
2169 | return event; |
---|
2170 | } |
---|
2171 | free(packet->buffer); |
---|
2172 | packet->buffer = NULL; |
---|
2173 | } |
---|
2174 | |
---|
2175 | packet->buf_control = TRACE_CTRL_EXTERNAL; |
---|
2176 | packet->type = TRACE_RT_DATA_DPDK; |
---|
2177 | event.type = TRACE_EVENT_PACKET; |
---|
2178 | packet->buffer = FORMAT(trace)->burst_pkts[ |
---|
2179 | FORMAT(trace)->burst_offset++]; |
---|
2180 | dpdk_prepare_packet(trace, packet, packet->buffer, packet->type, 0); |
---|
2181 | event.size = 1; // TODO should be bytes read, which essentially useless anyway |
---|
2182 | |
---|
2183 | /* XXX - Check this passes the filter trace_read_packet normally |
---|
2184 | * does this for us but this wont */ |
---|
2185 | if (trace->filter) { |
---|
2186 | if (!trace_apply_filter(trace->filter, packet)) { |
---|
2187 | /* Failed the filter so we loop for another packet */ |
---|
2188 | trace->filtered_packets ++; |
---|
2189 | continue; |
---|
2190 | } |
---|
2191 | } |
---|
2192 | trace->accepted_packets ++; |
---|
2193 | } else { |
---|
2194 | /* We only want to sleep for a very short time - we are non-blocking */ |
---|
2195 | event.type = TRACE_EVENT_SLEEP; |
---|
2196 | event.seconds = 0.0001; |
---|
2197 | event.size = 0; |
---|
2198 | } |
---|
2199 | |
---|
2200 | /* If we get here we have our event */ |
---|
2201 | break; |
---|
2202 | } while (1); |
---|
2203 | |
---|
2204 | return event; |
---|
2205 | } |
---|
2206 | |
---|
2207 | static void dpdk_help(void) { |
---|
2208 | printf("dpdk format module: %s (%d) \n", rte_version(), RTE_VERSION); |
---|
2209 | printf("Supported input URIs:\n"); |
---|
2210 | printf("\tdpdk:<domain:bus:devid.func>-<coreid>\n"); |
---|
2211 | printf("\tThe -<coreid> is optional \n"); |
---|
2212 | printf("\t e.g. dpdk:0000:01:00.1\n"); |
---|
2213 | printf("\t e.g. dpdk:0000:01:00.1-2 (Use the second CPU core)\n\n"); |
---|
2214 | printf("\t By default the last CPU core is used if not otherwise specified.\n"); |
---|
2215 | printf("\t Only a single libtrace instance of dpdk can use the same CPU core.\n"); |
---|
2216 | printf("\t Support for multiple simultaneous instances of dpdk format is currently limited.\n"); |
---|
2217 | printf("\n"); |
---|
2218 | printf("Supported output URIs:\n"); |
---|
2219 | printf("\tSame format as the input URI.\n"); |
---|
2220 | printf("\t e.g. dpdk:0000:01:00.1\n"); |
---|
2221 | printf("\t e.g. dpdk:0000:01:00.1-2 (Use the second CPU core)\n"); |
---|
2222 | printf("\n"); |
---|
2223 | } |
---|
2224 | |
---|
2225 | static struct libtrace_format_t dpdk = { |
---|
2226 | "dpdk", |
---|
2227 | "$Id$", |
---|
2228 | TRACE_FORMAT_DPDK, |
---|
2229 | NULL, /* probe filename */ |
---|
2230 | NULL, /* probe magic */ |
---|
2231 | dpdk_init_input, /* init_input */ |
---|
2232 | dpdk_config_input, /* config_input */ |
---|
2233 | dpdk_start_input, /* start_input */ |
---|
2234 | dpdk_pause_input, /* pause_input */ |
---|
2235 | dpdk_init_output, /* init_output */ |
---|
2236 | NULL, /* config_output */ |
---|
2237 | dpdk_start_output, /* start_ouput */ |
---|
2238 | dpdk_fin_input, /* fin_input */ |
---|
2239 | dpdk_fin_output, /* fin_output */ |
---|
2240 | dpdk_read_packet, /* read_packet */ |
---|
2241 | dpdk_prepare_packet, /* prepare_packet */ |
---|
2242 | dpdk_fin_packet, /* fin_packet */ |
---|
2243 | dpdk_write_packet, /* write_packet */ |
---|
2244 | NULL, /* flush_output */ |
---|
2245 | dpdk_get_link_type, /* get_link_type */ |
---|
2246 | dpdk_get_direction, /* get_direction */ |
---|
2247 | dpdk_set_direction, /* set_direction */ |
---|
2248 | NULL, /* get_erf_timestamp */ |
---|
2249 | dpdk_get_timeval, /* get_timeval */ |
---|
2250 | dpdk_get_timespec, /* get_timespec */ |
---|
2251 | NULL, /* get_seconds */ |
---|
2252 | NULL, /* seek_erf */ |
---|
2253 | NULL, /* seek_timeval */ |
---|
2254 | NULL, /* seek_seconds */ |
---|
2255 | NULL, /* get_meta_section */ |
---|
2256 | NULL, /* get_meta_section_item */ |
---|
2257 | dpdk_get_capture_length, /* get_capture_length */ |
---|
2258 | dpdk_get_wire_length, /* get_wire_length */ |
---|
2259 | dpdk_get_framing_length, /* get_framing_length */ |
---|
2260 | dpdk_set_capture_length, /* set_capture_length */ |
---|
2261 | NULL, /* get_received_packets */ |
---|
2262 | NULL, /* get_filtered_packets */ |
---|
2263 | NULL, /* get_dropped_packets */ |
---|
2264 | dpdk_get_stats, /* get_statistics */ |
---|
2265 | NULL, /* get_fd */ |
---|
2266 | dpdk_trace_event, /* trace_event */ |
---|
2267 | dpdk_help, /* help */ |
---|
2268 | NULL, /* next pointer */ |
---|
2269 | {true, 8}, /* Live, NICs typically have 8 threads */ |
---|
2270 | dpdk_pstart_input, /* pstart_input */ |
---|
2271 | dpdk_pread_packets, /* pread_packets */ |
---|
2272 | dpdk_pause_input, /* ppause */ |
---|
2273 | dpdk_fin_input, /* p_fin */ |
---|
2274 | dpdk_pregister_thread, /* pregister_thread */ |
---|
2275 | dpdk_punregister_thread, /* punregister_thread */ |
---|
2276 | NULL /* get thread stats */ |
---|
2277 | }; |
---|
2278 | |
---|
2279 | void dpdk_constructor(void) { |
---|
2280 | register_format(&dpdk); |
---|
2281 | } |
---|