X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fkni%2Fmain.c;h=249860dd09433c318fdd85aac11e317f00db5f80;hb=1c1d4d7a923d4804f1926fc5264f9ecdd8977b04;hp=34a6f4aa8b10f5eb16059bb764a8fbafa545d8ad;hpb=b6ea6408fbc784f174626aa6ea2fa49610b1f432;p=dpdk.git diff --git a/examples/kni/main.c b/examples/kni/main.c index 34a6f4aa8b..249860dd09 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -4,32 +4,31 @@ * Copyright(c) 2010-2013 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 @@ -107,6 +106,9 @@ /* Total octets in the FCS */ #define KNI_ENET_FCS_SIZE 4 +#define KNI_US_PER_SECOND 1000000 +#define KNI_SECOND_PER_DAY 86400 + /* * RX and TX Prefetch, Host, and Write-back threshold values should be * carefully set for optimal performance. Consult the network @@ -149,7 +151,7 @@ static struct rte_eth_conf port_conf = { .hw_strip_crc = 0, /* CRC stripped by hardware */ }, .txmode = { - .mq_mode = ETH_DCB_NONE, + .mq_mode = ETH_MQ_TX_NONE, }, }; @@ -209,6 +211,8 @@ static struct rte_kni_ops kni_ops = { .config_network_if = kni_config_network_interface, }; +static rte_atomic32_t kni_stop = RTE_ATOMIC32_INIT(0); + /* Print out statistics on packets handled */ static void print_stats(void) @@ -235,7 +239,7 @@ print_stats(void) printf("====== ============== ============ ============ ============ ============\n"); } -/* Custom handling of signals to handle stats */ +/* Custom handling of signals to handle stats and kni processing */ static void signal_handler(int signum) { @@ -250,6 +254,14 @@ signal_handler(int signum) printf("\n**Statistics have been reset**\n"); return; } + + /* When we receive a RTMIN signal, stop kni processing */ + if (signum == SIGRTMIN) { + printf("SIGRTMIN is received, and the KNI processing is " + "going to stop\n"); + rte_atomic32_inc(&kni_stop); + return; + } } static void @@ -290,6 +302,7 @@ kni_ingress(struct rte_kni *kni) num = rte_kni_tx_burst(kni, pkts_burst, nb_rx); kni_stats[port_id].rx_packets += num; + rte_kni_handle_request(kni); if (unlikely(num < nb_rx)) { /* Free mbufs not tx to kni interface */ kni_burst_free_mbufs(&pkts_burst[num], nb_rx - num); @@ -329,18 +342,14 @@ kni_egress(struct rte_kni *kni) } /* Main processing loop */ -static __attribute__((noreturn)) int +static int main_loop(__rte_unused void *arg) { uint8_t pid; const unsigned lcore_id = rte_lcore_id(); struct rte_kni *kni = kni_lcore_to_kni(lcore_id); - if (kni == NULL) { - RTE_LOG(INFO, APP, "Lcore %u has nothing to do\n", lcore_id); - for (;;) - ; /* loop doing nothing */ - } else { + if (kni != NULL) { pid = rte_kni_get_port_id(kni); if (pid >= RTE_MAX_ETHPORTS) rte_exit(EXIT_FAILURE, "Failure: port id >= %d\n", @@ -353,8 +362,13 @@ main_loop(__rte_unused void *arg) fflush(stdout); /* rx loop */ - while (1) + while (1) { + int32_t flag = rte_atomic32_read(&kni_stop); + + if (flag) + break; kni_ingress(kni); + } } else if (kni_port_info[pid].lcore_id_egress == lcore_id) { /* Running on lcores for output packets */ RTE_LOG(INFO, APP, "Lcore %u is writing to port %d\n", @@ -362,15 +376,20 @@ main_loop(__rte_unused void *arg) fflush(stdout); /* tx loop */ - while (1) + while (1) { + int32_t flag = rte_atomic32_read(&kni_stop); + + if (flag) + break; kni_egress(kni); - } else { - RTE_LOG(INFO, APP, "Lcore %u has nothing to do\n", - lcore_id); - for (;;) - ; /* loop doing nothing */ + } } } + + /* fallthrough to here if we don't have any work */ + RTE_LOG(INFO, APP, "Lcore %u has nothing to do\n", lcore_id); + + return 0; } /* Display usage instructions */ @@ -379,10 +398,11 @@ print_usage(const char *prgname) { RTE_LOG(INFO, APP, "\nUsage: %s [EAL options] -- -p PORTMASK " "-i IN_CORES -o OUT_CORES\n" - " -p PORTMASK: hex bitmask of ports to use\n" - " -i IN_CORES: hex bitmask of cores which read " + " -p PORTMASK: hex bitmask of ports to use\n" + " -i IN_CORES: hex bitmask of cores which read " "from NIC\n" - " -o OUT_CORES: hex bitmask of cores which write to NIC\n", + " -o OUT_CORES: hex bitmask of cores which write " + "to NIC\n", prgname); } @@ -436,7 +456,7 @@ kni_setup_port_affinities(uint8_t nb_port) } if (in_lcore != 0) { - /* It is be for packet receiving */ + /* It is for packet receiving */ while ((rx_port < nb_port) && ((ports_mask & (1 << rx_port)) == 0)) rx_port++; @@ -702,6 +722,7 @@ main(int argc, char** argv) /* Associate signal_hanlder function with USR signals */ signal(SIGUSR1, signal_handler); signal(SIGUSR2, signal_handler); + signal(SIGRTMIN, signal_handler); /* Initialise EAL */ ret = rte_eal_init(argc, argv); @@ -781,6 +802,13 @@ main(int argc, char** argv) return -1; } + for (port = 0; port < nb_sys_ports; port++) { + struct rte_kni *kni = kni_port_info[port].kni; + + if (kni != NULL) + rte_kni_release(kni); + } + return 0; }