From patchwork Thu Jul 29 15:25:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 96422 X-Patchwork-Delegate: thomas@monjalon.net 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 23F20A034F; Thu, 29 Jul 2021 17:26:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00A7D410F0; Thu, 29 Jul 2021 17:26:20 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id F40EB410E3 for ; Thu, 29 Jul 2021 17:26:17 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16TFA683031357; Thu, 29 Jul 2021 08:26:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=aDLPHxVwOM8f4kBQpSBdTVkXK3PTHv9xJREssN2NQ3o=; b=XUie+/uKYz9p11y/UdSP9WUaTCbL7oFz8w2DO9HFSxeZ3wUJXocDV0VtjbeIvTdcEayj CQfmwuFJaCxTAiTopu7PxkAvbYaE8/IgpZDcwUm50N8AlWxbX5ylk4JiRs8eVeBNhHCK Xvsnj3xqFo5v4cdIGqcreFuVWSayGa2wbm/rSVkiJzbvummwSW7CNaHtJMki0KAGStT0 KV/UtNYEuKwpdiB4Dz4L2i3eW0FELKL91W/OnjoXA7OnPCQ0CFqE/hBuNdCndI5RJvE0 u1wdGT0O7XZvg9ehoV3qMO59HA+5uPYn8HA1fN64Z8TvNMcfoEMD/XXt7jyi3RUIqe+q fg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3a3w5krk6e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 08:26:17 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 29 Jul 2021 08:26:15 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 29 Jul 2021 08:26:15 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 7853D3F7069; Thu, 29 Jul 2021 08:26:13 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , , , Gowrishankar Muthukrishnan Date: Thu, 29 Jul 2021 20:55:35 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-GUID: PRn6Tdzcbmb3mQ1PSXp0Ea41jN8LdiOd X-Proofpoint-ORIG-GUID: PRn6Tdzcbmb3mQ1PSXp0Ea41jN8LdiOd X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-29_10:2021-07-29, 2021-07-29 signatures=0 Subject: [dpdk-dev] [v1, 1/3] telemetry: enable storing pointer value 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 Sender: "dev" At present, value of pointer variable or address can only be stored in u64 type which is slightly not human readable, hence this patch is. It adds telemetry support to store pointer value, which is stringified. Signed-off-by: Gowrishankar Muthukrishnan --- lib/telemetry/rte_telemetry.h | 37 ++++++++++++++++++++++++++++++- lib/telemetry/telemetry.c | 21 ++++++++++++++++-- lib/telemetry/telemetry_data.c | 40 ++++++++++++++++++++++++++++++---- lib/telemetry/telemetry_data.h | 2 ++ lib/telemetry/telemetry_json.h | 31 ++++++++++++++++++++++++++ lib/telemetry/version.map | 2 ++ 6 files changed, 126 insertions(+), 7 deletions(-) diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h index 8776998b54..4c453d35d7 100644 --- a/lib/telemetry/rte_telemetry.h +++ b/lib/telemetry/rte_telemetry.h @@ -46,7 +46,8 @@ enum rte_tel_value_type { RTE_TEL_STRING_VAL, /** a string value */ RTE_TEL_INT_VAL, /** a signed 32-bit int value */ RTE_TEL_U64_VAL, /** an unsigned 64-bit int value */ - RTE_TEL_CONTAINER, /** a container struct */ + RTE_TEL_CONTAINER, /** a container struct */ + RTE_TEL_PTR_VAL, /** a pointer value */ }; /** @@ -137,6 +138,22 @@ __rte_experimental int rte_tel_data_add_array_u64(struct rte_tel_data *d, uint64_t x); +/** + * Add a pointer value to an array. + * The array must have been started by rte_tel_data_start_array() with + * RTE_TEL_PTR_VAL as the type parameter. + * + * @param d + * The data structure passed to the callback + * @param x + * The pointer value to be returned in the array + * @return + * 0 on success, negative errno on error + */ +__rte_experimental +int +rte_tel_data_add_array_ptr(struct rte_tel_data *d, void *x); + /** * Add a container to an array. A container is an existing telemetry data * array. The array the container is to be added to must have been started by @@ -213,6 +230,24 @@ int rte_tel_data_add_dict_u64(struct rte_tel_data *d, const char *name, uint64_t val); +/** + * Add a pointer value to a dictionary. + * The dict must have been started by rte_tel_data_start_dict(). + * + * @param d + * The data structure passed to the callback + * @param name + * The name the value is to be stored under in the dict + * @param val + * The pointer value to be stored in the dict + * @return + * 0 on success, negative errno on error, E2BIG on string truncation of name. + */ +__rte_experimental +int +rte_tel_data_add_dict_ptr(struct rte_tel_data *d, + const char *name, void *ptr); + /** * Add a container to a dictionary. A container is an existing telemetry data * array. The dict the container is to be added to must have been started by diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 8665db8d03..5842b28740 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -157,8 +157,10 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) size_t used = 0; unsigned int i; - if (d->type != RTE_TEL_ARRAY_U64 && d->type != RTE_TEL_ARRAY_INT - && d->type != RTE_TEL_ARRAY_STRING) + if (d->type != RTE_TEL_ARRAY_U64 + && d->type != RTE_TEL_ARRAY_INT + && d->type != RTE_TEL_ARRAY_PTR + && d->type != RTE_TEL_ARRAY_STRING) return snprintf(out_buf, buf_len, "null"); used = rte_tel_json_empty_array(out_buf, buf_len, 0); @@ -167,6 +169,11 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) used = rte_tel_json_add_array_u64(out_buf, buf_len, used, d->data.array[i].u64val); + if (d->type == RTE_TEL_ARRAY_PTR) + for (i = 0; i < d->data_len; i++) + used = rte_tel_json_add_array_ptr(out_buf, + buf_len, used, + d->data.array[i].ptrval); if (d->type == RTE_TEL_ARRAY_INT) for (i = 0; i < d->data_len; i++) used = rte_tel_json_add_array_int(out_buf, @@ -226,6 +233,11 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) buf_len, used, v->name, v->value.u64val); break; + case RTE_TEL_PTR_VAL: + used = rte_tel_json_add_obj_ptr(cb_data_buf, + buf_len, used, + v->name, v->value.ptrval); + break; case RTE_TEL_CONTAINER: { char temp[buf_len]; @@ -248,6 +260,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) case RTE_TEL_ARRAY_STRING: case RTE_TEL_ARRAY_INT: case RTE_TEL_ARRAY_U64: + case RTE_TEL_ARRAY_PTR: case RTE_TEL_ARRAY_CONTAINER: prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":", MAX_CMD_LEN, cmd); @@ -269,6 +282,10 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) used = rte_tel_json_add_array_u64(cb_data_buf, buf_len, used, d->data.array[i].u64val); + else if (d->type == RTE_TEL_ARRAY_PTR) + used = rte_tel_json_add_array_ptr(cb_data_buf, + buf_len, used, + d->data.array[i].ptrval); else if (d->type == RTE_TEL_ARRAY_CONTAINER) { char temp[buf_len]; const struct container *rec_data = diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c index 77b0fe09a5..9384f48589 100644 --- a/lib/telemetry/telemetry_data.c +++ b/lib/telemetry/telemetry_data.c @@ -15,6 +15,7 @@ rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type) RTE_TEL_ARRAY_INT, /* RTE_TEL_INT_VAL = 1 */ RTE_TEL_ARRAY_U64, /* RTE_TEL_u64_VAL = 2 */ RTE_TEL_ARRAY_CONTAINER, /* RTE_TEL_CONTAINER = 3 */ + RTE_TEL_ARRAY_PTR, /* RTE_TEL_PTR_VAL = 4 */ }; d->type = array_types[type]; d->data_len = 0; @@ -75,6 +76,17 @@ rte_tel_data_add_array_u64(struct rte_tel_data *d, uint64_t x) return 0; } +int +rte_tel_data_add_array_ptr(struct rte_tel_data *d, void *x) +{ + if (d->type != RTE_TEL_ARRAY_PTR) + return -EINVAL; + if (d->data_len >= RTE_TEL_MAX_ARRAY_ENTRIES) + return -ENOSPC; + d->data.array[d->data_len++].ptrval = x; + return 0; +} + int rte_tel_data_add_array_container(struct rte_tel_data *d, struct rte_tel_data *val, int keep) @@ -82,7 +94,8 @@ rte_tel_data_add_array_container(struct rte_tel_data *d, if (d->type != RTE_TEL_ARRAY_CONTAINER || (val->type != RTE_TEL_ARRAY_U64 && val->type != RTE_TEL_ARRAY_INT - && val->type != RTE_TEL_ARRAY_STRING)) + && val->type != RTE_TEL_ARRAY_STRING + && val->type != RTE_TEL_ARRAY_PTR)) return -EINVAL; if (d->data_len >= RTE_TEL_MAX_ARRAY_ENTRIES) return -ENOSPC; @@ -147,15 +160,34 @@ rte_tel_data_add_dict_u64(struct rte_tel_data *d, return bytes < RTE_TEL_MAX_STRING_LEN ? 0 : E2BIG; } +int +rte_tel_data_add_dict_ptr(struct rte_tel_data *d, + const char *name, void *ptr) +{ + struct tel_dict_entry *e = &d->data.dict[d->data_len]; + if (d->type != RTE_TEL_DICT) + return -EINVAL; + if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) + return -ENOSPC; + + d->data_len++; + e->type = RTE_TEL_PTR_VAL; + e->value.ptrval = ptr; + const size_t bytes = strlcpy(e->name, name, RTE_TEL_MAX_STRING_LEN); + return bytes < RTE_TEL_MAX_STRING_LEN ? 0 : E2BIG; +} + int rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name, struct rte_tel_data *val, int keep) { struct tel_dict_entry *e = &d->data.dict[d->data_len]; - if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64 - && val->type != RTE_TEL_ARRAY_INT - && val->type != RTE_TEL_ARRAY_STRING)) + if (d->type != RTE_TEL_DICT || + (val->type != RTE_TEL_ARRAY_U64 + && val->type != RTE_TEL_ARRAY_INT + && val->type != RTE_TEL_ARRAY_STRING + && val->type != RTE_TEL_ARRAY_PTR)) return -EINVAL; if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) return -ENOSPC; diff --git a/lib/telemetry/telemetry_data.h b/lib/telemetry/telemetry_data.h index adb84a09f1..bb361e3bcc 100644 --- a/lib/telemetry/telemetry_data.h +++ b/lib/telemetry/telemetry_data.h @@ -16,6 +16,7 @@ enum tel_container_types { RTE_TEL_ARRAY_INT, /** array of signed, 32-bit int values */ RTE_TEL_ARRAY_U64, /** array of unsigned 64-bit int values */ RTE_TEL_ARRAY_CONTAINER, /** array of container structs */ + RTE_TEL_ARRAY_PTR, /** array of pointer values */ }; struct container { @@ -31,6 +32,7 @@ union tel_value { char sval[RTE_TEL_MAX_STRING_LEN]; int ival; uint64_t u64val; + void *ptrval; struct container container; }; diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h index ad270b9b30..96762fc267 100644 --- a/lib/telemetry/telemetry_json.h +++ b/lib/telemetry/telemetry_json.h @@ -102,6 +102,19 @@ rte_tel_json_add_array_u64(char *buf, const int len, const int used, return ret == 0 ? used : end + ret; } +/* Appends a pointer value into the JSON array in the provided buffer. */ +static inline int +rte_tel_json_add_array_ptr(char *buf, const int len, const int used, + void *ptr) +{ + int ret, end = used - 1; /* strip off final delimiter */ + if (used <= 2) /* assume empty, since minimum is '[]' */ + return __json_snprintf(buf, len, "[\"%p\"]", ptr); + + ret = __json_snprintf(buf + end, len - end, ",\"%p\"]", ptr); + return ret == 0 ? used : end + ret; +} + /* * Add a new element with raw JSON value to the JSON array stored in the * provided buffer. @@ -136,6 +149,24 @@ rte_tel_json_add_obj_u64(char *buf, const int len, const int used, return ret == 0 ? used : end + ret; } +/** + * Add a new element with uint64_t value to the JSON object stored in the + * provided buffer. + */ +static inline int +rte_tel_json_add_obj_ptr(char *buf, const int len, const int used, + const char *name, void *ptr) +{ + int ret, end = used - 1; + if (used <= 2) /* assume empty, since minimum is '{}' */ + return __json_snprintf(buf, len, "{\"%s\":\"%p\"}", name, + ptr); + + ret = __json_snprintf(buf + end, len - end, ",\"%s\":\"%p\"}", + name, ptr); + return ret == 0 ? used : end + ret; +} + /** * Add a new element with int value to the JSON object stored in the * provided buffer. diff --git a/lib/telemetry/version.map b/lib/telemetry/version.map index bde80ce29b..d919340bc6 100644 --- a/lib/telemetry/version.map +++ b/lib/telemetry/version.map @@ -5,10 +5,12 @@ EXPERIMENTAL { rte_tel_data_add_array_int; rte_tel_data_add_array_string; rte_tel_data_add_array_u64; + rte_tel_data_add_array_ptr; rte_tel_data_add_dict_container; rte_tel_data_add_dict_int; rte_tel_data_add_dict_string; rte_tel_data_add_dict_u64; + rte_tel_data_add_dict_ptr; rte_tel_data_alloc; rte_tel_data_free; rte_tel_data_start_array; From patchwork Thu Jul 29 15:25:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 96423 X-Patchwork-Delegate: thomas@monjalon.net 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 20B41A034F; Thu, 29 Jul 2021 17:26:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 23F72410FB; Thu, 29 Jul 2021 17:26:24 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 4B566410FB for ; Thu, 29 Jul 2021 17:26:22 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16TFB7m7028635; Thu, 29 Jul 2021 08:26:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=bjmCCBk0eLvIMZm/3unP/Oy33Wd/SfrsK3Vb6QMs+io=; b=CGCrG6+IUcRlza7VSfcmmiDB4p4ig5jeJCjX+2AuSSWyqL0qxjKU9TGvUU5mR+ALRFVp Zh/YRpkiWK05SKubUbWby4YSVy8XMsvvbvOY74JhE6VvFqzwW2KCk8MGdYic17u84vDT xPJMKaN84pRBXZrT9DJ6fdvPpDTQSOwhSZAPUrcZ/grkQ4mx/9lRqOmUSNlrsyju/YcO e0bVaVKrf6Qj2Ij8AHlvV3JEmpyc/VCYWclNrNZKovxU6VsOQlbkadDnXJfJZAqNHZkO OyxTaJBGdND8exX6rfE7p/QMEz6kbPvQsLEUPLbfGa9kw9WwMMZSQef2s8Kzduxckr7z DA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3a35pr5gq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 08:26:21 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 29 Jul 2021 08:26:18 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 29 Jul 2021 08:26:18 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 379FF3F7085; Thu, 29 Jul 2021 08:26:15 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , , , Gowrishankar Muthukrishnan Date: Thu, 29 Jul 2021 20:55:36 +0530 Message-ID: <604cef7dae418edfa928e63731772e51ad26d6d3.1627572033.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OT924JCsqt0O-2qaikeMxy3hE1fAICIV X-Proofpoint-GUID: OT924JCsqt0O-2qaikeMxy3hE1fAICIV X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-29_10:2021-07-29, 2021-07-29 signatures=0 Subject: [dpdk-dev] [v1, 2/3] test/telemetry: add unit tests for pointer value 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 Sender: "dev" Adding tests to evaluate pointer value in array and dict. Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_telemetry_data.c | 124 +++++++++++++++++++++++++++++++++ app/test/test_telemetry_json.c | 28 ++++++-- 2 files changed, 145 insertions(+), 7 deletions(-) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index f34d691265..59f68f135a 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -301,6 +301,126 @@ test_array_with_array_u64_values(void) return TEST_OUTPUT("{\"/test\":[[0,1,2,3,4],[0,1,2,3,4]]}"); } +static int +test_case_array_ptr(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[120]; + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_array(&response_data, RTE_TEL_PTR_VAL); + + i = sprintf(exp, "{\"/test\":["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "\"%p\",", p); + rte_tel_data_add_array_ptr(&response_data, p); + } + + sprintf(exp + i - 1, "]}"); + return TEST_OUTPUT(exp); +} + +static int +test_case_add_dict_ptr(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char name[8], exp[160]; + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_dict(&response_data); + + i = sprintf(exp, "{\"/test\":{"); + for (j = 0; j < 5; j++) { + p = &a[j]; + sprintf(name, "dict_%d", j); + i += sprintf(exp + i, "\"%s\":\"%p\",", name, p); + rte_tel_data_add_dict_ptr(&response_data, name, p); + } + + sprintf(exp + i - 1, "}}"); + return TEST_OUTPUT(exp); +} + +static int +test_dict_with_array_ptr_values(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[256]; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_PTR_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_PTR_VAL); + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_dict(&response_data); + + i = sprintf(exp, "{\"/test\":{\"dict_0\":["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "\"%p\",", p); + rte_tel_data_add_array_ptr(child_data, p); + } + + i += sprintf(exp + i - 1, "],\"dict_1\":["); + for (j = 5; j > 0; j--) { + p = &a[j - 1]; + i += sprintf(exp + i - 1, "\"%p\",", p); + rte_tel_data_add_array_ptr(child_data2, p); + } + + sprintf(exp + i - 2, "]}}"); + rte_tel_data_add_dict_container(&response_data, "dict_0", + child_data, 0); + rte_tel_data_add_dict_container(&response_data, "dict_1", + child_data2, 0); + + return TEST_OUTPUT(exp); +} + +static int +test_array_with_array_ptr_values(void) +{ + int *p, i, j, a[] = {1, 2, 3, 4, 5}; + char exp[256]; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_PTR_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_PTR_VAL); + + memset(&response_data, 0, sizeof(response_data)); + memset(exp, 0, sizeof(exp)); + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + i = sprintf(exp, "{\"/test\":[["); + for (j = 0; j < 5; j++) { + p = &a[j]; + i += sprintf(exp + i, "\"%p\",", p); + rte_tel_data_add_array_ptr(child_data, p); + } + + i += sprintf(exp + i - 1, "],["); + for (j = 5; j > 0; j--) { + p = &a[j - 1]; + i += sprintf(exp + i - 1, "\"%p\",", p); + rte_tel_data_add_array_ptr(child_data2, p); + } + + sprintf(exp + i - 2, "]]}"); + + rte_tel_data_add_array_container(&response_data, child_data, 0); + rte_tel_data_add_array_container(&response_data, child_data2, 0); + + return TEST_OUTPUT(exp); +} + static int connect_to_socket(void) { @@ -350,13 +470,17 @@ test_telemetry_data(void) test_case test_cases[] = {test_case_array_string, test_case_array_int, test_case_array_u64, + test_case_array_ptr, test_case_add_dict_int, test_case_add_dict_u64, + test_case_add_dict_ptr, test_case_add_dict_string, test_dict_with_array_int_values, test_dict_with_array_u64_values, + test_dict_with_array_ptr_values, test_dict_with_array_string_values, test_array_with_array_int_values, test_array_with_array_u64_values, + test_array_with_array_ptr_values, test_array_with_array_string_values }; rte_telemetry_register_cmd(REQUEST_CMD, test_cb, "Test"); diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 790181d316..3e8e60638c 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -11,18 +11,22 @@ static int test_basic_array(void) { - const char *expected = "[\"meaning of life\",42]"; - char buf[1024]; - int used = 0; + char buf[1024], expected[80]; + int used = 0, n = 42, *p; printf("%s: ", __func__); used = rte_tel_json_empty_array(buf, sizeof(buf), used); if (used != 2 || strcmp(buf, "[]")) return -1; + p = &n; + memset(expected, 0, sizeof(expected)); + sprintf(expected, "[\"meaning of life\",42,\"%p\"]", p); + used = rte_tel_json_add_array_string(buf, sizeof(buf), used, "meaning of life"); - used = rte_tel_json_add_array_int(buf, sizeof(buf), used, 42); + used = rte_tel_json_add_array_int(buf, sizeof(buf), used, n); + used = rte_tel_json_add_array_ptr(buf, sizeof(buf), used, p); printf("buf = '%s', expected = '%s'\n", buf, expected); if (used != (int)strlen(expected)) @@ -33,14 +37,24 @@ test_basic_array(void) static int test_basic_obj(void) { - const char *expected = "{\"weddings\":4,\"funerals\":1}"; - char buf[1024]; - int used = 0; + char buf[1024], expected[80]; + int used = 0, n = 42, *p; + + p = &n; + memset(expected, 0, sizeof(expected)); + sprintf(expected, + "{\"weddings\":4,\"funerals\":1," + "\"address\":\"%p\",\"reset\":\"(nil)\"}", p); used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, "weddings", 4); used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, "funerals", 1); + used = rte_tel_json_add_obj_ptr(buf, sizeof(buf), used, + "address", p); + p = NULL; + used = rte_tel_json_add_obj_ptr(buf, sizeof(buf), used, + "reset", p); printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); if (used != (int)strlen(expected)) From patchwork Thu Jul 29 15:25:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 96424 X-Patchwork-Delegate: thomas@monjalon.net 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 C6790A034F; Thu, 29 Jul 2021 17:26:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 47D2541102; Thu, 29 Jul 2021 17:26:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 7A5F140DFB for ; Thu, 29 Jul 2021 17:26:23 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16TFB7m8028635; Thu, 29 Jul 2021 08:26:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=cPo14+WrLPRjsJU2av1Xqq1jABwVESnvTFPcN8sbazM=; b=UwHz2bmadpkUj6GNO8mblN/av2KaTJLxuKM2pTtVBzr5f0kaaogmCnKVbyUStURn+1C0 EgbI/aCuthtqbSW9em54txYO5OehaUNB1NwL0miHDRJEv4c7MPNFNOQgUbi7jx2cEv9i vcu7d25XN1ygWaxtu23/Skz20JXhaVboOsff4D+kjmgCrxMKyBW1mSAtMS4QZHsAXLyF ORpeGY50kZ9yfPFybKNhYLLf+7ghwSTNyCsH2aRg6rcCSmALEp1UQkbYNDw9a87RClrD gzOHmdPQtte2ni2HL9NWpWXNJc4NoQmTRcPjoIgwO/tPEXjV1svTKDnsh7lThMZT5KJb bw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3a35pr5gq9-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 08:26:22 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 29 Jul 2021 08:26:21 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 29 Jul 2021 08:26:20 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id F02973F7057; Thu, 29 Jul 2021 08:26:18 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , , , Gowrishankar Muthukrishnan Date: Thu, 29 Jul 2021 20:55:37 +0530 Message-ID: <04507ec4f18245b30d6b728b99bc80346132ed39.1627572033.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QOth3zxnV3Ei30M9-tg1JKy5A4RhpVQ2 X-Proofpoint-GUID: QOth3zxnV3Ei30M9-tg1JKy5A4RhpVQ2 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-29_10:2021-07-29, 2021-07-29 signatures=0 Subject: [dpdk-dev] [v1, 3/3] common/cnxk: add telemetry endpoints to npa 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 Sender: "dev" Add telemetry endpoints to npa. Signed-off-by: Gowrishankar Muthukrishnan --- drivers/common/cnxk/cnxk_telemetry.h | 23 +++ drivers/common/cnxk/cnxk_telemetry_npa.c | 227 +++++++++++++++++++++++ drivers/common/cnxk/meson.build | 4 + drivers/common/cnxk/roc_platform.h | 8 + 4 files changed, 262 insertions(+) create mode 100644 drivers/common/cnxk/cnxk_telemetry.h create mode 100644 drivers/common/cnxk/cnxk_telemetry_npa.c diff --git a/drivers/common/cnxk/cnxk_telemetry.h b/drivers/common/cnxk/cnxk_telemetry.h new file mode 100644 index 0000000000..9ac1487020 --- /dev/null +++ b/drivers/common/cnxk/cnxk_telemetry.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Marvell. + */ + +#ifndef __CNXK_TELEMETRY_H_ +#define __CNXK_TELEMETRY_H_ + +#define CNXK_TEL_STR(s) #s +#define CNXK_TEL_STR_PREFIX(s, p) CNXK_TEL_STR(p##s) +#define CNXK_TEL_DICT_INT(d, p, s, ...) \ + plt_tel_data_add_dict_int(d, CNXK_TEL_STR_PREFIX(s, __VA_ARGS__), \ + (p)->s) +#define CNXK_TEL_DICT_PTR(d, p, s, ...) \ + plt_tel_data_add_dict_ptr(d, CNXK_TEL_STR_PREFIX(s, __VA_ARGS__), \ + (void *)(p)->s) +#define CNXK_TEL_DICT_BF_PTR(d, p, s, ...) \ + plt_tel_data_add_dict_ptr(d, CNXK_TEL_STR_PREFIX(s, __VA_ARGS__), \ + (void *)(uint64_t)(p)->s) +#define CNXK_TEL_DICT_U64(d, p, s, ...) \ + plt_tel_data_add_dict_u64(d, CNXK_TEL_STR_PREFIX(s, __VA_ARGS__), \ + (p)->s) + +#endif /* __CNXK_TELEMETRY_H_ */ diff --git a/drivers/common/cnxk/cnxk_telemetry_npa.c b/drivers/common/cnxk/cnxk_telemetry_npa.c new file mode 100644 index 0000000000..1c2c2cd106 --- /dev/null +++ b/drivers/common/cnxk/cnxk_telemetry_npa.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell. + */ + +#include "cnxk_telemetry.h" +#include "roc_api.h" +#include "roc_priv.h" + +#include + +static int +cnxk_tel_npa(struct plt_tel_data *d) +{ + struct npa_lf *lf; + int aura_cnt = 0; + uint32_t i; + + lf = idev_npa_obj_get(); + if (lf == NULL) + return NPA_ERR_DEVICE_NOT_BOUNDED; + + for (i = 0; i < lf->nr_pools; i++) { + if (plt_bitmap_get(lf->npa_bmp, i)) + continue; + aura_cnt++; + } + + plt_tel_data_add_dict_ptr(d, "npa", lf); + plt_tel_data_add_dict_int(d, "pf", dev_get_pf(lf->pf_func)); + plt_tel_data_add_dict_int(d, "vf", dev_get_vf(lf->pf_func)); + plt_tel_data_add_dict_int(d, "aura_cnt", aura_cnt); + + CNXK_TEL_DICT_PTR(d, lf, pci_dev); + CNXK_TEL_DICT_PTR(d, lf, npa_bmp); + CNXK_TEL_DICT_PTR(d, lf, npa_bmp_mem); + CNXK_TEL_DICT_PTR(d, lf, npa_qint_mem); + CNXK_TEL_DICT_PTR(d, lf, intr_handle); + CNXK_TEL_DICT_PTR(d, lf, mbox); + CNXK_TEL_DICT_PTR(d, lf, base); + CNXK_TEL_DICT_INT(d, lf, stack_pg_ptrs); + CNXK_TEL_DICT_INT(d, lf, stack_pg_bytes); + CNXK_TEL_DICT_INT(d, lf, npa_msixoff); + CNXK_TEL_DICT_INT(d, lf, nr_pools); + CNXK_TEL_DICT_INT(d, lf, pf_func); + CNXK_TEL_DICT_INT(d, lf, aura_sz); + CNXK_TEL_DICT_INT(d, lf, qints); + + return 0; +} + +static int +cnxk_tel_npa_aura(int aura_id, struct plt_tel_data *d) +{ + __io struct npa_aura_s *aura; + struct npa_aq_enq_req *req; + struct npa_aq_enq_rsp *rsp; + struct npa_lf *lf; + int rc; + + lf = idev_npa_obj_get(); + if (lf == NULL) + return NPA_ERR_DEVICE_NOT_BOUNDED; + + if (rte_bitmap_get(lf->npa_bmp, aura_id)) + return -1; + + req = mbox_alloc_msg_npa_aq_enq(lf->mbox); + if (!req) { + plt_err("Failed to alloc aq enq for npa"); + return -1; + } + + req->aura_id = aura_id; + req->ctype = NPA_AQ_CTYPE_AURA; + req->op = NPA_AQ_INSTOP_READ; + + rc = mbox_process_msg(lf->mbox, (void *)&rsp); + if (rc) { + plt_err("Failed to get pool(%d) context", aura_id); + return rc; + } + + aura = &rsp->aura; + CNXK_TEL_DICT_PTR(d, aura, pool_addr, w0_); + CNXK_TEL_DICT_INT(d, aura, ena, w1_); + CNXK_TEL_DICT_INT(d, aura, pool_caching, w1_); + CNXK_TEL_DICT_INT(d, aura, pool_way_mask, w1_); + CNXK_TEL_DICT_INT(d, aura, avg_con, w1_); + CNXK_TEL_DICT_INT(d, aura, pool_drop_ena, w1_); + CNXK_TEL_DICT_INT(d, aura, aura_drop_ena, w1_); + CNXK_TEL_DICT_INT(d, aura, bp_ena, w1_); + CNXK_TEL_DICT_INT(d, aura, aura_drop, w1_); + CNXK_TEL_DICT_INT(d, aura, avg_level, w1_); + CNXK_TEL_DICT_U64(d, aura, count, w2_); + CNXK_TEL_DICT_INT(d, aura, nix0_bpid, w2_); + CNXK_TEL_DICT_INT(d, aura, nix1_bpid, w2_); + CNXK_TEL_DICT_U64(d, aura, limit, w3_); + CNXK_TEL_DICT_INT(d, aura, bp, w3_); + CNXK_TEL_DICT_INT(d, aura, fc_ena, w3_); + CNXK_TEL_DICT_INT(d, aura, fc_up_crossing, w3_); + CNXK_TEL_DICT_INT(d, aura, fc_stype, w3_); + CNXK_TEL_DICT_INT(d, aura, fc_hyst_bits, w3_); + CNXK_TEL_DICT_INT(d, aura, fc_addr, w4_); + CNXK_TEL_DICT_INT(d, aura, pool_drop, w5_); + CNXK_TEL_DICT_INT(d, aura, update_time, w5_); + CNXK_TEL_DICT_INT(d, aura, err_int, w5_); + CNXK_TEL_DICT_INT(d, aura, err_int_ena, w5_); + CNXK_TEL_DICT_INT(d, aura, thresh_int, w5_); + CNXK_TEL_DICT_INT(d, aura, thresh_int_ena, w5_); + CNXK_TEL_DICT_INT(d, aura, thresh_up, w5_); + CNXK_TEL_DICT_INT(d, aura, thresh_qint_idx, w5_); + CNXK_TEL_DICT_INT(d, aura, err_qint_idx, w5_); + CNXK_TEL_DICT_U64(d, aura, thresh, w6_); + + return 0; +} + +static int +cnxk_tel_npa_pool(int pool_id, struct plt_tel_data *d) +{ + __io struct npa_pool_s *pool; + struct npa_aq_enq_req *req; + struct npa_aq_enq_rsp *rsp; + struct npa_lf *lf; + int rc; + + lf = idev_npa_obj_get(); + if (lf == NULL) + return NPA_ERR_DEVICE_NOT_BOUNDED; + + if (rte_bitmap_get(lf->npa_bmp, pool_id)) + return -1; + + req = mbox_alloc_msg_npa_aq_enq(lf->mbox); + if (!req) { + plt_err("Failed to alloc aq enq for npa"); + return -1; + } + + req->aura_id = pool_id; + req->ctype = NPA_AQ_CTYPE_POOL; + req->op = NPA_AQ_INSTOP_READ; + + rc = mbox_process_msg(lf->mbox, (void *)&rsp); + if (rc) { + plt_err("Failed to get pool(%d) context", pool_id); + return rc; + } + + pool = &rsp->pool; + CNXK_TEL_DICT_PTR(d, pool, stack_base, w0_); + CNXK_TEL_DICT_INT(d, pool, ena, w1_); + CNXK_TEL_DICT_INT(d, pool, nat_align, w1_); + CNXK_TEL_DICT_INT(d, pool, stack_caching, w1_); + CNXK_TEL_DICT_INT(d, pool, stack_way_mask, w1_); + CNXK_TEL_DICT_INT(d, pool, buf_offset, w1_); + CNXK_TEL_DICT_INT(d, pool, buf_size, w1_); + CNXK_TEL_DICT_INT(d, pool, stack_max_pages, w2_); + CNXK_TEL_DICT_INT(d, pool, stack_pages, w2_); + CNXK_TEL_DICT_INT(d, pool, op_pc, w3_); + CNXK_TEL_DICT_INT(d, pool, stack_offset, w4_); + CNXK_TEL_DICT_INT(d, pool, shift, w4_); + CNXK_TEL_DICT_INT(d, pool, avg_level, w4_); + CNXK_TEL_DICT_INT(d, pool, avg_con, w4_); + CNXK_TEL_DICT_INT(d, pool, fc_ena, w4_); + CNXK_TEL_DICT_INT(d, pool, fc_stype, w4_); + CNXK_TEL_DICT_INT(d, pool, fc_hyst_bits, w4_); + CNXK_TEL_DICT_INT(d, pool, fc_up_crossing, w4_); + CNXK_TEL_DICT_INT(d, pool, update_time, w4_); + CNXK_TEL_DICT_PTR(d, pool, fc_addr, w5_); + CNXK_TEL_DICT_PTR(d, pool, ptr_start, w6_); + CNXK_TEL_DICT_PTR(d, pool, ptr_end, w7_); + CNXK_TEL_DICT_INT(d, pool, err_int, w8_); + CNXK_TEL_DICT_INT(d, pool, err_int_ena, w8_); + CNXK_TEL_DICT_INT(d, pool, thresh_int, w8_); + CNXK_TEL_DICT_INT(d, pool, thresh_int_ena, w8_); + CNXK_TEL_DICT_INT(d, pool, thresh_up, w8_); + CNXK_TEL_DICT_INT(d, pool, thresh_qint_idx, w8_); + CNXK_TEL_DICT_INT(d, pool, err_qint_idx, w8_); + + return 0; +} + +static int +cnxk_npa_tel_handle_info(const char *cmd __rte_unused, + const char *params __rte_unused, + struct rte_tel_data *d) +{ + plt_tel_data_start_dict(d); + cnxk_tel_npa(d); + return 0; +} + +static int +cnxk_npa_tel_handle_info_x(const char *cmd, const char *params, + struct rte_tel_data *d) +{ + int id, rc; + + if (params == NULL || strlen(params) == 0 || !isdigit(*params)) + return -1; + + id = atoi(params); + plt_tel_data_start_dict(d); + + if (strstr(cmd, "aura/info")) + rc = cnxk_tel_npa_aura(id, d); + else + rc = cnxk_tel_npa_pool(id, d); + + return rc; +} + +RTE_INIT(cnxk_telemetry_npa_init) +{ + rte_telemetry_register_cmd( + "/cnxk/npa/info", cnxk_npa_tel_handle_info, + "Returns npa information. Takes no parameters"); + + rte_telemetry_register_cmd( + "/cnxk/npa/aura/info", cnxk_npa_tel_handle_info_x, + "Returns npa aura information. Parameters: aura_id"); + + rte_telemetry_register_cmd( + "/cnxk/npa/pool/info", cnxk_npa_tel_handle_info_x, + "Returns npa pool information. Parameters: pool_id"); +} diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build index 6a7849f31c..3cc9a2ff37 100644 --- a/drivers/common/cnxk/meson.build +++ b/drivers/common/cnxk/meson.build @@ -60,5 +60,9 @@ sources = files( # Security common code sources += files('cnxk_security.c') +# Telemetry common code +sources += files('cnxk_telemetry_npa.c') + includes += include_directories('../../bus/pci') includes += include_directories('../../../lib/net') +includes += include_directories('../../../lib/telemetry') diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h index 285b24b82d..9fcaee8254 100644 --- a/drivers/common/cnxk/roc_platform.h +++ b/drivers/common/cnxk/roc_platform.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "roc_bits.h" @@ -139,6 +140,13 @@ #define plt_strlcpy rte_strlcpy +#define plt_tel_data rte_tel_data +#define plt_tel_data_start_dict rte_tel_data_start_dict +#define plt_tel_data_add_dict_int rte_tel_data_add_dict_int +#define plt_tel_data_add_dict_ptr rte_tel_data_add_dict_ptr +#define plt_tel_data_add_dict_string rte_tel_data_add_dict_string +#define plt_tel_data_add_dict_u64 rte_tel_data_add_dict_u64 + /* Log */ extern int cnxk_logtype_base; extern int cnxk_logtype_mbox;