From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dharton@cisco.com>
Received: from alln-iport-5.cisco.com (alln-iport-5.cisco.com [173.37.142.92])
 by dpdk.org (Postfix) with ESMTP id 6588E6A1A
 for <dev@dpdk.org>; Mon,  9 May 2016 15:59:15 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=cisco.com; i=@cisco.com; l=10011; q=dns/txt;
 s=iport; t=1462802355; x=1464011955;
 h=from:to:subject:date:message-id:references:in-reply-to:
 content-transfer-encoding:mime-version;
 bh=UDIwj3SSR9eVTfIDswZ6WLBdsMYBTnWip+inzjmT3UA=;
 b=i6JOJlhHX99HoefN7ac9Zm0adHlMuBz8ed4U/2uExZarHwPec7aiCmEx
 Ydaasuy7dQqmz5Lo0mYvXKzFKadNMUGyK29Dxvh4zv/kB7ez6Qp7ZrZRU
 GbJwoNLJHwwfnnudXRliy+z8SZpMaaRhYU9hi8rudbIwAzo9WSwNj4pte 8=;
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AYAgDNljBX/4kNJK1dgziBUga2cIIPA?=
 =?us-ascii?q?Q2BdoYQAoEtOBQBAQEBAQEBZSeEQQEBAQMBJxNEBwQCAQgRBAEBHwkHMhQJCAI?=
 =?us-ascii?q?EARIIDIgPCL8EAQEBAQEBAQEBAQEBAQEBAQEBAQEBFYYghEyEHIV8BY1eikQBi?=
 =?us-ascii?q?HOFIY8ejzoBHgEBQoIFG4FLbodJPn8BAQE?=
X-IronPort-AV: E=Sophos;i="5.24,600,1454976000"; d="scan'208";a="269465572"
Received: from alln-core-4.cisco.com ([173.36.13.137])
 by alln-iport-5.cisco.com with ESMTP/TLS/DHE-RSA-AES256-SHA;
 09 May 2016 13:59:14 +0000
Received: from XCH-RCD-019.cisco.com (xch-rcd-019.cisco.com [173.37.102.29])
 by alln-core-4.cisco.com (8.14.5/8.14.5) with ESMTP id u49DxEZp028761
 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL);
 Mon, 9 May 2016 13:59:14 GMT
Received: from xch-rcd-016.cisco.com (173.37.102.26) by XCH-RCD-019.cisco.com
 (173.37.102.29) with Microsoft SMTP Server (TLS) id 15.0.1104.5;
 Mon, 9 May 2016 08:59:13 -0500
Received: from xch-rcd-016.cisco.com ([173.37.102.26]) by
 XCH-RCD-016.cisco.com ([173.37.102.26]) with mapi id 15.00.1104.009; Mon, 9
 May 2016 08:59:13 -0500
From: "David Harton (dharton)" <dharton@cisco.com>
To: Remy Horton <remy.horton@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Thread-Topic: [dpdk-dev] [RFC PATCH v2 1/3] rte: change xstats to use integer
 keys
Thread-Index: AQHRp4gL6Mmj2U93TkacPKNDzPH1DJ+wpZlA
Date: Mon, 9 May 2016 13:59:13 +0000
Message-ID: <9ba773f49a7c4c82bdd55bd63d4cec2e@XCH-RCD-016.cisco.com>
References: <1462533074-1994-1-git-send-email-remy.horton@intel.com>
 <1462533074-1994-2-git-send-email-remy.horton@intel.com>
In-Reply-To: <1462533074-1994-2-git-send-email-remy.horton@intel.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-ms-exchange-transport-fromentityheader: Hosted
x-originating-ip: [10.82.169.253]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Re: [dpdk-dev] [RFC PATCH v2 1/3] rte: change xstats to use integer
 keys
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 09 May 2016 13:59:16 -0000


> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Remy Horton
> Sent: Friday, May 06, 2016 7:11 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [RFC PATCH v2 1/3] rte: change xstats to use integer
> keys
>=20
> Signed-off-by: Remy Horton <remy.horton@intel.com>
> ---
>  lib/librte_ether/rte_ethdev.c | 100 ++++++++++++++++++++++++++++++++++++=
-
> -----
>  lib/librte_ether/rte_ethdev.h |  55 +++++++++++++++++++++++
>  2 files changed, 142 insertions(+), 13 deletions(-)
>=20
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.=
c
> index a31018e..29ba12c 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -112,7 +112,6 @@ static const struct rte_eth_xstats_name_off
> rte_txq_stats_strings[] =3D {
>  #define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /	\
>  		sizeof(rte_txq_stats_strings[0]))
>=20
> -
>  /**
>   * The user application callback description.
>   *
> @@ -1507,6 +1506,87 @@ rte_eth_stats_reset(uint8_t port_id)
>  	dev->data->rx_mbuf_alloc_failed =3D 0;
>  }
>=20
> +int
> +rte_eth_xstats_count(uint8_t port_id)
> +{
> +	struct rte_eth_dev *dev;
> +	int count;
> +
> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
> +	dev =3D &rte_eth_devices[port_id];
> +	if (dev->dev_ops->xstats_names !=3D NULL) {
> +		count =3D (*dev->dev_ops->xstats_names)(dev, NULL, 0);
> +		if (count < 0)
> +			return count;
> +	} else
> +		count =3D 0;
> +	count +=3D RTE_NB_STATS;
> +	count +=3D dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
> +	count +=3D dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
> +	return count;
> +}
> +
> +int
> +rte_eth_xstats_names(uint8_t port_id, struct rte_eth_xstats_name
> *ptr_names,
> +	unsigned limit)
> +{
> +	struct rte_eth_dev *dev;
> +	int cnt_used_entries;
> +	int cnt_expected_entries;
> +	uint32_t idx, id_queue;
> +
> +	if (ptr_names =3D=3D NULL)
> +		return -EINVAL;
> +	cnt_expected_entries =3D rte_eth_xstats_count(port_id);
> +	if (cnt_expected_entries < 0)
> +		return cnt_expected_entries;
> +	if ((int)limit < cnt_expected_entries)
> +		return -ERANGE;
> +
> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
> +	dev =3D &rte_eth_devices[port_id];
> +	if (dev->dev_ops->xstats_names !=3D NULL) {
> +		cnt_used_entries =3D (*dev->dev_ops->xstats_names)(
> +			dev, ptr_names, limit);
> +		if (cnt_used_entries < 0)
> +			return cnt_used_entries;
> +	} else
> +		/* Driver itself does not support extended stats, but
> +		 * still have basic stats.
> +		 */
> +		cnt_used_entries =3D 0;
> +
> +	for (idx =3D 0; idx < RTE_NB_STATS; idx++) {
> +		ptr_names[cnt_used_entries].id =3D cnt_used_entries;
> +		snprintf(ptr_names[cnt_used_entries].name,
> +			sizeof(ptr_names[0].name),
> +			"%s", rte_stats_strings[idx].name);
> +		cnt_used_entries++;
> +	}
> +	for (id_queue =3D 0; id_queue < dev->data->nb_rx_queues; id_queue++) {
> +		for (idx =3D 0; idx < RTE_NB_RXQ_STATS; idx++) {
> +			ptr_names[cnt_used_entries].id =3D cnt_used_entries;
> +			snprintf(ptr_names[cnt_used_entries].name,
> +				sizeof(ptr_names[0].name),
> +				"rx_q%u%s",
> +				id_queue, rte_rxq_stats_strings[idx].name);
> +			cnt_used_entries++;
> +		}
> +
> +	}
> +	for (id_queue =3D 0; id_queue < dev->data->nb_tx_queues; id_queue++) {
> +		for (idx =3D 0; idx < RTE_NB_TXQ_STATS; idx++) {
> +			ptr_names[cnt_used_entries].id =3D cnt_used_entries;
> +			snprintf(ptr_names[cnt_used_entries].name,
> +				sizeof(ptr_names[0].name),
> +				"tx_q%u%s",
> +				id_queue, rte_txq_stats_strings[idx].name);
> +			cnt_used_entries++;
> +		}
> +	}
> +	return cnt_used_entries;
> +}
> +
>  /* retrieve ethdev extended statistics */  int
> rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, @@ -
> 1551,8 +1631,8 @@ rte_eth_xstats_get(uint8_t port_id, struct
> rte_eth_xstats *xstats,
>  		stats_ptr =3D RTE_PTR_ADD(&eth_stats,
>  					rte_stats_strings[i].offset);
>  		val =3D *stats_ptr;
> -		snprintf(xstats[count].name, sizeof(xstats[count].name),
> -			"%s", rte_stats_strings[i].name);
> +		xstats[count].name[0] =3D '\0';
> +		xstats[count].id =3D count + xcount;
>  		xstats[count++].value =3D val;
>  	}
>=20
> @@ -1563,9 +1643,8 @@ rte_eth_xstats_get(uint8_t port_id, struct
> rte_eth_xstats *xstats,
>  					rte_rxq_stats_strings[i].offset +
>  					q * sizeof(uint64_t));
>  			val =3D *stats_ptr;
> -			snprintf(xstats[count].name, sizeof(xstats[count].name),
> -				"rx_q%u_%s", q,
> -				rte_rxq_stats_strings[i].name);
> +			xstats[count].name[0] =3D '\0';
> +			xstats[count].id =3D count + xcount;
>  			xstats[count++].value =3D val;
>  		}
>  	}
> @@ -1577,9 +1656,8 @@ rte_eth_xstats_get(uint8_t port_id, struct
> rte_eth_xstats *xstats,
>  					rte_txq_stats_strings[i].offset +
>  					q * sizeof(uint64_t));
>  			val =3D *stats_ptr;
> -			snprintf(xstats[count].name, sizeof(xstats[count].name),
> -				"tx_q%u_%s", q,
> -				rte_txq_stats_strings[i].name);
> +			xstats[count].name[0] =3D '\0';
> +			xstats[count].id =3D count + xcount;
>  			xstats[count++].value =3D val;
>  		}
>  	}
> @@ -1621,7 +1699,6 @@ set_queue_stats_mapping(uint8_t port_id, uint16_t
> queue_id, uint8_t stat_idx,
>  			(dev, queue_id, stat_idx, is_rx);
>  }
>=20
> -

