From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2FA2C41B86; Tue, 31 Jan 2023 03:29:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 593CA427E9; Tue, 31 Jan 2023 03:29:30 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 3B74040EF0 for ; Tue, 31 Jan 2023 03:29:26 +0100 (CET) Received: from kwepemi500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4P5TWw4z7TzfZ8b; Tue, 31 Jan 2023 10:29:16 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemi500020.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 10:29:24 +0800 From: Jie Hai To: , , CC: , Subject: [PATCH v3 2/2] ring: add ring info telemetry cmd Date: Tue, 31 Jan 2023 10:28:41 +0800 Message-ID: <20230131022841.10775-3-haijie1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230131022841.10775-1-haijie1@huawei.com> References: <20230117130333.8707-1-haijie1@huawei.com> <20230131022841.10775-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500020.china.huawei.com (7.221.188.8) X-CFilter-Loop: Reflected 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 This patch supports dump of the info of ring by its name. An example using this command is shown below: --> /ring/info,MP_mb_pool_0 { "/ring/info": { "name": "MP_mb_pool_0", "socket": 0, "flags": 0, "producer_type": "MP", "consumer_type": "MC", "size": 262144, "mask": 262143, "capacity": 262143, "used_count": 147173, "consumer_tail": 8283, "consumer_head": 8283, "producer_tail": 155456, "producer_head": 155456, "mz_name": "RG_MP_mb_pool_0", "mz_len": 2097920, "mz_hugepage_sz": 1073741824, "mz_socket_id": 0, "mz_flags": 0 } } Signed-off-by: Jie Hai --- lib/ring/rte_ring.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c index e6aac332d88f..2e57aa653339 100644 --- a/lib/ring/rte_ring.c +++ b/lib/ring/rte_ring.c @@ -454,8 +454,91 @@ ring_handle_list(const char *cmd __rte_unused, return 0; } +static const char * +ring_prod_sync_type_to_name(struct rte_ring *r) +{ + switch (r->prod.sync_type) { + case RTE_RING_SYNC_MT: + return "MP"; + case RTE_RING_SYNC_ST: + return "SP"; + case RTE_RING_SYNC_MT_RTS: + return "MP_RTS"; + case RTE_RING_SYNC_MT_HTS: + return "MP_HTS"; + default: + return "Unknown"; + } +} + +static const char * +ring_cons_sync_type_to_name(struct rte_ring *r) +{ + switch (r->cons.sync_type) { + case RTE_RING_SYNC_MT: + return "MC"; + case RTE_RING_SYNC_ST: + return "SC"; + case RTE_RING_SYNC_MT_RTS: + return "MC_RTS"; + case RTE_RING_SYNC_MT_HTS: + return "MC_HTS"; + default: + return "Unknown"; + } +} + +static int +ring_handle_info(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + const struct rte_memzone *mz; + struct rte_ring *r; + + if (params == NULL || strlen(params) == 0 || + strlen(params) >= RTE_RING_NAMESIZE) + return -EINVAL; + + r = rte_ring_lookup(params); + if (r == NULL) + return -EINVAL; + + rte_mcfg_tailq_read_lock(); + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_string(d, "name", r->name); + rte_tel_data_add_dict_int(d, "socket", r->memzone->socket_id); + rte_tel_data_add_dict_int(d, "flags", r->flags); + rte_tel_data_add_dict_string(d, "producer_type", + ring_prod_sync_type_to_name(r)); + rte_tel_data_add_dict_string(d, "consumer_type", + ring_cons_sync_type_to_name(r)); + rte_tel_data_add_dict_u64(d, "size", r->size); + rte_tel_data_add_dict_u64(d, "mask", r->mask); + rte_tel_data_add_dict_u64(d, "capacity", r->capacity); + rte_tel_data_add_dict_u64(d, "used_count", rte_ring_count(r)); + rte_tel_data_add_dict_u64(d, "consumer_tail", r->cons.tail); + rte_tel_data_add_dict_u64(d, "consumer_head", r->cons.head); + rte_tel_data_add_dict_u64(d, "producer_tail", r->prod.tail); + rte_tel_data_add_dict_u64(d, "producer_head", r->prod.head); + + mz = r->memzone; + if (mz == NULL) + return 0; + rte_tel_data_add_dict_string(d, "mz_name", mz->name); + rte_tel_data_add_dict_int(d, "mz_len", mz->len); + rte_tel_data_add_dict_int(d, "mz_hugepage_sz", mz->hugepage_sz); + rte_tel_data_add_dict_int(d, "mz_socket_id", mz->socket_id); + rte_tel_data_add_dict_int(d, "mz_flags", mz->flags); + + rte_mcfg_tailq_read_unlock(); + return 0; +} + RTE_INIT(ring_init_telemetry) { rte_telemetry_register_cmd("/ring/list", ring_handle_list, "Returns list of available ring. Takes no parameters"); + rte_telemetry_register_cmd("/ring/info", ring_handle_info, + "Returns ring info. Parameters: ring_name."); } -- 2.33.0