1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
11 #include <sys/queue.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
22 #include <rte_malloc.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
26 #include <rte_launch.h>
27 #include <rte_atomic.h>
28 #include <rte_cycles.h>
29 #include <rte_prefetch.h>
30 #include <rte_lcore.h>
31 #include <rte_per_lcore.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_interrupts.h>
34 #include <rte_random.h>
35 #include <rte_debug.h>
36 #include <rte_ether.h>
37 #include <rte_ethdev.h>
38 #include <rte_mempool.h>
43 #include <rte_string_fns.h>
44 #include <rte_timer.h>
45 #include <rte_power.h>
46 #include <rte_spinlock.h>
47 #include <rte_power_empty_poll.h>
48 #include <rte_metrics.h>
50 #include "perf_core.h"
53 #define RTE_LOGTYPE_L3FWD_POWER RTE_LOGTYPE_USER1
55 #define MAX_PKT_BURST 32
57 #define MIN_ZERO_POLL_COUNT 10
60 #define TIMER_NUMBER_PER_SECOND 10
62 #define INTERVALS_PER_SECOND 100
64 #define SCALING_PERIOD (1000000/TIMER_NUMBER_PER_SECOND)
65 #define SCALING_DOWN_TIME_RATIO_THRESHOLD 0.25
67 #define APP_LOOKUP_EXACT_MATCH 0
68 #define APP_LOOKUP_LPM 1
69 #define DO_RFC_1812_CHECKS
71 #ifndef APP_LOOKUP_METHOD
72 #define APP_LOOKUP_METHOD APP_LOOKUP_LPM
75 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
77 #elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
80 #error "APP_LOOKUP_METHOD set to incorrect value"
84 #define IPv6_BYTES_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"\
85 "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
86 #define IPv6_BYTES(addr) \
87 addr[0], addr[1], addr[2], addr[3], \
88 addr[4], addr[5], addr[6], addr[7], \
89 addr[8], addr[9], addr[10], addr[11],\
90 addr[12], addr[13],addr[14], addr[15]
93 #define MAX_JUMBO_PKT_LEN 9600
95 #define IPV6_ADDR_LEN 16
97 #define MEMPOOL_CACHE_SIZE 256
100 * This expression is used to calculate the number of mbufs needed depending on
101 * user input, taking into account memory for rx and tx hardware rings, cache
102 * per lcore and mtable per port per lcore. RTE_MAX is used to ensure that
103 * NB_MBUF never goes below a minimum value of 8192.
106 #define NB_MBUF RTE_MAX ( \
107 (nb_ports*nb_rx_queue*nb_rxd + \
108 nb_ports*nb_lcores*MAX_PKT_BURST + \
109 nb_ports*n_tx_queue*nb_txd + \
110 nb_lcores*MEMPOOL_CACHE_SIZE), \
113 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
117 /* Configure how many packets ahead to prefetch, when reading packets */
118 #define PREFETCH_OFFSET 3
121 * Configurable number of RX/TX ring descriptors
123 #define RTE_TEST_RX_DESC_DEFAULT 1024
124 #define RTE_TEST_TX_DESC_DEFAULT 1024
127 * These two thresholds were decided on by running the training algorithm on
128 * a 2.5GHz Xeon. These defaults can be overridden by supplying non-zero values
129 * for the med_threshold and high_threshold parameters on the command line.
131 #define EMPTY_POLL_MED_THRESHOLD 350000UL
132 #define EMPTY_POLL_HGH_THRESHOLD 580000UL
136 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
137 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
139 /* ethernet addresses of ports */
140 static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
142 /* ethernet addresses of ports */
143 static rte_spinlock_t locks[RTE_MAX_ETHPORTS];
145 /* mask of enabled ports */
146 static uint32_t enabled_port_mask = 0;
147 /* Ports set in promiscuous mode off by default. */
148 static int promiscuous_on = 0;
149 /* NUMA is enabled by default. */
150 static int numa_on = 1;
151 static bool empty_poll_stop;
152 static bool empty_poll_train;
153 volatile bool quit_signal;
154 static struct ep_params *ep_params;
155 static struct ep_policy policy;
156 static long ep_med_edpi, ep_hgh_edpi;
157 /* timer to update telemetry every 500ms */
158 static struct rte_timer telemetry_timer;
160 /* stats index returned by metrics lib */
163 struct telstats_name {
164 char name[RTE_ETH_XSTATS_NAME_SIZE];
167 /* telemetry stats to be reported */
168 const struct telstats_name telstats_strings[] = {
174 /* core busyness in percentage */
181 /* reference poll count to measure core busyness */
182 #define DEFAULT_COUNT 10000
184 * reference CYCLES to be used to
185 * measure core busyness based on poll count
187 #define MIN_CYCLES 1500000ULL
188 #define MAX_CYCLES 2500000ULL
191 #define TELEMETRY_INTERVALS_PER_SEC 2
193 static int parse_ptype; /**< Parse packet type using rx callback, and */
194 /**< disabled by default */
202 enum appmode app_mode;
204 enum freq_scale_hint_t
212 struct lcore_rx_queue {
215 enum freq_scale_hint_t freq_up_hint;
216 uint32_t zero_rx_packet_count;
218 } __rte_cache_aligned;
220 #define MAX_RX_QUEUE_PER_LCORE 16
221 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
222 #define MAX_RX_QUEUE_PER_PORT 128
224 #define MAX_RX_QUEUE_INTERRUPT_PER_PORT 16
227 struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
228 static struct lcore_params lcore_params_array_default[] = {
240 struct lcore_params *lcore_params = lcore_params_array_default;
241 uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
242 sizeof(lcore_params_array_default[0]);
244 static struct rte_eth_conf port_conf = {
246 .mq_mode = ETH_MQ_RX_RSS,
247 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
249 .offloads = DEV_RX_OFFLOAD_CHECKSUM,
254 .rss_hf = ETH_RSS_UDP,
258 .mq_mode = ETH_MQ_TX_NONE,
265 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
268 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
271 #include <rte_hash_crc.h>
272 #define DEFAULT_HASH_FUNC rte_hash_crc
274 #include <rte_jhash.h>
275 #define DEFAULT_HASH_FUNC rte_jhash
284 } __attribute__((__packed__));
287 uint8_t ip_dst[IPV6_ADDR_LEN];
288 uint8_t ip_src[IPV6_ADDR_LEN];
292 } __attribute__((__packed__));
294 struct ipv4_l3fwd_route {
295 struct ipv4_5tuple key;
299 struct ipv6_l3fwd_route {
300 struct ipv6_5tuple key;
304 static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
305 {{RTE_IPV4(100,10,0,1), RTE_IPV4(200,10,0,1), 101, 11, IPPROTO_TCP}, 0},
306 {{RTE_IPV4(100,20,0,2), RTE_IPV4(200,20,0,2), 102, 12, IPPROTO_TCP}, 1},
307 {{RTE_IPV4(100,30,0,3), RTE_IPV4(200,30,0,3), 103, 13, IPPROTO_TCP}, 2},
308 {{RTE_IPV4(100,40,0,4), RTE_IPV4(200,40,0,4), 104, 14, IPPROTO_TCP}, 3},
311 static struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {
314 {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
316 {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a},
323 typedef struct rte_hash lookup_struct_t;
324 static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];
325 static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];
327 #define L3FWD_HASH_ENTRIES 1024
329 #define IPV4_L3FWD_NUM_ROUTES \
330 (sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
332 #define IPV6_L3FWD_NUM_ROUTES \
333 (sizeof(ipv6_l3fwd_route_array) / sizeof(ipv6_l3fwd_route_array[0]))
335 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
336 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
339 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
340 struct ipv4_l3fwd_route {
346 static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
347 {RTE_IPV4(1,1,1,0), 24, 0},
348 {RTE_IPV4(2,1,1,0), 24, 1},
349 {RTE_IPV4(3,1,1,0), 24, 2},
350 {RTE_IPV4(4,1,1,0), 24, 3},
351 {RTE_IPV4(5,1,1,0), 24, 4},
352 {RTE_IPV4(6,1,1,0), 24, 5},
353 {RTE_IPV4(7,1,1,0), 24, 6},
354 {RTE_IPV4(8,1,1,0), 24, 7},
357 #define IPV4_L3FWD_NUM_ROUTES \
358 (sizeof(ipv4_l3fwd_route_array) / sizeof(ipv4_l3fwd_route_array[0]))
360 #define IPV4_L3FWD_LPM_MAX_RULES 1024
362 typedef struct rte_lpm lookup_struct_t;
363 static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];
368 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
370 uint16_t tx_port_id[RTE_MAX_ETHPORTS];
371 uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
372 struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
373 lookup_struct_t * ipv4_lookup_struct;
374 lookup_struct_t * ipv6_lookup_struct;
375 } __rte_cache_aligned;
378 /* total sleep time in ms since last frequency scaling down */
380 /* number of long sleep recently */
381 uint32_t nb_long_sleep;
382 /* freq. scaling up trend */
384 /* total packet processed recently */
385 uint64_t nb_rx_processed;
386 /* total iterations looped recently */
387 uint64_t nb_iteration_looped;
389 * Represents empty and non empty polls
390 * of rte_eth_rx_burst();
391 * ep_nep[0] holds non empty polls
392 * i.e. 0 < nb_rx <= MAX_BURST
393 * ep_nep[1] holds empty polls.
398 * Represents full and empty+partial
399 * polls of rte_eth_rx_burst();
400 * ep_nep[0] holds empty+partial polls.
401 * i.e. 0 <= nb_rx < MAX_BURST
402 * ep_nep[1] holds full polls
403 * i.e. nb_rx == MAX_BURST
407 rte_spinlock_t telemetry_lock;
408 } __rte_cache_aligned;
410 static struct lcore_conf lcore_conf[RTE_MAX_LCORE] __rte_cache_aligned;
411 static struct lcore_stats stats[RTE_MAX_LCORE] __rte_cache_aligned;
412 static struct rte_timer power_timers[RTE_MAX_LCORE];
414 static inline uint32_t power_idle_heuristic(uint32_t zero_rx_packet_count);
415 static inline enum freq_scale_hint_t power_freq_scaleup_heuristic( \
416 unsigned int lcore_id, uint16_t port_id, uint16_t queue_id);
420 * These defaults are using the max frequency index (1), a medium index (9)
421 * and a typical low frequency index (14). These can be adjusted to use
422 * different indexes using the relevant command line parameters.
424 static uint8_t freq_tlb[] = {14, 9, 1};
426 static int is_done(void)
431 /* exit signal handler */
433 signal_exit_now(int sigtype)
439 if (sigtype == SIGINT) {
440 if (app_mode == APP_MODE_EMPTY_POLL ||
441 app_mode == APP_MODE_TELEMETRY)
445 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
446 if (rte_lcore_is_enabled(lcore_id) == 0)
449 /* init power management library */
450 ret = rte_power_exit(lcore_id);
452 rte_exit(EXIT_FAILURE, "Power management "
453 "library de-initialization failed on "
454 "core%u\n", lcore_id);
457 if (app_mode != APP_MODE_EMPTY_POLL) {
458 RTE_ETH_FOREACH_DEV(portid) {
459 if ((enabled_port_mask & (1 << portid)) == 0)
462 rte_eth_dev_stop(portid);
463 rte_eth_dev_close(portid);
468 if (app_mode != APP_MODE_EMPTY_POLL)
469 rte_exit(EXIT_SUCCESS, "User forced exit\n");
472 /* Freqency scale down timer callback */
474 power_timer_cb(__attribute__((unused)) struct rte_timer *tim,
475 __attribute__((unused)) void *arg)
478 float sleep_time_ratio;
479 unsigned lcore_id = rte_lcore_id();
481 /* accumulate total execution time in us when callback is invoked */
482 sleep_time_ratio = (float)(stats[lcore_id].sleep_time) /
483 (float)SCALING_PERIOD;
485 * check whether need to scale down frequency a step if it sleep a lot.
487 if (sleep_time_ratio >= SCALING_DOWN_TIME_RATIO_THRESHOLD) {
488 if (rte_power_freq_down)
489 rte_power_freq_down(lcore_id);
491 else if ( (unsigned)(stats[lcore_id].nb_rx_processed /
492 stats[lcore_id].nb_iteration_looped) < MAX_PKT_BURST) {
494 * scale down a step if average packet per iteration less
497 if (rte_power_freq_down)
498 rte_power_freq_down(lcore_id);
502 * initialize another timer according to current frequency to ensure
503 * timer interval is relatively fixed.
505 hz = rte_get_timer_hz();
506 rte_timer_reset(&power_timers[lcore_id], hz/TIMER_NUMBER_PER_SECOND,
507 SINGLE, lcore_id, power_timer_cb, NULL);
509 stats[lcore_id].nb_rx_processed = 0;
510 stats[lcore_id].nb_iteration_looped = 0;
512 stats[lcore_id].sleep_time = 0;
515 /* Enqueue a single packet, and send burst if queue is filled */
517 send_single_packet(struct rte_mbuf *m, uint16_t port)
520 struct lcore_conf *qconf;
522 lcore_id = rte_lcore_id();
523 qconf = &lcore_conf[lcore_id];
525 rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
526 qconf->tx_buffer[port], m);
531 #ifdef DO_RFC_1812_CHECKS
533 is_valid_ipv4_pkt(struct rte_ipv4_hdr *pkt, uint32_t link_len)
535 /* From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2 */
537 * 1. The packet length reported by the Link Layer must be large
538 * enough to hold the minimum length legal IP datagram (20 bytes).
540 if (link_len < sizeof(struct rte_ipv4_hdr))
543 /* 2. The IP checksum must be correct. */
544 /* this is checked in H/W */
547 * 3. The IP version number must be 4. If the version number is not 4
548 * then the packet may be another version of IP, such as IPng or
551 if (((pkt->version_ihl) >> 4) != 4)
554 * 4. The IP header length field must be large enough to hold the
555 * minimum length legal IP datagram (20 bytes = 5 words).
557 if ((pkt->version_ihl & 0xf) < 5)
561 * 5. The IP total length field must be large enough to hold the IP
562 * datagram header, whose length is specified in the IP header length
565 if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr))
572 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
574 print_ipv4_key(struct ipv4_5tuple key)
576 printf("IP dst = %08x, IP src = %08x, port dst = %d, port src = %d, "
577 "proto = %d\n", (unsigned)key.ip_dst, (unsigned)key.ip_src,
578 key.port_dst, key.port_src, key.proto);
581 print_ipv6_key(struct ipv6_5tuple key)
583 printf( "IP dst = " IPv6_BYTES_FMT ", IP src = " IPv6_BYTES_FMT ", "
584 "port dst = %d, port src = %d, proto = %d\n",
585 IPv6_BYTES(key.ip_dst), IPv6_BYTES(key.ip_src),
586 key.port_dst, key.port_src, key.proto);
589 static inline uint16_t
590 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
591 lookup_struct_t * ipv4_l3fwd_lookup_struct)
593 struct ipv4_5tuple key;
594 struct rte_tcp_hdr *tcp;
595 struct rte_udp_hdr *udp;
598 key.ip_dst = rte_be_to_cpu_32(ipv4_hdr->dst_addr);
599 key.ip_src = rte_be_to_cpu_32(ipv4_hdr->src_addr);
600 key.proto = ipv4_hdr->next_proto_id;
602 switch (ipv4_hdr->next_proto_id) {
604 tcp = (struct rte_tcp_hdr *)((unsigned char *)ipv4_hdr +
605 sizeof(struct rte_ipv4_hdr));
606 key.port_dst = rte_be_to_cpu_16(tcp->dst_port);
607 key.port_src = rte_be_to_cpu_16(tcp->src_port);
611 udp = (struct rte_udp_hdr *)((unsigned char *)ipv4_hdr +
612 sizeof(struct rte_ipv4_hdr));
613 key.port_dst = rte_be_to_cpu_16(udp->dst_port);
614 key.port_src = rte_be_to_cpu_16(udp->src_port);
623 /* Find destination port */
624 ret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);
625 return ((ret < 0) ? portid : ipv4_l3fwd_out_if[ret]);
628 static inline uint16_t
629 get_ipv6_dst_port(struct rte_ipv6_hdr *ipv6_hdr, uint16_t portid,
630 lookup_struct_t *ipv6_l3fwd_lookup_struct)
632 struct ipv6_5tuple key;
633 struct rte_tcp_hdr *tcp;
634 struct rte_udp_hdr *udp;
637 memcpy(key.ip_dst, ipv6_hdr->dst_addr, IPV6_ADDR_LEN);
638 memcpy(key.ip_src, ipv6_hdr->src_addr, IPV6_ADDR_LEN);
640 key.proto = ipv6_hdr->proto;
642 switch (ipv6_hdr->proto) {
644 tcp = (struct rte_tcp_hdr *)((unsigned char *) ipv6_hdr +
645 sizeof(struct rte_ipv6_hdr));
646 key.port_dst = rte_be_to_cpu_16(tcp->dst_port);
647 key.port_src = rte_be_to_cpu_16(tcp->src_port);
651 udp = (struct rte_udp_hdr *)((unsigned char *) ipv6_hdr +
652 sizeof(struct rte_ipv6_hdr));
653 key.port_dst = rte_be_to_cpu_16(udp->dst_port);
654 key.port_src = rte_be_to_cpu_16(udp->src_port);
663 /* Find destination port */
664 ret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);
665 return ((ret < 0) ? portid : ipv6_l3fwd_out_if[ret]);
669 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
670 static inline uint16_t
671 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
672 lookup_struct_t *ipv4_l3fwd_lookup_struct)
676 return ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct,
677 rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0)?
683 parse_ptype_one(struct rte_mbuf *m)
685 struct rte_ether_hdr *eth_hdr;
686 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
689 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
690 ether_type = eth_hdr->ether_type;
691 if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
692 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
693 else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
694 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
696 m->packet_type = packet_type;
700 cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
701 struct rte_mbuf *pkts[], uint16_t nb_pkts,
702 uint16_t max_pkts __rte_unused,
703 void *user_param __rte_unused)
707 for (i = 0; i < nb_pkts; ++i)
708 parse_ptype_one(pkts[i]);
714 add_cb_parse_ptype(uint16_t portid, uint16_t queueid)
716 printf("Port %d: softly parse packet type info\n", portid);
717 if (rte_eth_add_rx_callback(portid, queueid, cb_parse_ptype, NULL))
720 printf("Failed to add rx callback: port=%d\n", portid);
725 l3fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
726 struct lcore_conf *qconf)
728 struct rte_ether_hdr *eth_hdr;
729 struct rte_ipv4_hdr *ipv4_hdr;
733 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
735 if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
736 /* Handle IPv4 headers.*/
738 rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
739 sizeof(struct rte_ether_hdr));
741 #ifdef DO_RFC_1812_CHECKS
742 /* Check to make sure the packet is valid (RFC1812) */
743 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
749 dst_port = get_ipv4_dst_port(ipv4_hdr, portid,
750 qconf->ipv4_lookup_struct);
751 if (dst_port >= RTE_MAX_ETHPORTS ||
752 (enabled_port_mask & 1 << dst_port) == 0)
755 /* 02:00:00:00:00:xx */
756 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
757 *((uint64_t *)d_addr_bytes) =
758 0x000000000002 + ((uint64_t)dst_port << 40);
760 #ifdef DO_RFC_1812_CHECKS
761 /* Update time to live and header checksum */
762 --(ipv4_hdr->time_to_live);
763 ++(ipv4_hdr->hdr_checksum);
767 rte_ether_addr_copy(&ports_eth_addr[dst_port],
770 send_single_packet(m, dst_port);
771 } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
772 /* Handle IPv6 headers.*/
773 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
774 struct rte_ipv6_hdr *ipv6_hdr;
777 rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
778 sizeof(struct rte_ether_hdr));
780 dst_port = get_ipv6_dst_port(ipv6_hdr, portid,
781 qconf->ipv6_lookup_struct);
783 if (dst_port >= RTE_MAX_ETHPORTS ||
784 (enabled_port_mask & 1 << dst_port) == 0)
787 /* 02:00:00:00:00:xx */
788 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
789 *((uint64_t *)d_addr_bytes) =
790 0x000000000002 + ((uint64_t)dst_port << 40);
793 rte_ether_addr_copy(&ports_eth_addr[dst_port],
796 send_single_packet(m, dst_port);
798 /* We don't currently handle IPv6 packets in LPM mode. */
806 #define MINIMUM_SLEEP_TIME 1
807 #define SUSPEND_THRESHOLD 300
809 static inline uint32_t
810 power_idle_heuristic(uint32_t zero_rx_packet_count)
812 /* If zero count is less than 100, sleep 1us */
813 if (zero_rx_packet_count < SUSPEND_THRESHOLD)
814 return MINIMUM_SLEEP_TIME;
815 /* If zero count is less than 1000, sleep 100 us which is the
816 minimum latency switching from C3/C6 to C0
819 return SUSPEND_THRESHOLD;
822 static inline enum freq_scale_hint_t
823 power_freq_scaleup_heuristic(unsigned lcore_id,
827 uint32_t rxq_count = rte_eth_rx_queue_count(port_id, queue_id);
829 * HW Rx queue size is 128 by default, Rx burst read at maximum 32 entries
832 #define FREQ_GEAR1_RX_PACKET_THRESHOLD MAX_PKT_BURST
833 #define FREQ_GEAR2_RX_PACKET_THRESHOLD (MAX_PKT_BURST*2)
834 #define FREQ_GEAR3_RX_PACKET_THRESHOLD (MAX_PKT_BURST*3)
835 #define FREQ_UP_TREND1_ACC 1
836 #define FREQ_UP_TREND2_ACC 100
837 #define FREQ_UP_THRESHOLD 10000
839 if (likely(rxq_count > FREQ_GEAR3_RX_PACKET_THRESHOLD)) {
840 stats[lcore_id].trend = 0;
842 } else if (likely(rxq_count > FREQ_GEAR2_RX_PACKET_THRESHOLD))
843 stats[lcore_id].trend += FREQ_UP_TREND2_ACC;
844 else if (likely(rxq_count > FREQ_GEAR1_RX_PACKET_THRESHOLD))
845 stats[lcore_id].trend += FREQ_UP_TREND1_ACC;
847 if (likely(stats[lcore_id].trend > FREQ_UP_THRESHOLD)) {
848 stats[lcore_id].trend = 0;
856 * force polling thread sleep until one-shot rx interrupt triggers
865 sleep_until_rx_interrupt(int num)
867 struct rte_epoll_event event[num];
873 RTE_LOG(INFO, L3FWD_POWER,
874 "lcore %u sleeps until interrupt triggers\n",
877 n = rte_epoll_wait(RTE_EPOLL_PER_THREAD, event, num, -1);
878 for (i = 0; i < n; i++) {
879 data = event[i].epdata.data;
880 port_id = ((uintptr_t)data) >> CHAR_BIT;
881 queue_id = ((uintptr_t)data) &
882 RTE_LEN2MASK(CHAR_BIT, uint8_t);
883 rte_eth_dev_rx_intr_disable(port_id, queue_id);
884 RTE_LOG(INFO, L3FWD_POWER,
885 "lcore %u is waked up from rx interrupt on"
886 " port %d queue %d\n",
887 rte_lcore_id(), port_id, queue_id);
893 static void turn_on_intr(struct lcore_conf *qconf)
896 struct lcore_rx_queue *rx_queue;
900 for (i = 0; i < qconf->n_rx_queue; ++i) {
901 rx_queue = &(qconf->rx_queue_list[i]);
902 port_id = rx_queue->port_id;
903 queue_id = rx_queue->queue_id;
905 rte_spinlock_lock(&(locks[port_id]));
906 rte_eth_dev_rx_intr_enable(port_id, queue_id);
907 rte_spinlock_unlock(&(locks[port_id]));
911 static int event_register(struct lcore_conf *qconf)
913 struct lcore_rx_queue *rx_queue;
920 for (i = 0; i < qconf->n_rx_queue; ++i) {
921 rx_queue = &(qconf->rx_queue_list[i]);
922 portid = rx_queue->port_id;
923 queueid = rx_queue->queue_id;
924 data = portid << CHAR_BIT | queueid;
926 ret = rte_eth_dev_rx_intr_ctl_q(portid, queueid,
927 RTE_EPOLL_PER_THREAD,
929 (void *)((uintptr_t)data));
936 /* main processing loop */
938 main_telemetry_loop(__attribute__((unused)) void *dummy)
940 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
941 unsigned int lcore_id;
942 uint64_t prev_tsc, diff_tsc, cur_tsc, prev_tel_tsc;
946 struct lcore_conf *qconf;
947 struct lcore_rx_queue *rx_queue;
948 uint64_t ep_nep[2] = {0}, fp_nfp[2] = {0};
952 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
953 US_PER_S * BURST_TX_DRAIN_US;
959 lcore_id = rte_lcore_id();
960 qconf = &lcore_conf[lcore_id];
962 if (qconf->n_rx_queue == 0) {
963 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
968 RTE_LOG(INFO, L3FWD_POWER, "entering main telemetry loop on lcore %u\n",
971 for (i = 0; i < qconf->n_rx_queue; i++) {
972 portid = qconf->rx_queue_list[i].port_id;
973 queueid = qconf->rx_queue_list[i].queue_id;
974 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
975 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
980 cur_tsc = rte_rdtsc();
982 * TX burst queue drain
984 diff_tsc = cur_tsc - prev_tsc;
985 if (unlikely(diff_tsc > drain_tsc)) {
986 for (i = 0; i < qconf->n_tx_port; ++i) {
987 portid = qconf->tx_port_id[i];
988 rte_eth_tx_buffer_flush(portid,
989 qconf->tx_queue_id[portid],
990 qconf->tx_buffer[portid]);
996 * Read packet from RX queues
998 for (i = 0; i < qconf->n_rx_queue; ++i) {
999 rx_queue = &(qconf->rx_queue_list[i]);
1000 portid = rx_queue->port_id;
1001 queueid = rx_queue->queue_id;
1003 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1005 ep_nep[nb_rx == 0]++;
1006 fp_nfp[nb_rx == MAX_PKT_BURST]++;
1008 if (unlikely(nb_rx == 0))
1011 /* Prefetch first packets */
1012 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1013 rte_prefetch0(rte_pktmbuf_mtod(
1014 pkts_burst[j], void *));
1017 /* Prefetch and forward already prefetched packets */
1018 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1019 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1020 j + PREFETCH_OFFSET], void *));
1021 l3fwd_simple_forward(pkts_burst[j], portid,
1025 /* Forward remaining prefetched packets */
1026 for (; j < nb_rx; j++) {
1027 l3fwd_simple_forward(pkts_burst[j], portid,
1031 if (unlikely(poll_count >= DEFAULT_COUNT)) {
1032 diff_tsc = cur_tsc - prev_tel_tsc;
1033 if (diff_tsc >= MAX_CYCLES) {
1035 } else if (diff_tsc > MIN_CYCLES &&
1036 diff_tsc < MAX_CYCLES) {
1042 prev_tel_tsc = cur_tsc;
1043 /* update stats for telemetry */
1044 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
1045 stats[lcore_id].ep_nep[0] = ep_nep[0];
1046 stats[lcore_id].ep_nep[1] = ep_nep[1];
1047 stats[lcore_id].fp_nfp[0] = fp_nfp[0];
1048 stats[lcore_id].fp_nfp[1] = fp_nfp[1];
1049 stats[lcore_id].br = br;
1050 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
1056 /* main processing loop */
1058 main_empty_poll_loop(__attribute__((unused)) void *dummy)
1060 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1061 unsigned int lcore_id;
1062 uint64_t prev_tsc, diff_tsc, cur_tsc;
1066 struct lcore_conf *qconf;
1067 struct lcore_rx_queue *rx_queue;
1069 const uint64_t drain_tsc =
1070 (rte_get_tsc_hz() + US_PER_S - 1) /
1071 US_PER_S * BURST_TX_DRAIN_US;
1075 lcore_id = rte_lcore_id();
1076 qconf = &lcore_conf[lcore_id];
1078 if (qconf->n_rx_queue == 0) {
1079 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
1084 for (i = 0; i < qconf->n_rx_queue; i++) {
1085 portid = qconf->rx_queue_list[i].port_id;
1086 queueid = qconf->rx_queue_list[i].queue_id;
1087 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1088 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1091 while (!is_done()) {
1092 stats[lcore_id].nb_iteration_looped++;
1094 cur_tsc = rte_rdtsc();
1096 * TX burst queue drain
1098 diff_tsc = cur_tsc - prev_tsc;
1099 if (unlikely(diff_tsc > drain_tsc)) {
1100 for (i = 0; i < qconf->n_tx_port; ++i) {
1101 portid = qconf->tx_port_id[i];
1102 rte_eth_tx_buffer_flush(portid,
1103 qconf->tx_queue_id[portid],
1104 qconf->tx_buffer[portid]);
1110 * Read packet from RX queues
1112 for (i = 0; i < qconf->n_rx_queue; ++i) {
1113 rx_queue = &(qconf->rx_queue_list[i]);
1114 rx_queue->idle_hint = 0;
1115 portid = rx_queue->port_id;
1116 queueid = rx_queue->queue_id;
1118 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1121 stats[lcore_id].nb_rx_processed += nb_rx;
1125 rte_power_empty_poll_stat_update(lcore_id);
1129 rte_power_poll_stat_update(lcore_id, nb_rx);
1133 /* Prefetch first packets */
1134 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1135 rte_prefetch0(rte_pktmbuf_mtod(
1136 pkts_burst[j], void *));
1139 /* Prefetch and forward already prefetched packets */
1140 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1141 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1142 j + PREFETCH_OFFSET],
1144 l3fwd_simple_forward(pkts_burst[j], portid,
1148 /* Forward remaining prefetched packets */
1149 for (; j < nb_rx; j++) {
1150 l3fwd_simple_forward(pkts_burst[j], portid,
1160 /* main processing loop */
1162 main_loop(__attribute__((unused)) void *dummy)
1164 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1166 uint64_t prev_tsc, diff_tsc, cur_tsc, tim_res_tsc, hz;
1167 uint64_t prev_tsc_power = 0, cur_tsc_power, diff_tsc_power;
1171 struct lcore_conf *qconf;
1172 struct lcore_rx_queue *rx_queue;
1173 enum freq_scale_hint_t lcore_scaleup_hint;
1174 uint32_t lcore_rx_idle_count = 0;
1175 uint32_t lcore_idle_hint = 0;
1178 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
1181 hz = rte_get_timer_hz();
1182 tim_res_tsc = hz/TIMER_NUMBER_PER_SECOND;
1184 lcore_id = rte_lcore_id();
1185 qconf = &lcore_conf[lcore_id];
1187 if (qconf->n_rx_queue == 0) {
1188 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n", lcore_id);
1192 RTE_LOG(INFO, L3FWD_POWER, "entering main loop on lcore %u\n", lcore_id);
1194 for (i = 0; i < qconf->n_rx_queue; i++) {
1195 portid = qconf->rx_queue_list[i].port_id;
1196 queueid = qconf->rx_queue_list[i].queue_id;
1197 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1198 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1201 /* add into event wait list */
1202 if (event_register(qconf) == 0)
1205 RTE_LOG(INFO, L3FWD_POWER, "RX interrupt won't enable.\n");
1208 stats[lcore_id].nb_iteration_looped++;
1210 cur_tsc = rte_rdtsc();
1211 cur_tsc_power = cur_tsc;
1214 * TX burst queue drain
1216 diff_tsc = cur_tsc - prev_tsc;
1217 if (unlikely(diff_tsc > drain_tsc)) {
1218 for (i = 0; i < qconf->n_tx_port; ++i) {
1219 portid = qconf->tx_port_id[i];
1220 rte_eth_tx_buffer_flush(portid,
1221 qconf->tx_queue_id[portid],
1222 qconf->tx_buffer[portid]);
1227 diff_tsc_power = cur_tsc_power - prev_tsc_power;
1228 if (diff_tsc_power > tim_res_tsc) {
1230 prev_tsc_power = cur_tsc_power;
1235 * Read packet from RX queues
1237 lcore_scaleup_hint = FREQ_CURRENT;
1238 lcore_rx_idle_count = 0;
1239 for (i = 0; i < qconf->n_rx_queue; ++i) {
1240 rx_queue = &(qconf->rx_queue_list[i]);
1241 rx_queue->idle_hint = 0;
1242 portid = rx_queue->port_id;
1243 queueid = rx_queue->queue_id;
1245 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1248 stats[lcore_id].nb_rx_processed += nb_rx;
1249 if (unlikely(nb_rx == 0)) {
1251 * no packet received from rx queue, try to
1252 * sleep for a while forcing CPU enter deeper
1255 rx_queue->zero_rx_packet_count++;
1257 if (rx_queue->zero_rx_packet_count <=
1258 MIN_ZERO_POLL_COUNT)
1261 rx_queue->idle_hint = power_idle_heuristic(\
1262 rx_queue->zero_rx_packet_count);
1263 lcore_rx_idle_count++;
1265 rx_queue->zero_rx_packet_count = 0;
1268 * do not scale up frequency immediately as
1269 * user to kernel space communication is costly
1270 * which might impact packet I/O for received
1273 rx_queue->freq_up_hint =
1274 power_freq_scaleup_heuristic(lcore_id,
1278 /* Prefetch first packets */
1279 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1280 rte_prefetch0(rte_pktmbuf_mtod(
1281 pkts_burst[j], void *));
1284 /* Prefetch and forward already prefetched packets */
1285 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1286 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1287 j + PREFETCH_OFFSET], void *));
1288 l3fwd_simple_forward(pkts_burst[j], portid,
1292 /* Forward remaining prefetched packets */
1293 for (; j < nb_rx; j++) {
1294 l3fwd_simple_forward(pkts_burst[j], portid,
1299 if (likely(lcore_rx_idle_count != qconf->n_rx_queue)) {
1300 for (i = 1, lcore_scaleup_hint =
1301 qconf->rx_queue_list[0].freq_up_hint;
1302 i < qconf->n_rx_queue; ++i) {
1303 rx_queue = &(qconf->rx_queue_list[i]);
1304 if (rx_queue->freq_up_hint >
1306 lcore_scaleup_hint =
1307 rx_queue->freq_up_hint;
1310 if (lcore_scaleup_hint == FREQ_HIGHEST) {
1311 if (rte_power_freq_max)
1312 rte_power_freq_max(lcore_id);
1313 } else if (lcore_scaleup_hint == FREQ_HIGHER) {
1314 if (rte_power_freq_up)
1315 rte_power_freq_up(lcore_id);
1319 * All Rx queues empty in recent consecutive polls,
1320 * sleep in a conservative manner, meaning sleep as
1323 for (i = 1, lcore_idle_hint =
1324 qconf->rx_queue_list[0].idle_hint;
1325 i < qconf->n_rx_queue; ++i) {
1326 rx_queue = &(qconf->rx_queue_list[i]);
1327 if (rx_queue->idle_hint < lcore_idle_hint)
1328 lcore_idle_hint = rx_queue->idle_hint;
1331 if (lcore_idle_hint < SUSPEND_THRESHOLD)
1333 * execute "pause" instruction to avoid context
1334 * switch which generally take hundred of
1335 * microseconds for short sleep.
1337 rte_delay_us(lcore_idle_hint);
1339 /* suspend until rx interrupt trigges */
1341 turn_on_intr(qconf);
1342 sleep_until_rx_interrupt(
1345 * start receiving packets immediately
1350 stats[lcore_id].sleep_time += lcore_idle_hint;
1356 check_lcore_params(void)
1358 uint8_t queue, lcore;
1362 for (i = 0; i < nb_lcore_params; ++i) {
1363 queue = lcore_params[i].queue_id;
1364 if (queue >= MAX_RX_QUEUE_PER_PORT) {
1365 printf("invalid queue number: %hhu\n", queue);
1368 lcore = lcore_params[i].lcore_id;
1369 if (!rte_lcore_is_enabled(lcore)) {
1370 printf("error: lcore %hhu is not enabled in lcore "
1374 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
1376 printf("warning: lcore %hhu is on socket %d with numa "
1377 "off\n", lcore, socketid);
1379 if (app_mode == APP_MODE_TELEMETRY && lcore == rte_lcore_id()) {
1380 printf("cannot enable master core %d in config for telemetry mode\n",
1389 check_port_config(void)
1394 for (i = 0; i < nb_lcore_params; ++i) {
1395 portid = lcore_params[i].port_id;
1396 if ((enabled_port_mask & (1 << portid)) == 0) {
1397 printf("port %u is not enabled in port mask\n",
1401 if (!rte_eth_dev_is_valid_port(portid)) {
1402 printf("port %u is not present on the board\n",
1411 get_port_n_rx_queues(const uint16_t port)
1416 for (i = 0; i < nb_lcore_params; ++i) {
1417 if (lcore_params[i].port_id == port &&
1418 lcore_params[i].queue_id > queue)
1419 queue = lcore_params[i].queue_id;
1421 return (uint8_t)(++queue);
1425 init_lcore_rx_queues(void)
1427 uint16_t i, nb_rx_queue;
1430 for (i = 0; i < nb_lcore_params; ++i) {
1431 lcore = lcore_params[i].lcore_id;
1432 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
1433 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
1434 printf("error: too many queues (%u) for lcore: %u\n",
1435 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
1438 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
1439 lcore_params[i].port_id;
1440 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
1441 lcore_params[i].queue_id;
1442 lcore_conf[lcore].n_rx_queue++;
1450 print_usage(const char *prgname)
1452 printf ("%s [EAL options] -- -p PORTMASK -P"
1453 " [--config (port,queue,lcore)[,(port,queue,lcore]]"
1454 " [--high-perf-cores CORELIST"
1455 " [--perf-config (port,queue,hi_perf,lcore_index)[,(port,queue,hi_perf,lcore_index]]"
1456 " [--enable-jumbo [--max-pkt-len PKTLEN]]\n"
1457 " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
1458 " -P : enable promiscuous mode\n"
1459 " --config (port,queue,lcore): rx queues configuration\n"
1460 " --high-perf-cores CORELIST: list of high performance cores\n"
1461 " --perf-config: similar as config, cores specified as indices"
1462 " for bins containing high or regular performance cores\n"
1463 " --no-numa: optional, disable numa awareness\n"
1464 " --enable-jumbo: enable jumbo frame"
1465 " which max packet len is PKTLEN in decimal (64-9600)\n"
1466 " --parse-ptype: parse packet type by software\n"
1467 " --empty-poll: enable empty poll detection"
1468 " follow (training_flag, high_threshold, med_threshold)\n"
1469 " --telemetry: enable telemetry mode, to update"
1470 " empty polls, full polls, and core busyness to telemetry\n",
1474 static int parse_max_pkt_len(const char *pktlen)
1479 /* parse decimal string */
1480 len = strtoul(pktlen, &end, 10);
1481 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
1491 parse_portmask(const char *portmask)
1496 /* parse hexadecimal string */
1497 pm = strtoul(portmask, &end, 16);
1498 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
1508 parse_config(const char *q_arg)
1511 const char *p, *p0 = q_arg;
1519 unsigned long int_fld[_NUM_FLD];
1520 char *str_fld[_NUM_FLD];
1524 nb_lcore_params = 0;
1526 while ((p = strchr(p0,'(')) != NULL) {
1528 if((p0 = strchr(p,')')) == NULL)
1532 if(size >= sizeof(s))
1535 snprintf(s, sizeof(s), "%.*s", size, p);
1536 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') !=
1539 for (i = 0; i < _NUM_FLD; i++){
1541 int_fld[i] = strtoul(str_fld[i], &end, 0);
1542 if (errno != 0 || end == str_fld[i] || int_fld[i] >
1546 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
1547 printf("exceeded max number of lcore params: %hu\n",
1551 lcore_params_array[nb_lcore_params].port_id =
1552 (uint8_t)int_fld[FLD_PORT];
1553 lcore_params_array[nb_lcore_params].queue_id =
1554 (uint8_t)int_fld[FLD_QUEUE];
1555 lcore_params_array[nb_lcore_params].lcore_id =
1556 (uint8_t)int_fld[FLD_LCORE];
1559 lcore_params = lcore_params_array;
1564 parse_ep_config(const char *q_arg)
1567 const char *p = q_arg;
1577 ep_med_edpi = EMPTY_POLL_MED_THRESHOLD;
1578 ep_hgh_edpi = EMPTY_POLL_MED_THRESHOLD;
1580 strlcpy(s, p, sizeof(s));
1582 num_arg = rte_strsplit(s, sizeof(s), str_fld, 3, ',');
1584 empty_poll_train = false;
1591 training_flag = strtoul(str_fld[0], &end, 0);
1592 med_edpi = strtoul(str_fld[1], &end, 0);
1593 hgh_edpi = strtoul(str_fld[2], &end, 0);
1595 if (training_flag == 1)
1596 empty_poll_train = true;
1599 ep_med_edpi = med_edpi;
1602 ep_hgh_edpi = hgh_edpi;
1612 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
1613 #define CMD_LINE_OPT_TELEMETRY "telemetry"
1615 /* Parse the argument given in the command line of the application */
1617 parse_args(int argc, char **argv)
1623 char *prgname = argv[0];
1624 static struct option lgopts[] = {
1625 {"config", 1, 0, 0},
1626 {"perf-config", 1, 0, 0},
1627 {"high-perf-cores", 1, 0, 0},
1628 {"no-numa", 0, 0, 0},
1629 {"enable-jumbo", 0, 0, 0},
1630 {"empty-poll", 1, 0, 0},
1631 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
1632 {CMD_LINE_OPT_TELEMETRY, 0, 0, 0},
1638 while ((opt = getopt_long(argc, argvopt, "p:l:m:h:P",
1639 lgopts, &option_index)) != EOF) {
1644 enabled_port_mask = parse_portmask(optarg);
1645 if (enabled_port_mask == 0) {
1646 printf("invalid portmask\n");
1647 print_usage(prgname);
1652 printf("Promiscuous mode selected\n");
1656 limit = parse_max_pkt_len(optarg);
1657 freq_tlb[LOW] = limit;
1660 limit = parse_max_pkt_len(optarg);
1661 freq_tlb[MED] = limit;
1664 limit = parse_max_pkt_len(optarg);
1665 freq_tlb[HGH] = limit;
1669 if (!strncmp(lgopts[option_index].name, "config", 6)) {
1670 ret = parse_config(optarg);
1672 printf("invalid config\n");
1673 print_usage(prgname);
1678 if (!strncmp(lgopts[option_index].name,
1679 "perf-config", 11)) {
1680 ret = parse_perf_config(optarg);
1682 printf("invalid perf-config\n");
1683 print_usage(prgname);
1688 if (!strncmp(lgopts[option_index].name,
1689 "high-perf-cores", 15)) {
1690 ret = parse_perf_core_list(optarg);
1692 printf("invalid high-perf-cores\n");
1693 print_usage(prgname);
1698 if (!strncmp(lgopts[option_index].name,
1700 printf("numa is disabled \n");
1704 if (!strncmp(lgopts[option_index].name,
1705 "empty-poll", 10)) {
1706 if (app_mode == APP_MODE_TELEMETRY) {
1707 printf(" empty-poll cannot be enabled as telemetry mode is enabled\n");
1710 app_mode = APP_MODE_EMPTY_POLL;
1711 ret = parse_ep_config(optarg);
1714 printf("invalid empty poll config\n");
1715 print_usage(prgname);
1718 printf("empty-poll is enabled\n");
1721 if (!strncmp(lgopts[option_index].name,
1722 CMD_LINE_OPT_TELEMETRY,
1723 sizeof(CMD_LINE_OPT_TELEMETRY))) {
1724 if (app_mode == APP_MODE_EMPTY_POLL) {
1725 printf("telemetry mode cannot be enabled as empty poll mode is enabled\n");
1728 app_mode = APP_MODE_TELEMETRY;
1729 printf("telemetry mode is enabled\n");
1732 if (!strncmp(lgopts[option_index].name,
1733 "enable-jumbo", 12)) {
1734 struct option lenopts =
1735 {"max-pkt-len", required_argument, \
1738 printf("jumbo frame is enabled \n");
1739 port_conf.rxmode.offloads |=
1740 DEV_RX_OFFLOAD_JUMBO_FRAME;
1741 port_conf.txmode.offloads |=
1742 DEV_TX_OFFLOAD_MULTI_SEGS;
1745 * if no max-pkt-len set, use the default value
1748 if (0 == getopt_long(argc, argvopt, "",
1749 &lenopts, &option_index)) {
1750 ret = parse_max_pkt_len(optarg);
1752 (ret > MAX_JUMBO_PKT_LEN)){
1753 printf("invalid packet "
1755 print_usage(prgname);
1758 port_conf.rxmode.max_rx_pkt_len = ret;
1760 printf("set jumbo frame "
1761 "max packet length to %u\n",
1762 (unsigned int)port_conf.rxmode.max_rx_pkt_len);
1765 if (!strncmp(lgopts[option_index].name,
1766 CMD_LINE_OPT_PARSE_PTYPE,
1767 sizeof(CMD_LINE_OPT_PARSE_PTYPE))) {
1768 printf("soft parse-ptype is enabled\n");
1775 print_usage(prgname);
1781 argv[optind-1] = prgname;
1784 optind = 1; /* reset getopt lib */
1789 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
1791 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1792 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
1793 printf("%s%s", name, buf);
1796 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1798 setup_hash(int socketid)
1800 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
1802 .entries = L3FWD_HASH_ENTRIES,
1803 .key_len = sizeof(struct ipv4_5tuple),
1804 .hash_func = DEFAULT_HASH_FUNC,
1805 .hash_func_init_val = 0,
1808 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
1810 .entries = L3FWD_HASH_ENTRIES,
1811 .key_len = sizeof(struct ipv6_5tuple),
1812 .hash_func = DEFAULT_HASH_FUNC,
1813 .hash_func_init_val = 0,
1820 /* create ipv4 hash */
1821 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
1822 ipv4_l3fwd_hash_params.name = s;
1823 ipv4_l3fwd_hash_params.socket_id = socketid;
1824 ipv4_l3fwd_lookup_struct[socketid] =
1825 rte_hash_create(&ipv4_l3fwd_hash_params);
1826 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1827 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1828 "socket %d\n", socketid);
1830 /* create ipv6 hash */
1831 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
1832 ipv6_l3fwd_hash_params.name = s;
1833 ipv6_l3fwd_hash_params.socket_id = socketid;
1834 ipv6_l3fwd_lookup_struct[socketid] =
1835 rte_hash_create(&ipv6_l3fwd_hash_params);
1836 if (ipv6_l3fwd_lookup_struct[socketid] == NULL)
1837 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1838 "socket %d\n", socketid);
1841 /* populate the ipv4 hash */
1842 for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
1843 ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
1844 (void *) &ipv4_l3fwd_route_array[i].key);
1846 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1847 "l3fwd hash on socket %d\n", i, socketid);
1849 ipv4_l3fwd_out_if[ret] = ipv4_l3fwd_route_array[i].if_out;
1850 printf("Hash: Adding key\n");
1851 print_ipv4_key(ipv4_l3fwd_route_array[i].key);
1854 /* populate the ipv6 hash */
1855 for (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {
1856 ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
1857 (void *) &ipv6_l3fwd_route_array[i].key);
1859 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1860 "l3fwd hash on socket %d\n", i, socketid);
1862 ipv6_l3fwd_out_if[ret] = ipv6_l3fwd_route_array[i].if_out;
1863 printf("Hash: Adding key\n");
1864 print_ipv6_key(ipv6_l3fwd_route_array[i].key);
1869 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1871 setup_lpm(int socketid)
1877 /* create the LPM table */
1878 struct rte_lpm_config lpm_ipv4_config;
1880 lpm_ipv4_config.max_rules = IPV4_L3FWD_LPM_MAX_RULES;
1881 lpm_ipv4_config.number_tbl8s = 256;
1882 lpm_ipv4_config.flags = 0;
1884 snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
1885 ipv4_l3fwd_lookup_struct[socketid] =
1886 rte_lpm_create(s, socketid, &lpm_ipv4_config);
1887 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1888 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
1889 " on socket %d\n", socketid);
1891 /* populate the LPM table */
1892 for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
1893 ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
1894 ipv4_l3fwd_route_array[i].ip,
1895 ipv4_l3fwd_route_array[i].depth,
1896 ipv4_l3fwd_route_array[i].if_out);
1899 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the "
1900 "l3fwd LPM table on socket %d\n",
1904 printf("LPM: Adding route 0x%08x / %d (%d)\n",
1905 (unsigned)ipv4_l3fwd_route_array[i].ip,
1906 ipv4_l3fwd_route_array[i].depth,
1907 ipv4_l3fwd_route_array[i].if_out);
1913 init_mem(unsigned nb_mbuf)
1915 struct lcore_conf *qconf;
1920 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1921 if (rte_lcore_is_enabled(lcore_id) == 0)
1925 socketid = rte_lcore_to_socket_id(lcore_id);
1929 if (socketid >= NB_SOCKETS) {
1930 rte_exit(EXIT_FAILURE, "Socket %d of lcore %u is "
1931 "out of range %d\n", socketid,
1932 lcore_id, NB_SOCKETS);
1934 if (pktmbuf_pool[socketid] == NULL) {
1935 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
1936 pktmbuf_pool[socketid] =
1937 rte_pktmbuf_pool_create(s, nb_mbuf,
1938 MEMPOOL_CACHE_SIZE, 0,
1939 RTE_MBUF_DEFAULT_BUF_SIZE,
1941 if (pktmbuf_pool[socketid] == NULL)
1942 rte_exit(EXIT_FAILURE,
1943 "Cannot init mbuf pool on socket %d\n",
1946 printf("Allocated mbuf pool on socket %d\n",
1949 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1950 setup_lpm(socketid);
1952 setup_hash(socketid);
1955 qconf = &lcore_conf[lcore_id];
1956 qconf->ipv4_lookup_struct = ipv4_l3fwd_lookup_struct[socketid];
1957 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1958 qconf->ipv6_lookup_struct = ipv6_l3fwd_lookup_struct[socketid];
1964 /* Check the link status of all ports in up to 9s, and print them finally */
1966 check_all_ports_link_status(uint32_t port_mask)
1968 #define CHECK_INTERVAL 100 /* 100ms */
1969 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1970 uint8_t count, all_ports_up, print_flag = 0;
1972 struct rte_eth_link link;
1974 printf("\nChecking link status");
1976 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1978 RTE_ETH_FOREACH_DEV(portid) {
1979 if ((port_mask & (1 << portid)) == 0)
1981 memset(&link, 0, sizeof(link));
1982 rte_eth_link_get_nowait(portid, &link);
1983 /* print link status if flag set */
1984 if (print_flag == 1) {
1985 if (link.link_status)
1986 printf("Port %d Link Up - speed %u "
1987 "Mbps - %s\n", (uint8_t)portid,
1988 (unsigned)link.link_speed,
1989 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1990 ("full-duplex") : ("half-duplex\n"));
1992 printf("Port %d Link Down\n",
1996 /* clear all_ports_up flag if any link down */
1997 if (link.link_status == ETH_LINK_DOWN) {
2002 /* after finally printing all link status, get out */
2003 if (print_flag == 1)
2006 if (all_ports_up == 0) {
2009 rte_delay_ms(CHECK_INTERVAL);
2012 /* set the print_flag if all ports up or timeout */
2013 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
2020 static int check_ptype(uint16_t portid)
2023 int ptype_l3_ipv4 = 0;
2024 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2025 int ptype_l3_ipv6 = 0;
2027 uint32_t ptype_mask = RTE_PTYPE_L3_MASK;
2029 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
2033 uint32_t ptypes[ret];
2035 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
2036 for (i = 0; i < ret; ++i) {
2037 if (ptypes[i] & RTE_PTYPE_L3_IPV4)
2039 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2040 if (ptypes[i] & RTE_PTYPE_L3_IPV6)
2045 if (ptype_l3_ipv4 == 0)
2046 printf("port %d cannot parse RTE_PTYPE_L3_IPV4\n", portid);
2048 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2049 if (ptype_l3_ipv6 == 0)
2050 printf("port %d cannot parse RTE_PTYPE_L3_IPV6\n", portid);
2053 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
2055 #else /* APP_LOOKUP_EXACT_MATCH */
2056 if (ptype_l3_ipv4 && ptype_l3_ipv6)
2065 init_power_library(void)
2067 int ret = 0, lcore_id;
2068 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2069 if (rte_lcore_is_enabled(lcore_id)) {
2070 /* init power management library */
2071 ret = rte_power_init(lcore_id);
2074 "Library initialization failed on core %u\n",
2081 update_telemetry(__attribute__((unused)) struct rte_timer *tim,
2082 __attribute__((unused)) void *arg)
2084 unsigned int lcore_id = rte_lcore_id();
2085 struct lcore_conf *qconf;
2086 uint64_t app_eps = 0, app_fps = 0, app_br = 0;
2087 uint64_t values[3] = {0};
2091 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2092 qconf = &lcore_conf[lcore_id];
2093 if (qconf->n_rx_queue == 0)
2096 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
2097 app_eps += stats[lcore_id].ep_nep[1];
2098 app_fps += stats[lcore_id].fp_nfp[1];
2099 app_br += stats[lcore_id].br;
2100 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
2104 values[0] = app_eps/count;
2105 values[1] = app_fps/count;
2106 values[2] = app_br/count;
2113 ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
2114 values, RTE_DIM(values));
2116 RTE_LOG(WARNING, POWER, "failed to update metrcis\n");
2119 telemetry_setup_timer(void)
2121 int lcore_id = rte_lcore_id();
2122 uint64_t hz = rte_get_timer_hz();
2125 ticks = hz / TELEMETRY_INTERVALS_PER_SEC;
2126 rte_timer_reset_sync(&telemetry_timer,
2134 empty_poll_setup_timer(void)
2136 int lcore_id = rte_lcore_id();
2137 uint64_t hz = rte_get_timer_hz();
2139 struct ep_params *ep_ptr = ep_params;
2141 ep_ptr->interval_ticks = hz / INTERVALS_PER_SECOND;
2143 rte_timer_reset_sync(&ep_ptr->timer0,
2144 ep_ptr->interval_ticks,
2147 rte_empty_poll_detection,
2152 launch_timer(unsigned int lcore_id)
2154 int64_t prev_tsc = 0, cur_tsc, diff_tsc, cycles_10ms;
2156 RTE_SET_USED(lcore_id);
2159 if (rte_get_master_lcore() != lcore_id) {
2160 rte_panic("timer on lcore:%d which is not master core:%d\n",
2162 rte_get_master_lcore());
2165 RTE_LOG(INFO, POWER, "Bring up the Timer\n");
2167 if (app_mode == APP_MODE_EMPTY_POLL)
2168 empty_poll_setup_timer();
2170 telemetry_setup_timer();
2172 cycles_10ms = rte_get_timer_hz() / 100;
2174 while (!is_done()) {
2175 cur_tsc = rte_rdtsc();
2176 diff_tsc = cur_tsc - prev_tsc;
2177 if (diff_tsc > cycles_10ms) {
2180 cycles_10ms = rte_get_timer_hz() / 100;
2184 RTE_LOG(INFO, POWER, "Timer_subsystem is done\n");
2191 main(int argc, char **argv)
2193 struct lcore_conf *qconf;
2194 struct rte_eth_dev_info dev_info;
2195 struct rte_eth_txconf *txconf;
2201 uint32_t n_tx_queue, nb_lcores;
2202 uint32_t dev_rxq_num, dev_txq_num;
2203 uint8_t nb_rx_queue, queue, socketid;
2205 uint8_t num_telstats = RTE_DIM(telstats_strings);
2206 const char *ptr_strings[num_telstats];
2208 /* catch SIGINT and restore cpufreq governor to ondemand */
2209 signal(SIGINT, signal_exit_now);
2212 ret = rte_eal_init(argc, argv);
2214 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
2218 /* init RTE timer library to be used late */
2219 rte_timer_subsystem_init();
2221 /* parse application arguments (after the EAL ones) */
2222 ret = parse_args(argc, argv);
2224 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
2226 if (init_power_library())
2227 RTE_LOG(ERR, L3FWD_POWER, "init_power_library failed\n");
2229 if (update_lcore_params() < 0)
2230 rte_exit(EXIT_FAILURE, "update_lcore_params failed\n");
2232 if (check_lcore_params() < 0)
2233 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
2235 ret = init_lcore_rx_queues();
2237 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
2239 nb_ports = rte_eth_dev_count_avail();
2241 if (check_port_config() < 0)
2242 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
2244 nb_lcores = rte_lcore_count();
2246 /* initialize all ports */
2247 RTE_ETH_FOREACH_DEV(portid) {
2248 struct rte_eth_conf local_port_conf = port_conf;
2250 /* skip ports that are not enabled */
2251 if ((enabled_port_mask & (1 << portid)) == 0) {
2252 printf("\nSkipping disabled port %d\n", portid);
2257 printf("Initializing port %d ... ", portid );
2260 rte_eth_dev_info_get(portid, &dev_info);
2261 dev_rxq_num = dev_info.max_rx_queues;
2262 dev_txq_num = dev_info.max_tx_queues;
2264 nb_rx_queue = get_port_n_rx_queues(portid);
2265 if (nb_rx_queue > dev_rxq_num)
2266 rte_exit(EXIT_FAILURE,
2267 "Cannot configure not existed rxq: "
2268 "port=%d\n", portid);
2270 n_tx_queue = nb_lcores;
2271 if (n_tx_queue > dev_txq_num)
2272 n_tx_queue = dev_txq_num;
2273 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
2274 nb_rx_queue, (unsigned)n_tx_queue );
2275 /* If number of Rx queue is 0, no need to enable Rx interrupt */
2276 if (nb_rx_queue == 0)
2277 local_port_conf.intr_conf.rxq = 0;
2278 rte_eth_dev_info_get(portid, &dev_info);
2279 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
2280 local_port_conf.txmode.offloads |=
2281 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
2283 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
2284 dev_info.flow_type_rss_offloads;
2285 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
2286 port_conf.rx_adv_conf.rss_conf.rss_hf) {
2287 printf("Port %u modified RSS hash function based on hardware support,"
2288 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2290 port_conf.rx_adv_conf.rss_conf.rss_hf,
2291 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
2294 ret = rte_eth_dev_configure(portid, nb_rx_queue,
2295 (uint16_t)n_tx_queue, &local_port_conf);
2297 rte_exit(EXIT_FAILURE, "Cannot configure device: "
2298 "err=%d, port=%d\n", ret, portid);
2300 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
2303 rte_exit(EXIT_FAILURE,
2304 "Cannot adjust number of descriptors: err=%d, port=%d\n",
2307 rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
2308 print_ethaddr(" Address:", &ports_eth_addr[portid]);
2312 ret = init_mem(NB_MBUF);
2314 rte_exit(EXIT_FAILURE, "init_mem failed\n");
2316 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2317 if (rte_lcore_is_enabled(lcore_id) == 0)
2320 /* Initialize TX buffers */
2321 qconf = &lcore_conf[lcore_id];
2322 qconf->tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
2323 RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
2324 rte_eth_dev_socket_id(portid));
2325 if (qconf->tx_buffer[portid] == NULL)
2326 rte_exit(EXIT_FAILURE, "Can't allocate tx buffer for port %u\n",
2329 rte_eth_tx_buffer_init(qconf->tx_buffer[portid], MAX_PKT_BURST);
2332 /* init one TX queue per couple (lcore,port) */
2334 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2335 if (rte_lcore_is_enabled(lcore_id) == 0)
2338 if (queueid >= dev_txq_num)
2343 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2347 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
2350 txconf = &dev_info.default_txconf;
2351 txconf->offloads = local_port_conf.txmode.offloads;
2352 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
2355 rte_exit(EXIT_FAILURE,
2356 "rte_eth_tx_queue_setup: err=%d, "
2357 "port=%d\n", ret, portid);
2359 qconf = &lcore_conf[lcore_id];
2360 qconf->tx_queue_id[portid] = queueid;
2363 qconf->tx_port_id[qconf->n_tx_port] = portid;
2369 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2370 if (rte_lcore_is_enabled(lcore_id) == 0)
2373 if (app_mode == APP_MODE_LEGACY) {
2374 /* init timer structures for each enabled lcore */
2375 rte_timer_init(&power_timers[lcore_id]);
2376 hz = rte_get_timer_hz();
2377 rte_timer_reset(&power_timers[lcore_id],
2378 hz/TIMER_NUMBER_PER_SECOND,
2380 power_timer_cb, NULL);
2382 qconf = &lcore_conf[lcore_id];
2383 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
2385 /* init RX queues */
2386 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
2387 struct rte_eth_rxconf rxq_conf;
2388 struct rte_eth_dev *dev;
2389 struct rte_eth_conf *conf;
2391 portid = qconf->rx_queue_list[queue].port_id;
2392 queueid = qconf->rx_queue_list[queue].queue_id;
2393 dev = &rte_eth_devices[portid];
2394 conf = &dev->data->dev_conf;
2398 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2402 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
2405 rte_eth_dev_info_get(portid, &dev_info);
2406 rxq_conf = dev_info.default_rxconf;
2407 rxq_conf.offloads = conf->rxmode.offloads;
2408 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
2409 socketid, &rxq_conf,
2410 pktmbuf_pool[socketid]);
2412 rte_exit(EXIT_FAILURE,
2413 "rte_eth_rx_queue_setup: err=%d, "
2414 "port=%d\n", ret, portid);
2417 if (add_cb_parse_ptype(portid, queueid) < 0)
2418 rte_exit(EXIT_FAILURE,
2419 "Fail to add ptype cb\n");
2420 } else if (!check_ptype(portid))
2421 rte_exit(EXIT_FAILURE,
2422 "PMD can not provide needed ptypes\n");
2429 RTE_ETH_FOREACH_DEV(portid) {
2430 if ((enabled_port_mask & (1 << portid)) == 0) {
2434 ret = rte_eth_dev_start(portid);
2436 rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, "
2437 "port=%d\n", ret, portid);
2439 * If enabled, put device in promiscuous mode.
2440 * This allows IO forwarding mode to forward packets
2441 * to itself through 2 cross-connected ports of the
2445 rte_eth_promiscuous_enable(portid);
2446 /* initialize spinlock for each port */
2447 rte_spinlock_init(&(locks[portid]));
2450 check_all_ports_link_status(enabled_port_mask);
2452 if (app_mode == APP_MODE_EMPTY_POLL) {
2454 if (empty_poll_train) {
2455 policy.state = TRAINING;
2457 policy.state = MED_NORMAL;
2458 policy.med_base_edpi = ep_med_edpi;
2459 policy.hgh_base_edpi = ep_hgh_edpi;
2462 ret = rte_power_empty_poll_stat_init(&ep_params,
2466 rte_exit(EXIT_FAILURE, "empty poll init failed");
2470 /* launch per-lcore init on every lcore */
2471 if (app_mode == APP_MODE_LEGACY) {
2472 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
2473 } else if (app_mode == APP_MODE_EMPTY_POLL) {
2474 empty_poll_stop = false;
2475 rte_eal_mp_remote_launch(main_empty_poll_loop, NULL,
2480 /* Init metrics library */
2481 rte_metrics_init(rte_socket_id());
2482 /** Register stats with metrics library */
2483 for (i = 0; i < num_telstats; i++)
2484 ptr_strings[i] = telstats_strings[i].name;
2486 ret = rte_metrics_reg_names(ptr_strings, num_telstats);
2488 telstats_index = ret;
2490 rte_exit(EXIT_FAILURE, "failed to register metrics names");
2492 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2493 rte_spinlock_init(&stats[lcore_id].telemetry_lock);
2495 rte_timer_init(&telemetry_timer);
2496 rte_eal_mp_remote_launch(main_telemetry_loop, NULL,
2500 if (app_mode == APP_MODE_EMPTY_POLL || app_mode == APP_MODE_TELEMETRY)
2501 launch_timer(rte_lcore_id());
2503 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2504 if (rte_eal_wait_lcore(lcore_id) < 0)
2508 if (app_mode == APP_MODE_EMPTY_POLL)
2509 rte_power_empty_poll_stat_free();