From: Ivan Malov Date: Fri, 3 Mar 2017 12:49:25 +0000 (+0000) Subject: net/sfc: support statistics reset X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e8acb3298d170847c59ddd156e2cec44c636f6d4;p=dpdk.git net/sfc: support statistics reset Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko --- diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 8c6c02fe49..655328fc89 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -153,6 +153,7 @@ struct sfc_port { rte_spinlock_t mac_stats_lock; uint64_t *mac_stats_buf; efsys_mem_t mac_stats_dma_mem; + boolean_t mac_stats_reset_pending; uint32_t mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES]; }; @@ -281,6 +282,7 @@ void sfc_port_stop(struct sfc_adapter *sa); void sfc_port_link_mode_to_info(efx_link_mode_t link_mode, struct rte_eth_link *link_info); int sfc_port_update_mac_stats(struct sfc_adapter *sa); +int sfc_port_reset_mac_stats(struct sfc_adapter *sa); int sfc_set_rx_mode(struct sfc_adapter *sa); diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 71587fbbc5..cac01aca55 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -525,6 +525,27 @@ unlock: rte_spinlock_unlock(&port->mac_stats_lock); } +static void +sfc_stats_reset(struct rte_eth_dev *dev) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + int rc; + + if (sa->state != SFC_ADAPTER_STARTED) { + /* + * The operation cannot be done if port is not started; it + * will be scheduled to be done during the next port start + */ + port->mac_stats_reset_pending = B_TRUE; + return; + } + + rc = sfc_port_reset_mac_stats(sa); + if (rc != 0) + sfc_err(sa, "failed to reset statistics (rc = %d)", rc); +} + static int sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int xstats_count) @@ -1200,7 +1221,9 @@ static const struct eth_dev_ops sfc_eth_dev_ops = { .allmulticast_disable = sfc_dev_allmulti_disable, .link_update = sfc_dev_link_update, .stats_get = sfc_stats_get, + .stats_reset = sfc_stats_reset, .xstats_get = sfc_xstats_get, + .xstats_reset = sfc_stats_reset, .xstats_get_names = sfc_xstats_get_names, .dev_infos_get = sfc_dev_infos_get, .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get, diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index 5998a9904f..e2f504383b 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -61,6 +61,19 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) return 0; } +int +sfc_port_reset_mac_stats(struct sfc_adapter *sa) +{ + struct sfc_port *port = &sa->port; + int rc; + + rte_spinlock_lock(&port->mac_stats_lock); + rc = efx_mac_stats_clear(sa->nic); + rte_spinlock_unlock(&port->mac_stats_lock); + + return rc; +} + static int sfc_port_init_dev_link(struct sfc_adapter *sa) { @@ -140,6 +153,15 @@ sfc_port_start(struct sfc_adapter *sa) if (rc != 0) goto fail_mac_filter_set; + if (port->mac_stats_reset_pending) { + rc = sfc_port_reset_mac_stats(sa); + if (rc != 0) + sfc_err(sa, "statistics reset failed (requested " + "before the port was started)"); + + port->mac_stats_reset_pending = B_FALSE; + } + efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask, sizeof(port->mac_stats_mask)); @@ -237,6 +259,8 @@ sfc_port_init(struct sfc_adapter *sa) if (rc != 0) goto fail_mac_stats_dma_alloc; + port->mac_stats_reset_pending = B_FALSE; + sfc_log_init(sa, "done"); return 0;