[v3] cryptodev: add telemetry callbacks

Message ID 20211007141110.569739-1-rebecca.troy@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series [v3] cryptodev: add telemetry callbacks |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-spell-check-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional fail Functional Testing issues
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Rebecca Troy Oct. 7, 2021, 2:11 p.m. UTC
  The cryptodev library now registers commands with telemetry, and
implements the corresponding callback functions. These commands
allow a list of cryptodevs to be queried, as well as info and stats
for the corresponding cryptodev.

An example usage can be seen below:

Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
{"version": "DPDK 21.11.0-rc0", "pid": 1135019, "max_output_len": 16384}
--> /
{"/": ["/", "/cryptodev/info", "/cryptodev/list", "/cryptodev/stats", ...]}
--> /cryptodev/list
{"/cryptodev/list": [0,1,2,3]}
--> /cryptodev/info,0
{"/cryptodev/info": {"device_name": "0000:1c:01.0_qat_sym", \
	 "max_nb_queue_pairs": 2}}
--> /cryptodev/stats,0
{"/cryptodev/stats": {"enqueued_count": 0, "dequeued_count": 0, \
	"enqueue_err_count": 0, "dequeue_err_count": 0}}

Signed-off-by: Rebecca Troy <rebecca.troy@intel.com>

---
v3:
  - Added missing version tag to patch.
v2:
  - Added documentation and release notes.
  - Changed the /cryptodev/list command to list the devices as an
	array of IDs, rather than as names and IDs.
  - Added the /cryptodev/info command as described above.
---
---
 doc/guides/prog_guide/cryptodev_lib.rst | 30 ++++++++
 doc/guides/rel_notes/release_21_11.rst  |  5 ++
 lib/cryptodev/rte_cryptodev.c           | 92 +++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
  

Comments

Power, Ciara Oct. 12, 2021, 2:30 p.m. UTC | #1
Hi Becky,

>-----Original Message-----
>From: Troy, Rebecca <rebecca.troy@intel.com>
>Sent: Thursday 7 October 2021 15:11
>To: dev@dpdk.org
>Cc: Power, Ciara <ciara.power@intel.com>; Zhang, Roy Fan
><roy.fan.zhang@intel.com>; Troy, Rebecca <rebecca.troy@intel.com>; Akhil
>Goyal <gakhil@marvell.com>; Doherty, Declan <declan.doherty@intel.com>
>Subject: [PATCH v3] cryptodev: add telemetry callbacks
>
>The cryptodev library now registers commands with telemetry, and
>implements the corresponding callback functions. These commands allow a
>list of cryptodevs to be queried, as well as info and stats for the corresponding
>cryptodev.
>
>An example usage can be seen below:
>
>Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
>{"version": "DPDK 21.11.0-rc0", "pid": 1135019, "max_output_len": 16384}
>--> /
>{"/": ["/", "/cryptodev/info", "/cryptodev/list", "/cryptodev/stats", ...]}
>--> /cryptodev/list
>{"/cryptodev/list": [0,1,2,3]}
>--> /cryptodev/info,0
>{"/cryptodev/info": {"device_name": "0000:1c:01.0_qat_sym", \
>	 "max_nb_queue_pairs": 2}}
>--> /cryptodev/stats,0
>{"/cryptodev/stats": {"enqueued_count": 0, "dequeued_count": 0, \
>	"enqueue_err_count": 0, "dequeue_err_count": 0}}
>
>Signed-off-by: Rebecca Troy <rebecca.troy@intel.com>
>
>---
>v3:
>  - Added missing version tag to patch.
>v2:
>  - Added documentation and release notes.
>  - Changed the /cryptodev/list command to list the devices as an
>	array of IDs, rather than as names and IDs.
>  - Added the /cryptodev/info command as described above.
>---
>---
> doc/guides/prog_guide/cryptodev_lib.rst | 30 ++++++++
>doc/guides/rel_notes/release_21_11.rst  |  5 ++
> lib/cryptodev/rte_cryptodev.c           | 92 +++++++++++++++++++++++++
> 3 files changed, 127 insertions(+)
>
>diff --git a/doc/guides/prog_guide/cryptodev_lib.rst
>b/doc/guides/prog_guide/cryptodev_lib.rst
>index 9b1cf8d49f..b94d3caa60 100644
>--- a/doc/guides/prog_guide/cryptodev_lib.rst
>+++ b/doc/guides/prog_guide/cryptodev_lib.rst
>@@ -1282,3 +1282,33 @@ Asymmetric Crypto Device API
>
> The cryptodev Library API is described in the  `DPDK API Reference
><https://doc.dpdk.org/api/>`_
>+
>+
>+Device Statistics
>+~~~~~~~~~~~~~~~~~

