src/dpdk/drivers/net/mlx5/mlx5_stats.c
int
mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
	struct mlx5_priv *priv = dev->data->dev_private;
	struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
	struct rte_eth_stats tmp;
	unsigned int i;
	unsigned int idx;
	uint64_t wrap_n;
	int ret;

	memset(&tmp, 0, sizeof(tmp));
	/* Add software counters. */
	for (i = 0; (i != priv->rxqs_n); ++i) {
		struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];

		if (rxq == NULL)
			continue;
		idx = rxq->idx;
		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
#ifdef MLX5_PMD_SOFT_COUNTERS
			tmp.q_ipackets[idx] += rxq->stats.ipackets;
			tmp.q_ibytes[idx] += rxq->stats.ibytes;
#endif
			tmp.q_errors[idx] += (rxq->stats.idropped +
					      rxq->stats.rx_nombuf);
		}
#ifdef MLX5_PMD_SOFT_COUNTERS
		tmp.ipackets += rxq->stats.ipackets;
		tmp.ibytes += rxq->stats.ibytes;
#endif
		tmp.ierrors += rxq->stats.idropped;
		tmp.rx_nombuf += rxq->stats.rx_nombuf;
	}
	for (i = 0; (i != priv->txqs_n); ++i) {
		struct mlx5_txq_data *txq = (*priv->txqs)[i];

		if (txq == NULL)
			continue;
		idx = txq->idx;
		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
#ifdef MLX5_PMD_SOFT_COUNTERS
			tmp.q_opackets[idx] += txq->stats.opackets;
			tmp.q_obytes[idx] += txq->stats.obytes;
#endif
		}
#ifdef MLX5_PMD_SOFT_COUNTERS
		tmp.opackets += txq->stats.opackets;
		tmp.obytes += txq->stats.obytes;
#endif
		tmp.oerrors += txq->stats.oerrors;
	}
	ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &tmp.imissed);
	if (ret == 0) {
		tmp.imissed = (tmp.imissed - stats_ctrl->imissed_base) &
				 (uint64_t)UINT32_MAX;
		wrap_n = stats_ctrl->imissed >> 32;
		if (tmp.imissed < (stats_ctrl->imissed & (uint64_t)UINT32_MAX))
			wrap_n++;
		tmp.imissed |= (wrap_n) << 32;
		stats_ctrl->imissed = tmp.imissed;
	} else {
		tmp.imissed = stats_ctrl->imissed;
	}
#ifndef MLX5_PMD_SOFT_COUNTERS
	/* FIXME: retrieve and add hardware counters. */
#endif
	*stats = tmp;
	return 0;
}
/**
 * DPDK callback to get device statistics.
 *
 * @param dev
 *   Pointer to Ethernet device structure.
 * @param[out] stats
 *   Stats structure output buffer.
 *
 * @return
 *   0 on success and stats is filled, negative errno value otherwise and
 *   rte_errno is set.
 */
DPDK callback to get device statistics.
@param dev
Pointer to Ethernet device structure.
@param[out] stats
Stats structure output buffer.

@return
0 on success and stats is filled, negative errno value otherwise and
rte_errno is set.
DPDK callback to get device statistics . @param dev Pointer to Ethernet device structure . @param [ out ] stats Stats structure output buffer . @return 0 on success and stats is filled negative errno value otherwise and rte_errno is set .
int
mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
{
	struct mlx5_priv *priv = dev->data->dev_private;
	struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
	struct rte_eth_stats tmp;
	unsigned int i;
	unsigned int idx;
	uint64_t wrap_n;
	int ret;
	memset(&tmp, 0, sizeof(tmp));
	for (i = 0; (i != priv->rxqs_n); ++i) {
		struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
		if (rxq == NULL)
			continue;
		idx = rxq->idx;
		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
#ifdef MLX5_PMD_SOFT_COUNTERS
			tmp.q_ipackets[idx] += rxq->stats.ipackets;
			tmp.q_ibytes[idx] += rxq->stats.ibytes;
#endif
			tmp.q_errors[idx] += (rxq->stats.idropped +
					      rxq->stats.rx_nombuf);
		}
#ifdef MLX5_PMD_SOFT_COUNTERS
		tmp.ipackets += rxq->stats.ipackets;
		tmp.ibytes += rxq->stats.ibytes;
#endif
		tmp.ierrors += rxq->stats.idropped;
		tmp.rx_nombuf += rxq->stats.rx_nombuf;
	}
	for (i = 0; (i != priv->txqs_n); ++i) {
		struct mlx5_txq_data *txq = (*priv->txqs)[i];
		if (txq == NULL)
			continue;
		idx = txq->idx;
		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
#ifdef MLX5_PMD_SOFT_COUNTERS
			tmp.q_opackets[idx] += txq->stats.opackets;
			tmp.q_obytes[idx] += txq->stats.obytes;
#endif
		}
