31/01/2023 02:28, Jie Hai пишет:
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 <haij...@huawei.com>
---
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;
thanks for the update, but I think there still a potential problem here:
as we release tailq_lock inside ring_lookup() and then grab it after again.
Between these two points we have sort of race condition.
We need a way not to release it in between.
Probably the simplest way - make this function to use ring_walk()
that you introduced in previous patch, instead of ring_lookup().
Similar to what mempool_handle_info() is doing.
+
+ 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.");
}