remove trailing whitespaces
[dpdk.git] / examples / l3fwd-power / main.c
index d0b5289..046949f 100644 (file)
@@ -1,35 +1,34 @@
 /*-
  *   BSD LICENSE
- * 
- *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
- *   Redistribution and use in source and binary forms, with or without 
- *   modification, are permitted provided that the following conditions 
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
  *   are met:
- * 
- *     * Redistributions of source code must retain the above copyright 
+ *
+ *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright 
- *       notice, this list of conditions and the following disclaimer in 
- *       the documentation and/or other materials provided with the 
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its 
- *       contributors may be used to endorse or promote products derived 
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
  */
 
 #include <stdio.h>
@@ -236,6 +235,7 @@ static uint16_t nb_lcore_params = sizeof(lcore_params_array_default) /
 
 static struct rte_eth_conf port_conf = {
        .rxmode = {
+               .mq_mode        = ETH_MQ_RX_RSS,
                .max_rx_pkt_len = ETHER_MAX_LEN,
                .split_hdr_size = 0,
                .header_split   = 0, /**< Header Split disabled */
@@ -396,7 +396,7 @@ struct lcore_stats {
        uint64_t nb_rx_processed;
        /* total iterations looped recently */
        uint64_t nb_iteration_looped;
-       uint32_t padding[9]; 
+       uint32_t padding[9];
 } __rte_cache_aligned;
 
 static struct lcore_conf lcore_conf[RTE_MAX_LCORE] __rte_cache_aligned;
@@ -405,7 +405,7 @@ static struct rte_timer power_timers[RTE_MAX_LCORE];
 
 static inline uint32_t power_idle_heuristic(uint32_t zero_rx_packet_count);
 static inline enum freq_scale_hint_t power_freq_scaleup_heuristic( \
-                               unsigned lcore_id, uint32_t rx_ring_length);
+                       unsigned lcore_id, uint8_t port_id, uint16_t queue_id);
 
 /* exit signal handler */
 static void
@@ -443,7 +443,7 @@ power_timer_cb(__attribute__((unused)) struct rte_timer *tim,
        /* accumulate total execution time in us when callback is invoked */
        sleep_time_ratio = (float)(stats[lcore_id].sleep_time) /
                                        (float)SCALING_PERIOD;
-               
+
        /**
         * check whether need to scale down frequency a step if it sleep a lot.
         */
@@ -769,34 +769,33 @@ power_idle_heuristic(uint32_t zero_rx_packet_count)
 }
 
 static inline enum freq_scale_hint_t
-power_freq_scaleup_heuristic(unsigned lcore_id, uint32_t rx_ring_length)
+power_freq_scaleup_heuristic(unsigned lcore_id,
+                            uint8_t port_id,
+                            uint16_t queue_id)
 {
 /**
  * HW Rx queue size is 128 by default, Rx burst read at maximum 32 entries
  * per iteration
  */
 #define FREQ_GEAR1_RX_PACKET_THRESHOLD             MAX_PKT_BURST
-#define FREQ_GEAR2_RX_PACKET_THRESHOLD             64
-#define FREQ_GEAR3_RX_PACKET_THRESHOLD             96
+#define FREQ_GEAR2_RX_PACKET_THRESHOLD             (MAX_PKT_BURST*2)
+#define FREQ_GEAR3_RX_PACKET_THRESHOLD             (MAX_PKT_BURST*3)
 #define FREQ_UP_TREND1_ACC   1
 #define FREQ_UP_TREND2_ACC   100
 #define FREQ_UP_THRESHOLD    10000
 
-       /**
-        * there are received packets to process, staying at C0 state while
-        * trying to scale up frequency depending on how many entries on h/w
-        * queue. Determine frequency scaleup trend based on availiable entries
-        * on Rx queues.
-        */
-       if (rx_ring_length > FREQ_GEAR3_RX_PACKET_THRESHOLD) {
+       if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
+                       FREQ_GEAR3_RX_PACKET_THRESHOLD) > 0)) {
                stats[lcore_id].trend = 0;
                return FREQ_HIGHEST;
-       } else if (rx_ring_length > FREQ_GEAR2_RX_PACKET_THRESHOLD)
+       } else if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
+                       FREQ_GEAR2_RX_PACKET_THRESHOLD) > 0))
                stats[lcore_id].trend += FREQ_UP_TREND2_ACC;