#ifdef MLX5_PMD_SOFT_COUNTERS
		tmp.opackets += txq->stats.opackets;
		tmp.obytes += txq->stats.obytes;
#endif
		tmp.oerrors += txq->stats.oerrors;
	}
	ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &tmp.imissed);
	if (ret == 0) {
		tmp.imissed = (tmp.imissed - stats_ctrl->imissed_base) &
				 (uint64_t)UINT32_MAX;
		wrap_n = stats_ctrl->imissed >> 32;
		if (tmp.imissed < (stats_ctrl->imissed & (uint64_t)UINT32_MAX))
			wrap_n++;
		tmp.imissed |= (wrap_n) << 32;
		stats_ctrl->imissed = tmp.imissed;
	} else {
		tmp.imissed = stats_ctrl->imissed;
	}
#ifndef MLX5_PMD_SOFT_COUNTERS
#endif
	*stats = tmp;
	return 0;
}
int mlx5_stats_get ( struct rte_eth_dev * dev , struct rte_eth_stats * stats ) { struct mlx5_priv * priv = dev -> data -> dev_private ; struct mlx5_stats_ctrl * stats_ctrl = & priv -> stats_ctrl ; struct rte_eth_stats tmp ; unsigned int i ; unsigned int idx ; uint64_t wrap_n ; int ret ; memset ( & tmp , 0 , sizeof ( tmp ) ) ; for ( i = 0 ; ( i != priv -> rxqs_n ) ; ++ i ) { struct mlx5_rxq_data * rxq = ( * priv -> rxqs ) [ i ] ; if ( rxq == NULL ) continue ; idx = rxq -> idx ; if ( idx < RTE_ETHDEV_QUEUE_STAT_CNTRS ) { #ifdef MLX5_PMD_SOFT_COUNTERS tmp . q_ipackets [ idx ] += rxq -> stats . ipackets ; tmp . q_ibytes [ idx ] += rxq -> stats . ibytes ; #endif tmp . q_errors [ idx ] += ( rxq -> stats . idropped + rxq -> stats . rx_nombuf ) ; } #ifdef MLX5_PMD_SOFT_COUNTERS tmp . ipackets += rxq -> stats . ipackets ; tmp . ibytes += rxq -> stats . ibytes ; #endif tmp . ierrors += rxq -> stats . idropped ; tmp . rx_nombuf += rxq -> stats . rx_nombuf ; } for ( i = 0 ; ( i != priv -> txqs_n ) ; ++ i ) { struct mlx5_txq_data * txq = ( * priv -> txqs ) [ i ] ; if ( txq == NULL ) continue ; idx = txq -> idx ; if ( idx < RTE_ETHDEV_QUEUE_STAT_CNTRS ) { #ifdef MLX5_PMD_SOFT_COUNTERS tmp . q_opackets [ idx ] += txq -> stats . opackets ; tmp . q_obytes [ idx ] += txq -> stats . obytes ; #endif } #ifdef MLX5_PMD_SOFT_COUNTERS tmp . opackets += txq -> stats . opackets ; tmp . obytes += txq -> stats . obytes ; #endif tmp . oerrors += txq -> stats . oerrors ; } ret = mlx5_os_read_dev_stat ( priv , " " , & tmp . imissed ) ; if ( ret == 0 ) { tmp . imissed = ( tmp . imissed - stats_ctrl -> imissed_base ) & ( uint64_t ) UINT32_MAX ; wrap_n = stats_ctrl -> imissed >> 32 ; if ( tmp . imissed < ( stats_ctrl -> imissed & ( uint64_t ) UINT32_MAX ) ) wrap_n ++ ; tmp . imissed |= ( wrap_n ) << 32 ; stats_ctrl -> imissed = tmp . imissed ; } else { tmp . imissed = stats_ctrl -> imissed ; } #ifndef MLX5_PMD_SOFT_COUNTERS #endif * stats = tmp ; return 0 ; }
DPDK callback to get device statistics.
DPDK callback to get device statistics .
/* Add software counters. */ /* FIXME: retrieve and add hardware counters. */