This header underline (~~~) means this section will be a subsection of "Asymmetric crypto Sample code", which isn't correct.
I suggest changing the underline to "----" to move it up a level to be its own section.

>+
>+The Cryptodev library has support for displaying cryptodev information
>+through the Telemetry interface. Telemetry commands that can be used
>+are shown below.
>+
>+#. Get the list of available Crypto devices by ID::
>+
>+     --> /cryptodev/list
>+     {"/cryptodev/list": [0, 1, 2, 3]}
>+
>+#. Get general information from a Crypto device::
>+
>+     --> /cryptodev/info,0
>+     {"/cryptodev/info": {"device_name": "0000:1c:01.0_qat_sym",
>+     "max_nb_queue_pairs": 2}}
>+
>+#. Get the statistics for a particular Crypto device::
>+
>+     --> /cryptodev/stats,0
>+     {"/cryptodev/stats": {"enqueued_count": 0,
>+     "dequeued_count": 0, "enqueue_err_count": 0,
>+     "dequeue_err_count": 0}}
>+
>+
>+For more information on how to use the Telemetry interface, see the
>+:doc:../howto/telemetry.

There are ` symbols missing here, so this link doesn't work.
Needs to be:
     :doc:`../howto/telemetry`

<snip>

>+static int
>+cryptodev_handle_dev_info(const char *cmd __rte_unused,
>+		const char *params, struct rte_tel_data *d) {
>+	struct rte_cryptodev_info cryptodev_info;
>+	int dev_id;
>+	char *end_param;
>+
>+	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
>+		return -EINVAL;
>+
>+	dev_id = strtoul(params, &end_param, 0);
>+	if (*end_param != '\0')
>+		CDEV_LOG_ERR("Extra parameters passed to command,
>ignoring");
>+	if (!rte_cryptodev_is_valid_dev(dev_id))
>+		return -1;

Maybe -EINVAL return value would be better here, same comment for handle_dev_stats function.

<snip>

Thanks,
Ciara
  

Patch

diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst
index 9b1cf8d49f..b94d3caa60 100644
--- a/doc/guides/prog_guide/cryptodev_lib.rst
+++ b/doc/guides/prog_guide/cryptodev_lib.rst
@@ -1282,3 +1282,33 @@  Asymmetric Crypto Device API
 
 The cryptodev Library API is described in the
 `DPDK API Reference <https://doc.dpdk.org/api/>`_
+
+
+Device Statistics
+~~~~~~~~~~~~~~~~~
+
+The Cryptodev library has support for displaying cryptodev information
+through the Telemetry interface. Telemetry commands that can be used
+are shown below.
+
+#. Get the list of available Crypto devices by ID::
+
+     --> /cryptodev/list
+     {"/cryptodev/list": [0, 1, 2, 3]}
+
+#. Get general information from a Crypto device::
+
+     --> /cryptodev/info,0
+     {"/cryptodev/info": {"device_name": "0000:1c:01.0_qat_sym",
+     "max_nb_queue_pairs": 2}}
+
+#. Get the statistics for a particular Crypto device::
+
+     --> /cryptodev/stats,0
+     {"/cryptodev/stats": {"enqueued_count": 0,
+     "dequeued_count": 0, "enqueue_err_count": 0,
+     "dequeue_err_count": 0}}
+
+
+For more information on how to use the Telemetry interface, see
+the :doc:../howto/telemetry.
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index efeffe37a0..487a9b0c73 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -114,6 +114,11 @@  New Features
 
   * Added PDCP short MAC-I support.
 
