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 #ifdef RTE_LIBRTE_TELEMETRY
50 #include <rte_telemetry.h>
53 #include "perf_core.h"
56 #define RTE_LOGTYPE_L3FWD_POWER RTE_LOGTYPE_USER1
58 #define MAX_PKT_BURST 32
60 #define MIN_ZERO_POLL_COUNT 10
63 #define TIMER_NUMBER_PER_SECOND 10
65 #define INTERVALS_PER_SECOND 100
67 #define SCALING_PERIOD (1000000/TIMER_NUMBER_PER_SECOND)
68 #define SCALING_DOWN_TIME_RATIO_THRESHOLD 0.25
70 #define APP_LOOKUP_EXACT_MATCH 0
71 #define APP_LOOKUP_LPM 1
72 #define DO_RFC_1812_CHECKS
74 #ifndef APP_LOOKUP_METHOD
75 #define APP_LOOKUP_METHOD APP_LOOKUP_LPM
78 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
80 #elif (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
83 #error "APP_LOOKUP_METHOD set to incorrect value"
87 #define IPv6_BYTES_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"\
88 "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
89 #define IPv6_BYTES(addr) \
90 addr[0], addr[1], addr[2], addr[3], \
91 addr[4], addr[5], addr[6], addr[7], \
92 addr[8], addr[9], addr[10], addr[11],\
93 addr[12], addr[13],addr[14], addr[15]
96 #define MAX_JUMBO_PKT_LEN 9600
98 #define IPV6_ADDR_LEN 16
100 #define MEMPOOL_CACHE_SIZE 256
103 * This expression is used to calculate the number of mbufs needed depending on
104 * user input, taking into account memory for rx and tx hardware rings, cache
105 * per lcore and mtable per port per lcore. RTE_MAX is used to ensure that
106 * NB_MBUF never goes below a minimum value of 8192.
109 #define NB_MBUF RTE_MAX ( \
110 (nb_ports*nb_rx_queue*nb_rxd + \
111 nb_ports*nb_lcores*MAX_PKT_BURST + \
112 nb_ports*n_tx_queue*nb_txd + \
113 nb_lcores*MEMPOOL_CACHE_SIZE), \
116 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
120 /* Configure how many packets ahead to prefetch, when reading packets */
121 #define PREFETCH_OFFSET 3
124 * Configurable number of RX/TX ring descriptors
126 #define RTE_TEST_RX_DESC_DEFAULT 1024
127 #define RTE_TEST_TX_DESC_DEFAULT 1024
130 * These two thresholds were decided on by running the training algorithm on
131 * a 2.5GHz Xeon. These defaults can be overridden by supplying non-zero values
132 * for the med_threshold and high_threshold parameters on the command line.
134 #define EMPTY_POLL_MED_THRESHOLD 350000UL
135 #define EMPTY_POLL_HGH_THRESHOLD 580000UL
137 #define NUM_TELSTATS RTE_DIM(telstats_strings)
139 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
140 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
142 /* ethernet addresses of ports */
143 static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
145 /* ethernet addresses of ports */
146 static rte_spinlock_t locks[RTE_MAX_ETHPORTS];
148 /* mask of enabled ports */
149 static uint32_t enabled_port_mask = 0;
150 /* Ports set in promiscuous mode off by default. */
151 static int promiscuous_on = 0;
152 /* NUMA is enabled by default. */
153 static int numa_on = 1;
154 static bool empty_poll_stop;
155 static bool empty_poll_train;
156 volatile bool quit_signal;
157 static struct ep_params *ep_params;
158 static struct ep_policy policy;
159 static long ep_med_edpi, ep_hgh_edpi;
160 /* timer to update telemetry every 500ms */
161 static struct rte_timer telemetry_timer;
163 /* stats index returned by metrics lib */
166 struct telstats_name {
167 char name[RTE_ETH_XSTATS_NAME_SIZE];
170 /* telemetry stats to be reported */
171 const struct telstats_name telstats_strings[] = {
177 /* core busyness in percentage */
184 /* reference poll count to measure core busyness */
185 #define DEFAULT_COUNT 10000
187 * reference CYCLES to be used to
188 * measure core busyness based on poll count
190 #define MIN_CYCLES 1500000ULL
191 #define MAX_CYCLES 22000000ULL
194 #define TELEMETRY_INTERVALS_PER_SEC 2
196 static int parse_ptype; /**< Parse packet type using rx callback, and */
197 /**< disabled by default */
205 enum appmode app_mode;
207 enum freq_scale_hint_t
215 struct lcore_rx_queue {
218 enum freq_scale_hint_t freq_up_hint;
219 uint32_t zero_rx_packet_count;
221 } __rte_cache_aligned;
223 #define MAX_RX_QUEUE_PER_LCORE 16
224 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS
225 #define MAX_RX_QUEUE_PER_PORT 128
227 #define MAX_RX_QUEUE_INTERRUPT_PER_PORT 16
230 struct lcore_params lcore_params_array[MAX_LCORE_PARAMS];
231 static struct lcore_params lcore_params_array_default[] = {
243 struct lcore_params *lcore_params = lcore_params_array_default;
244 uint16_t nb_lcore_params = RTE_DIM(lcore_params_array_default);
246 static struct rte_eth_conf port_conf = {
248 .mq_mode = ETH_MQ_RX_RSS,
249 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
251 .offloads = DEV_RX_OFFLOAD_CHECKSUM,
256 .rss_hf = ETH_RSS_UDP,
260 .mq_mode = ETH_MQ_TX_NONE,
267 static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
270 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
273 #include <rte_hash_crc.h>
274 #define DEFAULT_HASH_FUNC rte_hash_crc
276 #include <rte_jhash.h>
277 #define DEFAULT_HASH_FUNC rte_jhash
289 uint8_t ip_dst[IPV6_ADDR_LEN];
290 uint8_t ip_src[IPV6_ADDR_LEN];
296 struct ipv4_l3fwd_route {
297 struct ipv4_5tuple key;
301 struct ipv6_l3fwd_route {
302 struct ipv6_5tuple key;
306 static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
307 {{RTE_IPV4(100,10,0,1), RTE_IPV4(200,10,0,1), 101, 11, IPPROTO_TCP}, 0},
308 {{RTE_IPV4(100,20,0,2), RTE_IPV4(200,20,0,2), 102, 12, IPPROTO_TCP}, 1},
309 {{RTE_IPV4(100,30,0,3), RTE_IPV4(200,30,0,3), 103, 13, IPPROTO_TCP}, 2},
310 {{RTE_IPV4(100,40,0,4), RTE_IPV4(200,40,0,4), 104, 14, IPPROTO_TCP}, 3},
313 static struct ipv6_l3fwd_route ipv6_l3fwd_route_array[] = {
316 {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x02, 0x1b, 0x21, 0xff, 0xfe, 0x91, 0x38, 0x05},
318 {0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x02, 0x1e, 0x67, 0xff, 0xfe, 0x0d, 0xb6, 0x0a},
325 typedef struct rte_hash lookup_struct_t;
326 static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];
327 static lookup_struct_t *ipv6_l3fwd_lookup_struct[NB_SOCKETS];
329 #define L3FWD_HASH_ENTRIES 1024
331 static uint16_t ipv4_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
332 static uint16_t ipv6_l3fwd_out_if[L3FWD_HASH_ENTRIES] __rte_cache_aligned;
335 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
336 struct ipv4_l3fwd_route {
342 static struct ipv4_l3fwd_route ipv4_l3fwd_route_array[] = {
343 {RTE_IPV4(1,1,1,0), 24, 0},
344 {RTE_IPV4(2,1,1,0), 24, 1},
345 {RTE_IPV4(3,1,1,0), 24, 2},
346 {RTE_IPV4(4,1,1,0), 24, 3},
347 {RTE_IPV4(5,1,1,0), 24, 4},
348 {RTE_IPV4(6,1,1,0), 24, 5},
349 {RTE_IPV4(7,1,1,0), 24, 6},
350 {RTE_IPV4(8,1,1,0), 24, 7},
353 #define IPV4_L3FWD_LPM_MAX_RULES 1024
355 typedef struct rte_lpm lookup_struct_t;
356 static lookup_struct_t *ipv4_l3fwd_lookup_struct[NB_SOCKETS];
361 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
363 uint16_t tx_port_id[RTE_MAX_ETHPORTS];
364 uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
365 struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
366 lookup_struct_t * ipv4_lookup_struct;
367 lookup_struct_t * ipv6_lookup_struct;
368 } __rte_cache_aligned;
371 /* total sleep time in ms since last frequency scaling down */
373 /* number of long sleep recently */
374 uint32_t nb_long_sleep;
375 /* freq. scaling up trend */
377 /* total packet processed recently */
378 uint64_t nb_rx_processed;
379 /* total iterations looped recently */
380 uint64_t nb_iteration_looped;
382 * Represents empty and non empty polls
383 * of rte_eth_rx_burst();
384 * ep_nep[0] holds non empty polls
385 * i.e. 0 < nb_rx <= MAX_BURST
386 * ep_nep[1] holds empty polls.
391 * Represents full and empty+partial
392 * polls of rte_eth_rx_burst();
393 * ep_nep[0] holds empty+partial polls.
394 * i.e. 0 <= nb_rx < MAX_BURST
395 * ep_nep[1] holds full polls
396 * i.e. nb_rx == MAX_BURST
400 rte_spinlock_t telemetry_lock;
401 } __rte_cache_aligned;
403 static struct lcore_conf lcore_conf[RTE_MAX_LCORE] __rte_cache_aligned;
404 static struct lcore_stats stats[RTE_MAX_LCORE] __rte_cache_aligned;
405 static struct rte_timer power_timers[RTE_MAX_LCORE];
407 static inline uint32_t power_idle_heuristic(uint32_t zero_rx_packet_count);
408 static inline enum freq_scale_hint_t power_freq_scaleup_heuristic( \
409 unsigned int lcore_id, uint16_t port_id, uint16_t queue_id);
413 * These defaults are using the max frequency index (1), a medium index (9)
414 * and a typical low frequency index (14). These can be adjusted to use
415 * different indexes using the relevant command line parameters.
417 static uint8_t freq_tlb[] = {14, 9, 1};
419 static int is_done(void)
424 /* exit signal handler */
426 signal_exit_now(int sigtype)
429 if (sigtype == SIGINT)
434 /* Freqency scale down timer callback */
436 power_timer_cb(__rte_unused struct rte_timer *tim,
437 __rte_unused void *arg)
440 float sleep_time_ratio;
441 unsigned lcore_id = rte_lcore_id();
443 /* accumulate total execution time in us when callback is invoked */
444 sleep_time_ratio = (float)(stats[lcore_id].sleep_time) /
445 (float)SCALING_PERIOD;
447 * check whether need to scale down frequency a step if it sleep a lot.
449 if (sleep_time_ratio >= SCALING_DOWN_TIME_RATIO_THRESHOLD) {
450 if (rte_power_freq_down)
451 rte_power_freq_down(lcore_id);
453 else if ( (unsigned)(stats[lcore_id].nb_rx_processed /
454 stats[lcore_id].nb_iteration_looped) < MAX_PKT_BURST) {
456 * scale down a step if average packet per iteration less
459 if (rte_power_freq_down)
460 rte_power_freq_down(lcore_id);
464 * initialize another timer according to current frequency to ensure
465 * timer interval is relatively fixed.
467 hz = rte_get_timer_hz();
468 rte_timer_reset(&power_timers[lcore_id], hz/TIMER_NUMBER_PER_SECOND,
469 SINGLE, lcore_id, power_timer_cb, NULL);
471 stats[lcore_id].nb_rx_processed = 0;
472 stats[lcore_id].nb_iteration_looped = 0;
474 stats[lcore_id].sleep_time = 0;
477 /* Enqueue a single packet, and send burst if queue is filled */
479 send_single_packet(struct rte_mbuf *m, uint16_t port)
482 struct lcore_conf *qconf;
484 lcore_id = rte_lcore_id();
485 qconf = &lcore_conf[lcore_id];
487 rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
488 qconf->tx_buffer[port], m);
493 #ifdef DO_RFC_1812_CHECKS
495 is_valid_ipv4_pkt(struct rte_ipv4_hdr *pkt, uint32_t link_len)
497 /* From http://www.rfc-editor.org/rfc/rfc1812.txt section 5.2.2 */
499 * 1. The packet length reported by the Link Layer must be large
500 * enough to hold the minimum length legal IP datagram (20 bytes).
502 if (link_len < sizeof(struct rte_ipv4_hdr))
505 /* 2. The IP checksum must be correct. */
506 /* this is checked in H/W */
509 * 3. The IP version number must be 4. If the version number is not 4
510 * then the packet may be another version of IP, such as IPng or
513 if (((pkt->version_ihl) >> 4) != 4)
516 * 4. The IP header length field must be large enough to hold the
517 * minimum length legal IP datagram (20 bytes = 5 words).
519 if ((pkt->version_ihl & 0xf) < 5)
523 * 5. The IP total length field must be large enough to hold the IP
524 * datagram header, whose length is specified in the IP header length
527 if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr))
534 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
536 print_ipv4_key(struct ipv4_5tuple key)
538 printf("IP dst = %08x, IP src = %08x, port dst = %d, port src = %d, "
539 "proto = %d\n", (unsigned)key.ip_dst, (unsigned)key.ip_src,
540 key.port_dst, key.port_src, key.proto);
543 print_ipv6_key(struct ipv6_5tuple key)
545 printf( "IP dst = " IPv6_BYTES_FMT ", IP src = " IPv6_BYTES_FMT ", "
546 "port dst = %d, port src = %d, proto = %d\n",
547 IPv6_BYTES(key.ip_dst), IPv6_BYTES(key.ip_src),
548 key.port_dst, key.port_src, key.proto);
551 static inline uint16_t
552 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
553 lookup_struct_t * ipv4_l3fwd_lookup_struct)
555 struct ipv4_5tuple key;
556 struct rte_tcp_hdr *tcp;
557 struct rte_udp_hdr *udp;
560 key.ip_dst = rte_be_to_cpu_32(ipv4_hdr->dst_addr);
561 key.ip_src = rte_be_to_cpu_32(ipv4_hdr->src_addr);
562 key.proto = ipv4_hdr->next_proto_id;
564 switch (ipv4_hdr->next_proto_id) {
566 tcp = (struct rte_tcp_hdr *)((unsigned char *)ipv4_hdr +
567 sizeof(struct rte_ipv4_hdr));
568 key.port_dst = rte_be_to_cpu_16(tcp->dst_port);
569 key.port_src = rte_be_to_cpu_16(tcp->src_port);
573 udp = (struct rte_udp_hdr *)((unsigned char *)ipv4_hdr +
574 sizeof(struct rte_ipv4_hdr));
575 key.port_dst = rte_be_to_cpu_16(udp->dst_port);
576 key.port_src = rte_be_to_cpu_16(udp->src_port);
585 /* Find destination port */
586 ret = rte_hash_lookup(ipv4_l3fwd_lookup_struct, (const void *)&key);
587 return ((ret < 0) ? portid : ipv4_l3fwd_out_if[ret]);
590 static inline uint16_t
591 get_ipv6_dst_port(struct rte_ipv6_hdr *ipv6_hdr, uint16_t portid,
592 lookup_struct_t *ipv6_l3fwd_lookup_struct)
594 struct ipv6_5tuple key;
595 struct rte_tcp_hdr *tcp;
596 struct rte_udp_hdr *udp;
599 memcpy(key.ip_dst, ipv6_hdr->dst_addr, IPV6_ADDR_LEN);
600 memcpy(key.ip_src, ipv6_hdr->src_addr, IPV6_ADDR_LEN);
602 key.proto = ipv6_hdr->proto;
604 switch (ipv6_hdr->proto) {
606 tcp = (struct rte_tcp_hdr *)((unsigned char *) ipv6_hdr +
607 sizeof(struct rte_ipv6_hdr));
608 key.port_dst = rte_be_to_cpu_16(tcp->dst_port);
609 key.port_src = rte_be_to_cpu_16(tcp->src_port);
613 udp = (struct rte_udp_hdr *)((unsigned char *) ipv6_hdr +
614 sizeof(struct rte_ipv6_hdr));
615 key.port_dst = rte_be_to_cpu_16(udp->dst_port);
616 key.port_src = rte_be_to_cpu_16(udp->src_port);
625 /* Find destination port */
626 ret = rte_hash_lookup(ipv6_l3fwd_lookup_struct, (const void *)&key);
627 return ((ret < 0) ? portid : ipv6_l3fwd_out_if[ret]);
631 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
632 static inline uint16_t
633 get_ipv4_dst_port(struct rte_ipv4_hdr *ipv4_hdr, uint16_t portid,
634 lookup_struct_t *ipv4_l3fwd_lookup_struct)
638 return ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct,
639 rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0)?
645 parse_ptype_one(struct rte_mbuf *m)
647 struct rte_ether_hdr *eth_hdr;
648 uint32_t packet_type = RTE_PTYPE_UNKNOWN;
651 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
652 ether_type = eth_hdr->ether_type;
653 if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
654 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
655 else if (ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6))
656 packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
658 m->packet_type = packet_type;
662 cb_parse_ptype(uint16_t port __rte_unused, uint16_t queue __rte_unused,
663 struct rte_mbuf *pkts[], uint16_t nb_pkts,
664 uint16_t max_pkts __rte_unused,
665 void *user_param __rte_unused)
669 for (i = 0; i < nb_pkts; ++i)
670 parse_ptype_one(pkts[i]);
676 add_cb_parse_ptype(uint16_t portid, uint16_t queueid)
678 printf("Port %d: softly parse packet type info\n", portid);
679 if (rte_eth_add_rx_callback(portid, queueid, cb_parse_ptype, NULL))
682 printf("Failed to add rx callback: port=%d\n", portid);
687 l3fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
688 struct lcore_conf *qconf)
690 struct rte_ether_hdr *eth_hdr;
691 struct rte_ipv4_hdr *ipv4_hdr;
695 eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
697 if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) {
698 /* Handle IPv4 headers.*/
700 rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
701 sizeof(struct rte_ether_hdr));
703 #ifdef DO_RFC_1812_CHECKS
704 /* Check to make sure the packet is valid (RFC1812) */
705 if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len) < 0) {
711 dst_port = get_ipv4_dst_port(ipv4_hdr, portid,
712 qconf->ipv4_lookup_struct);
713 if (dst_port >= RTE_MAX_ETHPORTS ||
714 (enabled_port_mask & 1 << dst_port) == 0)
717 /* 02:00:00:00:00:xx */
718 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
719 *((uint64_t *)d_addr_bytes) =
720 0x000000000002 + ((uint64_t)dst_port << 40);
722 #ifdef DO_RFC_1812_CHECKS
723 /* Update time to live and header checksum */
724 --(ipv4_hdr->time_to_live);
725 ++(ipv4_hdr->hdr_checksum);
729 rte_ether_addr_copy(&ports_eth_addr[dst_port],
732 send_single_packet(m, dst_port);
733 } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) {
734 /* Handle IPv6 headers.*/
735 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
736 struct rte_ipv6_hdr *ipv6_hdr;
739 rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
740 sizeof(struct rte_ether_hdr));
742 dst_port = get_ipv6_dst_port(ipv6_hdr, portid,
743 qconf->ipv6_lookup_struct);
745 if (dst_port >= RTE_MAX_ETHPORTS ||
746 (enabled_port_mask & 1 << dst_port) == 0)
749 /* 02:00:00:00:00:xx */
750 d_addr_bytes = ð_hdr->d_addr.addr_bytes[0];
751 *((uint64_t *)d_addr_bytes) =
752 0x000000000002 + ((uint64_t)dst_port << 40);
755 rte_ether_addr_copy(&ports_eth_addr[dst_port],
758 send_single_packet(m, dst_port);
760 /* We don't currently handle IPv6 packets in LPM mode. */
768 #define MINIMUM_SLEEP_TIME 1
769 #define SUSPEND_THRESHOLD 300
771 static inline uint32_t
772 power_idle_heuristic(uint32_t zero_rx_packet_count)
774 /* If zero count is less than 100, sleep 1us */
775 if (zero_rx_packet_count < SUSPEND_THRESHOLD)
776 return MINIMUM_SLEEP_TIME;
777 /* If zero count is less than 1000, sleep 100 us which is the
778 minimum latency switching from C3/C6 to C0
781 return SUSPEND_THRESHOLD;
784 static inline enum freq_scale_hint_t
785 power_freq_scaleup_heuristic(unsigned lcore_id,
789 uint32_t rxq_count = rte_eth_rx_queue_count(port_id, queue_id);
791 * HW Rx queue size is 128 by default, Rx burst read at maximum 32 entries
794 #define FREQ_GEAR1_RX_PACKET_THRESHOLD MAX_PKT_BURST
795 #define FREQ_GEAR2_RX_PACKET_THRESHOLD (MAX_PKT_BURST*2)
796 #define FREQ_GEAR3_RX_PACKET_THRESHOLD (MAX_PKT_BURST*3)
797 #define FREQ_UP_TREND1_ACC 1
798 #define FREQ_UP_TREND2_ACC 100
799 #define FREQ_UP_THRESHOLD 10000
801 if (likely(rxq_count > FREQ_GEAR3_RX_PACKET_THRESHOLD)) {
802 stats[lcore_id].trend = 0;
804 } else if (likely(rxq_count > FREQ_GEAR2_RX_PACKET_THRESHOLD))
805 stats[lcore_id].trend += FREQ_UP_TREND2_ACC;
806 else if (likely(rxq_count > FREQ_GEAR1_RX_PACKET_THRESHOLD))
807 stats[lcore_id].trend += FREQ_UP_TREND1_ACC;
809 if (likely(stats[lcore_id].trend > FREQ_UP_THRESHOLD)) {
810 stats[lcore_id].trend = 0;
818 * force polling thread sleep until one-shot rx interrupt triggers
827 sleep_until_rx_interrupt(int num)
829 struct rte_epoll_event event[num];
835 RTE_LOG(INFO, L3FWD_POWER,
836 "lcore %u sleeps until interrupt triggers\n",
839 n = rte_epoll_wait(RTE_EPOLL_PER_THREAD, event, num, -1);
840 for (i = 0; i < n; i++) {
841 data = event[i].epdata.data;
842 port_id = ((uintptr_t)data) >> CHAR_BIT;
843 queue_id = ((uintptr_t)data) &
844 RTE_LEN2MASK(CHAR_BIT, uint8_t);
845 RTE_LOG(INFO, L3FWD_POWER,
846 "lcore %u is waked up from rx interrupt on"
847 " port %d queue %d\n",
848 rte_lcore_id(), port_id, queue_id);
854 static void turn_on_off_intr(struct lcore_conf *qconf, bool on)
857 struct lcore_rx_queue *rx_queue;
861 for (i = 0; i < qconf->n_rx_queue; ++i) {
862 rx_queue = &(qconf->rx_queue_list[i]);
863 port_id = rx_queue->port_id;
864 queue_id = rx_queue->queue_id;
866 rte_spinlock_lock(&(locks[port_id]));
868 rte_eth_dev_rx_intr_enable(port_id, queue_id);
870 rte_eth_dev_rx_intr_disable(port_id, queue_id);
871 rte_spinlock_unlock(&(locks[port_id]));
875 static int event_register(struct lcore_conf *qconf)
877 struct lcore_rx_queue *rx_queue;
884 for (i = 0; i < qconf->n_rx_queue; ++i) {
885 rx_queue = &(qconf->rx_queue_list[i]);
886 portid = rx_queue->port_id;
887 queueid = rx_queue->queue_id;
888 data = portid << CHAR_BIT | queueid;
890 ret = rte_eth_dev_rx_intr_ctl_q(portid, queueid,
891 RTE_EPOLL_PER_THREAD,
893 (void *)((uintptr_t)data));
900 /* main processing loop */
902 main_telemetry_loop(__rte_unused void *dummy)
904 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
905 unsigned int lcore_id;
906 uint64_t prev_tsc, diff_tsc, cur_tsc, prev_tel_tsc;
910 struct lcore_conf *qconf;
911 struct lcore_rx_queue *rx_queue;
912 uint64_t ep_nep[2] = {0}, fp_nfp[2] = {0};
916 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) /
917 US_PER_S * BURST_TX_DRAIN_US;
923 lcore_id = rte_lcore_id();
924 qconf = &lcore_conf[lcore_id];
926 if (qconf->n_rx_queue == 0) {
927 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
932 RTE_LOG(INFO, L3FWD_POWER, "entering main telemetry loop on lcore %u\n",
935 for (i = 0; i < qconf->n_rx_queue; i++) {
936 portid = qconf->rx_queue_list[i].port_id;
937 queueid = qconf->rx_queue_list[i].queue_id;
938 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
939 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
944 cur_tsc = rte_rdtsc();
946 * TX burst queue drain
948 diff_tsc = cur_tsc - prev_tsc;
949 if (unlikely(diff_tsc > drain_tsc)) {
950 for (i = 0; i < qconf->n_tx_port; ++i) {
951 portid = qconf->tx_port_id[i];
952 rte_eth_tx_buffer_flush(portid,
953 qconf->tx_queue_id[portid],
954 qconf->tx_buffer[portid]);
960 * Read packet from RX queues
962 for (i = 0; i < qconf->n_rx_queue; ++i) {
963 rx_queue = &(qconf->rx_queue_list[i]);
964 portid = rx_queue->port_id;
965 queueid = rx_queue->queue_id;
967 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
969 ep_nep[nb_rx == 0]++;
970 fp_nfp[nb_rx == MAX_PKT_BURST]++;
972 if (unlikely(nb_rx == 0))
975 /* Prefetch first packets */
976 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
977 rte_prefetch0(rte_pktmbuf_mtod(
978 pkts_burst[j], void *));
981 /* Prefetch and forward already prefetched packets */
982 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
983 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
984 j + PREFETCH_OFFSET], void *));
985 l3fwd_simple_forward(pkts_burst[j], portid,
989 /* Forward remaining prefetched packets */
990 for (; j < nb_rx; j++) {
991 l3fwd_simple_forward(pkts_burst[j], portid,
995 if (unlikely(poll_count >= DEFAULT_COUNT)) {
996 diff_tsc = cur_tsc - prev_tel_tsc;
997 if (diff_tsc >= MAX_CYCLES) {
999 } else if (diff_tsc > MIN_CYCLES &&
1000 diff_tsc < MAX_CYCLES) {
1001 br = (diff_tsc * 100) / MAX_CYCLES;
1006 prev_tel_tsc = cur_tsc;
1007 /* update stats for telemetry */
1008 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
1009 stats[lcore_id].ep_nep[0] = ep_nep[0];
1010 stats[lcore_id].ep_nep[1] = ep_nep[1];
1011 stats[lcore_id].fp_nfp[0] = fp_nfp[0];
1012 stats[lcore_id].fp_nfp[1] = fp_nfp[1];
1013 stats[lcore_id].br = br;
1014 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
1020 /* main processing loop */
1022 main_empty_poll_loop(__rte_unused void *dummy)
1024 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1025 unsigned int lcore_id;
1026 uint64_t prev_tsc, diff_tsc, cur_tsc;
1030 struct lcore_conf *qconf;
1031 struct lcore_rx_queue *rx_queue;
1033 const uint64_t drain_tsc =
1034 (rte_get_tsc_hz() + US_PER_S - 1) /
1035 US_PER_S * BURST_TX_DRAIN_US;
1039 lcore_id = rte_lcore_id();
1040 qconf = &lcore_conf[lcore_id];
1042 if (qconf->n_rx_queue == 0) {
1043 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n",
1048 for (i = 0; i < qconf->n_rx_queue; i++) {
1049 portid = qconf->rx_queue_list[i].port_id;
1050 queueid = qconf->rx_queue_list[i].queue_id;
1051 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1052 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1055 while (!is_done()) {
1056 stats[lcore_id].nb_iteration_looped++;
1058 cur_tsc = rte_rdtsc();
1060 * TX burst queue drain
1062 diff_tsc = cur_tsc - prev_tsc;
1063 if (unlikely(diff_tsc > drain_tsc)) {
1064 for (i = 0; i < qconf->n_tx_port; ++i) {
1065 portid = qconf->tx_port_id[i];
1066 rte_eth_tx_buffer_flush(portid,
1067 qconf->tx_queue_id[portid],
1068 qconf->tx_buffer[portid]);
1074 * Read packet from RX queues
1076 for (i = 0; i < qconf->n_rx_queue; ++i) {
1077 rx_queue = &(qconf->rx_queue_list[i]);
1078 rx_queue->idle_hint = 0;
1079 portid = rx_queue->port_id;
1080 queueid = rx_queue->queue_id;
1082 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1085 stats[lcore_id].nb_rx_processed += nb_rx;
1089 rte_power_empty_poll_stat_update(lcore_id);
1093 rte_power_poll_stat_update(lcore_id, nb_rx);
1097 /* Prefetch first packets */
1098 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1099 rte_prefetch0(rte_pktmbuf_mtod(
1100 pkts_burst[j], void *));
1103 /* Prefetch and forward already prefetched packets */
1104 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1105 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1106 j + PREFETCH_OFFSET],
1108 l3fwd_simple_forward(pkts_burst[j], portid,
1112 /* Forward remaining prefetched packets */
1113 for (; j < nb_rx; j++) {
1114 l3fwd_simple_forward(pkts_burst[j], portid,
1124 /* main processing loop */
1126 main_loop(__rte_unused void *dummy)
1128 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1130 uint64_t prev_tsc, diff_tsc, cur_tsc, tim_res_tsc, hz;
1131 uint64_t prev_tsc_power = 0, cur_tsc_power, diff_tsc_power;
1135 struct lcore_conf *qconf;
1136 struct lcore_rx_queue *rx_queue;
1137 enum freq_scale_hint_t lcore_scaleup_hint;
1138 uint32_t lcore_rx_idle_count = 0;
1139 uint32_t lcore_idle_hint = 0;
1142 const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
1145 hz = rte_get_timer_hz();
1146 tim_res_tsc = hz/TIMER_NUMBER_PER_SECOND;
1148 lcore_id = rte_lcore_id();
1149 qconf = &lcore_conf[lcore_id];
1151 if (qconf->n_rx_queue == 0) {
1152 RTE_LOG(INFO, L3FWD_POWER, "lcore %u has nothing to do\n", lcore_id);
1156 RTE_LOG(INFO, L3FWD_POWER, "entering main loop on lcore %u\n", lcore_id);
1158 for (i = 0; i < qconf->n_rx_queue; i++) {
1159 portid = qconf->rx_queue_list[i].port_id;
1160 queueid = qconf->rx_queue_list[i].queue_id;
1161 RTE_LOG(INFO, L3FWD_POWER, " -- lcoreid=%u portid=%u "
1162 "rxqueueid=%hhu\n", lcore_id, portid, queueid);
1165 /* add into event wait list */
1166 if (event_register(qconf) == 0)
1169 RTE_LOG(INFO, L3FWD_POWER, "RX interrupt won't enable.\n");
1171 while (!is_done()) {
1172 stats[lcore_id].nb_iteration_looped++;
1174 cur_tsc = rte_rdtsc();
1175 cur_tsc_power = cur_tsc;
1178 * TX burst queue drain
1180 diff_tsc = cur_tsc - prev_tsc;
1181 if (unlikely(diff_tsc > drain_tsc)) {
1182 for (i = 0; i < qconf->n_tx_port; ++i) {
1183 portid = qconf->tx_port_id[i];
1184 rte_eth_tx_buffer_flush(portid,
1185 qconf->tx_queue_id[portid],
1186 qconf->tx_buffer[portid]);
1191 diff_tsc_power = cur_tsc_power - prev_tsc_power;
1192 if (diff_tsc_power > tim_res_tsc) {
1194 prev_tsc_power = cur_tsc_power;
1199 * Read packet from RX queues
1201 lcore_scaleup_hint = FREQ_CURRENT;
1202 lcore_rx_idle_count = 0;
1203 for (i = 0; i < qconf->n_rx_queue; ++i) {
1204 rx_queue = &(qconf->rx_queue_list[i]);
1205 rx_queue->idle_hint = 0;
1206 portid = rx_queue->port_id;
1207 queueid = rx_queue->queue_id;
1209 nb_rx = rte_eth_rx_burst(portid, queueid, pkts_burst,
1212 stats[lcore_id].nb_rx_processed += nb_rx;
1213 if (unlikely(nb_rx == 0)) {
1215 * no packet received from rx queue, try to
1216 * sleep for a while forcing CPU enter deeper
1219 rx_queue->zero_rx_packet_count++;
1221 if (rx_queue->zero_rx_packet_count <=
1222 MIN_ZERO_POLL_COUNT)
1225 rx_queue->idle_hint = power_idle_heuristic(\
1226 rx_queue->zero_rx_packet_count);
1227 lcore_rx_idle_count++;
1229 rx_queue->zero_rx_packet_count = 0;
1232 * do not scale up frequency immediately as
1233 * user to kernel space communication is costly
1234 * which might impact packet I/O for received
1237 rx_queue->freq_up_hint =
1238 power_freq_scaleup_heuristic(lcore_id,
1242 /* Prefetch first packets */
1243 for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) {
1244 rte_prefetch0(rte_pktmbuf_mtod(
1245 pkts_burst[j], void *));
1248 /* Prefetch and forward already prefetched packets */
1249 for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) {
1250 rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[
1251 j + PREFETCH_OFFSET], void *));
1252 l3fwd_simple_forward(pkts_burst[j], portid,
1256 /* Forward remaining prefetched packets */
1257 for (; j < nb_rx; j++) {
1258 l3fwd_simple_forward(pkts_burst[j], portid,
1263 if (likely(lcore_rx_idle_count != qconf->n_rx_queue)) {
1264 for (i = 1, lcore_scaleup_hint =
1265 qconf->rx_queue_list[0].freq_up_hint;
1266 i < qconf->n_rx_queue; ++i) {
1267 rx_queue = &(qconf->rx_queue_list[i]);
1268 if (rx_queue->freq_up_hint >
1270 lcore_scaleup_hint =
1271 rx_queue->freq_up_hint;
1274 if (lcore_scaleup_hint == FREQ_HIGHEST) {
1275 if (rte_power_freq_max)
1276 rte_power_freq_max(lcore_id);
1277 } else if (lcore_scaleup_hint == FREQ_HIGHER) {
1278 if (rte_power_freq_up)
1279 rte_power_freq_up(lcore_id);
1283 * All Rx queues empty in recent consecutive polls,
1284 * sleep in a conservative manner, meaning sleep as
1287 for (i = 1, lcore_idle_hint =
1288 qconf->rx_queue_list[0].idle_hint;
1289 i < qconf->n_rx_queue; ++i) {
1290 rx_queue = &(qconf->rx_queue_list[i]);
1291 if (rx_queue->idle_hint < lcore_idle_hint)
1292 lcore_idle_hint = rx_queue->idle_hint;
1295 if (lcore_idle_hint < SUSPEND_THRESHOLD)
1297 * execute "pause" instruction to avoid context
1298 * switch which generally take hundred of
1299 * microseconds for short sleep.
1301 rte_delay_us(lcore_idle_hint);
1303 /* suspend until rx interrupt triggers */
1305 turn_on_off_intr(qconf, 1);
1306 sleep_until_rx_interrupt(
1308 turn_on_off_intr(qconf, 0);
1310 * start receiving packets immediately
1315 stats[lcore_id].sleep_time += lcore_idle_hint;
1323 check_lcore_params(void)
1325 uint8_t queue, lcore;
1329 for (i = 0; i < nb_lcore_params; ++i) {
1330 queue = lcore_params[i].queue_id;
1331 if (queue >= MAX_RX_QUEUE_PER_PORT) {
1332 printf("invalid queue number: %hhu\n", queue);
1335 lcore = lcore_params[i].lcore_id;
1336 if (!rte_lcore_is_enabled(lcore)) {
1337 printf("error: lcore %hhu is not enabled in lcore "
1341 if ((socketid = rte_lcore_to_socket_id(lcore) != 0) &&
1343 printf("warning: lcore %hhu is on socket %d with numa "
1344 "off\n", lcore, socketid);
1346 if (app_mode == APP_MODE_TELEMETRY && lcore == rte_lcore_id()) {
1347 printf("cannot enable master core %d in config for telemetry mode\n",
1356 check_port_config(void)
1361 for (i = 0; i < nb_lcore_params; ++i) {
1362 portid = lcore_params[i].port_id;
1363 if ((enabled_port_mask & (1 << portid)) == 0) {
1364 printf("port %u is not enabled in port mask\n",
1368 if (!rte_eth_dev_is_valid_port(portid)) {
1369 printf("port %u is not present on the board\n",
1378 get_port_n_rx_queues(const uint16_t port)
1383 for (i = 0; i < nb_lcore_params; ++i) {
1384 if (lcore_params[i].port_id == port &&
1385 lcore_params[i].queue_id > queue)
1386 queue = lcore_params[i].queue_id;
1388 return (uint8_t)(++queue);
1392 init_lcore_rx_queues(void)
1394 uint16_t i, nb_rx_queue;
1397 for (i = 0; i < nb_lcore_params; ++i) {
1398 lcore = lcore_params[i].lcore_id;
1399 nb_rx_queue = lcore_conf[lcore].n_rx_queue;
1400 if (nb_rx_queue >= MAX_RX_QUEUE_PER_LCORE) {
1401 printf("error: too many queues (%u) for lcore: %u\n",
1402 (unsigned)nb_rx_queue + 1, (unsigned)lcore);
1405 lcore_conf[lcore].rx_queue_list[nb_rx_queue].port_id =
1406 lcore_params[i].port_id;
1407 lcore_conf[lcore].rx_queue_list[nb_rx_queue].queue_id =
1408 lcore_params[i].queue_id;
1409 lcore_conf[lcore].n_rx_queue++;
1417 print_usage(const char *prgname)
1419 printf ("%s [EAL options] -- -p PORTMASK -P"
1420 " [--config (port,queue,lcore)[,(port,queue,lcore]]"
1421 " [--high-perf-cores CORELIST"
1422 " [--perf-config (port,queue,hi_perf,lcore_index)[,(port,queue,hi_perf,lcore_index]]"
1423 " [--enable-jumbo [--max-pkt-len PKTLEN]]\n"
1424 " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
1425 " -P : enable promiscuous mode\n"
1426 " --config (port,queue,lcore): rx queues configuration\n"
1427 " --high-perf-cores CORELIST: list of high performance cores\n"
1428 " --perf-config: similar as config, cores specified as indices"
1429 " for bins containing high or regular performance cores\n"
1430 " --no-numa: optional, disable numa awareness\n"
1431 " --enable-jumbo: enable jumbo frame"
1432 " which max packet len is PKTLEN in decimal (64-9600)\n"
1433 " --parse-ptype: parse packet type by software\n"
1434 " --empty-poll: enable empty poll detection"
1435 " follow (training_flag, high_threshold, med_threshold)\n"
1436 " --telemetry: enable telemetry mode, to update"
1437 " empty polls, full polls, and core busyness to telemetry\n",
1441 static int parse_max_pkt_len(const char *pktlen)
1446 /* parse decimal string */
1447 len = strtoul(pktlen, &end, 10);
1448 if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
1458 parse_portmask(const char *portmask)
1463 /* parse hexadecimal string */
1464 pm = strtoul(portmask, &end, 16);
1465 if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
1475 parse_config(const char *q_arg)
1478 const char *p, *p0 = q_arg;
1486 unsigned long int_fld[_NUM_FLD];
1487 char *str_fld[_NUM_FLD];
1491 nb_lcore_params = 0;
1493 while ((p = strchr(p0,'(')) != NULL) {
1495 if((p0 = strchr(p,')')) == NULL)
1499 if(size >= sizeof(s))
1502 snprintf(s, sizeof(s), "%.*s", size, p);
1503 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') !=
1506 for (i = 0; i < _NUM_FLD; i++){
1508 int_fld[i] = strtoul(str_fld[i], &end, 0);
1509 if (errno != 0 || end == str_fld[i] || int_fld[i] >
1513 if (nb_lcore_params >= MAX_LCORE_PARAMS) {
1514 printf("exceeded max number of lcore params: %hu\n",
1518 lcore_params_array[nb_lcore_params].port_id =
1519 (uint8_t)int_fld[FLD_PORT];
1520 lcore_params_array[nb_lcore_params].queue_id =
1521 (uint8_t)int_fld[FLD_QUEUE];
1522 lcore_params_array[nb_lcore_params].lcore_id =
1523 (uint8_t)int_fld[FLD_LCORE];
1526 lcore_params = lcore_params_array;
1531 parse_ep_config(const char *q_arg)
1534 const char *p = q_arg;
1544 ep_med_edpi = EMPTY_POLL_MED_THRESHOLD;
1545 ep_hgh_edpi = EMPTY_POLL_MED_THRESHOLD;
1547 strlcpy(s, p, sizeof(s));
1549 num_arg = rte_strsplit(s, sizeof(s), str_fld, 3, ',');
1551 empty_poll_train = false;
1558 training_flag = strtoul(str_fld[0], &end, 0);
1559 med_edpi = strtoul(str_fld[1], &end, 0);
1560 hgh_edpi = strtoul(str_fld[2], &end, 0);
1562 if (training_flag == 1)
1563 empty_poll_train = true;
1566 ep_med_edpi = med_edpi;
1569 ep_hgh_edpi = hgh_edpi;
1579 #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
1580 #define CMD_LINE_OPT_TELEMETRY "telemetry"
1582 /* Parse the argument given in the command line of the application */
1584 parse_args(int argc, char **argv)
1590 char *prgname = argv[0];
1591 static struct option lgopts[] = {
1592 {"config", 1, 0, 0},
1593 {"perf-config", 1, 0, 0},
1594 {"high-perf-cores", 1, 0, 0},
1595 {"no-numa", 0, 0, 0},
1596 {"enable-jumbo", 0, 0, 0},
1597 {"empty-poll", 1, 0, 0},
1598 {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
1599 {CMD_LINE_OPT_TELEMETRY, 0, 0, 0},
1605 while ((opt = getopt_long(argc, argvopt, "p:l:m:h:P",
1606 lgopts, &option_index)) != EOF) {
1611 enabled_port_mask = parse_portmask(optarg);
1612 if (enabled_port_mask == 0) {
1613 printf("invalid portmask\n");
1614 print_usage(prgname);
1619 printf("Promiscuous mode selected\n");
1623 limit = parse_max_pkt_len(optarg);
1624 freq_tlb[LOW] = limit;
1627 limit = parse_max_pkt_len(optarg);
1628 freq_tlb[MED] = limit;
1631 limit = parse_max_pkt_len(optarg);
1632 freq_tlb[HGH] = limit;
1636 if (!strncmp(lgopts[option_index].name, "config", 6)) {
1637 ret = parse_config(optarg);
1639 printf("invalid config\n");
1640 print_usage(prgname);
1645 if (!strncmp(lgopts[option_index].name,
1646 "perf-config", 11)) {
1647 ret = parse_perf_config(optarg);
1649 printf("invalid perf-config\n");
1650 print_usage(prgname);
1655 if (!strncmp(lgopts[option_index].name,
1656 "high-perf-cores", 15)) {
1657 ret = parse_perf_core_list(optarg);
1659 printf("invalid high-perf-cores\n");
1660 print_usage(prgname);
1665 if (!strncmp(lgopts[option_index].name,
1667 printf("numa is disabled \n");
1671 if (!strncmp(lgopts[option_index].name,
1672 "empty-poll", 10)) {
1673 if (app_mode == APP_MODE_TELEMETRY) {
1674 printf(" empty-poll cannot be enabled as telemetry mode is enabled\n");
1677 app_mode = APP_MODE_EMPTY_POLL;
1678 ret = parse_ep_config(optarg);
1681 printf("invalid empty poll config\n");
1682 print_usage(prgname);
1685 printf("empty-poll is enabled\n");
1688 if (!strncmp(lgopts[option_index].name,
1689 CMD_LINE_OPT_TELEMETRY,
1690 sizeof(CMD_LINE_OPT_TELEMETRY))) {
1691 if (app_mode == APP_MODE_EMPTY_POLL) {
1692 printf("telemetry mode cannot be enabled as empty poll mode is enabled\n");
1695 app_mode = APP_MODE_TELEMETRY;
1696 printf("telemetry mode is enabled\n");
1699 if (!strncmp(lgopts[option_index].name,
1700 "enable-jumbo", 12)) {
1701 struct option lenopts =
1702 {"max-pkt-len", required_argument, \
1705 printf("jumbo frame is enabled \n");
1706 port_conf.rxmode.offloads |=
1707 DEV_RX_OFFLOAD_JUMBO_FRAME;
1708 port_conf.txmode.offloads |=
1709 DEV_TX_OFFLOAD_MULTI_SEGS;
1712 * if no max-pkt-len set, use the default value
1715 if (0 == getopt_long(argc, argvopt, "",
1716 &lenopts, &option_index)) {
1717 ret = parse_max_pkt_len(optarg);
1719 (ret > MAX_JUMBO_PKT_LEN)){
1720 printf("invalid packet "
1722 print_usage(prgname);
1725 port_conf.rxmode.max_rx_pkt_len = ret;
1727 printf("set jumbo frame "
1728 "max packet length to %u\n",
1729 (unsigned int)port_conf.rxmode.max_rx_pkt_len);
1732 if (!strncmp(lgopts[option_index].name,
1733 CMD_LINE_OPT_PARSE_PTYPE,
1734 sizeof(CMD_LINE_OPT_PARSE_PTYPE))) {
1735 printf("soft parse-ptype is enabled\n");
1742 print_usage(prgname);
1748 argv[optind-1] = prgname;
1751 optind = 1; /* reset getopt lib */
1756 print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr)
1758 char buf[RTE_ETHER_ADDR_FMT_SIZE];
1759 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
1760 printf("%s%s", name, buf);
1763 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1765 setup_hash(int socketid)
1767 struct rte_hash_parameters ipv4_l3fwd_hash_params = {
1769 .entries = L3FWD_HASH_ENTRIES,
1770 .key_len = sizeof(struct ipv4_5tuple),
1771 .hash_func = DEFAULT_HASH_FUNC,
1772 .hash_func_init_val = 0,
1775 struct rte_hash_parameters ipv6_l3fwd_hash_params = {
1777 .entries = L3FWD_HASH_ENTRIES,
1778 .key_len = sizeof(struct ipv6_5tuple),
1779 .hash_func = DEFAULT_HASH_FUNC,
1780 .hash_func_init_val = 0,
1787 /* create ipv4 hash */
1788 snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
1789 ipv4_l3fwd_hash_params.name = s;
1790 ipv4_l3fwd_hash_params.socket_id = socketid;
1791 ipv4_l3fwd_lookup_struct[socketid] =
1792 rte_hash_create(&ipv4_l3fwd_hash_params);
1793 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1794 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1795 "socket %d\n", socketid);
1797 /* create ipv6 hash */
1798 snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
1799 ipv6_l3fwd_hash_params.name = s;
1800 ipv6_l3fwd_hash_params.socket_id = socketid;
1801 ipv6_l3fwd_lookup_struct[socketid] =
1802 rte_hash_create(&ipv6_l3fwd_hash_params);
1803 if (ipv6_l3fwd_lookup_struct[socketid] == NULL)
1804 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
1805 "socket %d\n", socketid);
1808 /* populate the ipv4 hash */
1809 for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
1810 ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
1811 (void *) &ipv4_l3fwd_route_array[i].key);
1813 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1814 "l3fwd hash on socket %d\n", i, socketid);
1816 ipv4_l3fwd_out_if[ret] = ipv4_l3fwd_route_array[i].if_out;
1817 printf("Hash: Adding key\n");
1818 print_ipv4_key(ipv4_l3fwd_route_array[i].key);
1821 /* populate the ipv6 hash */
1822 for (i = 0; i < RTE_DIM(ipv6_l3fwd_route_array); i++) {
1823 ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
1824 (void *) &ipv6_l3fwd_route_array[i].key);
1826 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
1827 "l3fwd hash on socket %d\n", i, socketid);
1829 ipv6_l3fwd_out_if[ret] = ipv6_l3fwd_route_array[i].if_out;
1830 printf("Hash: Adding key\n");
1831 print_ipv6_key(ipv6_l3fwd_route_array[i].key);
1836 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1838 setup_lpm(int socketid)
1844 /* create the LPM table */
1845 struct rte_lpm_config lpm_ipv4_config;
1847 lpm_ipv4_config.max_rules = IPV4_L3FWD_LPM_MAX_RULES;
1848 lpm_ipv4_config.number_tbl8s = 256;
1849 lpm_ipv4_config.flags = 0;
1851 snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
1852 ipv4_l3fwd_lookup_struct[socketid] =
1853 rte_lpm_create(s, socketid, &lpm_ipv4_config);
1854 if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
1855 rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
1856 " on socket %d\n", socketid);
1858 /* populate the LPM table */
1859 for (i = 0; i < RTE_DIM(ipv4_l3fwd_route_array); i++) {
1860 ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
1861 ipv4_l3fwd_route_array[i].ip,
1862 ipv4_l3fwd_route_array[i].depth,
1863 ipv4_l3fwd_route_array[i].if_out);
1866 rte_exit(EXIT_FAILURE, "Unable to add entry %u to the "
1867 "l3fwd LPM table on socket %d\n",
1871 printf("LPM: Adding route 0x%08x / %d (%d)\n",
1872 (unsigned)ipv4_l3fwd_route_array[i].ip,
1873 ipv4_l3fwd_route_array[i].depth,
1874 ipv4_l3fwd_route_array[i].if_out);
1880 init_mem(unsigned nb_mbuf)
1882 struct lcore_conf *qconf;
1887 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1888 if (rte_lcore_is_enabled(lcore_id) == 0)
1892 socketid = rte_lcore_to_socket_id(lcore_id);
1896 if (socketid >= NB_SOCKETS) {
1897 rte_exit(EXIT_FAILURE, "Socket %d of lcore %u is "
1898 "out of range %d\n", socketid,
1899 lcore_id, NB_SOCKETS);
1901 if (pktmbuf_pool[socketid] == NULL) {
1902 snprintf(s, sizeof(s), "mbuf_pool_%d", socketid);
1903 pktmbuf_pool[socketid] =
1904 rte_pktmbuf_pool_create(s, nb_mbuf,
1905 MEMPOOL_CACHE_SIZE, 0,
1906 RTE_MBUF_DEFAULT_BUF_SIZE,
1908 if (pktmbuf_pool[socketid] == NULL)
1909 rte_exit(EXIT_FAILURE,
1910 "Cannot init mbuf pool on socket %d\n",
1913 printf("Allocated mbuf pool on socket %d\n",
1916 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
1917 setup_lpm(socketid);
1919 setup_hash(socketid);
1922 qconf = &lcore_conf[lcore_id];
1923 qconf->ipv4_lookup_struct = ipv4_l3fwd_lookup_struct[socketid];
1924 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
1925 qconf->ipv6_lookup_struct = ipv6_l3fwd_lookup_struct[socketid];
1931 /* Check the link status of all ports in up to 9s, and print them finally */
1933 check_all_ports_link_status(uint32_t port_mask)
1935 #define CHECK_INTERVAL 100 /* 100ms */
1936 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1937 uint8_t count, all_ports_up, print_flag = 0;
1939 struct rte_eth_link link;
1942 printf("\nChecking link status");
1944 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1946 RTE_ETH_FOREACH_DEV(portid) {
1947 if ((port_mask & (1 << portid)) == 0)
1949 memset(&link, 0, sizeof(link));
1950 ret = rte_eth_link_get_nowait(portid, &link);
1953 if (print_flag == 1)
1954 printf("Port %u link get failed: %s\n",
1955 portid, rte_strerror(-ret));
1958 /* print link status if flag set */
1959 if (print_flag == 1) {
1960 if (link.link_status)
1961 printf("Port %d Link Up - speed %u "
1962 "Mbps - %s\n", (uint8_t)portid,
1963 (unsigned)link.link_speed,
1964 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1965 ("full-duplex") : ("half-duplex\n"));
1967 printf("Port %d Link Down\n",
1971 /* clear all_ports_up flag if any link down */
1972 if (link.link_status == ETH_LINK_DOWN) {
1977 /* after finally printing all link status, get out */
1978 if (print_flag == 1)
1981 if (all_ports_up == 0) {
1984 rte_delay_ms(CHECK_INTERVAL);
1987 /* set the print_flag if all ports up or timeout */
1988 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1995 static int check_ptype(uint16_t portid)
1998 int ptype_l3_ipv4 = 0;
1999 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2000 int ptype_l3_ipv6 = 0;
2002 uint32_t ptype_mask = RTE_PTYPE_L3_MASK;
2004 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
2008 uint32_t ptypes[ret];
2010 ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
2011 for (i = 0; i < ret; ++i) {
2012 if (ptypes[i] & RTE_PTYPE_L3_IPV4)
2014 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2015 if (ptypes[i] & RTE_PTYPE_L3_IPV6)
2020 if (ptype_l3_ipv4 == 0)
2021 printf("port %d cannot parse RTE_PTYPE_L3_IPV4\n", portid);
2023 #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
2024 if (ptype_l3_ipv6 == 0)
2025 printf("port %d cannot parse RTE_PTYPE_L3_IPV6\n", portid);
2028 #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
2030 #else /* APP_LOOKUP_EXACT_MATCH */
2031 if (ptype_l3_ipv4 && ptype_l3_ipv6)
2040 init_power_library(void)
2042 unsigned int lcore_id;
2045 RTE_LCORE_FOREACH(lcore_id) {
2046 /* init power management library */
2047 ret = rte_power_init(lcore_id);
2050 "Library initialization failed on core %u\n",
2059 deinit_power_library(void)
2061 unsigned int lcore_id;
2064 RTE_LCORE_FOREACH(lcore_id) {
2065 /* deinit power management library */
2066 ret = rte_power_exit(lcore_id);
2069 "Library deinitialization failed on core %u\n",
2078 get_current_stat_values(uint64_t *values)
2080 unsigned int lcore_id = rte_lcore_id();
2081 struct lcore_conf *qconf;
2082 uint64_t app_eps = 0, app_fps = 0, app_br = 0;
2085 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2086 qconf = &lcore_conf[lcore_id];
2087 if (qconf->n_rx_queue == 0)
2090 rte_spinlock_lock(&stats[lcore_id].telemetry_lock);
2091 app_eps += stats[lcore_id].ep_nep[1];
2092 app_fps += stats[lcore_id].fp_nfp[1];
2093 app_br += stats[lcore_id].br;
2094 rte_spinlock_unlock(&stats[lcore_id].telemetry_lock);
2098 values[0] = app_eps/count;
2099 values[1] = app_fps/count;
2100 values[2] = app_br/count;
2102 memset(values, 0, sizeof(uint64_t) * NUM_TELSTATS);
2107 update_telemetry(__rte_unused struct rte_timer *tim,
2108 __rte_unused void *arg)
2111 uint64_t values[NUM_TELSTATS] = {0};
2113 get_current_stat_values(values);
2114 ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
2115 values, RTE_DIM(values));
2117 RTE_LOG(WARNING, POWER, "failed to update metrcis\n");
2119 #ifdef RTE_LIBRTE_TELEMETRY
2121 handle_app_stats(const char *cmd __rte_unused,
2122 const char *params __rte_unused,
2123 struct rte_tel_data *d)
2125 uint64_t values[NUM_TELSTATS] = {0};
2128 rte_tel_data_start_dict(d);
2129 get_current_stat_values(values);
2130 for (i = 0; i < NUM_TELSTATS; i++)
2131 rte_tel_data_add_dict_u64(d, telstats_strings[i].name,
2137 telemetry_setup_timer(void)
2139 int lcore_id = rte_lcore_id();
2140 uint64_t hz = rte_get_timer_hz();
2143 ticks = hz / TELEMETRY_INTERVALS_PER_SEC;
2144 rte_timer_reset_sync(&telemetry_timer,
2152 empty_poll_setup_timer(void)
2154 int lcore_id = rte_lcore_id();
2155 uint64_t hz = rte_get_timer_hz();
2157 struct ep_params *ep_ptr = ep_params;
2159 ep_ptr->interval_ticks = hz / INTERVALS_PER_SECOND;
2161 rte_timer_reset_sync(&ep_ptr->timer0,
2162 ep_ptr->interval_ticks,
2165 rte_empty_poll_detection,
2170 launch_timer(unsigned int lcore_id)
2172 int64_t prev_tsc = 0, cur_tsc, diff_tsc, cycles_10ms;
2174 RTE_SET_USED(lcore_id);
2177 if (rte_get_master_lcore() != lcore_id) {
2178 rte_panic("timer on lcore:%d which is not master core:%d\n",
2180 rte_get_master_lcore());
2183 RTE_LOG(INFO, POWER, "Bring up the Timer\n");
2185 if (app_mode == APP_MODE_EMPTY_POLL)
2186 empty_poll_setup_timer();
2188 telemetry_setup_timer();
2190 cycles_10ms = rte_get_timer_hz() / 100;
2192 while (!is_done()) {
2193 cur_tsc = rte_rdtsc();
2194 diff_tsc = cur_tsc - prev_tsc;
2195 if (diff_tsc > cycles_10ms) {
2198 cycles_10ms = rte_get_timer_hz() / 100;
2202 RTE_LOG(INFO, POWER, "Timer_subsystem is done\n");
2209 main(int argc, char **argv)
2211 struct lcore_conf *qconf;
2212 struct rte_eth_dev_info dev_info;
2213 struct rte_eth_txconf *txconf;
2219 uint32_t n_tx_queue, nb_lcores;
2220 uint32_t dev_rxq_num, dev_txq_num;
2221 uint8_t nb_rx_queue, queue, socketid;
2223 const char *ptr_strings[NUM_TELSTATS];
2225 /* catch SIGINT and restore cpufreq governor to ondemand */
2226 signal(SIGINT, signal_exit_now);
2229 ret = rte_eal_init(argc, argv);
2231 rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
2235 /* init RTE timer library to be used late */
2236 rte_timer_subsystem_init();
2238 /* parse application arguments (after the EAL ones) */
2239 ret = parse_args(argc, argv);
2241 rte_exit(EXIT_FAILURE, "Invalid L3FWD parameters\n");
2243 if (app_mode != APP_MODE_TELEMETRY && init_power_library())
2244 rte_exit(EXIT_FAILURE, "init_power_library failed\n");
2246 if (update_lcore_params() < 0)
2247 rte_exit(EXIT_FAILURE, "update_lcore_params failed\n");
2249 if (check_lcore_params() < 0)
2250 rte_exit(EXIT_FAILURE, "check_lcore_params failed\n");
2252 ret = init_lcore_rx_queues();
2254 rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
2256 nb_ports = rte_eth_dev_count_avail();
2258 if (check_port_config() < 0)
2259 rte_exit(EXIT_FAILURE, "check_port_config failed\n");
2261 nb_lcores = rte_lcore_count();
2263 /* initialize all ports */
2264 RTE_ETH_FOREACH_DEV(portid) {
2265 struct rte_eth_conf local_port_conf = port_conf;
2267 /* skip ports that are not enabled */
2268 if ((enabled_port_mask & (1 << portid)) == 0) {
2269 printf("\nSkipping disabled port %d\n", portid);
2274 printf("Initializing port %d ... ", portid );
2277 ret = rte_eth_dev_info_get(portid, &dev_info);
2279 rte_exit(EXIT_FAILURE,
2280 "Error during getting device (port %u) info: %s\n",
2281 portid, strerror(-ret));
2283 dev_rxq_num = dev_info.max_rx_queues;
2284 dev_txq_num = dev_info.max_tx_queues;
2286 nb_rx_queue = get_port_n_rx_queues(portid);
2287 if (nb_rx_queue > dev_rxq_num)
2288 rte_exit(EXIT_FAILURE,
2289 "Cannot configure not existed rxq: "
2290 "port=%d\n", portid);
2292 n_tx_queue = nb_lcores;
2293 if (n_tx_queue > dev_txq_num)
2294 n_tx_queue = dev_txq_num;
2295 printf("Creating queues: nb_rxq=%d nb_txq=%u... ",
2296 nb_rx_queue, (unsigned)n_tx_queue );
2297 /* If number of Rx queue is 0, no need to enable Rx interrupt */
2298 if (nb_rx_queue == 0)
2299 local_port_conf.intr_conf.rxq = 0;
2301 ret = rte_eth_dev_info_get(portid, &dev_info);
2303 rte_exit(EXIT_FAILURE,
2304 "Error during getting device (port %u) info: %s\n",
2305 portid, strerror(-ret));
2307 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
2308 local_port_conf.txmode.offloads |=
2309 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
2311 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
2312 dev_info.flow_type_rss_offloads;
2313 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
2314 port_conf.rx_adv_conf.rss_conf.rss_hf) {
2315 printf("Port %u modified RSS hash function based on hardware support,"
2316 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2318 port_conf.rx_adv_conf.rss_conf.rss_hf,
2319 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
2322 ret = rte_eth_dev_configure(portid, nb_rx_queue,
2323 (uint16_t)n_tx_queue, &local_port_conf);
2325 rte_exit(EXIT_FAILURE, "Cannot configure device: "
2326 "err=%d, port=%d\n", ret, portid);
2328 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
2331 rte_exit(EXIT_FAILURE,
2332 "Cannot adjust number of descriptors: err=%d, port=%d\n",
2335 ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
2337 rte_exit(EXIT_FAILURE,
2338 "Cannot get MAC address: err=%d, port=%d\n",
2341 print_ethaddr(" Address:", &ports_eth_addr[portid]);
2345 ret = init_mem(NB_MBUF);
2347 rte_exit(EXIT_FAILURE, "init_mem failed\n");
2349 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2350 if (rte_lcore_is_enabled(lcore_id) == 0)
2353 /* Initialize TX buffers */
2354 qconf = &lcore_conf[lcore_id];
2355 qconf->tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
2356 RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
2357 rte_eth_dev_socket_id(portid));
2358 if (qconf->tx_buffer[portid] == NULL)
2359 rte_exit(EXIT_FAILURE, "Can't allocate tx buffer for port %u\n",
2362 rte_eth_tx_buffer_init(qconf->tx_buffer[portid], MAX_PKT_BURST);
2365 /* init one TX queue per couple (lcore,port) */
2367 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2368 if (rte_lcore_is_enabled(lcore_id) == 0)
2371 if (queueid >= dev_txq_num)
2376 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2380 printf("txq=%u,%d,%d ", lcore_id, queueid, socketid);
2383 txconf = &dev_info.default_txconf;
2384 txconf->offloads = local_port_conf.txmode.offloads;
2385 ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd,
2388 rte_exit(EXIT_FAILURE,
2389 "rte_eth_tx_queue_setup: err=%d, "
2390 "port=%d\n", ret, portid);
2392 qconf = &lcore_conf[lcore_id];
2393 qconf->tx_queue_id[portid] = queueid;
2396 qconf->tx_port_id[qconf->n_tx_port] = portid;
2402 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
2403 if (rte_lcore_is_enabled(lcore_id) == 0)
2406 if (app_mode == APP_MODE_LEGACY) {
2407 /* init timer structures for each enabled lcore */
2408 rte_timer_init(&power_timers[lcore_id]);
2409 hz = rte_get_timer_hz();
2410 rte_timer_reset(&power_timers[lcore_id],
2411 hz/TIMER_NUMBER_PER_SECOND,
2413 power_timer_cb, NULL);
2415 qconf = &lcore_conf[lcore_id];
2416 printf("\nInitializing rx queues on lcore %u ... ", lcore_id );
2418 /* init RX queues */
2419 for(queue = 0; queue < qconf->n_rx_queue; ++queue) {
2420 struct rte_eth_rxconf rxq_conf;
2422 portid = qconf->rx_queue_list[queue].port_id;
2423 queueid = qconf->rx_queue_list[queue].queue_id;
2427 (uint8_t)rte_lcore_to_socket_id(lcore_id);
2431 printf("rxq=%d,%d,%d ", portid, queueid, socketid);
2434 ret = rte_eth_dev_info_get(portid, &dev_info);
2436 rte_exit(EXIT_FAILURE,
2437 "Error during getting device (port %u) info: %s\n",
2438 portid, strerror(-ret));
2440 rxq_conf = dev_info.default_rxconf;
2441 rxq_conf.offloads = port_conf.rxmode.offloads;
2442 ret = rte_eth_rx_queue_setup(portid, queueid, nb_rxd,
2443 socketid, &rxq_conf,
2444 pktmbuf_pool[socketid]);
2446 rte_exit(EXIT_FAILURE,
2447 "rte_eth_rx_queue_setup: err=%d, "
2448 "port=%d\n", ret, portid);
2451 if (add_cb_parse_ptype(portid, queueid) < 0)
2452 rte_exit(EXIT_FAILURE,
2453 "Fail to add ptype cb\n");
2454 } else if (!check_ptype(portid))
2455 rte_exit(EXIT_FAILURE,
2456 "PMD can not provide needed ptypes\n");
2463 RTE_ETH_FOREACH_DEV(portid) {
2464 if ((enabled_port_mask & (1 << portid)) == 0) {
2468 ret = rte_eth_dev_start(portid);
2470 rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, "
2471 "port=%d\n", ret, portid);
2473 * If enabled, put device in promiscuous mode.
2474 * This allows IO forwarding mode to forward packets
2475 * to itself through 2 cross-connected ports of the
2478 if (promiscuous_on) {
2479 ret = rte_eth_promiscuous_enable(portid);
2481 rte_exit(EXIT_FAILURE,
2482 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
2483 rte_strerror(-ret), portid);
2485 /* initialize spinlock for each port */
2486 rte_spinlock_init(&(locks[portid]));
2489 check_all_ports_link_status(enabled_port_mask);
2491 if (app_mode == APP_MODE_EMPTY_POLL) {
2493 if (empty_poll_train) {
2494 policy.state = TRAINING;
2496 policy.state = MED_NORMAL;
2497 policy.med_base_edpi = ep_med_edpi;
2498 policy.hgh_base_edpi = ep_hgh_edpi;
2501 ret = rte_power_empty_poll_stat_init(&ep_params,
2505 rte_exit(EXIT_FAILURE, "empty poll init failed");
2509 /* launch per-lcore init on every lcore */
2510 if (app_mode == APP_MODE_LEGACY) {
2511 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER);
2512 } else if (app_mode == APP_MODE_EMPTY_POLL) {
2513 empty_poll_stop = false;
2514 rte_eal_mp_remote_launch(main_empty_poll_loop, NULL,
2519 /* Init metrics library */
2520 rte_metrics_init(rte_socket_id());
2521 /** Register stats with metrics library */
2522 for (i = 0; i < NUM_TELSTATS; i++)
2523 ptr_strings[i] = telstats_strings[i].name;
2525 ret = rte_metrics_reg_names(ptr_strings, NUM_TELSTATS);
2527 telstats_index = ret;
2529 rte_exit(EXIT_FAILURE, "failed to register metrics names");
2531 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2532 rte_spinlock_init(&stats[lcore_id].telemetry_lock);
2534 rte_timer_init(&telemetry_timer);
2535 #ifdef RTE_LIBRTE_TELEMETRY
2536 rte_telemetry_register_cmd("/l3fwd-power/stats",
2538 "Returns global power stats. Parameters: None");
2540 rte_eal_mp_remote_launch(main_telemetry_loop, NULL,
2544 if (app_mode == APP_MODE_EMPTY_POLL || app_mode == APP_MODE_TELEMETRY)
2545 launch_timer(rte_lcore_id());
2547 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
2548 if (rte_eal_wait_lcore(lcore_id) < 0)
2552 RTE_ETH_FOREACH_DEV(portid)
2554 if ((enabled_port_mask & (1 << portid)) == 0)
2557 rte_eth_dev_stop(portid);
2558 rte_eth_dev_close(portid);
2561 if (app_mode == APP_MODE_EMPTY_POLL)
2562 rte_power_empty_poll_stat_free();
2564 if (app_mode != APP_MODE_TELEMETRY && deinit_power_library())
2565 rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
2567 if (rte_eal_cleanup() < 0)
2568 RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");