-       else if (rx_ring_length > FREQ_GEAR1_RX_PACKET_THRESHOLD)
+       else if (likely(rte_eth_rx_descriptor_done(port_id, queue_id,
+                       FREQ_GEAR1_RX_PACKET_THRESHOLD) > 0))
                stats[lcore_id].trend += FREQ_UP_TREND1_ACC;
 
-       if (stats[lcore_id].trend > FREQ_UP_THRESHOLD) {
+       if (likely(stats[lcore_id].trend > FREQ_UP_THRESHOLD)) {
                stats[lcore_id].trend = 0;
                return FREQ_HIGHER;
        }
@@ -816,9 +815,8 @@ main_loop(__attribute__((unused)) void *dummy)
        uint8_t portid, queueid;
        struct lcore_conf *qconf;
        struct lcore_rx_queue *rx_queue;
-       uint32_t rx_ring_length;
        enum freq_scale_hint_t lcore_scaleup_hint;
-       
+
        uint32_t lcore_rx_idle_count = 0;
        uint32_t lcore_idle_hint = 0;
 
@@ -908,15 +906,6 @@ main_loop(__attribute__((unused)) void *dummy)
                                        rx_queue->zero_rx_packet_count);
                                lcore_rx_idle_count++;
                        } else {
-                               /**
-                                * get availiable descriptor number via MMIO read is costly,
-                                 * so only do it when recent poll returns maximum number. 
-                                */
-                               if (nb_rx >= MAX_PKT_BURST)
-                                    rx_ring_length = rte_eth_rx_queue_count(portid, queueid);
-                               else 
-                                    rx_ring_length = 0;
-
                                rx_queue->zero_rx_packet_count = 0;
 
                                /**
@@ -927,7 +916,7 @@ main_loop(__attribute__((unused)) void *dummy)
                                 */
                                rx_queue->freq_up_hint =
                                        power_freq_scaleup_heuristic(lcore_id,
-                                                       rx_ring_length);
+                                                       portid, queueid);
                        }
 
                        /* Prefetch first packets */
@@ -960,8 +949,8 @@ main_loop(__attribute__((unused)) void *dummy)
                                                lcore_scaleup_hint)
                                        lcore_scaleup_hint =
                                                rx_queue->freq_up_hint;
-                       }       
-               
+                       }
+
                        if (lcore_scaleup_hint == FREQ_HIGHEST)
                                rte_power_freq_max(lcore_id);
                        else if (lcore_scaleup_hint == FREQ_HIGHER)
@@ -1240,7 +1229,7 @@ parse_args(int argc, char **argv)
                                printf("numa is disabled \n");
                                numa_on = 0;
                        }
-                       
+
                        if (!strncmp(lgopts[option_index].name,
                                        "enable-jumbo", 12)) {
                                struct option lenopts =
@@ -1249,7 +1238,7 @@ parse_args(int argc, char **argv)
 
                                printf("jumbo frame is enabled \n");
                                port_conf.rxmode.jumbo_frame = 1;
-       
+
                                /**
                                 * if no max-pkt-len set, use the default value
                                 * ETHER_MAX_LEN
@@ -1270,7 +1259,7 @@ parse_args(int argc, char **argv)
                                        "max packet length to %u\n",
                                (unsigned int)port_conf.rxmode.max_rx_pkt_len);
                        }
-                       
+
                        break;
 
                default:
@@ -1558,10 +1547,6 @@ MAIN(int argc, char **argv)
                rte_exit(EXIT_FAILURE, "init_lcore_rx_queues failed\n");
 
 
-       /* init driver(s) */
-       if (rte_pmd_init_all() < 0)
-               rte_exit(EXIT_FAILURE, "Cannot init pmd\n");
-
        if (rte_eal_pci_probe() < 0)
                rte_exit(EXIT_FAILURE, "Cannot probe PCI\n");