Not sure how the community feels about white-space only changes.
Just mentioning in case some folks get excited about it.  One here and a fe=
w below.

>  int
>  rte_eth_dev_set_tx_queue_stats_mapping(uint8_t port_id, uint16_t
> tx_queue_id,
>  		uint8_t stat_idx)
> @@ -1630,7 +1707,6 @@ rte_eth_dev_set_tx_queue_stats_mapping(uint8_t
> port_id, uint16_t tx_queue_id,
>  			STAT_QMAP_TX);
>  }
>=20
> -
>  int
>  rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t
> rx_queue_id,
>  		uint8_t stat_idx)
> @@ -1639,7 +1715,6 @@ rte_eth_dev_set_rx_queue_stats_mapping(uint8_t
> port_id, uint16_t rx_queue_id,
>  			STAT_QMAP_RX);
>  }
>=20
> -
>  void
>  rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
> { @@ -1699,7 +1774,6 @@ rte_eth_macaddr_get(uint8_t port_id, struct
> ether_addr *mac_addr)
>  	ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);  }
>=20
> -
>  int
>  rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)  { diff --git
> a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index
> 022733e..eaeb703 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -941,10 +941,23 @@ struct rte_eth_txq_info {
>   * structure.
>   */
>  struct rte_eth_xstats {
> +	/* FIXME: Remove name[] once remaining drivers converted */
>  	char name[RTE_ETH_XSTATS_NAME_SIZE];
> +	uint64_t id;
>  	uint64_t value;
>  };
>=20
> +/**
> + * A name-key lookup element for extended statistics.
> + *
> + * This structure is used to map between names and ID numbers
> + * for extended ethernet statistics.
> + */
> +struct rte_eth_xstats_name {
> +	char name[RTE_ETH_XSTATS_NAME_SIZE];
> +	uint64_t id;
> +};
> +
>  #define ETH_DCB_NUM_TCS    8
>  #define ETH_MAX_VMDQ_POOL  64
>=20
> @@ -1080,6 +1093,13 @@ typedef int (*eth_xstats_get_t)(struct rte_eth_dev
> *dev,  typedef void (*eth_xstats_reset_t)(struct rte_eth_dev *dev);  /**<
> @internal Reset extended stats of an Ethernet device. */
>=20
> +typedef int (*eth_xstats_names_t)(struct rte_eth_dev *dev,
> +	struct rte_eth_xstats_name *ptr_names, unsigned limit); /**<
> @internal
> +Get names of extended stats of an Ethernet device. */
> +
> +typedef int (*eth_xstats_count_t)(struct rte_eth_dev *dev); /**<
> +@internal Get count of extended stats of an Ethernet device. */
> +
>  typedef int (*eth_queue_stats_mapping_set_t)(struct rte_eth_dev *dev,
>  					     uint16_t queue_id,
>  					     uint8_t stat_idx,
> @@ -1427,6 +1447,10 @@ struct eth_dev_ops {
>  	eth_stats_reset_t          stats_reset;   /**< Reset generic device
> statistics. */
>  	eth_xstats_get_t           xstats_get;    /**< Get extended device
> statistics. */
>  	eth_xstats_reset_t         xstats_reset;  /**< Reset extended device
> statistics. */
> +	eth_xstats_names_t         xstats_names;
> +	/**< Get names of extended statistics. */
> +	eth_xstats_count_t         xstats_count;
> +	/**< Get number of extended statistics. */
>  	eth_queue_stats_mapping_set_t queue_stats_mapping_set;
>  	/**< Configure per queue stat counter mapping. */
>  	eth_dev_infos_get_t        dev_infos_get; /**< Get device info. */
> @@ -2279,6 +2303,37 @@ int rte_eth_stats_get(uint8_t port_id, struct
> rte_eth_stats *stats);  void rte_eth_stats_reset(uint8_t port_id);
>=20
>  /**
> + * Retrieve names of extended statistics of an Ethernet device.
> + *
> + * Names within ptr_strings will be aligned to RTE_ETH_XSTATS_NAME_SIZE
> +and
> + * will be listed in ascending mapping order.
> + *
> + * @param port_id
> + *   The port identifier of the Ethernet device.
> + * @param ptr_names
> + *  Block of memory to insert names into. Must be at least limit in size=
.
> + * @param limit
> + *  Capacity of ptr_strings (number of names).
> + * @return
> + *  If successful, number of statistics; negative on error.
> + */
> +int rte_eth_xstats_names(uint8_t port_id, struct rte_eth_xstats_name
> *ptr_names,
> +	unsigned limit);
> +
> +/**
> + * Retrieve number of extended statistics of an Ethernet device.
> + *
> + * Names within ptr_strings will be aligned to RTE_ETH_XSTATS_NAME_SIZE
> +and
> + * will be listed in ascending mapping order.
> + *
> + * @param port_id
> + *   The port identifier of the Ethernet device.
> + * @return
> + *  If successful, number of statistics; negative on error.
> + */
> +int rte_eth_xstats_count(uint8_t port_id);
> +
> +/**
>   * Retrieve extended statistics of an Ethernet device.
>   *
>   * @param port_id
> --
> 2.5.5

Acked-by: David Harton <dharton@cisco.com>