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>
49 #include <rte_telemetry.h>
51 #include "perf_core.h"
54 #define RTE_LOGTYPE_L3FWD_POWER RTE_LOGTYPE_USER1
56 #define MAX_PKT_BURST 32
58 #define MIN_ZERO_POLL_COUNT 10
61 #define TIMER_NUMBER_PER_SECOND 10
63 #define INTERVALS_PER_SECOND 100
65 #define SCALING_PERIOD (1000000/TIMER_NUMBER_PER_SECOND)
66 #define SCALING_DOWN_TIME_RATIO_THRESHOLD 0.25
68 #define APP_LOOKUP_EXACT_MATCH 0
69 #define APP_LOOKUP_LPM 1
70 #define DO_RFC_1812_CHECKS
72 #ifndef APP_LOOKUP_METHOD
73 #define APP_LOOKUP_METHOD APP_LOOKUP_LPM
76 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
78 #elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
81 #error "APP_LOOKUP_METHOD set to incorrect value"
85 #define IPv6_BYTES_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"\
86 "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
87 #define IPv6_BYTES(addr) \
88 addr[0], addr[1], addr[2], addr[3], \
89 addr[4], addr[5], addr[6], addr[7], \
90 addr[8], addr[9], addr[10], addr[11],\
91 addr[12], addr[13],addr[14], addr[15]
94 #define MAX_JUMBO_PKT_LEN 9600
96 #define IPV6_ADDR_LEN 16
98 #define MEMPOOL_CACHE_SIZE 256
101 * This expression is used to calculate the number of mbufs needed depending on
102 * user input, taking into account memory for rx and tx hardware rings, cache
103 * per lcore and mtable per port per lcore. RTE_MAX is used to ensure that
104 * NB_MBUF never goes below a minimum value of 8192.
107 #define NB_MBUF RTE_MAX ( \
108 (nb_ports*nb_rx_queue*nb_rxd + \
109 nb_ports*nb_lcores*MAX_PKT_BURST + \
110 nb_ports*n_tx_queue*nb_txd + \
111 nb_lcores*MEMPOOL_CACHE_SIZE), \
114 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
118 /* Configure how many packets ahead to prefetch, when reading packets */
119 #define PREFETCH_OFFSET 3
122 * Configurable number of RX/TX ring descriptors
124 #define RTE_TEST_RX_DESC_DEFAULT 1024
125 #define RTE_TEST_TX_DESC_DEFAULT 1024
128 * These two thresholds were decided on by running the training algorithm on
129 * a 2.5GHz Xeon. These defaults can be overridden by supplying non-zero values
130 * for the med_threshold and high_threshold parameters on the command line.
132 #define EMPTY_POLL_MED_THRESHOLD 350000UL
133 #define EMPTY_POLL_HGH_THRESHOLD 580000UL
135 #define NUM_TELSTATS RTE_DIM(telstats_strings)
137 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
138 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
140 /* ethernet addresses of ports */
141 static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
143 /* ethernet addresses of ports */
144 static rte_spinlock_t locks[RTE_MAX_ETHPORTS];
146 /* mask of enabled ports */
147 static uint32_t enabled_port_mask = 0;
148 /* Ports set in promiscuous mode off by default. */
149 static int promiscuous_on = 0;
150 /* NUMA is enabled by default. */
151 static int numa_on = 1;
152 static bool empty_poll_stop;
153 static bool empty_poll_train;
154 volatile bool quit_signal;
155 static struct ep_params *ep_params;
156 static struct ep_policy policy;
157 static long ep_med_edpi, ep_hgh_edpi;
158 /* timer to update telemetry every 500ms */
159 static struct rte_timer telemetry_timer;
161 /* stats index returned by metrics lib */
164 struct telstats_name {
165 char name[RTE_ETH_XSTATS_NAME_SIZE];
168 /* telemetry stats to be reported */
169 const struct telstats_name telstats_strings[] = {
175 /* core busyness in percentage */
182 /* reference poll count to measure core busyness */
183 #define DEFAULT_COUNT 10000
185 * reference CYCLES to be used to
186 * measure core busyness based on poll count
188 #define MIN_CYCLES 1500000ULL
189 #define MAX_CYCLES 22000000ULL
192 #define TELEMETRY_INTERVALS_PER_SEC 2
194 static int parse_ptype; /**< Parse packet type using rx callback, and */
195 /**< disabled by default */
203 enum appmode app_mode;
205 enum freq_scale_hint_t
213 struct lcore_rx_queue {
216 enum freq_scale_hint_t freq_up_hint;
217 uint32_t zero_rx_packet_count;
219 } __rte_cache_aligned;
221 #define MAX_RX_QUEUE_PER_LCORE 16
222 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
223 #define MAX_RX_QUEUE_PER_PORT 128
225 #define MAX_RX_QUEUE_INTERRUPT_PER_PORT 16
228 struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
229 static struct lcore_params lcore_params_array_default[] = {
241 struct lcore_params *lcore_params = lcore_params_array_default;
242 uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);
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
287 uint8_t ip_dst[IPV6_ADDR_LEN];
288 uint8_t ip_src[IPV6_ADDR_LEN];
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 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
330 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
333 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
334 struct ipv4_l3fwd_route {
340 static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
341 {RTE_IPV4(1,1,1,0), 24, 0},
342 {RTE_IPV4(2,1,1,0), 24, 1},
343 {RTE_IPV4(3,1,1,0), 24, 2},
344 {RTE_IPV4(4,1,1,0), 24, 3},
345 {RTE_IPV4(5,1,1,0), 24, 4},
346 {RTE_IPV4(6,1,1,0), 24, 5},
347 {RTE_IPV4(7,1,1,0), 24, 6},
348 {RTE_IPV4(8,1,1,0), 24, 7},
351 #define IPV4_L3FWD_LPM_MAX_RULES 1024
353 typedef struct rte_lpm lookup_struct_t;
354 static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];
359 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
361 uint16_t tx_port_id[RTE_MAX_ETHPORTS];
362 uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
363 struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
364 lookup_struct_t * ipv4_lookup_struct;
365 lookup_struct_t * ipv6_lookup_struct;
366 } __rte_cache_aligned;
369 /* total sleep time in ms since last frequency scaling down */
371 /* number of long sleep recently */
372 uint32_t nb_long_sleep;
373 /* freq. scaling up trend */
375 /* total packet processed recently */
376 uint64_t nb_rx_processed;
377 /* total iterations looped recently */
378 uint64_t nb_iteration_looped;
380 * Represents empty and non empty polls
381 * of rte_eth_rx_burst();
382 * ep_nep[0] holds non empty polls
383 * i.e. 0 < nb_rx <= MAX_BURST
384 * ep_nep[1] holds empty polls.
389 * Represents full and empty+partial
390 * polls of rte_eth_rx_burst();
391 * ep_nep[0] holds empty+partial polls.
392 * i.e. 0 <= nb_rx < MAX_BURST
393 * ep_nep[1] holds full polls
394 * i.e. nb_rx == MAX_BURST
398 rte_spinlock_t telemetry_lock;
399 } __rte_cache_aligned;
401 static struct lcore_conf lcore_conf[RTE_MAX_LCORE] __rte_cache_aligned;
402 static struct lcore_stats stats[RTE_MAX_LCORE] __rte_cache_aligned;
403 static struct rte_timer power_timers[RTE_MAX_LCORE];
405 static inline uint32_t power_idle_heuristic(uint32_t zero_rx_packet_count);
406 static inline enum freq_scale_hint_t power_freq_scaleup_heuristic( \
407 unsigned int lcore_id, uint16_t port_id, uint16_t queue_id);
411 * These defaults are using the max frequency index (1), a medium index (9)
412 * and a typical low frequency index (14). These can be adjusted to use
413 * different indexes using the relevant command line parameters.
415 static uint8_t freq_tlb[] = {14, 9, 1};
417 static int is_done(void)
422 /* exit signal handler */
424 signal_exit_now(int sigtype)
427 if (sigtype == SIGINT)
432 /* Freqency scale down timer callback */
434 power_timer_cb(__rte_unused struct rte_timer *tim,
435 __rte_unused void *arg)
438 float sleep_time_ratio;
439 unsigned lcore_id = rte_lcore_id();
441 /* accumulate total execution time in us when callback is invoked */
442 sleep_time_ratio = (float)(stats[lcore_id].sleep_time) /
443 (float)SCALING_PERIOD;
445 * check whether need to scale down frequency a step if it sleep a lot.
447 if (sleep_time_ratio >= SCALING_DOWN_TIME_RATIO_THRESHOLD) {
448 if (rte_power_freq_down)
449 rte_power_freq_down(lcore_id);
451 else if ( (unsigned)(stats[lcore_id].nb_rx_processed /
452 stats[lcore_id].nb_iteration_looped) < MAX_PKT_BURST) {
454 * scale down a step if average packet per iteration less
457 if (rte_power_freq_down)
458 rte_power_freq_down(lcore_id);
462 * initialize another timer according to current frequency to ensure
463 * timer interval is relatively fixed.
465 hz = rte_get_timer_hz();
466 rte_timer_reset(&power_timers[lcore_id], hz/TIMER_NUMBER_PER_SECOND,
467 SINGLE, lcore_id, power_timer_cb, NULL);
469 stats[lcore_id].nb_rx_processed = 0;
470 stats[lcore_id].nb_iteration_looped = 0;
472 stats[lcore_id].sleep_time = 0;
475 /* Enqueue a single packet, and send burst if queue is filled */
477 send_single_packet(struct rte_mbuf *m, uint16_t port)
480 struct lcore_conf *qconf;
482 lcore_id = rte_lcore_id();
483 qconf = &lcore_conf[lcore_id];
485 rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
486 qconf->tx_buffer[port], m);
491 #ifdef DO_RFC_1812_CHECKS
493 is_valid_ipv4_pkt(struct rte_ipv4_hdr *pkt, uint32_t link_len)
495 /* From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2 */
497 * 1. The packet length reported by the Link Layer must be large
498 * enough to hold the minimum length legal IP datagram (20 bytes).
500 if (link_len < sizeof(struct rte_ipv4_hdr))
503 /* 2. The IP checksum must be correct. */
504 /* this is checked in H/W */
507 * 3. The IP version number must be 4. If the version number is not 4
508 * then the packet may be another version of IP, such as IPng or
511 if (((pkt->version_ihl) >> 4) != 4)
514 * 4. The IP header length field must be large enough to hold the
515 * minimum length legal IP datagram (20 bytes = 5 words).
517 if ((pkt->version_ihl & 0xf) < 5)
521 * 5. The IP total length field must be large enough to hold the IP
522 * datagram header, whose length is specified in the IP header length
525 if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr))
532 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
534 print_ipv4_key(struct ipv4_5tuple key)
536 printf("IP dst = %08x, IP src = %08x, port dst = %d, port src = %d, "
537 "proto = %d\n", (unsigned)key.ip_dst, (unsigned)key.ip_src,
538 key.port_dst, key.port_src, key.proto);
541 print_ipv6_key(struct ipv6_5tuple key)
543 printf( "IP dst = " IPv6_BYTES_FMT ", IP src = " IPv6_BYTES_FMT ", "
544 "port dst = %d, port src = %d, proto = %d\n",
545 IPv6_BYTES(key.ip_dst), IPv6_BYTES(key.ip_src),
546 key.port_dst, key.port_src, key.proto);
549 static inline uint16_t
550 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
551 lookup_struct_t * ipv4_l3fwd_lookup_struct)
553 struct ipv4_5tuple key;
554 struct rte_tcp_hdr *tcp;
555 struct rte_udp_hdr *udp;
558 key.ip_dst = rte_be_to_cpu_32(ipv4_hdr->dst_addr);
559 key.ip_src = rte_be_to_cpu_32(ipv4_hdr->src_addr);
560 key.proto = ipv4_hdr->next_proto_id;
562 switch (ipv4_hdr->next_proto_id) {
564 tcp = (struct rte_tcp_hdr *)((unsigned char *)ipv4_hdr +
565 sizeof(struct rte_ipv4_hdr));
566 key.port_dst = rte_be_to_cpu_16(tcp->dst_port);
567 key.port_src = rte_be_to_cpu_16(tcp->src_port);
571 udp = (struct rte_udp_hdr *)((unsigned char *)ipv4_hdr +
572 sizeof(struct rte_ipv4_hdr));
573 key.port_dst = rte_be_to_cpu_16(udp->dst_port);
574 key.port_src = rte_be_to_cpu_16(udp->src_port);
583 /* Find destination port */
584 ret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);
585 return ((ret < 0) ? portid : ipv4_l3fwd_out_if[ret]);
588 static inline uint16_t
589 get_ipv6_dst_port(struct rte_ipv6_hdr *ipv6_hdr, uint16_t portid,
590 lookup_struct_t *ipv6_l3fwd_lookup_struct)
592 struct ipv6_5tuple key;
593 struct rte_tcp_hdr *tcp;
594 struct rte_udp_hdr *udp;
597 memcpy(key.ip_dst, ipv6_hdr->dst_addr, IPV6_ADDR_LEN);
598 memcpy(key.ip_src, ipv6_hdr->src_addr, IPV6_ADDR_LEN);
600 key.proto = ipv6_hdr->proto;
602 switch (ipv6_hdr->proto) {
604 tcp = (struct rte_tcp_hdr *)((unsigned char *) ipv6_hdr +
605 sizeof(struct rte_ipv6_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 *) ipv6_hdr +
612 sizeof(struct rte_ipv6_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(ipv6_l3fwd_lookup_struct, (const void *)&key);
625 return ((ret < 0) ? portid : ipv6_l3fwd_out_if[ret]);
629 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
630 static inline uint16_t
631 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
632 lookup_struct_t *ipv4_l3fwd_lookup_struct)
636 return ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct,
637 rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0)?
643 parse_ptype_one(struct rte_mbuf *m)
645 struct rte_ether_hdr *eth_hdr;
646 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
649 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
650 ether_type = eth_hdr->ether_type;
651 if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
652 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
653 else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
654 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
656 m->packet_type = packet_type;
660 cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
661 struct rte_mbuf *pkts[], uint16_t nb_pkts,
662 uint16_t max_pkts __rte_unused,
663 void *user_param __rte_unused)
667 for (i = 0; i < nb_pkts; ++i)
668 parse_ptype_one(pkts[i]);
674 add_cb_parse_ptype(uint16_t portid, uint16_t queueid)
676 printf("Port %d: softly parse packet type info\n", portid);
677 if (rte_eth_add_rx_callback(portid, queueid, cb_parse_ptype, NULL))
680 printf("Failed to add rx callback: port=%d\n", portid);
685 l3fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
686 struct lcore_conf *qconf)
688 struct rte_ether_hdr *eth_hdr;
689 struct rte_ipv4_hdr *ipv4_hdr;
693 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
695 if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
696 /* Handle IPv4 headers.*/
698 rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
699 sizeof(struct rte_ether_hdr));
701 #ifdef DO_RFC_1812_CHECKS
702 /* Check to make sure the packet is valid (RFC1812) */
703 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
709 dst_port = get_ipv4_dst_port(ipv4_hdr, portid,
710 qconf->ipv4_lookup_struct);
711 if (dst_port >= RTE_MAX_ETHPORTS ||
712 (enabled_port_mask & 1 << dst_port) == 0)
715 /* 02:00:00:00:00:xx */
716 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
717 *((uint64_t *)d_addr_bytes) =
718 0x000000000002 + ((uint64_t)dst_port << 40);
720 #ifdef DO_RFC_1812_CHECKS
721 /* Update time to live and header checksum */
722 --(ipv4_hdr->time_to_live);
723 ++(ipv4_hdr->hdr_checksum);
727 rte_ether_addr_copy(&ports_eth_addr[dst_port],
730 send_single_packet(m, dst_port);
731 } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
732 /* Handle IPv6 headers.*/
733 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
734 struct rte_ipv6_hdr *ipv6_hdr;
737 rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
738 sizeof(struct rte_ether_hdr));
740 dst_port = get_ipv6_dst_port(ipv6_hdr, portid,
741 qconf->ipv6_lookup_struct);
743 if (dst_port >= RTE_MAX_ETHPORTS ||
744 (enabled_port_mask & 1 << dst_port) == 0)
747 /* 02:00:00:00:00:xx */
748 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
749 *((uint64_t *)d_addr_bytes) =
750 0x000000000002 + ((uint64_t)dst_port << 40);
753 rte_ether_addr_copy(&ports_eth_addr[dst_port],
756 send_single_packet(m, dst_port);
758 /* We don't currently handle IPv6 packets in LPM mode. */
766 #define MINIMUM_SLEEP_TIME 1
767 #define SUSPEND_THRESHOLD 300
769 static inline uint32_t
770 power_idle_heuristic(uint32_t zero_rx_packet_count)
772 /* If zero count is less than 100, sleep 1us */
773 if (zero_rx_packet_count < SUSPEND_THRESHOLD)
774 return MINIMUM_SLEEP_TIME;
775 /* If zero count is less than 1000, sleep 100 us which is the
776 minimum latency switching from C3/C6 to C0
779 return SUSPEND_THRESHOLD;
782 static inline enum freq_scale_hint_t
783 power_freq_scaleup_heuristic(unsigned lcore_id,
787 uint32_t rxq_count = rte_eth_rx_queue_count(port_id, queue_id);
789 * HW Rx queue size is 128 by default, Rx burst read at maximum 32 entries
792 #define FREQ_GEAR1_RX_PACKET_THRESHOLD MAX_PKT_BURST
793 #define FREQ_GEAR2_RX_PACKET_THRESHOLD (MAX_PKT_BURST*2)
794 #define FREQ_GEAR3_RX_PACKET_THRESHOLD (MAX_PKT_BURST*3)
795 #define FREQ_UP_TREND1_ACC 1
796 #define FREQ_UP_TREND2_ACC 100
797 #define FREQ_UP_THRESHOLD 10000
799 if (likely(rxq_count > FREQ_GEAR3_RX_PACKET_THRESHOLD)) {
800 stats[lcore_id].trend = 0;
802 } else if (likely(rxq_count > FREQ_GEAR2_RX_PACKET_THRESHOLD))
803 stats[lcore_id].trend += FREQ_UP_TREND2_ACC;
804 else if (likely(rxq_count > FREQ_GEAR1_RX_PACKET_THRESHOLD))
805 stats[lcore_id].trend += FREQ_UP_TREND1_ACC;
807 if (likely(stats[lcore_id].trend > FREQ_UP_THRESHOLD)) {
808 stats[lcore_id].trend = 0;
816 * force polling thread sleep until one-shot rx interrupt triggers
825 sleep_until_rx_interrupt(int num)
828 * we want to track when we are woken up by traffic so that we can go
829 * back to sleep again without log spamming.
832 struct rte_epoll_event event[num];
839 RTE_LOG(INFO, L3FWD_POWER,
840 "lcore %u sleeps until interrupt triggers\n",
844 n = rte_epoll_wait(RTE_EPOLL_PER_THREAD, event, num, 10);
845 for (i = 0; i < n; i++) {
846 data = event[i].epdata.data;
847 port_id = ((uintptr_t)data) >> CHAR_BIT;
848 queue_id = ((uintptr_t)data) &
849 RTE_LEN2MASK(CHAR_BIT, uint8_t);
850 RTE_LOG(INFO, L3FWD_POWER,
851 "lcore %u is waked up from rx interrupt on"
852 " port %d queue %d\n",
853 rte_lcore_id(), port_id, queue_id);
860 static void turn_on_off_intr(struct lcore_conf *qconf, bool on)
863 struct lcore_rx_queue *rx_queue;
867 for (i = 0; i < qconf->n_rx_queue; ++i) {
868 rx_queue = &(qconf->rx_queue_list[i]);
869 port_id = rx_queue->port_id;
870 queue_id = rx_queue->queue_id;
872 rte_spinlock_lock(&(locks[port_id]));
874 rte_eth_dev_rx_intr_enable(port_id, queue_id);
876 rte_eth_dev_rx_intr_disable(port_id, queue_id);
877 rte_spinlock_unlock(&(locks[port_id]));
881 static int event_register(struct lcore_conf *qconf)
883 struct lcore_rx_queue *rx_queue;
890 for (i = 0; i < qconf->n_rx_queue; ++i) {
891 rx_queue = &(qconf->rx_queue_list[i]);
892 portid = rx_queue->port_id;
893 queueid = rx_queue->queue_id;
894 data = portid << CHAR_BIT | queueid;
896 ret = rte_eth_dev_rx_intr_ctl_q(portid, queueid,
897 RTE_EPOLL_PER_THREAD,
899 (void *)((uintptr_t)data));
906 /* main processing loop */
908 main_telemetry_loop(__rte_unused void *dummy)
910 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
911 unsigned int lcore_id;
912 uint64_t prev_tsc, diff_tsc, cur_tsc, prev_tel_tsc;
916 struct lcore_conf *qconf;
917 struct lcore_rx_queue *rx_queue;
918 uint64_t ep_nep[2] = {0}, fp_nfp[2] = {0};
922 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
923 US_PER_S * BURST_TX_DRAIN_US;
929 lcore_id = rte_lcore_id();
930 qconf = &lcore_conf[lcore_id];
932 if (qconf->n_rx_queue == 0) {
933 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
938 RTE_LOG(INFO, L3FWD_POWER, "entering main telemetry loop on lcore %u\n",
941 for (i = 0; i < qconf->n_rx_queue; i++) {
942 portid = qconf->rx_queue_list[i].port_id;
943 queueid = qconf->rx_queue_list[i].queue_id;
944 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
945 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
950 cur_tsc = rte_rdtsc();
952 * TX burst queue drain
954 diff_tsc = cur_tsc - prev_tsc;
955 if (unlikely(diff_tsc > drain_tsc)) {
956 for (i = 0; i < qconf->n_tx_port; ++i) {
957 portid = qconf->tx_port_id[i];
958 rte_eth_tx_buffer_flush(portid,
959 qconf->tx_queue_id[portid],
960 qconf->tx_buffer[portid]);
966 * Read packet from RX queues
968 for (i = 0; i < qconf->n_rx_queue; ++i) {
969 rx_queue = &(qconf->rx_queue_list[i]);
970 portid = rx_queue->port_id;
971 queueid = rx_queue->queue_id;
973 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
975 ep_nep[nb_rx == 0]++;
976 fp_nfp[nb_rx == MAX_PKT_BURST]++;
978 if (unlikely(nb_rx == 0))
981 /* Prefetch first packets */
982 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
983 rte_prefetch0(rte_pktmbuf_mtod(
984 pkts_burst[j], void *));
987 /* Prefetch and forward already prefetched packets */
988 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
989 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
990 j + PREFETCH_OFFSET], void *));
991 l3fwd_simple_forward(pkts_burst[j], portid,
995 /* Forward remaining prefetched packets */
996 for (; j < nb_rx; j++) {
997 l3fwd_simple_forward(pkts_burst[j], portid,
1001 if (unlikely(poll_count >= DEFAULT_COUNT)) {
1002 diff_tsc = cur_tsc - prev_tel_tsc;
1003 if (diff_tsc >= MAX_CYCLES) {
1005 } else if (diff_tsc > MIN_CYCLES &&
1006 diff_tsc < MAX_CYCLES) {
1007 br = (diff_tsc * 100) / MAX_CYCLES;
1012 prev_tel_tsc = cur_tsc;
1013 /* update stats for telemetry */
1014 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
1015 stats[lcore_id].ep_nep[0] = ep_nep[0];
1016 stats[lcore_id].ep_nep[1] = ep_nep[1];
1017 stats[lcore_id].fp_nfp[0] = fp_nfp[0];
1018 stats[lcore_id].fp_nfp[1] = fp_nfp[1];
1019 stats[lcore_id].br = br;
1020 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
1026 /* main processing loop */
1028 main_empty_poll_loop(__rte_unused void *dummy)
1030 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1031 unsigned int lcore_id;
1032 uint64_t prev_tsc, diff_tsc, cur_tsc;
1036 struct lcore_conf *qconf;
1037 struct lcore_rx_queue *rx_queue;
1039 const uint64_t drain_tsc =
1040 (rte_get_tsc_hz() + US_PER_S - 1) /
1041 US_PER_S * BURST_TX_DRAIN_US;
1045 lcore_id = rte_lcore_id();
1046 qconf = &lcore_conf[lcore_id];
1048 if (qconf->n_rx_queue == 0) {
1049 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
1054 for (i = 0; i < qconf->n_rx_queue; i++) {
1055 portid = qconf->rx_queue_list[i].port_id;
1056 queueid = qconf->rx_queue_list[i].queue_id;
1057 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1058 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1061 while (!is_done()) {
1062 stats[lcore_id].nb_iteration_looped++;
1064 cur_tsc = rte_rdtsc();
1066 * TX burst queue drain
1068 diff_tsc = cur_tsc - prev_tsc;
1069 if (unlikely(diff_tsc > drain_tsc)) {
1070 for (i = 0; i < qconf->n_tx_port; ++i) {
1071 portid = qconf->tx_port_id[i];
1072 rte_eth_tx_buffer_flush(portid,
1073 qconf->tx_queue_id[portid],
1074 qconf->tx_buffer[portid]);
1080 * Read packet from RX queues
1082 for (i = 0; i < qconf->n_rx_queue; ++i) {
1083 rx_queue = &(qconf->rx_queue_list[i]);
1084 rx_queue->idle_hint = 0;
1085 portid = rx_queue->port_id;
1086 queueid = rx_queue->queue_id;
1088 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1091 stats[lcore_id].nb_rx_processed += nb_rx;
1095 rte_power_empty_poll_stat_update(lcore_id);
1099 rte_power_poll_stat_update(lcore_id, nb_rx);
1103 /* Prefetch first packets */
1104 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1105 rte_prefetch0(rte_pktmbuf_mtod(
1106 pkts_burst[j], void *));
1109 /* Prefetch and forward already prefetched packets */
1110 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1111 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1112 j + PREFETCH_OFFSET],
1114 l3fwd_simple_forward(pkts_burst[j], portid,
1118 /* Forward remaining prefetched packets */
1119 for (; j < nb_rx; j++) {
1120 l3fwd_simple_forward(pkts_burst[j], portid,
1130 /* main processing loop */
1132 main_loop(__rte_unused void *dummy)
1134 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1136 uint64_t prev_tsc, diff_tsc, cur_tsc, tim_res_tsc, hz;
1137 uint64_t prev_tsc_power = 0, cur_tsc_power, diff_tsc_power;
1141 struct lcore_conf *qconf;
1142 struct lcore_rx_queue *rx_queue;
1143 enum freq_scale_hint_t lcore_scaleup_hint;
1144 uint32_t lcore_rx_idle_count = 0;
1145 uint32_t lcore_idle_hint = 0;
1148 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
1151 hz = rte_get_timer_hz();
1152 tim_res_tsc = hz/TIMER_NUMBER_PER_SECOND;
1154 lcore_id = rte_lcore_id();
1155 qconf = &lcore_conf[lcore_id];
1157 if (qconf->n_rx_queue == 0) {
1158 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n", lcore_id);
1162 RTE_LOG(INFO, L3FWD_POWER, "entering main loop on lcore %u\n", lcore_id);
1164 for (i = 0; i < qconf->n_rx_queue; i++) {
1165 portid = qconf->rx_queue_list[i].port_id;
1166 queueid = qconf->rx_queue_list[i].queue_id;
1167 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1168 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1171 /* add into event wait list */
1172 if (event_register(qconf) == 0)
1175 RTE_LOG(INFO, L3FWD_POWER, "RX interrupt won't enable.\n");
1177 while (!is_done()) {
1178 stats[lcore_id].nb_iteration_looped++;
1180 cur_tsc = rte_rdtsc();
1181 cur_tsc_power = cur_tsc;
1184 * TX burst queue drain
1186 diff_tsc = cur_tsc - prev_tsc;
1187 if (unlikely(diff_tsc > drain_tsc)) {
1188 for (i = 0; i < qconf->n_tx_port; ++i) {
1189 portid = qconf->tx_port_id[i];
1190 rte_eth_tx_buffer_flush(portid,
1191 qconf->tx_queue_id[portid],
1192 qconf->tx_buffer[portid]);
1197 diff_tsc_power = cur_tsc_power - prev_tsc_power;
1198 if (diff_tsc_power > tim_res_tsc) {
1200 prev_tsc_power = cur_tsc_power;
1205 * Read packet from RX queues
1207 lcore_scaleup_hint = FREQ_CURRENT;
1208 lcore_rx_idle_count = 0;
1209 for (i = 0; i < qconf->n_rx_queue; ++i) {
1210 rx_queue = &(qconf->rx_queue_list[i]);
1211 rx_queue->idle_hint = 0;
1212 portid = rx_queue->port_id;
1213 queueid = rx_queue->queue_id;
1215 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1218 stats[lcore_id].nb_rx_processed += nb_rx;
1219 if (unlikely(nb_rx == 0)) {
1221 * no packet received from rx queue, try to
1222 * sleep for a while forcing CPU enter deeper
1225 rx_queue->zero_rx_packet_count++;
1227 if (rx_queue->zero_rx_packet_count <=
1228 MIN_ZERO_POLL_COUNT)
1231 rx_queue->idle_hint = power_idle_heuristic(\
1232 rx_queue->zero_rx_packet_count);
1233 lcore_rx_idle_count++;
1235 rx_queue->zero_rx_packet_count = 0;
1238 * do not scale up frequency immediately as
1239 * user to kernel space communication is costly
1240 * which might impact packet I/O for received
1243 rx_queue->freq_up_hint =
1244 power_freq_scaleup_heuristic(lcore_id,
1248 /* Prefetch first packets */
1249 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1250 rte_prefetch0(rte_pktmbuf_mtod(
1251 pkts_burst[j], void *));
1254 /* Prefetch and forward already prefetched packets */
1255 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1256 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1257 j + PREFETCH_OFFSET], void *));
1258 l3fwd_simple_forward(pkts_burst[j], portid,
1262 /* Forward remaining prefetched packets */
1263 for (; j < nb_rx; j++) {
1264 l3fwd_simple_forward(pkts_burst[j], portid,
1269 if (likely(lcore_rx_idle_count != qconf->n_rx_queue)) {
1270 for (i = 1, lcore_scaleup_hint =
1271 qconf->rx_queue_list[0].freq_up_hint;
1272 i < qconf->n_rx_queue; ++i) {
1273 rx_queue = &(qconf->rx_queue_list[i]);
1274 if (rx_queue->freq_up_hint >
1276 lcore_scaleup_hint =
1277 rx_queue->freq_up_hint;
1280 if (lcore_scaleup_hint == FREQ_HIGHEST) {
1281 if (rte_power_freq_max)
1282 rte_power_freq_max(lcore_id);
1283 } else if (lcore_scaleup_hint == FREQ_HIGHER) {
1284 if (rte_power_freq_up)
1285 rte_power_freq_up(lcore_id);
1289 * All Rx queues empty in recent consecutive polls,
1290 * sleep in a conservative manner, meaning sleep as
1293 for (i = 1, lcore_idle_hint =
1294 qconf->rx_queue_list[0].idle_hint;
1295 i < qconf->n_rx_queue; ++i) {
1296 rx_queue = &(qconf->rx_queue_list[i]);
1297 if (rx_queue->idle_hint < lcore_idle_hint)
1298 lcore_idle_hint = rx_queue->idle_hint;
1301 if (lcore_idle_hint < SUSPEND_THRESHOLD)
1303 * execute "pause" instruction to avoid context
1304 * switch which generally take hundred of
1305 * microseconds for short sleep.
1307 rte_delay_us(lcore_idle_hint);
1309 /* suspend until rx interrupt triggers */
1311 turn_on_off_intr(qconf, 1);
1312 sleep_until_rx_interrupt(
1314 turn_on_off_intr(qconf, 0);
1316 * start receiving packets immediately
1318 if (likely(!is_done()))
1322 stats[lcore_id].sleep_time += lcore_idle_hint;
1330 check_lcore_params(void)
1332 uint8_t queue, lcore;
1336 for (i = 0; i < nb_lcore_params; ++i) {
1337 queue = lcore_params[i].queue_id;
1338 if (queue >= MAX_RX_QUEUE_PER_PORT) {
1339 printf("invalid queue number: %hhu\n", queue);
1342 lcore = lcore_params[i].lcore_id;
1343 if (!rte_lcore_is_enabled(lcore)) {
1344 printf("error: lcore %hhu is not enabled in lcore "
1348 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
1350 printf("warning: lcore %hhu is on socket %d with numa "
1351 "off\n", lcore, socketid);
1353 if (app_mode == APP_MODE_TELEMETRY && lcore == rte_lcore_id()) {
1354 printf("cannot enable master core %d in config for telemetry mode\n",
1363 check_port_config(void)
1368 for (i = 0; i < nb_lcore_params; ++i) {
1369 portid = lcore_params[i].port_id;
1370 if ((enabled_port_mask & (1 << portid)) == 0) {
1371 printf("port %u is not enabled in port mask\n",
1375 if (!rte_eth_dev_is_valid_port(portid)) {
1376 printf("port %u is not present on the board\n",
1385 get_port_n_rx_queues(const uint16_t port)
1390 for (i = 0; i < nb_lcore_params; ++i) {
1391 if (lcore_params[i].port_id == port &&
1392 lcore_params[i].queue_id > queue)
1393 queue = lcore_params[i].queue_id;
1395 return (uint8_t)(++queue);
1399 init_lcore_rx_queues(void)
1401 uint16_t i, nb_rx_queue;
1404 for (i = 0; i < nb_lcore_params; ++i) {
1405 lcore = lcore_params[i].lcore_id;
1406 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
1407 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
1408 printf("error: too many queues (%u) for lcore: %u\n",
1409 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
1412 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
1413 lcore_params[i].port_id;
1414 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
1415 lcore_params[i].queue_id;
1416 lcore_conf[lcore].n_rx_queue++;
1424 print_usage(const char *prgname)
1426 printf ("%s [EAL options] -- -p PORTMASK -P"
1427 " [--config (port,queue,lcore)[,(port,queue,lcore]]"
1428 " [--high-perf-cores CORELIST"
1429 " [--perf-config (port,queue,hi_perf,lcore_index)[,(port,queue,hi_perf,lcore_index]]"
1430 " [--enable-jumbo [--max-pkt-len PKTLEN]]\n"
1431 " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
1432 " -P : enable promiscuous mode\n"
1433 " --config (port,queue,lcore): rx queues configuration\n"
1434 " --high-perf-cores CORELIST: list of high performance cores\n"
1435 " --perf-config: similar as config, cores specified as indices"
1436 " for bins containing high or regular performance cores\n"
1437 " --no-numa: optional, disable numa awareness\n"
1438 " --enable-jumbo: enable jumbo frame"
1439 " which max packet len is PKTLEN in decimal (64-9600)\n"
1440 " --parse-ptype: parse packet type by software\n"
1441 " --empty-poll: enable empty poll detection"
1442 " follow (training_flag, high_threshold, med_threshold)\n"
1443 " --telemetry: enable telemetry mode, to update"
1444 " empty polls, full polls, and core busyness to telemetry\n",
1448 static int parse_max_pkt_len(const char *pktlen)
1453 /* parse decimal string */
1454 len = strtoul(pktlen, &end, 10);
1455 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
1465 parse_portmask(const char *portmask)
1470 /* parse hexadecimal string */
1471 pm = strtoul(portmask, &end, 16);
1472 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
1482 parse_config(const char *q_arg)
1485 const char *p, *p0 = q_arg;
1493 unsigned long int_fld[_NUM_FLD];
1494 char *str_fld[_NUM_FLD];
1498 nb_lcore_params = 0;
1500 while ((p = strchr(p0,'(')) != NULL) {
1502 if((p0 = strchr(p,')')) == NULL)
1506 if(size >= sizeof(s))
1509 snprintf(s, sizeof(s), "%.*s", size, p);
1510 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') !=
1513 for (i = 0; i < _NUM_FLD; i++){
1515 int_fld[i] = strtoul(str_fld[i], &end, 0);
1516 if (errno != 0 || end == str_fld[i] || int_fld[i] >
1520 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
1521 printf("exceeded max number of lcore params: %hu\n",
1525 lcore_params_array[nb_lcore_params].port_id =
1526 (uint8_t)int_fld[FLD_PORT];
1527 lcore_params_array[nb_lcore_params].queue_id =
1528 (uint8_t)int_fld[FLD_QUEUE];
1529 lcore_params_array[nb_lcore_params].lcore_id =
1530 (uint8_t)int_fld[FLD_LCORE];
1533 lcore_params = lcore_params_array;
1538 parse_ep_config(const char *q_arg)
1541 const char *p = q_arg;
1551 ep_med_edpi = EMPTY_POLL_MED_THRESHOLD;
1552 ep_hgh_edpi = EMPTY_POLL_MED_THRESHOLD;
1554 strlcpy(s, p, sizeof(s));
1556 num_arg = rte_strsplit(s, sizeof(s), str_fld, 3, ',');
1558 empty_poll_train = false;
1565 training_flag = strtoul(str_fld[0], &end, 0);
1566 med_edpi = strtoul(str_fld[1], &end, 0);
1567 hgh_edpi = strtoul(str_fld[2], &end, 0);
1569 if (training_flag == 1)
1570 empty_poll_train = true;
1573 ep_med_edpi = med_edpi;
1576 ep_hgh_edpi = hgh_edpi;
1586 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
1587 #define CMD_LINE_OPT_TELEMETRY "telemetry"
1589 /* Parse the argument given in the command line of the application */
1591 parse_args(int argc, char **argv)
1597 char *prgname = argv[0];
1598 static struct option lgopts[] = {
1599 {"config", 1, 0, 0},
1600 {"perf-config", 1, 0, 0},
1601 {"high-perf-cores", 1, 0, 0},
1602 {"no-numa", 0, 0, 0},
1603 {"enable-jumbo", 0, 0, 0},
1604 {"empty-poll", 1, 0, 0},
1605 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
1606 {CMD_LINE_OPT_TELEMETRY, 0, 0, 0},
1612 while ((opt = getopt_long(argc, argvopt, "p:l:m:h:P",
1613 lgopts, &option_index)) != EOF) {
1618 enabled_port_mask = parse_portmask(optarg);
1619 if (enabled_port_mask == 0) {
1620 printf("invalid portmask\n");
1621 print_usage(prgname);
1626 printf("Promiscuous mode selected\n");
1630 limit = parse_max_pkt_len(optarg);
1631 freq_tlb[LOW] = limit;
1634 limit = parse_max_pkt_len(optarg);
1635 freq_tlb[MED] = limit;
1638 limit = parse_max_pkt_len(optarg);
1639 freq_tlb[HGH] = limit;
1643 if (!strncmp(lgopts[option_index].name, "config", 6)) {
1644 ret = parse_config(optarg);
1646 printf("invalid config\n");
1647 print_usage(prgname);
1652 if (!strncmp(lgopts[option_index].name,
1653 "perf-config", 11)) {
1654 ret = parse_perf_config(optarg);
1656 printf("invalid perf-config\n");
1657 print_usage(prgname);
1662 if (!strncmp(lgopts[option_index].name,
1663 "high-perf-cores", 15)) {
1664 ret = parse_perf_core_list(optarg);
1666 printf("invalid high-perf-cores\n");
1667 print_usage(prgname);
1672 if (!strncmp(lgopts[option_index].name,
1674 printf("numa is disabled \n");
1678 if (!strncmp(lgopts[option_index].name,
1679 "empty-poll", 10)) {
1680 if (app_mode == APP_MODE_TELEMETRY) {
1681 printf(" empty-poll cannot be enabled as telemetry mode is enabled\n");
1684 app_mode = APP_MODE_EMPTY_POLL;
1685 ret = parse_ep_config(optarg);
1688 printf("invalid empty poll config\n");
1689 print_usage(prgname);
1692 printf("empty-poll is enabled\n");
1695 if (!strncmp(lgopts[option_index].name,
1696 CMD_LINE_OPT_TELEMETRY,
1697 sizeof(CMD_LINE_OPT_TELEMETRY))) {
1698 if (app_mode == APP_MODE_EMPTY_POLL) {
1699 printf("telemetry mode cannot be enabled as empty poll mode is enabled\n");
1702 app_mode = APP_MODE_TELEMETRY;
1703 printf("telemetry mode is enabled\n");
1706 if (!strncmp(lgopts[option_index].name,
1707 "enable-jumbo", 12)) {
1708 struct option lenopts =
1709 {"max-pkt-len", required_argument, \
1712 printf("jumbo frame is enabled \n");
1713 port_conf.rxmode.offloads |=
1714 DEV_RX_OFFLOAD_JUMBO_FRAME;
1715 port_conf.txmode.offloads |=
1716 DEV_TX_OFFLOAD_MULTI_SEGS;
1719 * if no max-pkt-len set, use the default value
1722 if (0 == getopt_long(argc, argvopt, "",
1723 &lenopts, &option_index)) {
1724 ret = parse_max_pkt_len(optarg);
1726 (ret > MAX_JUMBO_PKT_LEN)){
1727 printf("invalid packet "
1729 print_usage(prgname);
1732 port_conf.rxmode.max_rx_pkt_len = ret;
1734 printf("set jumbo frame "
1735 "max packet length to %u\n",
1736 (unsigned int)port_conf.rxmode.max_rx_pkt_len);
1739 if (!strncmp(lgopts[option_index].name,
1740 CMD_LINE_OPT_PARSE_PTYPE,
1741 sizeof(CMD_LINE_OPT_PARSE_PTYPE))) {
1742 printf("soft parse-ptype is enabled\n");
1749 print_usage(prgname);
1755 argv[optind-1] = prgname;
1758 optind = 1; /* reset getopt lib */
1763 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
1765 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1766 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
1767 printf("%s%s", name, buf);
1770 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1772 setup_hash(int socketid)
1774 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
1776 .entries = L3FWD_HASH_ENTRIES,
1777 .key_len = sizeof(struct ipv4_5tuple),
1778 .hash_func = DEFAULT_HASH_FUNC,
1779 .hash_func_init_val = 0,
1782 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
1784 .entries = L3FWD_HASH_ENTRIES,
1785 .key_len = sizeof(struct ipv6_5tuple),
1786 .hash_func = DEFAULT_HASH_FUNC,
1787 .hash_func_init_val = 0,
1794 /* create ipv4 hash */
1795 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
1796 ipv4_l3fwd_hash_params.name = s;
1797 ipv4_l3fwd_hash_params.socket_id = socketid;
1798 ipv4_l3fwd_lookup_struct[socketid] =
1799 rte_hash_create(&ipv4_l3fwd_hash_params);
1800 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1801 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1802 "socket %d\n", socketid);
1804 /* create ipv6 hash */
1805 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
1806 ipv6_l3fwd_hash_params.name = s;
1807 ipv6_l3fwd_hash_params.socket_id = socketid;
1808 ipv6_l3fwd_lookup_struct[socketid] =
1809 rte_hash_create(&ipv6_l3fwd_hash_params);
1810 if (ipv6_l3fwd_lookup_struct[socketid] == NULL)
1811 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1812 "socket %d\n", socketid);
1815 /* populate the ipv4 hash */
1816 for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
1817 ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
1818 (void *) &ipv4_l3fwd_route_array[i].key);
1820 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1821 "l3fwd hash on socket %d\n", i, socketid);
1823 ipv4_l3fwd_out_if[ret] = ipv4_l3fwd_route_array[i].if_out;
1824 printf("Hash: Adding key\n");
1825 print_ipv4_key(ipv4_l3fwd_route_array[i].key);
1828 /* populate the ipv6 hash */
1829 for (i = 0; i < RTE_DIM(ipv6_l3fwd_route_array); i++) {
1830 ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
1831 (void *) &ipv6_l3fwd_route_array[i].key);
1833 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1834 "l3fwd hash on socket %d\n", i, socketid);
1836 ipv6_l3fwd_out_if[ret] = ipv6_l3fwd_route_array[i].if_out;
1837 printf("Hash: Adding key\n");
1838 print_ipv6_key(ipv6_l3fwd_route_array[i].key);
1843 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1845 setup_lpm(int socketid)
1851 /* create the LPM table */
1852 struct rte_lpm_config lpm_ipv4_config;
1854 lpm_ipv4_config.max_rules = IPV4_L3FWD_LPM_MAX_RULES;
1855 lpm_ipv4_config.number_tbl8s = 256;
1856 lpm_ipv4_config.flags = 0;
1858 snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
1859 ipv4_l3fwd_lookup_struct[socketid] =
1860 rte_lpm_create(s, socketid, &lpm_ipv4_config);
1861 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1862 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
1863 " on socket %d\n", socketid);
1865 /* populate the LPM table */
1866 for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
1867 ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
1868 ipv4_l3fwd_route_array[i].ip,
1869 ipv4_l3fwd_route_array[i].depth,
1870 ipv4_l3fwd_route_array[i].if_out);
1873 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the "
1874 "l3fwd LPM table on socket %d\n",
1878 printf("LPM: Adding route 0x%08x / %d (%d)\n",
1879 (unsigned)ipv4_l3fwd_route_array[i].ip,
1880 ipv4_l3fwd_route_array[i].depth,
1881 ipv4_l3fwd_route_array[i].if_out);
1887 init_mem(unsigned nb_mbuf)
1889 struct lcore_conf *qconf;
1894 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1895 if (rte_lcore_is_enabled(lcore_id) == 0)
1899 socketid = rte_lcore_to_socket_id(lcore_id);
1903 if (socketid >= NB_SOCKETS) {
1904 rte_exit(EXIT_FAILURE, "Socket %d of lcore %u is "
1905 "out of range %d\n", socketid,
1906 lcore_id, NB_SOCKETS);
1908 if (pktmbuf_pool[socketid] == NULL) {
1909 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
1910 pktmbuf_pool[socketid] =
1911 rte_pktmbuf_pool_create(s, nb_mbuf,
1912 MEMPOOL_CACHE_SIZE, 0,
1913 RTE_MBUF_DEFAULT_BUF_SIZE,
1915 if (pktmbuf_pool[socketid] == NULL)
1916 rte_exit(EXIT_FAILURE,
1917 "Cannot init mbuf pool on socket %d\n",
1920 printf("Allocated mbuf pool on socket %d\n",
1923 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1924 setup_lpm(socketid);
1926 setup_hash(socketid);
1929 qconf = &lcore_conf[lcore_id];
1930 qconf->ipv4_lookup_struct = ipv4_l3fwd_lookup_struct[socketid];
1931 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1932 qconf->ipv6_lookup_struct = ipv6_l3fwd_lookup_struct[socketid];
1938 /* Check the link status of all ports in up to 9s, and print them finally */
1940 check_all_ports_link_status(uint32_t port_mask)
1942 #define CHECK_INTERVAL 100 /* 100ms */
1943 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1944 uint8_t count, all_ports_up, print_flag = 0;
1946 struct rte_eth_link link;
1949 printf("\nChecking link status");
1951 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1953 RTE_ETH_FOREACH_DEV(portid) {
1954 if ((port_mask & (1 << portid)) == 0)
1956 memset(&link, 0, sizeof(link));
1957 ret = rte_eth_link_get_nowait(portid, &link);
1960 if (print_flag == 1)
1961 printf("Port %u link get failed: %s\n",
1962 portid, rte_strerror(-ret));
1965 /* print link status if flag set */
1966 if (print_flag == 1) {
1967 if (link.link_status)
1968 printf("Port %d Link Up - speed %u "
1969 "Mbps - %s\n", (uint8_t)portid,
1970 (unsigned)link.link_speed,
1971 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1972 ("full-duplex") : ("half-duplex"));
1974 printf("Port %d Link Down\n",
1978 /* clear all_ports_up flag if any link down */
1979 if (link.link_status == ETH_LINK_DOWN) {
1984 /* after finally printing all link status, get out */
1985 if (print_flag == 1)
1988 if (all_ports_up == 0) {
1991 rte_delay_ms(CHECK_INTERVAL);
1994 /* set the print_flag if all ports up or timeout */
1995 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
2002 static int check_ptype(uint16_t portid)
2005 int ptype_l3_ipv4 = 0;
2006 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2007 int ptype_l3_ipv6 = 0;
2009 uint32_t ptype_mask = RTE_PTYPE_L3_MASK;
2011 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
2015 uint32_t ptypes[ret];
2017 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
2018 for (i = 0; i < ret; ++i) {
2019 if (ptypes[i] & RTE_PTYPE_L3_IPV4)
2021 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2022 if (ptypes[i] & RTE_PTYPE_L3_IPV6)
2027 if (ptype_l3_ipv4 == 0)
2028 printf("port %d cannot parse RTE_PTYPE_L3_IPV4\n", portid);
2030 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2031 if (ptype_l3_ipv6 == 0)
2032 printf("port %d cannot parse RTE_PTYPE_L3_IPV6\n", portid);
2035 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
2037 #else /* APP_LOOKUP_EXACT_MATCH */
2038 if (ptype_l3_ipv4 && ptype_l3_ipv6)
2047 init_power_library(void)
2049 unsigned int lcore_id;
2052 RTE_LCORE_FOREACH(lcore_id) {
2053 /* init power management library */
2054 ret = rte_power_init(lcore_id);
2057 "Library initialization failed on core %u\n",
2066 deinit_power_library(void)
2068 unsigned int lcore_id;
2071 RTE_LCORE_FOREACH(lcore_id) {
2072 /* deinit power management library */
2073 ret = rte_power_exit(lcore_id);
2076 "Library deinitialization failed on core %u\n",
2085 get_current_stat_values(uint64_t *values)
2087 unsigned int lcore_id = rte_lcore_id();
2088 struct lcore_conf *qconf;
2089 uint64_t app_eps = 0, app_fps = 0, app_br = 0;
2092 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2093 qconf = &lcore_conf[lcore_id];
2094 if (qconf->n_rx_queue == 0)
2097 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
2098 app_eps += stats[lcore_id].ep_nep[1];
2099 app_fps += stats[lcore_id].fp_nfp[1];
2100 app_br += stats[lcore_id].br;
2101 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
2105 values[0] = app_eps/count;
2106 values[1] = app_fps/count;
2107 values[2] = app_br/count;
2109 memset(values, 0, sizeof(uint64_t) * NUM_TELSTATS);
2114 update_telemetry(__rte_unused struct rte_timer *tim,
2115 __rte_unused void *arg)
2118 uint64_t values[NUM_TELSTATS] = {0};
2120 get_current_stat_values(values);
2121 ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
2122 values, RTE_DIM(values));
2124 RTE_LOG(WARNING, POWER, "failed to update metrcis\n");
2128 handle_app_stats(const char *cmd __rte_unused,
2129 const char *params __rte_unused,
2130 struct rte_tel_data *d)
2132 uint64_t values[NUM_TELSTATS] = {0};
2135 rte_tel_data_start_dict(d);
2136 get_current_stat_values(values);
2137 for (i = 0; i < NUM_TELSTATS; i++)
2138 rte_tel_data_add_dict_u64(d, telstats_strings[i].name,
2144 telemetry_setup_timer(void)
2146 int lcore_id = rte_lcore_id();
2147 uint64_t hz = rte_get_timer_hz();
2150 ticks = hz / TELEMETRY_INTERVALS_PER_SEC;
2151 rte_timer_reset_sync(&telemetry_timer,
2159 empty_poll_setup_timer(void)
2161 int lcore_id = rte_lcore_id();
2162 uint64_t hz = rte_get_timer_hz();
2164 struct ep_params *ep_ptr = ep_params;
2166 ep_ptr->interval_ticks = hz / INTERVALS_PER_SECOND;
2168 rte_timer_reset_sync(&ep_ptr->timer0,
2169 ep_ptr->interval_ticks,
2172 rte_empty_poll_detection,
2177 launch_timer(unsigned int lcore_id)
2179 int64_t prev_tsc = 0, cur_tsc, diff_tsc, cycles_10ms;
2181 RTE_SET_USED(lcore_id);
2184 if (rte_get_master_lcore() != lcore_id) {
2185 rte_panic("timer on lcore:%d which is not master core:%d\n",
2187 rte_get_master_lcore());
2190 RTE_LOG(INFO, POWER, "Bring up the Timer\n");
2192 if (app_mode == APP_MODE_EMPTY_POLL)
2193 empty_poll_setup_timer();
2195 telemetry_setup_timer();
2197 cycles_10ms = rte_get_timer_hz() / 100;
2199 while (!is_done()) {
2200 cur_tsc = rte_rdtsc();
2201 diff_tsc = cur_tsc - prev_tsc;
2202 if (diff_tsc > cycles_10ms) {
2205 cycles_10ms = rte_get_timer_hz() / 100;
2209 RTE_LOG(INFO, POWER, "Timer_subsystem is done\n");
2216 main(int argc, char **argv)
2218 struct lcore_conf *qconf;
2219 struct rte_eth_dev_info dev_info;
2220 struct rte_eth_txconf *txconf;
2226 uint32_t n_tx_queue, nb_lcores;
2227 uint32_t dev_rxq_num, dev_txq_num;
2228 uint8_t nb_rx_queue, queue, socketid;
2230 const char *ptr_strings[NUM_TELSTATS];
2232 /* catch SIGINT and restore cpufreq governor to ondemand */
2233 signal(SIGINT, signal_exit_now);
2236 ret = rte_eal_init(argc, argv);
2238 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
2242 /* init RTE timer library to be used late */
2243 rte_timer_subsystem_init();
2245 /* parse application arguments (after the EAL ones) */
2246 ret = parse_args(argc, argv);
2248 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
2250 if (app_mode != APP_MODE_TELEMETRY && init_power_library())
2251 rte_exit(EXIT_FAILURE, "init_power_library failed\n");
2253 if (update_lcore_params() < 0)
2254 rte_exit(EXIT_FAILURE, "update_lcore_params failed\n");
2256 if (check_lcore_params() < 0)
2257 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
2259 ret = init_lcore_rx_queues();
2261 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
2263 nb_ports = rte_eth_dev_count_avail();
2265 if (check_port_config() < 0)
2266 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
2268 nb_lcores = rte_lcore_count();
2270 /* initialize all ports */
2271 RTE_ETH_FOREACH_DEV(portid) {
2272 struct rte_eth_conf local_port_conf = port_conf;
2274 /* skip ports that are not enabled */
2275 if ((enabled_port_mask & (1 << portid)) == 0) {
2276 printf("\nSkipping disabled port %d\n", portid);
2281 printf("Initializing port %d ... ", portid );
2284 ret = rte_eth_dev_info_get(portid, &dev_info);
2286 rte_exit(EXIT_FAILURE,
2287 "Error during getting device (port %u) info: %s\n",
2288 portid, strerror(-ret));
2290 dev_rxq_num = dev_info.max_rx_queues;
2291 dev_txq_num = dev_info.max_tx_queues;
2293 nb_rx_queue = get_port_n_rx_queues(portid);
2294 if (nb_rx_queue > dev_rxq_num)
2295 rte_exit(EXIT_FAILURE,
2296 "Cannot configure not existed rxq: "
2297 "port=%d\n", portid);
2299 n_tx_queue = nb_lcores;
2300 if (n_tx_queue > dev_txq_num)
2301 n_tx_queue = dev_txq_num;
2302 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
2303 nb_rx_queue, (unsigned)n_tx_queue );
2304 /* If number of Rx queue is 0, no need to enable Rx interrupt */
2305 if (nb_rx_queue == 0)
2306 local_port_conf.intr_conf.rxq = 0;
2308 ret = rte_eth_dev_info_get(portid, &dev_info);
2310 rte_exit(EXIT_FAILURE,
2311 "Error during getting device (port %u) info: %s\n",
2312 portid, strerror(-ret));
2314 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
2315 local_port_conf.txmode.offloads |=
2316 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
2318 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
2319 dev_info.flow_type_rss_offloads;
2320 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
2321 port_conf.rx_adv_conf.rss_conf.rss_hf) {
2322 printf("Port %u modified RSS hash function based on hardware support,"
2323 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2325 port_conf.rx_adv_conf.rss_conf.rss_hf,
2326 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
2329 ret = rte_eth_dev_configure(portid, nb_rx_queue,
2330 (uint16_t)n_tx_queue, &local_port_conf);
2332 rte_exit(EXIT_FAILURE, "Cannot configure device: "
2333 "err=%d, port=%d\n", ret, portid);
2335 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
2338 rte_exit(EXIT_FAILURE,
2339 "Cannot adjust number of descriptors: err=%d, port=%d\n",
2342 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
2344 rte_exit(EXIT_FAILURE,
2345 "Cannot get MAC address: err=%d, port=%d\n",
2348 print_ethaddr(" Address:", &ports_eth_addr[portid]);
2352 ret = init_mem(NB_MBUF);
2354 rte_exit(EXIT_FAILURE, "init_mem failed\n");
2356 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2357 if (rte_lcore_is_enabled(lcore_id) == 0)
2360 /* Initialize TX buffers */
2361 qconf = &lcore_conf[lcore_id];
2362 qconf->tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
2363 RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
2364 rte_eth_dev_socket_id(portid));
2365 if (qconf->tx_buffer[portid] == NULL)
2366 rte_exit(EXIT_FAILURE, "Can't allocate tx buffer for port %u\n",
2369 rte_eth_tx_buffer_init(qconf->tx_buffer[portid], MAX_PKT_BURST);
2372 /* init one TX queue per couple (lcore,port) */
2374 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2375 if (rte_lcore_is_enabled(lcore_id) == 0)
2378 if (queueid >= dev_txq_num)
2383 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2387 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
2390 txconf = &dev_info.default_txconf;
2391 txconf->offloads = local_port_conf.txmode.offloads;
2392 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
2395 rte_exit(EXIT_FAILURE,
2396 "rte_eth_tx_queue_setup: err=%d, "
2397 "port=%d\n", ret, portid);
2399 qconf = &lcore_conf[lcore_id];
2400 qconf->tx_queue_id[portid] = queueid;
2403 qconf->tx_port_id[qconf->n_tx_port] = portid;
2409 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2410 if (rte_lcore_is_enabled(lcore_id) == 0)
2413 if (app_mode == APP_MODE_LEGACY) {
2414 /* init timer structures for each enabled lcore */
2415 rte_timer_init(&power_timers[lcore_id]);
2416 hz = rte_get_timer_hz();
2417 rte_timer_reset(&power_timers[lcore_id],
2418 hz/TIMER_NUMBER_PER_SECOND,
2420 power_timer_cb, NULL);
2422 qconf = &lcore_conf[lcore_id];
2423 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
2425 /* init RX queues */
2426 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
2427 struct rte_eth_rxconf rxq_conf;
2429 portid = qconf->rx_queue_list[queue].port_id;
2430 queueid = qconf->rx_queue_list[queue].queue_id;
2434 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2438 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
2441 ret = rte_eth_dev_info_get(portid, &dev_info);
2443 rte_exit(EXIT_FAILURE,
2444 "Error during getting device (port %u) info: %s\n",
2445 portid, strerror(-ret));
2447 rxq_conf = dev_info.default_rxconf;
2448 rxq_conf.offloads = port_conf.rxmode.offloads;
2449 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
2450 socketid, &rxq_conf,
2451 pktmbuf_pool[socketid]);
2453 rte_exit(EXIT_FAILURE,
2454 "rte_eth_rx_queue_setup: err=%d, "
2455 "port=%d\n", ret, portid);
2458 if (add_cb_parse_ptype(portid, queueid) < 0)
2459 rte_exit(EXIT_FAILURE,
2460 "Fail to add ptype cb\n");
2461 } else if (!check_ptype(portid))
2462 rte_exit(EXIT_FAILURE,
2463 "PMD can not provide needed ptypes\n");
2470 RTE_ETH_FOREACH_DEV(portid) {
2471 if ((enabled_port_mask & (1 << portid)) == 0) {
2475 ret = rte_eth_dev_start(portid);
2477 rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, "
2478 "port=%d\n", ret, portid);
2480 * If enabled, put device in promiscuous mode.
2481 * This allows IO forwarding mode to forward packets
2482 * to itself through 2 cross-connected ports of the
2485 if (promiscuous_on) {
2486 ret = rte_eth_promiscuous_enable(portid);
2488 rte_exit(EXIT_FAILURE,
2489 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
2490 rte_strerror(-ret), portid);
2492 /* initialize spinlock for each port */
2493 rte_spinlock_init(&(locks[portid]));
2496 check_all_ports_link_status(enabled_port_mask);
2498 if (app_mode == APP_MODE_EMPTY_POLL) {
2500 if (empty_poll_train) {
2501 policy.state = TRAINING;
2503 policy.state = MED_NORMAL;
2504 policy.med_base_edpi = ep_med_edpi;
2505 policy.hgh_base_edpi = ep_hgh_edpi;
2508 ret = rte_power_empty_poll_stat_init(&ep_params,
2512 rte_exit(EXIT_FAILURE, "empty poll init failed");
2516 /* launch per-lcore init on every lcore */
2517 if (app_mode == APP_MODE_LEGACY) {
2518 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
2519 } else if (app_mode == APP_MODE_EMPTY_POLL) {
2520 empty_poll_stop = false;
2521 rte_eal_mp_remote_launch(main_empty_poll_loop, NULL,
2526 /* Init metrics library */
2527 rte_metrics_init(rte_socket_id());
2528 /** Register stats with metrics library */
2529 for (i = 0; i < NUM_TELSTATS; i++)
2530 ptr_strings[i] = telstats_strings[i].name;
2532 ret = rte_metrics_reg_names(ptr_strings, NUM_TELSTATS);
2534 telstats_index = ret;
2536 rte_exit(EXIT_FAILURE, "failed to register metrics names");
2538 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2539 rte_spinlock_init(&stats[lcore_id].telemetry_lock);
2541 rte_timer_init(&telemetry_timer);
2542 rte_telemetry_register_cmd("/l3fwd-power/stats",
2544 "Returns global power stats. Parameters: None");
2545 rte_eal_mp_remote_launch(main_telemetry_loop, NULL,
2549 if (app_mode == APP_MODE_EMPTY_POLL || app_mode == APP_MODE_TELEMETRY)
2550 launch_timer(rte_lcore_id());
2552 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2553 if (rte_eal_wait_lcore(lcore_id) < 0)
2557 RTE_ETH_FOREACH_DEV(portid)
2559 if ((enabled_port_mask & (1 << portid)) == 0)
2562 rte_eth_dev_stop(portid);
2563 rte_eth_dev_close(portid);
2566 if (app_mode == APP_MODE_EMPTY_POLL)
2567 rte_power_empty_poll_stat_free();
2569 if (app_mode != APP_MODE_TELEMETRY && deinit_power_library())
2570 rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
2572 if (rte_eal_cleanup() < 0)
2573 RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");