[v6,5/5] telemetry: add /eal/lcore/usage endpoint

Message ID 20230119150656.418404-6-rjarry@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series lcore telemetry improvements |

Checks

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

Commit Message

Robin Jarry Jan. 19, 2023, 3:06 p.m. UTC
  Allow fetching CPU cycles usage for all lcores with a single request.
This endpoint is intended for repeated and frequent invocations by
external monitoring systems and therefore returns condensed data.

It consists of a single dictionary with three keys: "lcore_ids",
"total_cycles" and "busy_cycles" that are mapped to three arrays of
integer values. Each array has the same number of values, one per lcore,
in the same order.

Example:

 --> /eal/lcore/usage
 {
   "/eal/lcore/usage": {
     "lcore_ids": [
       4,
       5
     ],
     "total_cycles": [
       23846845590,
       23900558914
     ],
     "busy_cycles": [
       21043446682,
       21448837316
     ]
   }
 }

Cc: Kevin Laatz <kevin.laatz@intel.com>
Cc: Morten Brørup <mb@smartsharesystems.com>
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---

Notes:
    v6: new patch

 lib/eal/common/eal_common_lcore.c | 64 +++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
  

Comments

Morten Brørup Jan. 19, 2023, 4:21 p.m. UTC | #1
> From: Robin Jarry [mailto:rjarry@redhat.com]
> Sent: Thursday, 19 January 2023 16.07
> 
> Allow fetching CPU cycles usage for all lcores with a single request.
> This endpoint is intended for repeated and frequent invocations by
> external monitoring systems and therefore returns condensed data.
> 
> It consists of a single dictionary with three keys: "lcore_ids",
> "total_cycles" and "busy_cycles" that are mapped to three arrays of
> integer values. Each array has the same number of values, one per
> lcore,
> in the same order.

[...]

> +	rte_telemetry_register_cmd(
> +			"/eal/lcore/usage", handle_lcore_usage,
> +			"Returns lcore cycles usage. Takes no parameters");

In the future, the rte_lcore_usage structure may contain more fields, and some may not be related to the TSC. So consider removing "cycles" from the description of the telemetry path.

Don't waste time changing it unless you are providing a new patch version anyway!
  
Robin Jarry Jan. 19, 2023, 4:34 p.m. UTC | #2
Morten Brørup, Jan 19, 2023 at 17:21:
> In the future, the rte_lcore_usage structure may contain more fields,
> and some may not be related to the TSC. So consider removing "cycles"
> from the description of the telemetry path.
>
> Don't waste time changing it unless you are providing a new patch
> version anyway!

Ok, I assume the "cycles" word can be removed later if people add more
fields that are not related to cycles in the rte_lcore_usage structure.
For now, we only are talking about cycles :)
  
Morten Brørup Jan. 19, 2023, 4:45 p.m. UTC | #3
> From: Robin Jarry [mailto:rjarry@redhat.com]
> Sent: Thursday, 19 January 2023 17.35
> 
> Morten Brørup, Jan 19, 2023 at 17:21:
> > In the future, the rte_lcore_usage structure may contain more fields,
> > and some may not be related to the TSC. So consider removing "cycles"
> > from the description of the telemetry path.
> >
> > Don't waste time changing it unless you are providing a new patch
> > version anyway!
> 
> Ok, I assume the "cycles" word can be removed later if people add more
> fields that are not related to cycles in the rte_lcore_usage structure.
> For now, we only are talking about cycles :)

Agreed!

This part of the patch is new, and I forgot to ACK it in a previous response, so here goes...

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Kevin Laatz Jan. 19, 2023, 7:42 p.m. UTC | #4
On 19/01/2023 15:06, Robin Jarry wrote:
> Allow fetching CPU cycles usage for all lcores with a single request.
> This endpoint is intended for repeated and frequent invocations by
> external monitoring systems and therefore returns condensed data.
>
> It consists of a single dictionary with three keys: "lcore_ids",
> "total_cycles" and "busy_cycles" that are mapped to three arrays of
> integer values. Each array has the same number of values, one per lcore,
> in the same order.
>
> Example:
>
>   --> /eal/lcore/usage
>   {
>     "/eal/lcore/usage": {
>       "lcore_ids": [
>         4,
>         5
>       ],
>       "total_cycles": [
>         23846845590,
>         23900558914
>       ],
>       "busy_cycles": [
>         21043446682,
>         21448837316
>       ]
>     }
>   }
>
> Cc: Kevin Laatz <kevin.laatz@intel.com>
> Cc: Morten Brørup <mb@smartsharesystems.com>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
>
> Notes:
>      v6: new patch
>
>   lib/eal/common/eal_common_lcore.c | 64 +++++++++++++++++++++++++++++++
>   1 file changed, 64 insertions(+)
>
Thanks for adding this!

