From patchwork Wed Feb 8 08:45:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robin Jarry X-Patchwork-Id: 123445 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5C6ED41C3C; Wed, 8 Feb 2023 09:45:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7AE8F41153; Wed, 8 Feb 2023 09:45:49 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 8F6AA42B8E for ; Wed, 8 Feb 2023 09:45:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675845947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g4aodA0tW4w72nTc2pJb1Tk4UYX7CGHAEkfFsVYXWdY=; b=IMxbQYWREKzvo5eLxPIC5ii93FMoURqRWLjPHW5gYh6wwWCZY7u2LPHRL8h3OO87DwRrI9 +cuAyFPfwAAgF09cG/wlFZ4pPw6uAGmQ98CjuFERcaD0GC7NXfFnyuGsUSzmFdlKarZVhJ qFMXxZCFabMQnUjMlF2CQ9sP8vzDrlI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-443-3IVMPsA5OK-gXd0R3-BiDQ-1; Wed, 08 Feb 2023 03:45:43 -0500 X-MC-Unique: 3IVMPsA5OK-gXd0R3-BiDQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADFCF380673F; Wed, 8 Feb 2023 08:45:42 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92784492C3C; Wed, 8 Feb 2023 08:45:41 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Cc: Robin Jarry , =?utf-8?q?Morten_Br=C3=B8rup?= , Kevin Laatz Subject: [RESEND PATCH v9 1/5] eal: add lcore info in telemetry Date: Wed, 8 Feb 2023 09:45:03 +0100 Message-Id: <20230208084507.1328625-2-rjarry@redhat.com> In-Reply-To: <20230208084507.1328625-1-rjarry@redhat.com> References: <20221123102612.1688865-1-rjarry@redhat.com> <20230208084507.1328625-1-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Acked-by: Morten Brørup Reviewed-by: Kevin Laatz --- 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 #include #include +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#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 */