[PATCH v3 2/2] net/gve: add Rx/Tx queue stats as extended stats
Ferruh Yigit
ferruh.yigit at amd.com
Mon Feb 20 23:57:30 CET 2023
On 2/20/2023 9:11 PM, Levend Sayar wrote:
> Google Virtual NIC rx/tx queue stats are added as extended stats.
>
> Signed-off-by: Levend Sayar <levendsayar at gmail.com>
Thank you for the update, mainly looks good to me, there area a few
minor questions/comments below.
<...>
> +static const struct gve_xstats_name_offset tx_xstats_name_offset[] = {
> + { "packets", offsetof(struct gve_tx_stats, packets) },
> + { "bytes", offsetof(struct gve_tx_stats, bytes) },
> + { "errors", offsetof(struct gve_tx_stats, errors) },
> +};
> +
It is possible to create macros to get offsets to prevent any mistakes
but not quite sure if it is needed with above limited number of items,
so up to you, I mean something like:
#define RX_QUEUE_STATS_OFFSET(x) offsetof(struct gve_rx_stats, X)
#define TX_QUEUE_STATS_OFFSET(x) offsetof(struct gve_tx_stats, X)
> +static const struct gve_xstats_name_offset rx_xstats_name_offset[] = {
> + { "packets", offsetof(struct gve_rx_stats, packets) },
> + { "bytes", offsetof(struct gve_rx_stats, bytes) },
> + { "errors", offsetof(struct gve_rx_stats, errors) },
> +};
> +
Is 'no_mbufs' omitted intentionally?
<...>
>
> +static int
> +gve_xstats_count(struct rte_eth_dev *dev)
> +{
> + uint16_t i, count = 0;
> +
> + for (i = 0; i < dev->data->nb_tx_queues; i++) {
> + if (dev->data->tx_queues[i])
Normally 'dev->data->tx_queues[i]' shouldn't be NULL, but I can see
driver checks this in a few locations.
Is there a case that 'dev->data->tx_queues[i]' can be NULL where "0 <= i
< dev->data->nb_tx_queues" ?
> + count += RTE_DIM(tx_xstats_name_offset);
> + }
> +
> + for (i = 0; i < dev->data->nb_rx_queues; i++) {
> + if (dev->data->rx_queues[i])
> + count += RTE_DIM(rx_xstats_name_offset);
> + }
> +
> + return count;
> +}
> +
> +static int
> +gve_xstats_get(struct rte_eth_dev *dev,
> + struct rte_eth_xstat *xstats,
> + unsigned int size)
> +{
> + uint16_t i, count = 0;
> +
> + if (!xstats)
> + return (size == 0) ? gve_xstats_count(dev) : -EINVAL;
Error case (xstats == NULL && size != 0) should be handled by ethdev, so
driver can only check "xstats == NULL" case.
btw, although we have mixed usage and not very strict on it, coding
convention requires testing against NULL [1] instead of '!'.
[1]
https://doc.dpdk.org/guides/contributing/coding_style.html#null-pointers
> +
> + for (i = 0; i < dev->data->nb_tx_queues; i++) {
> + const struct gve_tx_queue *txq = dev->data->tx_queues[i];
> + if (!txq)
> + continue;
> +
similar to above comment, I expect 'txq' not to be NULL, isn't this
correct for the driver?
> + if (count >= size)
> + break;
> +
Instead of above check in a loop, it is possible to check once at the
beginning of the function like
count = gve_xstats_count(dev)
if (size < count)
return count;
Because when there is not enough room in the xstats array, API doesn't
expect existing elements of array to be correct, returning a value
bigger than 'size' indicates error case and content of xstats is invalid
anyway.
> + uint16_t j = 0;
> + const char *stats = (const char *)&txq->stats;
Can you please move variable declarations at the beginning of the scope,
for above variables it is just after for statement, according coding
convention.
> + for (j = 0; j < RTE_DIM(tx_xstats_name_offset); j++, count++) {
> + xstats[count].id = count;
> + xstats[count].value = *(const uint64_t *)
> + (stats + tx_xstats_name_offset[j].offset);
> + }
> + }
> +
> + for (i = 0; i < dev->data->nb_rx_queues; i++) {
> + const struct gve_rx_queue *rxq = dev->data->rx_queues[i];
> + if (!rxq)
> + continue;
> +
> + if (count >= size)
> + break;
> +
> + uint16_t j = 0;
> + const char *stats = (const char *)&rxq->stats;
> + for (j = 0; j < RTE_DIM(rx_xstats_name_offset); j++, count++) {
> + xstats[count].id = count;
> + xstats[count].value = *(const uint64_t *)
> + (stats + rx_xstats_name_offset[j].offset);
> + }
> + }
> +
> + return count;
> +}
> +
> +static int
> +gve_xstats_get_names(struct rte_eth_dev *dev,
> + struct rte_eth_xstat_name *xstats_names,
> + unsigned int size)
> +{
> + uint16_t i, count = 0;
> +
> + if (!xstats_names)
> + return (size == 0) ? gve_xstats_count(dev) : -EINVAL;
> +
> + for (i = 0; i < dev->data->nb_tx_queues; i++) {
> + if (!dev->data->tx_queues[i])
> + continue;
> +
> + if (count >= size)
> + break;
> +
> + uint16_t j = 0;
> + for (; j < RTE_DIM(tx_xstats_name_offset); j++)
> + snprintf(xstats_names[count++].name,
> + RTE_ETH_XSTATS_NAME_SIZE,
> + "tx_q%u_%s", i, tx_xstats_name_offset[j].name);
> + }
> +
> + for (i = 0; i < dev->data->nb_rx_queues; i++) {
> + if (!dev->data->rx_queues[i])
> + continue;
> +
> + if (count >= size)
> + break;
> +
> + uint16_t j = 0;
> + for (; j < RTE_DIM(rx_xstats_name_offset); j++)
> + snprintf(xstats_names[count++].name,
> + RTE_ETH_XSTATS_NAME_SIZE,
> + "rx_q%u_%s", i, rx_xstats_name_offset[j].name);
> + }
> +
> + return count;
> +}
> +
comments on 'gve_xstats_get()' valid here too.
More information about the dev
mailing list