+* **Added Telemetry callbacks to Cryptodev library.**
+
+  Added Telemetry callback functions which allow a list of Crypto devices,
+  stats for a Crypto device, and other device information to be queried.
+
 * **Added multi-process support for testpmd.**
 
   Added command-line options to specify total number of processes and
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index b913c434c5..78394c1c65 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -35,6 +35,7 @@ 
 #include <rte_errno.h>
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
+#include <rte_telemetry.h>
 
 #include "rte_crypto.h"
 #include "rte_cryptodev.h"
@@ -2426,3 +2427,94 @@  rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
 
 	return nb_drivers++;
 }
+
+static int
+cryptodev_handle_dev_list(const char *cmd __rte_unused,
+		const char *params __rte_unused,
+		struct rte_tel_data *d)
+{
+	int dev_id;
+
+	if (rte_cryptodev_count() < 1)
+		return -1;
+
+	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
+	for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++)
+		if (rte_cryptodev_is_valid_dev(dev_id))
+			rte_tel_data_add_array_int(d, dev_id);
+
+	return 0;
+}
+
+static int
+cryptodev_handle_dev_info(const char *cmd __rte_unused,
+		const char *params, struct rte_tel_data *d)
+{
+	struct rte_cryptodev_info cryptodev_info;
+	int dev_id;
+	char *end_param;
+
+	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+		return -EINVAL;
+
+	dev_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
+	if (!rte_cryptodev_is_valid_dev(dev_id))
+		return -1;
+
+	rte_cryptodev_info_get(dev_id, &cryptodev_info);
+
+	rte_tel_data_start_dict(d);
+	rte_tel_data_add_dict_string(d, "device_name",
+		cryptodev_info.device->name);
+	rte_tel_data_add_dict_int(d, "max_nb_queue_pairs",
+		cryptodev_info.max_nb_queue_pairs);
+
+	return 0;
+}
+
+#define ADD_DICT_STAT(s) rte_tel_data_add_dict_u64(d, #s, cryptodev_stats.s)
+
+static int
+cryptodev_handle_dev_stats(const char *cmd __rte_unused,
+		const char *params,
+		struct rte_tel_data *d)
+{
+	struct rte_cryptodev_stats cryptodev_stats;
+	int dev_id, ret;
+	char *end_param;
+
+	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+		return -EINVAL;
+
+	dev_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		CDEV_LOG_ERR("Extra parameters passed to command, ignoring");
+	if (!rte_cryptodev_is_valid_dev(dev_id))
+		return -1;
+
+	ret = rte_cryptodev_stats_get(dev_id, &cryptodev_stats);
+	if (ret < 0)
+		return ret;
+
+	rte_tel_data_start_dict(d);
+	ADD_DICT_STAT(enqueued_count);
+	ADD_DICT_STAT(dequeued_count);
+	ADD_DICT_STAT(enqueue_err_count);
+	ADD_DICT_STAT(dequeue_err_count);
+
+	return 0;
+}
+
+RTE_INIT(cryptodev_init_telemetry)
+{
+	rte_telemetry_register_cmd("/cryptodev/info", cryptodev_handle_dev_info,
+			"Returns information for a cryptodev. Parameters: int dev_id");
+	rte_telemetry_register_cmd("/cryptodev/list",
+			cryptodev_handle_dev_list,
+			"Returns list of available crypto devices by IDs. No parameters.");
+	rte_telemetry_register_cmd("/cryptodev/stats",
+			cryptodev_handle_dev_stats,
+			"Returns the stats for a cryptodev. Parameters: int dev_id");
+}