X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=examples%2Fkni%2Fmain.c;h=4710d717690f5728db613e938ab4748510884551;hb=f319d9937977479528870c6859bd3a227c212f75;hp=4fda5171340c06947bc3010472303f9a41690686;hpb=724beb913b44b4686b1d3f70bb5548d4210c1ca2;p=dpdk.git diff --git a/examples/kni/main.c b/examples/kni/main.c index 4fda517134..4710d71769 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -132,6 +132,7 @@ static int kni_config_network_interface(uint16_t port_id, uint8_t if_up); static int kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]); static rte_atomic32_t kni_stop = RTE_ATOMIC32_INIT(0); +static rte_atomic32_t kni_pause = RTE_ATOMIC32_INIT(0); /* Print out statistics on packets handled */ static void @@ -171,14 +172,13 @@ signal_handler(int signum) /* When we receive a USR2 signal, reset stats */ if (signum == SIGUSR2) { memset(&kni_stats, 0, sizeof(kni_stats)); - printf("\n**Statistics have been reset**\n"); + printf("\n** Statistics have been reset **\n"); return; } /* When we receive a RTMIN or SIGINT signal, stop kni processing */ if (signum == SIGRTMIN || signum == SIGINT){ - printf("SIGRTMIN is received, and the KNI processing is " - "going to stop\n"); + printf("\nSIGRTMIN/SIGINT received. KNI processing stopping.\n"); rte_atomic32_inc(&kni_stop); return; } @@ -224,7 +224,8 @@ kni_ingress(struct kni_port_params *p) } /* Burst tx to kni */ num = rte_kni_tx_burst(p->kni[i], pkts_burst, nb_rx); - kni_stats[port_id].rx_packets += num; + if (num) + kni_stats[port_id].rx_packets += num; rte_kni_handle_request(p->kni[i]); if (unlikely(num < nb_rx)) { @@ -261,7 +262,8 @@ kni_egress(struct kni_port_params *p) } /* Burst tx to eth */ nb_tx = rte_eth_tx_burst(port_id, 0, pkts_burst, (uint16_t)num); - kni_stats[port_id].tx_packets += nb_tx; + if (nb_tx) + kni_stats[port_id].tx_packets += nb_tx; if (unlikely(nb_tx < num)) { /* Free mbufs not tx to NIC */ kni_burst_free_mbufs(&pkts_burst[nb_tx], num - nb_tx); @@ -275,6 +277,7 @@ main_loop(__rte_unused void *arg) { uint16_t i; int32_t f_stop; + int32_t f_pause; const unsigned lcore_id = rte_lcore_id(); enum lcore_rxtx { LCORE_NONE, @@ -303,8 +306,11 @@ main_loop(__rte_unused void *arg) kni_port_params_array[i]->port_id); while (1) { f_stop = rte_atomic32_read(&kni_stop); + f_pause = rte_atomic32_read(&kni_pause); if (f_stop) break; + if (f_pause) + continue; kni_ingress(kni_port_params_array[i]); } } else if (flag == LCORE_TX) { @@ -313,8 +319,11 @@ main_loop(__rte_unused void *arg) kni_port_params_array[i]->port_id); while (1) { f_stop = rte_atomic32_read(&kni_stop); + f_pause = rte_atomic32_read(&kni_pause); if (f_stop) break; + if (f_pause) + continue; kni_egress(kni_port_params_array[i]); } } else @@ -751,7 +760,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) memcpy(&conf, &port_conf, sizeof(conf)); /* Set new MTU */ - if (new_mtu > ETHER_MAX_LEN) + if (new_mtu > RTE_ETHER_MAX_LEN) conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME; else conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME; @@ -806,12 +815,16 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up) RTE_LOG(INFO, APP, "Configure network interface of %d %s\n", port_id, if_up ? "up" : "down"); + rte_atomic32_inc(&kni_pause); + if (if_up != 0) { /* Configure network interface up */ rte_eth_dev_stop(port_id); ret = rte_eth_dev_start(port_id); } else /* Configure network interface down */ rte_eth_dev_stop(port_id); + rte_atomic32_dec(&kni_pause); + if (ret < 0) RTE_LOG(ERR, APP, "Failed to start port %d\n", port_id); @@ -819,10 +832,10 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up) } static void -print_ethaddr(const char *name, struct ether_addr *mac_addr) +print_ethaddr(const char *name, struct rte_ether_addr *mac_addr) { - char buf[ETHER_ADDR_FMT_SIZE]; - ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, mac_addr); + char buf[RTE_ETHER_ADDR_FMT_SIZE]; + rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, mac_addr); RTE_LOG(INFO, APP, "\t%s%s\n", name, buf); } @@ -838,10 +851,10 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]) } RTE_LOG(INFO, APP, "Configure mac address of %d\n", port_id); - print_ethaddr("Address:", (struct ether_addr *)mac_addr); + print_ethaddr("Address:", (struct rte_ether_addr *)mac_addr); ret = rte_eth_dev_default_mac_addr_set(port_id, - (struct ether_addr *)mac_addr); + (struct rte_ether_addr *)mac_addr); if (ret < 0) RTE_LOG(ERR, APP, "Failed to config mac_addr for port %d\n", port_id); @@ -884,22 +897,13 @@ kni_alloc(uint16_t port_id) if (i == 0) { struct rte_kni_ops ops; struct rte_eth_dev_info dev_info; - const struct rte_pci_device *pci_dev; - const struct rte_bus *bus = NULL; memset(&dev_info, 0, sizeof(dev_info)); rte_eth_dev_info_get(port_id, &dev_info); - if (dev_info.device) - bus = rte_bus_find_by_device(dev_info.device); - if (bus && !strcmp(bus->name, "pci")) { - pci_dev = RTE_DEV_TO_PCI(dev_info.device); - conf.addr = pci_dev->addr; - conf.id = pci_dev->id; - } /* Get the interface default mac address */ rte_eth_macaddr_get(port_id, - (struct ether_addr *)&conf.mac_addr); + (struct rte_ether_addr *)&conf.mac_addr); rte_eth_dev_get_mtu(port_id, &conf.mtu); @@ -950,6 +954,7 @@ main(int argc, char** argv) unsigned i; void *retval; pthread_t kni_link_tid; + int pid; /* Associate signal_hanlder function with USR signals */ signal(SIGUSR1, signal_handler); @@ -1006,6 +1011,16 @@ main(int argc, char** argv) } check_all_ports_link_status(ports_mask); + pid = getpid(); + RTE_LOG(INFO, APP, "========================\n"); + RTE_LOG(INFO, APP, "KNI Running\n"); + RTE_LOG(INFO, APP, "kill -SIGUSR1 %d\n", pid); + RTE_LOG(INFO, APP, " Show KNI Statistics.\n"); + RTE_LOG(INFO, APP, "kill -SIGUSR2 %d\n", pid); + RTE_LOG(INFO, APP, " Zero KNI Statistics.\n"); + RTE_LOG(INFO, APP, "========================\n"); + fflush(stdout); + ret = rte_ctrl_thread_create(&kni_link_tid, "KNI link status check", NULL, monitor_all_ports_link_status, NULL);