X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fqos_meter%2Fmain.c;h=a0f78e4ad65df043b82a36156213975a7c48ae7c;hb=198db0c9e29dfeeffe96f70a308a927b716a5f22;hp=ca0e9e8635a8423384d7e3118147a22e88048dc8;hpb=ab3ce1e0c19329c8a2d21480b0db55be259bc168;p=dpdk.git diff --git a/examples/qos_meter/main.c b/examples/qos_meter/main.c index ca0e9e8635..a0f78e4ad6 100644 --- a/examples/qos_meter/main.c +++ b/examples/qos_meter/main.c @@ -14,10 +14,7 @@ #include #include -/* - * Traffic metering configuration - * - */ +/* Traffic metering configuration. 8< */ #define APP_MODE_FWD 0 #define APP_MODE_SRTCM_COLOR_BLIND 1 #define APP_MODE_SRTCM_COLOR_AWARE 2 @@ -25,6 +22,7 @@ #define APP_MODE_TRTCM_COLOR_AWARE 4 #define APP_MODE APP_MODE_SRTCM_COLOR_BLIND +/* >8 End of traffic metering configuration. */ #include "main.h" @@ -53,20 +51,18 @@ static struct rte_mempool *pool = NULL; ***/ static struct rte_eth_conf port_conf = { .rxmode = { - .mq_mode = ETH_MQ_RX_RSS, - .max_rx_pkt_len = ETHER_MAX_LEN, + .mq_mode = RTE_ETH_MQ_RX_RSS, .split_hdr_size = 0, - .offloads = (DEV_RX_OFFLOAD_CHECKSUM | - DEV_RX_OFFLOAD_CRC_STRIP), + .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM, }, .rx_adv_conf = { .rss_conf = { .rss_key = NULL, - .rss_hf = ETH_RSS_IP, + .rss_hf = RTE_ETH_RSS_IP, }, }, .txmode = { - .mq_mode = ETH_DCB_NONE, + .mq_mode = RTE_ETH_MQ_TX_NONE, }, }; @@ -80,15 +76,16 @@ static struct rte_eth_conf port_conf = { * Packet RX/TX * ***/ -#define PKT_RX_BURST_MAX 32 -#define PKT_TX_BURST_MAX 32 +#define RTE_MBUF_F_RX_BURST_MAX 32 +#define RTE_MBUF_F_TX_BURST_MAX 32 #define TIME_TX_DRAIN 200000ULL static uint16_t port_rx; static uint16_t port_tx; -static struct rte_mbuf *pkts_rx[PKT_RX_BURST_MAX]; +static struct rte_mbuf *pkts_rx[RTE_MBUF_F_RX_BURST_MAX]; struct rte_eth_dev_tx_buffer *tx_buffer; +/* Traffic meter parameters are configured in the application. 8< */ struct rte_meter_srtcm_params app_srtcm_params = { .cir = 1000000 * 46, .cbs = 2048, @@ -103,6 +100,7 @@ struct rte_meter_trtcm_params app_trtcm_params = { .cbs = 2048, .pbs = 2048 }; +/* >8 End of traffic meter parameters are configured in the application. */ struct rte_meter_trtcm_profile app_trtcm_profile; @@ -146,7 +144,8 @@ app_pkt_handle(struct rte_mbuf *pkt, uint64_t time) { uint8_t input_color, output_color; uint8_t *pkt_data = rte_pktmbuf_mtod(pkt, uint8_t *); - uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - sizeof(struct ether_hdr); + uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt) - + sizeof(struct rte_ether_hdr); uint8_t flow_id = (uint8_t)(pkt_data[APP_PKT_FLOW_POS] & (APP_FLOWS_MAX - 1)); input_color = pkt_data[APP_PKT_COLOR_POS]; enum policer_action action; @@ -156,7 +155,7 @@ app_pkt_handle(struct rte_mbuf *pkt, uint64_t time) &PROFILE, time, pkt_len, - (enum rte_meter_color) input_color); + (enum rte_color) input_color); /* Apply policing and set the output color */ action = policer_table[input_color][output_color]; @@ -166,8 +165,8 @@ app_pkt_handle(struct rte_mbuf *pkt, uint64_t time) } -static __attribute__((noreturn)) int -main_loop(__attribute__((unused)) void *dummy) +static __rte_noreturn int +main_loop(__rte_unused void *dummy) { uint64_t current_time, last_time = rte_rdtsc(); uint32_t lcore_id = rte_lcore_id(); @@ -188,7 +187,7 @@ main_loop(__attribute__((unused)) void *dummy) } /* Read packet burst from NIC RX */ - nb_rx = rte_eth_rx_burst(port_rx, NIC_RX_QUEUE, pkts_rx, PKT_RX_BURST_MAX); + nb_rx = rte_eth_rx_burst(port_rx, NIC_RX_QUEUE, pkts_rx, RTE_MBUF_F_RX_BURST_MAX); /* Handle packets */ for (i = 0; i < nb_rx; i ++) { @@ -220,10 +219,7 @@ parse_portmask(const char *portmask) /* parse hexadecimal string */ pm = strtoul(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) - return -1; - - if (pm == 0) - return -1; + return 0; return pm; } @@ -329,9 +325,26 @@ main(int argc, char **argv) /* NIC init */ conf = port_conf; - rte_eth_dev_info_get(port_rx, &dev_info); - if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) - conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; + + ret = rte_eth_dev_info_get(port_rx, &dev_info); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Error during getting device (port %u) info: %s\n", + port_rx, strerror(-ret)); + + if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) + conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE; + + conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads; + if (conf.rx_adv_conf.rss_conf.rss_hf != + port_conf.rx_adv_conf.rss_conf.rss_hf) { + printf("Port %u modified RSS hash function based on hardware support," + "requested:%#"PRIx64" configured:%#"PRIx64"\n", + port_rx, + port_conf.rx_adv_conf.rss_conf.rss_hf, + conf.rx_adv_conf.rss_conf.rss_hf); + } + ret = rte_eth_dev_configure(port_rx, 1, 1, &conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Port %d configuration error (%d)\n", port_rx, ret); @@ -358,9 +371,26 @@ main(int argc, char **argv) rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_rx, ret); conf = port_conf; - rte_eth_dev_info_get(port_tx, &dev_info); - if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) - conf.txmode.offloads |= DEV_TX_OFFLOAD_MBUF_FAST_FREE; + + ret = rte_eth_dev_info_get(port_tx, &dev_info); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Error during getting device (port %u) info: %s\n", + port_tx, strerror(-ret)); + + if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) + conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE; + + conf.rx_adv_conf.rss_conf.rss_hf &= dev_info.flow_type_rss_offloads; + if (conf.rx_adv_conf.rss_conf.rss_hf != + port_conf.rx_adv_conf.rss_conf.rss_hf) { + printf("Port %u modified RSS hash function based on hardware support," + "requested:%#"PRIx64" configured:%#"PRIx64"\n", + port_tx, + port_conf.rx_adv_conf.rss_conf.rss_hf, + conf.rx_adv_conf.rss_conf.rss_hf); + } + ret = rte_eth_dev_configure(port_tx, 1, 1, &conf); if (ret < 0) rte_exit(EXIT_FAILURE, "Port %d configuration error (%d)\n", port_tx, ret); @@ -389,13 +419,13 @@ main(int argc, char **argv) rte_exit(EXIT_FAILURE, "Port %d TX queue setup error (%d)\n", port_tx, ret); tx_buffer = rte_zmalloc_socket("tx_buffer", - RTE_ETH_TX_BUFFER_SIZE(PKT_TX_BURST_MAX), 0, + RTE_ETH_TX_BUFFER_SIZE(RTE_MBUF_F_TX_BURST_MAX), 0, rte_eth_dev_socket_id(port_tx)); if (tx_buffer == NULL) rte_exit(EXIT_FAILURE, "Port %d TX buffer allocation error\n", port_tx); - rte_eth_tx_buffer_init(tx_buffer, PKT_TX_BURST_MAX); + rte_eth_tx_buffer_init(tx_buffer, RTE_MBUF_F_TX_BURST_MAX); ret = rte_eth_dev_start(port_rx); if (ret < 0) @@ -405,9 +435,17 @@ main(int argc, char **argv) if (ret < 0) rte_exit(EXIT_FAILURE, "Port %d start error (%d)\n", port_tx, ret); - rte_eth_promiscuous_enable(port_rx); + ret = rte_eth_promiscuous_enable(port_rx); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Port %d promiscuous mode enable error (%s)\n", + port_rx, rte_strerror(-ret)); - rte_eth_promiscuous_enable(port_tx); + ret = rte_eth_promiscuous_enable(port_tx); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Port %d promiscuous mode enable error (%s)\n", + port_rx, rte_strerror(-ret)); /* App configuration */ ret = app_configure_flow_table(); @@ -415,11 +453,14 @@ main(int argc, char **argv) rte_exit(EXIT_FAILURE, "Invalid configure flow table\n"); /* Launch per-lcore init on every lcore */ - rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); - RTE_LCORE_FOREACH_SLAVE(lcore_id) { + rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN); + RTE_LCORE_FOREACH_WORKER(lcore_id) { if (rte_eal_wait_lcore(lcore_id) < 0) return -1; } + /* clean up the EAL */ + rte_eal_cleanup(); + return 0; }