[v2,2/2] ethdev: add basic stats for telemetry
Checks
Commit Message
The ethdev library now registers a telemetry command for basic ethdev
statistics.
An example usage is shown below:
Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
{"version": "DPDK 20.08.0-rc0", "pid": 14119, "max_output_len": 16384}
--> /ethdev/stats,0
{"/ethdev/stats": {"ipackets": 0, "opackets": 0, "ibytes": 0, "obytes": \
0, "imissed": 0, "ierrors": 0, "oerrors": 0, "rx_nombuf": 0, \
"q_ipackets": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
"q_opackets": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
"q_ibytes": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
"q_obytes": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
"q_errors": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}
Signed-off-by: Ciara Power <ciara.power@intel.com>
---
v2:
- Updated to use memory management APIs.
---
lib/librte_ethdev/rte_ethdev.c | 53 ++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
Comments
On Wed, Jun 24, 2020 at 02:48:24PM +0100, Ciara Power wrote:
> The ethdev library now registers a telemetry command for basic ethdev
> statistics.
>
> An example usage is shown below:
>
> Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
> {"version": "DPDK 20.08.0-rc0", "pid": 14119, "max_output_len": 16384}
> --> /ethdev/stats,0
> {"/ethdev/stats": {"ipackets": 0, "opackets": 0, "ibytes": 0, "obytes": \
> 0, "imissed": 0, "ierrors": 0, "oerrors": 0, "rx_nombuf": 0, \
> "q_ipackets": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
> "q_opackets": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
> "q_ibytes": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
> "q_obytes": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \
> "q_errors": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}
>
> Signed-off-by: Ciara Power <ciara.power@intel.com>
>
One comment inline below, otherwise:
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> v2:
> - Updated to use memory management APIs.
> ---
> lib/librte_ethdev/rte_ethdev.c | 53 ++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 8e10a6fc3..23de93b50 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -5215,6 +5215,57 @@ handle_port_list(const char *cmd __rte_unused,
> return 0;
> }
>
> +static void
> +add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats,
> + const char *stat_name)
> +{
> + int q;
> + struct rte_tel_data *q_data = rte_tel_data_alloc();
> + rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL);
> + for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++)
> + rte_tel_data_add_array_u64(q_data, q_stats[q]);
> + rte_tel_data_add_dict_container(d, stat_name, q_data, 0);
> +}
> +
> +#define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s)
> +
> +static int
> +handle_port_stats(const char *cmd __rte_unused,
> + const char *params,
> + struct rte_tel_data *d)
> +{
> + struct rte_eth_stats stats;
> + int port_id, ret;
> +
> + if (params == NULL || strlen(params) == 0 || !isdigit(*params))
> + return -1;
> +
> + port_id = atoi(params);
> + if (!rte_eth_dev_is_valid_port(port_id))
> + return -1;
> +
> + ret = rte_eth_stats_get(port_id, &stats);
> + if (ret < 0)
> + return -1;
> +
> + rte_tel_data_start_dict(d);
> + ADD_DICT_STAT(stats, ipackets);
> + ADD_DICT_STAT(stats, opackets);
> + ADD_DICT_STAT(stats, ibytes);
> + ADD_DICT_STAT(stats, obytes);
> + ADD_DICT_STAT(stats, imissed);
> + ADD_DICT_STAT(stats, ierrors);
> + ADD_DICT_STAT(stats, oerrors);
> + ADD_DICT_STAT(stats, rx_nombuf);
> + add_port_queue_stats(d, stats.q_ipackets, "q_ipackets");
> + add_port_queue_stats(d, stats.q_opackets, "q_opackets");
> + add_port_queue_stats(d, stats.q_ibytes, "q_ibytes");
> + add_port_queue_stats(d, stats.q_obytes, "q_obytes");
> + add_port_queue_stats(d, stats.q_errors, "q_errors");
> +
> + return 0;
> +}
> +
> static int
> handle_port_xstats(const char *cmd __rte_unused,
> const char *params,
> @@ -5302,6 +5353,8 @@ RTE_INIT(ethdev_init_log)
> rte_log_set_level(rte_eth_dev_logtype, RTE_LOG_INFO);
> rte_telemetry_register_cmd("/ethdev/list", handle_port_list,
> "Returns list of available ethdev ports. Takes no parameters");
> + rte_telemetry_register_cmd("/ethdev/stats", handle_port_stats,
> + "Returns the basic stats for a port. Parameters: int port_id");
I think "common stats" or "standard stats" may be better than calling them
"basic stats" since the main advantage of them is that they are
common/standard across all drivers and are not NIC-specific.
> rte_telemetry_register_cmd("/ethdev/xstats", handle_port_xstats,
> "Returns the extended stats for a port. Parameters: int port_id");
> rte_telemetry_register_cmd("/ethdev/link_status",
> --
> 2.17.1
>
@@ -5215,6 +5215,57 @@ handle_port_list(const char *cmd __rte_unused,
return 0;
}
+static void
+add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats,
+ const char *stat_name)
+{
+ int q;
+ struct rte_tel_data *q_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL);
+ for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++)
+ rte_tel_data_add_array_u64(q_data, q_stats[q]);
+ rte_tel_data_add_dict_container(d, stat_name, q_data, 0);
+}
+
+#define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s)
+
+static int
+handle_port_stats(const char *cmd __rte_unused,
+ const char *params,
+ struct rte_tel_data *d)
+{
+ struct rte_eth_stats stats;
+ int port_id, ret;
+
+ if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+ return -1;
+
+ port_id = atoi(params);
+ if (!rte_eth_dev_is_valid_port(port_id))
+ return -1;
+
+ ret = rte_eth_stats_get(port_id, &stats);
+ if (ret < 0)
+ return -1;
+
+ rte_tel_data_start_dict(d);
+ ADD_DICT_STAT(stats, ipackets);
+ ADD_DICT_STAT(stats, opackets);
+ ADD_DICT_STAT(stats, ibytes);
+ ADD_DICT_STAT(stats, obytes);
+ ADD_DICT_STAT(stats, imissed);
+ ADD_DICT_STAT(stats, ierrors);
+ ADD_DICT_STAT(stats, oerrors);
+ ADD_DICT_STAT(stats, rx_nombuf);
+ add_port_queue_stats(d, stats.q_ipackets, "q_ipackets");
+ add_port_queue_stats(d, stats.q_opackets, "q_opackets");
+ add_port_queue_stats(d, stats.q_ibytes, "q_ibytes");
+ add_port_queue_stats(d, stats.q_obytes, "q_obytes");
+ add_port_queue_stats(d, stats.q_errors, "q_errors");
+
+ return 0;
+}
+
static int
handle_port_xstats(const char *cmd __rte_unused,
const char *params,
@@ -5302,6 +5353,8 @@ RTE_INIT(ethdev_init_log)
rte_log_set_level(rte_eth_dev_logtype, RTE_LOG_INFO);
rte_telemetry_register_cmd("/ethdev/list", handle_port_list,
"Returns list of available ethdev ports. Takes no parameters");
+ rte_telemetry_register_cmd("/ethdev/stats", handle_port_stats,
+ "Returns the basic stats for a port. Parameters: int port_id");
rte_telemetry_register_cmd("/ethdev/xstats", handle_port_xstats,
"Returns the extended stats for a port. Parameters: int port_id");
rte_telemetry_register_cmd("/ethdev/link_status",