net/sfc: support xstats retrieval by ID

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Remy Horton <remy.horton@intel.com>
This commit is contained in:
Ivan Malov 2017-07-08 16:45:15 +01:00 committed by Ferruh Yigit
parent 3b257f7e6c
commit 73280c1e4f
3 changed files with 87 additions and 0 deletions

View File

@ -165,6 +165,7 @@ struct sfc_port {
rte_spinlock_t mac_stats_lock;
uint64_t *mac_stats_buf;
unsigned int mac_stats_nb_supported;
efsys_mem_t mac_stats_dma_mem;
boolean_t mac_stats_reset_pending;
uint16_t mac_stats_update_period_ms;

View File

@ -665,6 +665,85 @@ sfc_xstats_get_names(struct rte_eth_dev *dev,
return nstats;
}
static int
sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
uint64_t *values, unsigned int n)
{
struct sfc_adapter *sa = dev->data->dev_private;
struct sfc_port *port = &sa->port;
uint64_t *mac_stats;
unsigned int nb_supported = 0;
unsigned int nb_written = 0;
unsigned int i;
int ret;
int rc;
if (unlikely(values == NULL) ||
unlikely((ids == NULL) && (n < port->mac_stats_nb_supported)))
return port->mac_stats_nb_supported;
rte_spinlock_lock(&port->mac_stats_lock);
rc = sfc_port_update_mac_stats(sa);
if (rc != 0) {
SFC_ASSERT(rc > 0);
ret = -rc;
goto unlock;
}
mac_stats = port->mac_stats_buf;
for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) {
if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
continue;
if ((ids == NULL) || (ids[nb_written] == nb_supported))
values[nb_written++] = mac_stats[i];
++nb_supported;
}
ret = nb_written;
unlock:
rte_spinlock_unlock(&port->mac_stats_lock);
return ret;
}
static int
sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
struct rte_eth_xstat_name *xstats_names,
const uint64_t *ids, unsigned int size)
{
struct sfc_adapter *sa = dev->data->dev_private;
struct sfc_port *port = &sa->port;
unsigned int nb_supported = 0;
unsigned int nb_written = 0;
unsigned int i;
if (unlikely(xstats_names == NULL) ||
unlikely((ids == NULL) && (size < port->mac_stats_nb_supported)))
return port->mac_stats_nb_supported;
for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) {
if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
continue;
if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
char *name = xstats_names[nb_written++].name;
strncpy(name, efx_mac_stat_name(sa->nic, i),
sizeof(xstats_names[0].name));
name[sizeof(xstats_names[0].name) - 1] = '\0';
}
++nb_supported;
}
return nb_written;
}
static int
sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
{
@ -1406,6 +1485,8 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
.rxq_info_get = sfc_rx_queue_info_get,
.txq_info_get = sfc_tx_queue_info_get,
.fw_version_get = sfc_fw_version_get,
.xstats_get_by_id = sfc_xstats_get_by_id,
.xstats_get_names_by_id = sfc_xstats_get_names_by_id,
};
/**

View File

@ -151,6 +151,7 @@ sfc_port_start(struct sfc_adapter *sa)
uint32_t phy_adv_cap;
const uint32_t phy_pause_caps =
((1u << EFX_PHY_CAP_PAUSE) | (1u << EFX_PHY_CAP_ASYM));
unsigned int i;
sfc_log_init(sa, "entry");
@ -222,6 +223,10 @@ sfc_port_start(struct sfc_adapter *sa)
efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask,
sizeof(port->mac_stats_mask));
for (i = 0, port->mac_stats_nb_supported = 0; i < EFX_MAC_NSTATS; ++i)
if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
port->mac_stats_nb_supported++;
port->mac_stats_update_generation = 0;
if (port->mac_stats_update_period_ms != 0) {