[v9,1/5] eal: add lcore info in telemetry
Checks
Commit Message
Report the same information than rte_lcore_dump() in the telemetry
API into /eal/lcore/list and /eal/lcore/info,ID.
Example:
--> /eal/lcore/info,3
{
"/eal/lcore/info": {
"lcore_id": 3,
"socket": 0,
"role": "RTE",
"cpuset": [
3
]
}
}
Signed-off-by: Robin Jarry <rjarry@redhat.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Reviewed-by: Kevin Laatz <kevin.laatz@intel.com>
---
Notes:
v8 -> v9: Updated with 64 bits integers telemetry functions
lib/eal/common/eal_common_lcore.c | 123 +++++++++++++++++++++++++-----
1 file changed, 105 insertions(+), 18 deletions(-)
Comments
在 2023/2/8 3:37, Robin Jarry 写道:
> Report the same information than rte_lcore_dump() in the telemetry
> API into /eal/lcore/list and /eal/lcore/info,ID.
>
> Example:
>
> --> /eal/lcore/info,3
> {
> "/eal/lcore/info": {
> "lcore_id": 3,
> "socket": 0,
> "role": "RTE",
> "cpuset": [
> 3
> ]
> }
> }
>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> Reviewed-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
>
> Notes:
> v8 -> v9: Updated with 64 bits integers telemetry functions
>
> lib/eal/common/eal_common_lcore.c | 123 +++++++++++++++++++++++++-----
> 1 file changed, 105 insertions(+), 18 deletions(-)
>
> diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
> index 06c594b0224f..f53fc17b4d04 100644
> --- a/lib/eal/common/eal_common_lcore.c
> +++ b/lib/eal/common/eal_common_lcore.c
> @@ -10,6 +10,9 @@
> #include <rte_errno.h>
> #include <rte_lcore.h>
> #include <rte_log.h>
> +#ifndef RTE_EXEC_ENV_WINDOWS
> +#include <rte_telemetry.h>
> +#endif
>
> #include "eal_private.h"
> #include "eal_thread.h"
> @@ -419,35 +422,35 @@ rte_lcore_iterate(rte_lcore_iterate_cb cb, void *arg)
> return ret;
> }
>
> +static const char *
> +lcore_role_str(enum rte_lcore_role_t role)
> +{
> + switch (role) {
> + case ROLE_RTE:
> + return "RTE";
> + case ROLE_SERVICE:
> + return "SERVICE";
> + case ROLE_NON_EAL:
> + return "NON_EAL";
> + default:
> + return "UNKNOWN";
> + }
> +}
> +
> static int
> lcore_dump_cb(unsigned int lcore_id, void *arg)
> {
> struct rte_config *cfg = rte_eal_get_configuration();
> char cpuset[RTE_CPU_AFFINITY_STR_LEN];
> - const char *role;
> FILE *f = arg;
> int ret;
>
> - switch (cfg->lcore_role[lcore_id]) {
> - case ROLE_RTE:
> - role = "RTE";
> - break;
> - case ROLE_SERVICE:
> - role = "SERVICE";
> - break;
> - case ROLE_NON_EAL:
> - role = "NON_EAL";
> - break;
> - default:
> - role = "UNKNOWN";
> - break;
> - }
> -
> ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
> sizeof(cpuset));
> fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s\n", lcore_id,
> - rte_lcore_to_socket_id(lcore_id), role, cpuset,
> - ret == 0 ? "" : "...");
> + rte_lcore_to_socket_id(lcore_id),
> + lcore_role_str(cfg->lcore_role[lcore_id]),
> + cpuset, ret == 0 ? "" : "...");
> return 0;
> }
The above modification doesn't seem to be related to this patch. Suggest
remove or delete it from this patch.
>
> @@ -456,3 +459,87 @@ rte_lcore_dump(FILE *f)
> {
> rte_lcore_iterate(lcore_dump_cb, f);
> }
> +
> +#ifndef RTE_EXEC_ENV_WINDOWS
> +static int
> +lcore_telemetry_id_cb(unsigned int lcore_id, void *arg)
> +{
> + struct rte_tel_data *d = arg;
> + return rte_tel_data_add_array_int(d, lcore_id);
> +}
> +
> +static int
> +handle_lcore_list(const char *cmd __rte_unused,
> + const char *params __rte_unused,
> + struct rte_tel_data *d)
> +{
> + int ret = rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
> + if (ret)
> + return ret;
> + return rte_lcore_iterate(lcore_telemetry_id_cb, d);
> +}
> +
> +struct lcore_telemetry_info {
> + unsigned int lcore_id;
> + struct rte_tel_data *d;
> +};
> +
> +static int
> +lcore_telemetry_info_cb(unsigned int lcore_id, void *arg)
> +{
> + struct rte_config *cfg = rte_eal_get_configuration();
> + struct lcore_telemetry_info *info = arg;
> + struct rte_tel_data *cpuset;
> + unsigned int cpu;
> +
> + if (info->lcore_id != lcore_id)
Suggest: info->lcore_id != lcore_id -> lcore_id != info->lcore_id
Here, info->lcore_id is a target and lcore_id is the variable to be judged, right?
> + return 0;
> +
> + rte_tel_data_start_dict(info->d);
> + rte_tel_data_add_dict_int(info->d, "lcore_id", lcore_id);
> + rte_tel_data_add_dict_int(info->d, "socket", rte_lcore_to_socket_id(lcore_id));
> + rte_tel_data_add_dict_string(info->d, "role", lcore_role_str(cfg->lcore_role[lcore_id]));
> + cpuset = rte_tel_data_alloc();
> + if (cpuset == NULL)
> + return -ENOMEM;
> + rte_tel_data_start_array(cpuset, RTE_TEL_INT_VAL);
> + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
> + if (CPU_ISSET(cpu, &lcore_config[lcore_id].cpuset))
> + rte_tel_data_add_array_int(cpuset, cpu);
> + }
> + rte_tel_data_add_dict_container(info->d, "cpuset", cpuset, 0);
> +
> + return 0;
> +}
> +
> +static int
> +handle_lcore_info(const char *cmd __rte_unused, const char *params, struct rte_tel_data *d)
> +{
> + struct lcore_telemetry_info info = { .d = d };
> + unsigned long lcore_id;
> + char *endptr;
> +
> + if (params == NULL)
> + return -EINVAL;
> + errno = 0;
> + lcore_id = strtoul(params, &endptr, 10);
> + if (errno)
> + return -errno;
> + if (*params == '\0' || *endptr != '\0' || lcore_id >= RTE_MAX_LCORE)
> + return -EINVAL;
> +
> + info.lcore_id = lcore_id;
> +
> + return rte_lcore_iterate(lcore_telemetry_info_cb, &info);
> +}
> +
> +RTE_INIT(lcore_telemetry)
> +{
> + rte_telemetry_register_cmd(
> + "/eal/lcore/list", handle_lcore_list,
> + "List of lcore ids. Takes no parameters");
> + rte_telemetry_register_cmd(
> + "/eal/lcore/info", handle_lcore_info,
> + "Returns lcore info. Parameters: int lcore_id");
> +}
> +#endif /* !RTE_EXEC_ENV_WINDOWS */
Hi lihuisong,
lihuisong (C), Feb 08, 2023 at 03:24:
> > static int
> > lcore_dump_cb(unsigned int lcore_id, void *arg)
> > {
> > struct rte_config *cfg = rte_eal_get_configuration();
> > char cpuset[RTE_CPU_AFFINITY_STR_LEN];
> > - const char *role;
> > FILE *f = arg;
> > int ret;
> >
> > - switch (cfg->lcore_role[lcore_id]) {
> > - case ROLE_RTE:
> > - role = "RTE";
> > - break;
> > - case ROLE_SERVICE:
> > - role = "SERVICE";
> > - break;
> > - case ROLE_NON_EAL:
> > - role = "NON_EAL";
> > - break;
> > - default:
> > - role = "UNKNOWN";
> > - break;
> > - }
> > -
> > ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
> > sizeof(cpuset));
> > fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s\n", lcore_id,
> > - rte_lcore_to_socket_id(lcore_id), role, cpuset,
> > - ret == 0 ? "" : "...");
> > + rte_lcore_to_socket_id(lcore_id),
> > + lcore_role_str(cfg->lcore_role[lcore_id]),
> > + cpuset, ret == 0 ? "" : "...");
> > return 0;
> > }
> The above modification doesn't seem to be related to this patch.
> Suggest remove or delete it from this patch.
I was asked in an earlier review to factorize this into an helper to
avoid code duplication.
> > + if (info->lcore_id != lcore_id)
>
> Suggest: info->lcore_id != lcore_id -> lcore_id != info->lcore_id
> Here, info->lcore_id is a target and lcore_id is the variable to be
> judged, right?
Yeah that looks better. I didn't pay too much attention since this
principle is not well respected in the current code base.
在 2023/2/9 1:04, Robin Jarry 写道:
> Hi lihuisong,
>
> lihuisong (C), Feb 08, 2023 at 03:24:
>>> static int
>>> lcore_dump_cb(unsigned int lcore_id, void *arg)
>>> {
>>> struct rte_config *cfg = rte_eal_get_configuration();
>>> char cpuset[RTE_CPU_AFFINITY_STR_LEN];
>>> - const char *role;
>>> FILE *f = arg;
>>> int ret;
>>>
>>> - switch (cfg->lcore_role[lcore_id]) {
>>> - case ROLE_RTE:
>>> - role = "RTE";
>>> - break;
>>> - case ROLE_SERVICE:
>>> - role = "SERVICE";
>>> - break;
>>> - case ROLE_NON_EAL:
>>> - role = "NON_EAL";
>>> - break;
>>> - default:
>>> - role = "UNKNOWN";
>>> - break;
>>> - }
>>> -
>>> ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
>>> sizeof(cpuset));
>>> fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s\n", lcore_id,
>>> - rte_lcore_to_socket_id(lcore_id), role, cpuset,
>>> - ret == 0 ? "" : "...");
>>> + rte_lcore_to_socket_id(lcore_id),
>>> + lcore_role_str(cfg->lcore_role[lcore_id]),
>>> + cpuset, ret == 0 ? "" : "...");
>>> return 0;
>>> }
>> The above modification doesn't seem to be related to this patch.
>> Suggest remove or delete it from this patch.
> I was asked in an earlier review to factorize this into an helper to
> avoid code duplication.
ok, this patch also use lcore_role_str function. please ignore this comment.
>
>>> + if (info->lcore_id != lcore_id)
>> Suggest: info->lcore_id != lcore_id -> lcore_id != info->lcore_id
>> Here, info->lcore_id is a target and lcore_id is the variable to be
>> judged, right?
> Yeah that looks better. I didn't pay too much attention since this
> principle is not well respected in the current code base.
That's not a very good reason.
It's similar to "ret != 0" and "p != NULL" in DPDK coding style.
>
> .
On Thu, Feb 9, 2023 at 3:19 AM lihuisong (C) <lihuisong@huawei.com> wrote:
> >>> + if (info->lcore_id != lcore_id)
> >> Suggest: info->lcore_id != lcore_id -> lcore_id != info->lcore_id
> >> Here, info->lcore_id is a target and lcore_id is the variable to be
> >> judged, right?
> > Yeah that looks better. I didn't pay too much attention since this
> > principle is not well respected in the current code base.
> That's not a very good reason.
> It's similar to "ret != 0" and "p != NULL" in DPDK coding style.
I'll squash this suggestion when applying.
On Thu, Feb 9, 2023 at 9:31 AM David Marchand <david.marchand@redhat.com> wrote:
>
> On Thu, Feb 9, 2023 at 3:19 AM lihuisong (C) <lihuisong@huawei.com> wrote:
> > >>> + if (info->lcore_id != lcore_id)
> > >> Suggest: info->lcore_id != lcore_id -> lcore_id != info->lcore_id
> > >> Here, info->lcore_id is a target and lcore_id is the variable to be
> > >> judged, right?
> > > Yeah that looks better. I didn't pay too much attention since this
> > > principle is not well respected in the current code base.
> > That's not a very good reason.
> > It's similar to "ret != 0" and "p != NULL" in DPDK coding style.
>
> I'll squash this suggestion when applying.
Hum, well, I have some other comments later in this series, so Robin
will fix this himself.
@@ -10,6 +10,9 @@
#include <rte_errno.h>
#include <rte_lcore.h>
#include <rte_log.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
+#include <rte_telemetry.h>
+#endif
#include "eal_private.h"
#include "eal_thread.h"
@@ -419,35 +422,35 @@ rte_lcore_iterate(rte_lcore_iterate_cb cb, void *arg)
return ret;
}
+static const char *
+lcore_role_str(enum rte_lcore_role_t role)
+{
+ switch (role) {
+ case ROLE_RTE:
+ return "RTE";
+ case ROLE_SERVICE:
+ return "SERVICE";
+ case ROLE_NON_EAL:
+ return "NON_EAL";
+ default:
+ return "UNKNOWN";
+ }
+}
+
static int
lcore_dump_cb(unsigned int lcore_id, void *arg)
{
struct rte_config *cfg = rte_eal_get_configuration();
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- const char *role;
FILE *f = arg;
int ret;
- switch (cfg->lcore_role[lcore_id]) {
- case ROLE_RTE:
- role = "RTE";
- break;
- case ROLE_SERVICE:
- role = "SERVICE";
- break;
- case ROLE_NON_EAL:
- role = "NON_EAL";
- break;
- default:
- role = "UNKNOWN";
- break;
- }
-
ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
sizeof(cpuset));
fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s\n", lcore_id,
- rte_lcore_to_socket_id(lcore_id), role, cpuset,
- ret == 0 ? "" : "...");
+ rte_lcore_to_socket_id(lcore_id),
+ lcore_role_str(cfg->lcore_role[lcore_id]),
+ cpuset, ret == 0 ? "" : "...");
return 0;
}
@@ -456,3 +459,87 @@ rte_lcore_dump(FILE *f)
{
rte_lcore_iterate(lcore_dump_cb, f);
}
+
+#ifndef RTE_EXEC_ENV_WINDOWS
+static int
+lcore_telemetry_id_cb(unsigned int lcore_id, void *arg)
+{
+ struct rte_tel_data *d = arg;
+ return rte_tel_data_add_array_int(d, lcore_id);
+}
+
+static int
+handle_lcore_list(const char *cmd __rte_unused,
+ const char *params __rte_unused,
+ struct rte_tel_data *d)
+{
+ int ret = rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
+ if (ret)
+ return ret;
+ return rte_lcore_iterate(lcore_telemetry_id_cb, d);
+}
+
+struct lcore_telemetry_info {
+ unsigned int lcore_id;
+ struct rte_tel_data *d;
+};
+
+static int
+lcore_telemetry_info_cb(unsigned int lcore_id, void *arg)
+{
+ struct rte_config *cfg = rte_eal_get_configuration();
+ struct lcore_telemetry_info *info = arg;
+ struct rte_tel_data *cpuset;
+ unsigned int cpu;
+
+ if (info->lcore_id != lcore_id)
+ return 0;
+
+ rte_tel_data_start_dict(info->d);
+ rte_tel_data_add_dict_int(info->d, "lcore_id", lcore_id);
+ rte_tel_data_add_dict_int(info->d, "socket", rte_lcore_to_socket_id(lcore_id));
+ rte_tel_data_add_dict_string(info->d, "role", lcore_role_str(cfg->lcore_role[lcore_id]));
+ cpuset = rte_tel_data_alloc();
+ if (cpuset == NULL)
+ return -ENOMEM;
+ rte_tel_data_start_array(cpuset, RTE_TEL_INT_VAL);
+ for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
+ if (CPU_ISSET(cpu, &lcore_config[lcore_id].cpuset))
+ rte_tel_data_add_array_int(cpuset, cpu);
+ }
+ rte_tel_data_add_dict_container(info->d, "cpuset", cpuset, 0);
+
+ return 0;
+}
+
+static int
+handle_lcore_info(const char *cmd __rte_unused, const char *params, struct rte_tel_data *d)
+{
+ struct lcore_telemetry_info info = { .d = d };
+ unsigned long lcore_id;
+ char *endptr;
+
+ if (params == NULL)
+ return -EINVAL;
+ errno = 0;
+ lcore_id = strtoul(params, &endptr, 10);
+ if (errno)
+ return -errno;
+ if (*params == '\0' || *endptr != '\0' || lcore_id >= RTE_MAX_LCORE)
+ return -EINVAL;
+
+ info.lcore_id = lcore_id;
+
+ return rte_lcore_iterate(lcore_telemetry_info_cb, &info);
+}
+
+RTE_INIT(lcore_telemetry)
+{
+ rte_telemetry_register_cmd(
+ "/eal/lcore/list", handle_lcore_list,
+ "List of lcore ids. Takes no parameters");
+ rte_telemetry_register_cmd(
+ "/eal/lcore/info", handle_lcore_info,
+ "Returns lcore info. Parameters: int lcore_id");
+}
+#endif /* !RTE_EXEC_ENV_WINDOWS */