Reviewed-by: Kevin Laatz <kevin.laatz@intel.com>
  

Patch

diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
index 80513cfe3725..2f310ad19672 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -581,6 +581,67 @@  handle_lcore_info(const char *cmd __rte_unused, const char *params, struct rte_t
 	return rte_lcore_iterate(lcore_telemetry_info_cb, &info);
 }
 
+struct lcore_telemetry_usage {
+	struct rte_tel_data *lcore_ids;
+	struct rte_tel_data *total_cycles;
+	struct rte_tel_data *busy_cycles;
+};
+
+static int
+lcore_telemetry_usage_cb(unsigned int lcore_id, void *arg)
+{
+	struct lcore_telemetry_usage *u = arg;
+	struct rte_lcore_usage usage;
+	rte_lcore_usage_cb usage_cb;
+
+	/* The callback may not set all the fields in the structure, so clear it here. */
+	memset(&usage, 0, sizeof(usage));
+	/*
+	 * Guard against concurrent modification of lcore_usage_cb.
+	 * rte_lcore_register_usage_cb() should only be called once at application init
+	 * but nothing prevents and application to reset the callback to NULL.
+	 */
+	usage_cb = lcore_usage_cb;
+	if (usage_cb != NULL && usage_cb(lcore_id, &usage) == 0) {
+		rte_tel_data_add_array_int(u->lcore_ids, lcore_id);
+		rte_tel_data_add_array_u64(u->total_cycles, usage.total_cycles);
+		rte_tel_data_add_array_u64(u->busy_cycles, usage.busy_cycles);
+	}
+
+	return 0;
+}
+
+static int
+handle_lcore_usage(const char *cmd __rte_unused,
+		const char *params __rte_unused,
+		struct rte_tel_data *d)
+{
+	struct lcore_telemetry_usage usage;
+	struct rte_tel_data *lcore_ids = rte_tel_data_alloc();
+	struct rte_tel_data *total_cycles = rte_tel_data_alloc();
+	struct rte_tel_data *busy_cycles = rte_tel_data_alloc();
+
+	if (!lcore_ids || !total_cycles || !busy_cycles) {
+		rte_tel_data_free(lcore_ids);
+		rte_tel_data_free(total_cycles);
+		rte_tel_data_free(busy_cycles);
+		return -ENOMEM;
+	}
+
+	rte_tel_data_start_dict(d);
+	rte_tel_data_start_array(lcore_ids, RTE_TEL_INT_VAL);
+	rte_tel_data_start_array(total_cycles, RTE_TEL_U64_VAL);
+	rte_tel_data_start_array(busy_cycles, RTE_TEL_U64_VAL);
+	rte_tel_data_add_dict_container(d, "lcore_ids", lcore_ids, 0);
+	rte_tel_data_add_dict_container(d, "total_cycles", total_cycles, 0);
+	rte_tel_data_add_dict_container(d, "busy_cycles", busy_cycles, 0);
+	usage.lcore_ids = lcore_ids;
+	usage.total_cycles = total_cycles;
+	usage.busy_cycles = busy_cycles;
+
+	return rte_lcore_iterate(lcore_telemetry_usage_cb, &usage);
+}
+
 RTE_INIT(lcore_telemetry)
 {
 	rte_telemetry_register_cmd(
@@ -589,5 +650,8 @@  RTE_INIT(lcore_telemetry)
 	rte_telemetry_register_cmd(
 			"/eal/lcore/info", handle_lcore_info,
 			"Returns lcore info. Parameters: int lcore_id");
+	rte_telemetry_register_cmd(
+			"/eal/lcore/usage", handle_lcore_usage,
+			"Returns lcore cycles usage. Takes no parameters");
 }
 #endif /* !RTE_EXEC_ENV_WINDOWS */