!362 [sync] PR-347: telemetry: support display as hexadecimal

From: @openeuler-sync-bot 
Reviewed-by: @li-huisong 
Signed-off-by: @li-huisong
This commit is contained in:
openeuler-ci-bot 2023-04-28 09:40:10 +00:00 committed by Gitee
commit 0f5fe4ceb6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 1461 additions and 1 deletions

View File

@ -0,0 +1,39 @@
From 8cd9ea525b1e9c2a966fdf3616d68c7037b3820a Mon Sep 17 00:00:00 2001
From: Yunjian Wang <wangyunjian@huawei.com>
Date: Sat, 8 Jan 2022 15:51:57 +0800
Subject: ethdev: fix Rx queue telemetry memory leak on failure
[ upstream commit 52b49ea06ffb2cfbef8fe9578149f1e2dba99e89 ]
In eth_dev_handle_port_info() allocated memory for rxq_state,
we should free it when error happens, otherwise it will lead
to memory leak.
Fixes: 58b43c1ddfd1 ("ethdev: add telemetry endpoint for device info")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
lib/ethdev/rte_ethdev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index df5a627cbe..d466efffc7 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -6383,8 +6383,10 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
return -ENOMEM;
txq_state = rte_tel_data_alloc();
- if (!txq_state)
+ if (!txq_state) {
+ rte_tel_data_free(rxq_state);
return -ENOMEM;
+ }
rte_tel_data_start_dict(d);
rte_tel_data_add_dict_string(d, "name", eth_dev->data->name);
--
2.23.0

View File

@ -0,0 +1,53 @@
From db1ea57482d4d11c1c86ad9941c6be782a17ec57 Mon Sep 17 00:00:00 2001
From: David Marchand <david.marchand@redhat.com>
Date: Wed, 16 Feb 2022 15:13:16 +0100
Subject: ethdev: fix MAC address in telemetry device info
[ upstream commit ffe77e911f6a3d62757bc740670c4fda28f882f2 ]
The right size for a human readable MAC is RTE_ETHER_ADDR_FMT_SIZE.
While at it, the net library provides a helper for MAC address
formatting. Prefer it.
Fixes: 58b43c1ddfd1 ("ethdev: add telemetry endpoint for device info")
Cc: stable@dpdk.org
Reported-by: Christophe Fontaine <cfontain@redhat.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
lib/ethdev/rte_ethdev.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index d466efffc7..d82819a458 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -6358,7 +6358,7 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
struct rte_tel_data *d)
{
struct rte_tel_data *rxq_state, *txq_state;
- char mac_addr[RTE_ETHER_ADDR_LEN];
+ char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
struct rte_eth_dev *eth_dev;
char *end_param;
int port_id, i;
@@ -6401,13 +6401,8 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
eth_dev->data->min_rx_buf_size);
rte_tel_data_add_dict_int(d, "rx_mbuf_alloc_fail",
eth_dev->data->rx_mbuf_alloc_failed);
- snprintf(mac_addr, RTE_ETHER_ADDR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
- eth_dev->data->mac_addrs->addr_bytes[0],
- eth_dev->data->mac_addrs->addr_bytes[1],
- eth_dev->data->mac_addrs->addr_bytes[2],
- eth_dev->data->mac_addrs->addr_bytes[3],
- eth_dev->data->mac_addrs->addr_bytes[4],
- eth_dev->data->mac_addrs->addr_bytes[5]);
+ rte_ether_format_addr(mac_addr, sizeof(mac_addr),
+ eth_dev->data->mac_addrs);
rte_tel_data_add_dict_string(d, "mac_addr", mac_addr);
rte_tel_data_add_dict_int(d, "promiscuous",
eth_dev->data->promiscuous);
--
2.23.0

View File

@ -0,0 +1,44 @@
From 08b69766da122d7d3e20cee328a9166a12f320cb Mon Sep 17 00:00:00 2001
From: David Marchand <david.marchand@redhat.com>
Date: Thu, 24 Mar 2022 16:28:30 +0100
Subject: eventdev/eth_rx: fix telemetry Rx stats reset
[ upstream commit b450a990b07e008077377a6dfa45a562b3f9a496 ]
Caught by covscan:
1. dpdk-21.11/lib/eventdev/rte_event_eth_rx_adapter.c:3279:
logical_vs_bitwise: "~(*__ctype_b_loc()[(int)*params] & 2048 /*
(unsigned short)_ISdigit */)" is always 1/true regardless of the values
of its operand. This occurs as the logical second operand of "||".
2. dpdk-21.11/lib/eventdev/rte_event_eth_rx_adapter.c:3279: remediation:
Did you intend to use "!" rather than "~"?
While isdigit return value should be compared as an int to 0,
prefer ! since all of this file uses this convention.
Fixes: 814d01709328 ("eventdev/eth_rx: support telemetry")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Jay Jayatheerthan <jay.jayatheerthan@intel.com>
---
lib/eventdev/rte_event_eth_rx_adapter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index 3182b52c23..6f160b03c2 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -3276,7 +3276,7 @@ handle_rxa_stats_reset(const char *cmd __rte_unused,
{
uint8_t rx_adapter_id;
- if (params == NULL || strlen(params) == 0 || ~isdigit(*params))
+ if (params == NULL || strlen(params) == 0 || !isdigit(*params))
return -1;
/* Get Rx adapter ID from parameter string */
--
2.23.0

View File

@ -0,0 +1,369 @@
From 9e0c047add440fb5fbe84ef5131d5574f7cdcf37 Mon Sep 17 00:00:00 2001
From: Bruce Richardson <bruce.richardson@intel.com>
Date: Fri, 9 Sep 2022 10:35:20 +0100
Subject: test/telemetry_data: refactor for maintainability
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 1306df2cd1d9ae654c2e5b3b0f40ca19ab440006 ]
To help with the writing and maintaining of test cases in this file we
can make the following changes to it:
- rename non-test-case functions i.e. the infrastructure functions, to
not start with "test_", so that each sub-test case can be identified
by starting with that prefix.
- add a comment at the start of the file explaining how tests are to be
written and managed, so as to keep consistency.
- add a trivial test-case for returning a simple string value to use as
a reference example for those wanting to add test cases.
- improve the key macro used for validating the output from each
function, so that the standard json preamble can be skipped for each
function. This hides more of the infrastructure implementation from
the user i.e. they don't need to worry what the actual command used is
called, and also shortens the output strings so we can avoid line
splitting in most cases.
- add clearing the "response_data" structure to the loop calling each
test to avoid each test function having to do so individually.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Ciara Power <ciara.power@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test/test_telemetry_data.c | 101 ++++++++++++++++++++-------------
1 file changed, 60 insertions(+), 41 deletions(-)
diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 18b93db8ef..75aca8791f 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -19,18 +19,45 @@
#define TELEMETRY_VERSION "v2"
#define REQUEST_CMD "/test"
#define BUF_SIZE 1024
-#define TEST_OUTPUT(exp) test_output(__func__, exp)
+#define CHECK_OUTPUT(exp) check_output(__func__, "{\"" REQUEST_CMD "\":" exp "}")
+
+/*
+ * Runs a series of test cases, checking the output of telemetry for various different types of
+ * responses. On init, a single connection to DPDK telemetry is made, and a single telemetry
+ * callback "/test" is registered. That callback always returns the value of the static global
+ * variable "response_data", so each test case builds up that structure, and then calls the
+ * "check_output" function to ensure the response received over the socket for "/test" matches
+ * that expected for the response_data value populated.
+ *
+ * NOTE:
+ * - each test case function in this file should be added to the "test_cases" array in
+ * test_telemetry_data function at the bottom of the file.
+ * - each test case function should populate the "response_data" global variable (below)
+ * with the appropriate values which would be returned from a simulated telemetry function.
+ * Then the test case function should have "return CHECK_OUTPUT(<expected_data>);" as it's
+ * last line. The test infrastructure will then validate that the output when returning
+ * "response_data" structure matches that in "<expected_data>".
+ * - the response_data structure will be zeroed on entry to each test function, so each function
+ * can begin with a call to "rte_tel_data_string/start_array/start_dict" as so desired.
+ * - the expected_output for each function can be just the actual json data from the
+ * "response_data" value. The CHECK_OUTPUT macro will include the appropriate "{\"/test\": ... }"
+ * structure around the json output.
+ *
+ * See test_simple_string(), or test_case_array_int() for a basic examples of test cases.
+ */
+
static struct rte_tel_data response_data;
static int sock;
+
/*
* This function is the callback registered with Telemetry to be used when
* the /test command is requested. This callback returns the global data built
* up by the individual test cases.
*/
static int
-test_cb(const char *cmd __rte_unused, const char *params __rte_unused,
+telemetry_test_cb(const char *cmd __rte_unused, const char *params __rte_unused,
struct rte_tel_data *d)
{
*d = response_data;
@@ -44,7 +71,7 @@ test_cb(const char *cmd __rte_unused, const char *params __rte_unused,
* and is compared to the actual response received from Telemetry.
*/
static int
-test_output(const char *func_name, const char *expected)
+check_output(const char *func_name, const char *expected)
{
int bytes;
char buf[BUF_SIZE * 16];
@@ -64,6 +91,14 @@ test_output(const char *func_name, const char *expected)
return strncmp(expected, buf, sizeof(buf));
}
+static int
+test_simple_string(void)
+{
+ rte_tel_data_string(&response_data, "Simple string");
+
+ return CHECK_OUTPUT("\"Simple string\"");
+}
+
static int
test_dict_with_array_int_values(void)
{
@@ -75,7 +110,6 @@ test_dict_with_array_int_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_INT_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
for (i = 0; i < 5; i++) {
@@ -88,8 +122,7 @@ test_dict_with_array_int_values(void)
rte_tel_data_add_dict_container(&response_data, "dict_1",
child_data2, 0);
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":[0,1,2,3,4],"
- "\"dict_1\":[0,1,2,3,4]}}");
+ return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4],\"dict_1\":[0,1,2,3,4]}");
}
static int
@@ -103,7 +136,6 @@ test_array_with_array_int_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_INT_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
for (i = 0; i < 5; i++) {
@@ -113,18 +145,18 @@ test_array_with_array_int_values(void)
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("{\"/test\":[[0,1,2,3,4],[0,1,2,3,4]]}");
+ return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]");
}
static int
test_case_array_int(void)
{
int i;
- memset(&response_data, 0, sizeof(response_data));
+
rte_tel_data_start_array(&response_data, RTE_TEL_INT_VAL);
for (i = 0; i < 5; i++)
rte_tel_data_add_array_int(&response_data, i);
- return TEST_OUTPUT("{\"/test\":[0,1,2,3,4]}");
+ return CHECK_OUTPUT("[0,1,2,3,4]");
}
static int
@@ -133,7 +165,6 @@ test_case_add_dict_int(void)
int i = 0;
char name_of_value[8];
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
for (i = 0; i < 5; i++) {
@@ -141,14 +172,12 @@ test_case_add_dict_int(void)
rte_tel_data_add_dict_int(&response_data, name_of_value, i);
}
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,"
- "\"dict_3\":3,\"dict_4\":4}}");
+ return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}");
}
static int
test_case_array_string(void)
{
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL);
rte_tel_data_add_array_string(&response_data, "aaaa");
rte_tel_data_add_array_string(&response_data, "bbbb");
@@ -156,14 +185,12 @@ test_case_array_string(void)
rte_tel_data_add_array_string(&response_data, "dddd");
rte_tel_data_add_array_string(&response_data, "eeee");
- return TEST_OUTPUT("{\"/test\":[\"aaaa\",\"bbbb\",\"cccc\",\"dddd\","
- "\"eeee\"]}");
+ return CHECK_OUTPUT("[\"aaaa\",\"bbbb\",\"cccc\",\"dddd\",\"eeee\"]");
}
static int
test_case_add_dict_string(void)
{
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
rte_tel_data_add_dict_string(&response_data, "dict_0", "aaaa");
@@ -171,8 +198,7 @@ test_case_add_dict_string(void)
rte_tel_data_add_dict_string(&response_data, "dict_2", "cccc");
rte_tel_data_add_dict_string(&response_data, "dict_3", "dddd");
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":\"aaaa\",\"dict_1\":"
- "\"bbbb\",\"dict_2\":\"cccc\",\"dict_3\":\"dddd\"}}");
+ return CHECK_OUTPUT("{\"dict_0\":\"aaaa\",\"dict_1\":\"bbbb\",\"dict_2\":\"cccc\",\"dict_3\":\"dddd\"}");
}
@@ -185,7 +211,6 @@ test_dict_with_array_string_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
rte_tel_data_add_array_string(child_data, "aaaa");
@@ -196,8 +221,7 @@ test_dict_with_array_string_values(void)
rte_tel_data_add_dict_container(&response_data, "dict_1",
child_data2, 0);
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":[\"aaaa\"],\"dict_1\":"
- "[\"bbbb\"]}}");
+ return CHECK_OUTPUT("{\"dict_0\":[\"aaaa\"],\"dict_1\":[\"bbbb\"]}");
}
static int
@@ -212,7 +236,6 @@ test_dict_with_dict_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
rte_tel_data_add_array_string(child_data, "aaaa");
@@ -224,8 +247,7 @@ test_dict_with_dict_values(void)
rte_tel_data_add_dict_container(&response_data, "dict_of_dicts",
dict_of_dicts, 0);
- return TEST_OUTPUT("{\"/test\":{\"dict_of_dicts\":{\"dict_0\":"
- "[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}}");
+ return CHECK_OUTPUT("{\"dict_of_dicts\":{\"dict_0\":[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}");
}
static int
@@ -237,7 +259,6 @@ test_array_with_array_string_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
rte_tel_data_add_array_string(child_data, "aaaa");
@@ -246,18 +267,18 @@ test_array_with_array_string_values(void)
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("{\"/test\":[[\"aaaa\"],[\"bbbb\"]]}");
+ return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]");
}
static int
test_case_array_u64(void)
{
int i;
- memset(&response_data, 0, sizeof(response_data));
+
rte_tel_data_start_array(&response_data, RTE_TEL_U64_VAL);
for (i = 0; i < 5; i++)
rte_tel_data_add_array_u64(&response_data, i);
- return TEST_OUTPUT("{\"/test\":[0,1,2,3,4]}");
+ return CHECK_OUTPUT("[0,1,2,3,4]");
}
static int
@@ -266,15 +287,13 @@ test_case_add_dict_u64(void)
int i = 0;
char name_of_value[8];
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
for (i = 0; i < 5; i++) {
sprintf(name_of_value, "dict_%d", i);
rte_tel_data_add_dict_u64(&response_data, name_of_value, i);
}
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,"
- "\"dict_3\":3,\"dict_4\":4}}");
+ return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}");
}
static int
@@ -288,7 +307,6 @@ test_dict_with_array_u64_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_U64_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_dict(&response_data);
for (i = 0; i < 10; i++) {
@@ -301,8 +319,7 @@ test_dict_with_array_u64_values(void)
rte_tel_data_add_dict_container(&response_data, "dict_1",
child_data2, 0);
- return TEST_OUTPUT("{\"/test\":{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],"
- "\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}}");
+ return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}");
}
static int
@@ -316,7 +333,6 @@ test_array_with_array_u64_values(void)
struct rte_tel_data *child_data2 = rte_tel_data_alloc();
rte_tel_data_start_array(child_data2, RTE_TEL_U64_VAL);
- memset(&response_data, 0, sizeof(response_data));
rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
for (i = 0; i < 5; i++) {
@@ -326,7 +342,7 @@ test_array_with_array_u64_values(void)
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("{\"/test\":[[0,1,2,3,4],[0,1,2,3,4]]}");
+ return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]");
}
static int
@@ -367,7 +383,7 @@ connect_to_socket(void)
}
static int
-test_telemetry_data(void)
+telemetry_data_autotest(void)
{
typedef int (*test_case)(void);
unsigned int i = 0;
@@ -376,7 +392,9 @@ test_telemetry_data(void)
if (sock <= 0)
return -1;
- test_case test_cases[] = {test_case_array_string,
+ test_case test_cases[] = {
+ test_simple_string,
+ test_case_array_string,
test_case_array_int, test_case_array_u64,
test_case_add_dict_int, test_case_add_dict_u64,
test_case_add_dict_string,
@@ -388,8 +406,9 @@ test_telemetry_data(void)
test_array_with_array_u64_values,
test_array_with_array_string_values };
- rte_telemetry_register_cmd(REQUEST_CMD, test_cb, "Test");
+ rte_telemetry_register_cmd(REQUEST_CMD, telemetry_test_cb, "Test");
for (i = 0; i < RTE_DIM(test_cases); i++) {
+ memset(&response_data, 0, sizeof(response_data));
if (test_cases[i]() != 0) {
close(sock);
return -1;
@@ -399,4 +418,4 @@ test_telemetry_data(void)
return 0;
}
-REGISTER_TEST_COMMAND(telemetry_data_autotest, test_telemetry_data);
+REGISTER_TEST_COMMAND(telemetry_data_autotest, telemetry_data_autotest);
--
2.23.0

View File

@ -0,0 +1,74 @@
From 9da99d5eaf004c1ea202753c4618dcaa48744ba3 Mon Sep 17 00:00:00 2001
From: Bruce Richardson <bruce.richardson@intel.com>
Date: Fri, 9 Sep 2022 10:35:21 +0100
Subject: test/telemetry_data: add test cases for character escaping
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit d0049f7a2c1654ffe704d7c1803db0402e49a2a7 ]
Add in some basic unit tests to validate the character escaping being
done on string data values, which tests end-to-end processing of those
values beyond just the json-encoding steps tested by the
"telemetry_json_autotest".
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Ciara Power <ciara.power@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test/test_telemetry_data.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 75aca8791f..79ec48063f 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -345,6 +345,30 @@ test_array_with_array_u64_values(void)
return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]");
}
+static int
+test_string_char_escaping(void)
+{
+ rte_tel_data_string(&response_data, "hello,\nworld\n");
+ return CHECK_OUTPUT("\"hello,\\nworld\\n\"");
+}
+
+static int
+test_array_char_escaping(void)
+{
+ rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL);
+ rte_tel_data_add_array_string(&response_data, "\\escape\r");
+ rte_tel_data_add_array_string(&response_data, "characters\n");
+ return CHECK_OUTPUT("[\"\\\\escape\\r\",\"characters\\n\"]");
+}
+
+static int
+test_dict_char_escaping(void)
+{
+ rte_tel_data_start_dict(&response_data);
+ rte_tel_data_add_dict_string(&response_data, "name", "escaped\n\tvalue");
+ return CHECK_OUTPUT("{\"name\":\"escaped\\n\\tvalue\"}");
+}
+
static int
connect_to_socket(void)
{
@@ -404,7 +428,11 @@ telemetry_data_autotest(void)
test_dict_with_dict_values,
test_array_with_array_int_values,
test_array_with_array_u64_values,
- test_array_with_array_string_values };
+ test_array_with_array_string_values,
+ test_string_char_escaping,
+ test_array_char_escaping,
+ test_dict_char_escaping,
+ };
rte_telemetry_register_cmd(REQUEST_CMD, telemetry_test_cb, "Test");
for (i = 0; i < RTE_DIM(test_cases); i++) {
--
2.23.0

View File

@ -0,0 +1,87 @@
From dccf49c20f2be4f9b92a635117dc06c9d17be545 Mon Sep 17 00:00:00 2001
From: Chengwen Feng <fengchengwen@huawei.com>
Date: Mon, 17 Oct 2022 07:41:02 +0000
Subject: usertools/telemetry: add JSON pretty print
[ upstream commit 66542840dfd184c06813e6740664b280ef77d4e0 ]
Currently, the dpdk-telemetry.py show JSON in raw format under
interactive mode, which is not good for human reading.
E.g. The command '/ethdev/xstats,0' will output:
{"/ethdev/xstats": {"rx_good_packets": 0, "tx_good_packets": 0,
"rx_good_bytes": 0, "tx_good_bytes": 0, "rx_missed_errors": 0,
"rx_errors": 0, "tx_errors": 0, "rx_mbuf_allocation_errors": 0,
"rx_q0_packets": 0,...}}
This patch supports JSON pretty print by adding extra indent=2
parameter under interactive mode, so the same command will output:
{
"/ethdev/xstats": {
"rx_good_packets": 0,
"tx_good_packets": 0,
"rx_good_bytes": 0,
"tx_good_bytes": 0,
"rx_missed_errors": 0,
"rx_errors": 0,
"rx_mbuf_allocation_errors": 0,
"rx_q0_packets": 0,
...
}
}
Note: the non-interactive mode is made machine-readable and remains the
original way (it means don't use indent to pretty print).
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: David Marchand <david.marchand@redhat.com>
Acked-by: Ciara Power <ciara.power@intel.com>
Tested-by: Bruce Richardson <bruce.richardson@intel.com>
---
usertools/dpdk-telemetry.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
index 5b3bf83356..e36b0af811 100755
--- a/usertools/dpdk-telemetry.py
+++ b/usertools/dpdk-telemetry.py
@@ -23,7 +23,7 @@
CMDS = []
-def read_socket(sock, buf_len, echo=True):
+def read_socket(sock, buf_len, echo=True, pretty=False):
""" Read data from socket and return it in JSON format """
reply = sock.recv(buf_len).decode()
try:
@@ -33,7 +33,8 @@ def read_socket(sock, buf_len, echo=True):
sock.close()
raise
if echo:
- print(json.dumps(ret))
+ indent = 2 if pretty else None
+ print(json.dumps(ret, indent=indent))
return ret
@@ -123,7 +124,7 @@ def handle_socket(args, path):
else:
list_fp()
return
- json_reply = read_socket(sock, 1024, prompt)
+ json_reply = read_socket(sock, 1024, prompt, prompt)
output_buf_len = json_reply["max_output_len"]
app_name = get_app_name(json_reply["pid"])
if app_name and prompt:
@@ -139,7 +140,7 @@ def handle_socket(args, path):
while text != "quit":
if text.startswith('/'):
sock.send(text.encode())
- read_socket(sock, output_buf_len)
+ read_socket(sock, output_buf_len, pretty=prompt)
text = input(prompt).strip()
except EOFError:
pass
--
2.23.0

View File

@ -0,0 +1,52 @@
From 46fdcb394e83402924e6fdcf2d6da2873570d2f4 Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:41 +0800
Subject: telemetry: move include after guard
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit f7b74387be1de6803716262d7988794accd6d39f ]
The "stdint.h" header is outside '_RTE_TELEMETRY_H_' macro, which cause
this header is unconditional. So this patch moves this header to inside
'_RTE_TELEMETRY_H_'.
Fixes: 99a2dd955fba ("lib: remove librte_ prefix from directory names")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/telemetry/rte_telemetry.h | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index fadea48cb9..08d7f18dff 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -2,10 +2,6 @@
* Copyright(c) 2018 Intel Corporation
*/
-#include <stdint.h>
-
-#include <rte_compat.h>
-
#ifndef _RTE_TELEMETRY_H_
#define _RTE_TELEMETRY_H_
@@ -13,6 +9,8 @@
extern "C" {
#endif
+#include <stdint.h>
+
/** Maximum length for string used in object. */
#define RTE_TEL_MAX_STRING_LEN 128
/** Maximum length of string. */
--
2.23.0

View File

@ -0,0 +1,59 @@
From f4f89120a7df52f92fcac89e3fe13cfac1097051 Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:42 +0800
Subject: ethdev: fix telemetry data truncation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 7db3f2af573287abb9201d46a92b4ca3ebc5d9ad ]
The 'u32' and 'u64' data can not assigned to 'int' type variable.
They need to use the 'u64' APIs to add.
Fixes: 58b43c1ddfd1 ("ethdev: add telemetry endpoint for device info")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/ethdev/rte_ethdev.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index d82819a458..c216091e79 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -6397,9 +6397,9 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
eth_dev->data->nb_tx_queues);
rte_tel_data_add_dict_int(d, "port_id", eth_dev->data->port_id);
rte_tel_data_add_dict_int(d, "mtu", eth_dev->data->mtu);
- rte_tel_data_add_dict_int(d, "rx_mbuf_size_min",
+ rte_tel_data_add_dict_u64(d, "rx_mbuf_size_min",
eth_dev->data->min_rx_buf_size);
- rte_tel_data_add_dict_int(d, "rx_mbuf_alloc_fail",
+ rte_tel_data_add_dict_u64(d, "rx_mbuf_alloc_fail",
eth_dev->data->rx_mbuf_alloc_failed);
rte_ether_format_addr(mac_addr, sizeof(mac_addr),
eth_dev->data->mac_addrs);
@@ -6428,12 +6428,12 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
rte_tel_data_add_dict_container(d, "rxq_state", rxq_state, 0);
rte_tel_data_add_dict_container(d, "txq_state", txq_state, 0);
rte_tel_data_add_dict_int(d, "numa_node", eth_dev->data->numa_node);
- rte_tel_data_add_dict_int(d, "dev_flags", eth_dev->data->dev_flags);
- rte_tel_data_add_dict_int(d, "rx_offloads",
+ rte_tel_data_add_dict_u64(d, "dev_flags", eth_dev->data->dev_flags);
+ rte_tel_data_add_dict_u64(d, "rx_offloads",
eth_dev->data->dev_conf.rxmode.offloads);
- rte_tel_data_add_dict_int(d, "tx_offloads",
+ rte_tel_data_add_dict_u64(d, "tx_offloads",
eth_dev->data->dev_conf.txmode.offloads);
- rte_tel_data_add_dict_int(d, "ethdev_rss_hf",
+ rte_tel_data_add_dict_u64(d, "ethdev_rss_hf",
eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
return 0;
--
2.23.0

View File

@ -0,0 +1,70 @@
From 2d3ca311972da8c7d4770697e62e6a4812665c5b Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:43 +0800
Subject: mempool: fix telemetry data truncation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 4eebfcf70a21b2b608e3bb9f20b5ee23338172ec ]
The 'u32' and 'u64' data can not assigned to 'int' type variable.
They need to use the 'u64' APIs to add.
Fixes: 2f5c4025abb3 ("mempool: add telemetry endpoint")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/mempool/rte_mempool.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index c5a699b1d6..871f4d1fe3 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -1517,27 +1517,27 @@ mempool_info_cb(struct rte_mempool *mp, void *arg)
return;
rte_tel_data_add_dict_string(info->d, "name", mp->name);
- rte_tel_data_add_dict_int(info->d, "pool_id", mp->pool_id);
- rte_tel_data_add_dict_int(info->d, "flags", mp->flags);
+ rte_tel_data_add_dict_u64(info->d, "pool_id", mp->pool_id);
+ rte_tel_data_add_dict_u64(info->d, "flags", mp->flags);
rte_tel_data_add_dict_int(info->d, "socket_id", mp->socket_id);
- rte_tel_data_add_dict_int(info->d, "size", mp->size);
- rte_tel_data_add_dict_int(info->d, "cache_size", mp->cache_size);
- rte_tel_data_add_dict_int(info->d, "elt_size", mp->elt_size);
- rte_tel_data_add_dict_int(info->d, "header_size", mp->header_size);
- rte_tel_data_add_dict_int(info->d, "trailer_size", mp->trailer_size);
- rte_tel_data_add_dict_int(info->d, "private_data_size",
+ rte_tel_data_add_dict_u64(info->d, "size", mp->size);
+ rte_tel_data_add_dict_u64(info->d, "cache_size", mp->cache_size);
+ rte_tel_data_add_dict_u64(info->d, "elt_size", mp->elt_size);
+ rte_tel_data_add_dict_u64(info->d, "header_size", mp->header_size);
+ rte_tel_data_add_dict_u64(info->d, "trailer_size", mp->trailer_size);
+ rte_tel_data_add_dict_u64(info->d, "private_data_size",
mp->private_data_size);
rte_tel_data_add_dict_int(info->d, "ops_index", mp->ops_index);
- rte_tel_data_add_dict_int(info->d, "populated_size",
+ rte_tel_data_add_dict_u64(info->d, "populated_size",
mp->populated_size);
mz = mp->mz;
rte_tel_data_add_dict_string(info->d, "mz_name", mz->name);
- rte_tel_data_add_dict_int(info->d, "mz_len", mz->len);
- rte_tel_data_add_dict_int(info->d, "mz_hugepage_sz",
+ rte_tel_data_add_dict_u64(info->d, "mz_len", mz->len);
+ rte_tel_data_add_dict_u64(info->d, "mz_hugepage_sz",
mz->hugepage_sz);
rte_tel_data_add_dict_int(info->d, "mz_socket_id", mz->socket_id);
- rte_tel_data_add_dict_int(info->d, "mz_flags", mz->flags);
+ rte_tel_data_add_dict_u64(info->d, "mz_flags", mz->flags);
}
static int
--
2.23.0

View File

@ -0,0 +1,39 @@
From 5af68a4b3406c0477a2a0c33c546795d6be7f6a5 Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:44 +0800
Subject: cryptodev: fix telemetry data truncation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 45038f04ab577db8844ef54d7f523119be6c205f ]
The 'u32' data can not assigned to 'int' type variable. The 'u32' data
needs to use the 'u64' APIs to add.
Fixes: d3d98f5ce9d0 ("cryptodev: support telemetry")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/cryptodev/rte_cryptodev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c
index a40536c5ea..23e079d639 100644
--- a/lib/cryptodev/rte_cryptodev.c
+++ b/lib/cryptodev/rte_cryptodev.c
@@ -2472,7 +2472,7 @@ cryptodev_handle_dev_info(const char *cmd __rte_unused,
rte_tel_data_start_dict(d);
rte_tel_data_add_dict_string(d, "device_name",
cryptodev_info.device->name);
- rte_tel_data_add_dict_int(d, "max_nb_queue_pairs",
+ rte_tel_data_add_dict_u64(d, "max_nb_queue_pairs",
cryptodev_info.max_nb_queue_pairs);
return 0;
--
2.23.0

View File

@ -0,0 +1,65 @@
From ecdcf5720497371f360dde918df83dbc56f32284 Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:45 +0800
Subject: mem: fix telemetry data truncation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 6243e36b837b754c33017718cf79f7574a52b09c ]
The 'u32' and 'u64' data can not assigned to 'int' type variable.
They need to use the 'u64' APIs to add.
Fixes: e6732d0d6e26 ("mem: add telemetry infos")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/common/eal_common_memory.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index 69dea8f72b..f2f8858e22 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1191,7 +1191,7 @@ handle_eal_heap_info_request(const char *cmd __rte_unused, const char *params,
malloc_heap_get_stats(heap, &sock_stats);
rte_tel_data_start_dict(d);
- rte_tel_data_add_dict_int(d, "Head id", heap_id);
+ rte_tel_data_add_dict_u64(d, "Head id", heap_id);
rte_tel_data_add_dict_string(d, "Name", heap->name);
rte_tel_data_add_dict_u64(d, "Heap_size",
sock_stats.heap_totalsz_bytes);
@@ -1253,13 +1253,13 @@ handle_eal_memzone_info_request(const char *cmd __rte_unused,
mz = rte_fbarray_get(&mcfg->memzones, mz_idx);
rte_tel_data_start_dict(d);
- rte_tel_data_add_dict_int(d, "Zone", mz_idx);
+ rte_tel_data_add_dict_u64(d, "Zone", mz_idx);
rte_tel_data_add_dict_string(d, "Name", mz->name);
- rte_tel_data_add_dict_int(d, "Length", mz->len);
+ rte_tel_data_add_dict_u64(d, "Length", mz->len);
snprintf(addr, ADDR_STR, "%p", mz->addr);
rte_tel_data_add_dict_string(d, "Address", addr);
rte_tel_data_add_dict_int(d, "Socket", mz->socket_id);
- rte_tel_data_add_dict_int(d, "Flags", mz->flags);
+ rte_tel_data_add_dict_u64(d, "Flags", mz->flags);
/* go through each page occupied by this memzone */
msl = rte_mem_virt2memseg_list(mz->addr);
@@ -1274,7 +1274,7 @@ handle_eal_memzone_info_request(const char *cmd __rte_unused,
ms_idx = RTE_PTR_DIFF(mz->addr, msl->base_va) / page_sz;
ms = rte_fbarray_get(&msl->memseg_arr, ms_idx);
- rte_tel_data_add_dict_int(d, "Hugepage_size", page_sz);
+ rte_tel_data_add_dict_u64(d, "Hugepage_size", page_sz);
snprintf(addr, ADDR_STR, "%p", ms->addr);
rte_tel_data_add_dict_string(d, "Hugepage_base", addr);
--
2.23.0

View File

@ -0,0 +1,426 @@
From cec570b800d47867e900c30761c7b50018184bbf Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:46 +0800
Subject: telemetry: support adding integer as hexadecimal
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 82c33481c6abdec2fc58f1199ca6202e7400c08d ]
Sometimes displaying an unsigned integer value as hexadecimal encoded style
is more expected for human consumption, such as, offload capability and
device flag. This patch introduces two APIs to add unsigned integer value
as hexadecimal encoded string to array or dictionary. And user can choose
whether the stored value is padded to the specified width.
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_telemetry_data.c | 150 +++++++++++++++++++++++++++++++++
lib/telemetry/rte_telemetry.h | 47 +++++++++++
lib/telemetry/telemetry_data.c | 74 ++++++++++++++++
lib/telemetry/version.map | 10 +++
4 files changed, 281 insertions(+)
diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 79ec48063f..7d9be376a6 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -201,6 +201,39 @@ test_case_add_dict_string(void)
return CHECK_OUTPUT("{\"dict_0\":\"aaaa\",\"dict_1\":\"bbbb\",\"dict_2\":\"cccc\",\"dict_3\":\"dddd\"}");
}
+static int
+test_case_add_dict_uint_hex_padding(void)
+{
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_0",
+ (uint8_t)0x8, 8);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_1",
+ (uint16_t)0x88, 16);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_2",
+ (uint32_t)0x888, 32);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_3",
+ (uint64_t)0x8888, 64);
+
+ return CHECK_OUTPUT("{\"dict_0\":\"0x08\",\"dict_1\":\"0x0088\",\"dict_2\":\"0x00000888\",\"dict_3\":\"0x0000000000008888\"}");
+}
+
+static int
+test_case_add_dict_uint_hex_nopadding(void)
+{
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_0",
+ (uint8_t)0x8, 0);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_1",
+ (uint16_t)0x88, 0);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_2",
+ (uint32_t)0x888, 0);
+ rte_tel_data_add_dict_uint_hex(&response_data, "dict_3",
+ (uint64_t)0x8888, 0);
+
+ return CHECK_OUTPUT("{\"dict_0\":\"0x8\",\"dict_1\":\"0x88\",\"dict_2\":\"0x888\",\"dict_3\":\"0x8888\"}");
+}
static int
test_dict_with_array_string_values(void)
@@ -224,6 +257,50 @@ test_dict_with_array_string_values(void)
return CHECK_OUTPUT("{\"dict_0\":[\"aaaa\"],\"dict_1\":[\"bbbb\"]}");
}
+static int
+test_dict_with_array_uint_hex_values_padding(void)
+{
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_array_uint_hex(child_data, (uint32_t)0x888, 32);
+ rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 64);
+
+ 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 CHECK_OUTPUT("{\"dict_0\":[\"0x00000888\"],\"dict_1\":[\"0x0000000000008888\"]}");
+}
+
+static int
+test_dict_with_array_uint_hex_values_nopadding(void)
+{
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_array_uint_hex(child_data, (uint32_t)0x888, 0);
+ rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 0);
+
+ 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 CHECK_OUTPUT("{\"dict_0\":[\"0x888\"],\"dict_1\":[\"0x8888\"]}");
+}
+
static int
test_dict_with_dict_values(void)
{
@@ -270,6 +347,47 @@ test_array_with_array_string_values(void)
return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]");
}
+static int
+test_array_with_array_uint_hex_values_padding(void)
+{
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
+
+ rte_tel_data_add_array_uint_hex(child_data, (uint32_t)0x888, 32);
+ rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 64);
+
+ rte_tel_data_add_array_container(&response_data, child_data, 0);
+ rte_tel_data_add_array_container(&response_data, child_data2, 0);
+
+ return CHECK_OUTPUT("[[\"0x00000888\"],[\"0x0000000000008888\"]]");
+}
+
+
+static int
+test_array_with_array_uint_hex_values_nopadding(void)
+{
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER);
+
+ rte_tel_data_add_array_uint_hex(child_data, (uint32_t)0x888, 0);
+ rte_tel_data_add_array_uint_hex(child_data2, (uint64_t)0x8888, 0);
+
+ rte_tel_data_add_array_container(&response_data, child_data, 0);
+ rte_tel_data_add_array_container(&response_data, child_data2, 0);
+
+ return CHECK_OUTPUT("[[\"0x888\"],[\"0x8888\"]]");
+}
+
static int
test_case_array_u64(void)
{
@@ -281,6 +399,30 @@ test_case_array_u64(void)
return CHECK_OUTPUT("[0,1,2,3,4]");
}
+static int
+test_case_array_uint_hex_padding(void)
+{
+ rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint8_t)0x8, 8);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint16_t)0x88, 16);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint32_t)0x888, 32);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint64_t)0x8888, 64);
+
+ return CHECK_OUTPUT("[\"0x08\",\"0x0088\",\"0x00000888\",\"0x0000000000008888\"]");
+}
+
+static int
+test_case_array_uint_hex_nopadding(void)
+{
+ rte_tel_data_start_array(&response_data, RTE_TEL_STRING_VAL);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint8_t)0x8, 0);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint16_t)0x88, 0);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint32_t)0x888, 0);
+ rte_tel_data_add_array_uint_hex(&response_data, (uint64_t)0x8888, 0);
+
+ return CHECK_OUTPUT("[\"0x8\",\"0x88\",\"0x888\",\"0x8888\"]");
+}
+
static int
test_case_add_dict_u64(void)
{
@@ -420,15 +562,23 @@ telemetry_data_autotest(void)
test_simple_string,
test_case_array_string,
test_case_array_int, test_case_array_u64,
+ test_case_array_uint_hex_padding,
+ test_case_array_uint_hex_nopadding,
test_case_add_dict_int, test_case_add_dict_u64,
test_case_add_dict_string,
+ test_case_add_dict_uint_hex_padding,
+ test_case_add_dict_uint_hex_nopadding,
test_dict_with_array_int_values,
test_dict_with_array_u64_values,
test_dict_with_array_string_values,
+ test_dict_with_array_uint_hex_values_padding,
+ test_dict_with_array_uint_hex_values_nopadding,
test_dict_with_dict_values,
test_array_with_array_int_values,
test_array_with_array_u64_values,
test_array_with_array_string_values,
+ test_array_with_array_uint_hex_values_padding,
+ test_array_with_array_uint_hex_values_nopadding,
test_string_char_escaping,
test_array_char_escaping,
test_dict_char_escaping,
diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 08d7f18dff..5d5b75b683 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -10,6 +10,7 @@ extern "C" {
#endif
#include <stdint.h>
+#include <rte_compat.h>
/** Maximum length for string used in object. */
#define RTE_TEL_MAX_STRING_LEN 128
@@ -153,6 +154,28 @@ int
rte_tel_data_add_array_container(struct rte_tel_data *d,
struct rte_tel_data *val, int keep);
+/**
+ * Convert an unsigned integer to hexadecimal encoded strings
+ * and add this string to an array.
+ * The array must have been started by rte_tel_data_start_array()
+ * with RTE_TEL_STRING_VAL as the type parameter.
+ *
+ * @param d
+ * The data structure passed to the callback.
+ * @param val
+ * The number to be returned in the array as a hexadecimal encoded strings.
+ * @param display_bitwidth
+ * The display bit width of the 'val'. If 'display_bitwidth' is zero, the
+ * value is stored in the array as no-padding zero hexadecimal encoded string,
+ * or the value is stored as padding zero to specified hexadecimal width.
+ * @return
+ * 0 on success, negative errno on error.
+ */
+__rte_experimental
+int
+rte_tel_data_add_array_uint_hex(struct rte_tel_data *d, uint64_t val,
+ uint8_t display_bitwidth);
+
/**
* Add a string value to a dictionary.
* The dict must have been started by rte_tel_data_start_dict().
@@ -231,6 +254,30 @@ int
rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
struct rte_tel_data *val, int keep);
+/**
+ * Convert an unsigned integer to hexadecimal encoded strings
+ * and add this string to an 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 of the value is to be stored in the dict.
+ * Must contain only alphanumeric characters or the symbols: '_' or '/'.
+ * @param val
+ * The number to be stored in the dict as a hexadecimal encoded strings.
+ * @param display_bitwidth
+ * The display bit width of the 'val'. If 'display_bitwidth' is zero, the
+ * value is stored in the array as no-padding zero hexadecimal encoded string,
+ * or the value is stored as padding zero to specified hexadecimal width.
+ * @return
+ * 0 on success, negative errno on error.
+ */
+__rte_experimental
+int
+rte_tel_data_add_dict_uint_hex(struct rte_tel_data *d, const char *name,
+ uint64_t val, uint8_t display_bitwidth);
+
/**
* This telemetry callback is used when registering a telemetry command.
* It handles getting and formatting information to be returned to telemetry
diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index be46054c29..61d9eeac6a 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -2,12 +2,16 @@
* Copyright(c) 2020 Intel Corporation
*/
+#include <inttypes.h>
+
#undef RTE_USE_LIBBSD
#include <stdbool.h>
#include <rte_string_fns.h>
#include "telemetry_data.h"
+#define RTE_TEL_UINT_HEX_STR_BUF_LEN 64
+
int
rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type)
{
@@ -93,6 +97,60 @@ rte_tel_data_add_array_container(struct rte_tel_data *d,
return 0;
}
+/* To suppress compiler warning about format string. */
+#if defined(RTE_TOOLCHAIN_GCC)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#elif defined(RTE_TOOLCHAIN_CLANG)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
+
+static int
+rte_tel_uint_to_hex_encoded_str(char *buf, size_t buf_len, uint64_t val,
+ uint8_t display_bitwidth)
+{
+#define RTE_TEL_HEX_FORMAT_LEN 16
+
+ uint8_t spec_hex_width = (display_bitwidth + 3) / 4;
+ char format[RTE_TEL_HEX_FORMAT_LEN];
+
+ if (display_bitwidth != 0) {
+ if (snprintf(format, RTE_TEL_HEX_FORMAT_LEN, "0x%%0%u" PRIx64,
+ spec_hex_width) >= RTE_TEL_HEX_FORMAT_LEN)
+ return -EINVAL;
+
+ if (snprintf(buf, buf_len, format, val) >= (int)buf_len)
+ return -EINVAL;
+ } else {
+ if (snprintf(buf, buf_len, "0x%" PRIx64, val) >= (int)buf_len)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+#if defined(RTE_TOOLCHAIN_GCC)
+#pragma GCC diagnostic pop
+#elif defined(RTE_TOOLCHAIN_CLANG)
+#pragma clang diagnostic pop
+#endif
+
+int
+rte_tel_data_add_array_uint_hex(struct rte_tel_data *d, uint64_t val,
+ uint8_t display_bitwidth)
+{
+ char hex_str[RTE_TEL_UINT_HEX_STR_BUF_LEN];
+ int ret;
+
+ ret = rte_tel_uint_to_hex_encoded_str(hex_str,
+ RTE_TEL_UINT_HEX_STR_BUF_LEN, val, display_bitwidth);
+ if (ret != 0)
+ return ret;
+
+ return rte_tel_data_add_array_string(d, hex_str);
+}
+
static bool
valid_name(const char *name)
{
@@ -200,6 +258,22 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
return bytes < RTE_TEL_MAX_STRING_LEN ? 0 : E2BIG;
}
+int
+rte_tel_data_add_dict_uint_hex(struct rte_tel_data *d, const char *name,
+ uint64_t val, uint8_t display_bitwidth)
+{
+ char hex_str[RTE_TEL_UINT_HEX_STR_BUF_LEN];
+ int ret;
+
+ ret = rte_tel_uint_to_hex_encoded_str(hex_str,
+ RTE_TEL_UINT_HEX_STR_BUF_LEN, val, display_bitwidth);
+ if (ret != 0)
+ return ret;
+
+
+ return rte_tel_data_add_dict_string(d, name, hex_str);
+}
+
struct rte_tel_data *
rte_tel_data_alloc(void)
{
diff --git a/lib/telemetry/version.map b/lib/telemetry/version.map
index 77528bb1fe..576ac55297 100644
--- a/lib/telemetry/version.map
+++ b/lib/telemetry/version.map
@@ -19,6 +19,16 @@ DPDK_22 {
local: *;
};
+EXPERIMENTAL {
+ global:
+
+ # added in 23.03
+ rte_tel_data_add_array_uint_hex;
+ rte_tel_data_add_dict_uint_hex;
+
+ local: *;
+};
+
INTERNAL {
rte_telemetry_legacy_register;
rte_telemetry_init;
--
2.23.0

View File

@ -0,0 +1,62 @@
From baa8bc0cc5736e2804e53c09b6cadf193993ce45 Mon Sep 17 00:00:00 2001
From: Huisong Li <lihuisong@huawei.com>
Date: Mon, 19 Dec 2022 15:06:48 +0800
Subject: ethdev: get capabilities from telemetry in hexadecimal
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit 796b031608d8d52e040f83304c676d3cda5af617 ]
The 'dev_flags', 'rx_offloads', 'tx_offloads' and 'rss_hf' are better
displayed in hexadecimal format.
Like:
--> old display by input /ethdev/info,0
"dev_flags": 3,
"rx_offloads": 524288,
"tx_offloads": 65536,
"ethdev_rss_hf": 9100
--> new display
"dev_flags": "0x3",
"rx_offloads": "0x80000",
"tx_offloads": "0x10000",
"ethdev_rss_hf": "0x238c"
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/ethdev/rte_ethdev.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index c216091e79..4e5499ad2d 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -6428,13 +6428,14 @@ eth_dev_handle_port_info(const char *cmd __rte_unused,
rte_tel_data_add_dict_container(d, "rxq_state", rxq_state, 0);
rte_tel_data_add_dict_container(d, "txq_state", txq_state, 0);
rte_tel_data_add_dict_int(d, "numa_node", eth_dev->data->numa_node);
- rte_tel_data_add_dict_u64(d, "dev_flags", eth_dev->data->dev_flags);
- rte_tel_data_add_dict_u64(d, "rx_offloads",
- eth_dev->data->dev_conf.rxmode.offloads);
- rte_tel_data_add_dict_u64(d, "tx_offloads",
- eth_dev->data->dev_conf.txmode.offloads);
- rte_tel_data_add_dict_u64(d, "ethdev_rss_hf",
- eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
+ rte_tel_data_add_dict_uint_hex(d, "dev_flags",
+ eth_dev->data->dev_flags, 0);
+ rte_tel_data_add_dict_uint_hex(d, "rx_offloads",
+ eth_dev->data->dev_conf.rxmode.offloads, 0);
+ rte_tel_data_add_dict_uint_hex(d, "tx_offloads",
+ eth_dev->data->dev_conf.txmode.offloads, 0);
+ rte_tel_data_add_dict_uint_hex(d, "ethdev_rss_hf",
+ eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf, 0);
return 0;
}
--
2.23.0

View File

@ -1,6 +1,6 @@
Name: dpdk
Version: 21.11
Release: 40
Release: 41
Packager: packaging@6wind.com
URL: http://dpdk.org
%global source_version 21.11
@ -282,6 +282,19 @@ Patch9260: 0260-net-virtio-support-private-dump.patch
Patch9261: 0261-net-vhost-support-private-dump.patch
Patch9262: 0262-app-testpmd-show-private-info-in-port-info.patch
Patch9263: 0263-app-testpmd-display-RSS-hash-key-of-flow-rule.patch
Patch9264: 0264-ethdev-fix-Rx-queue-telemetry-memory-leak-on-failure.patch
Patch9265: 0265-ethdev-fix-MAC-address-in-telemetry-device-info.patch
Patch9266: 0266-eventdev-eth_rx-fix-telemetry-Rx-stats-reset.patch
Patch9267: 0267-test-telemetry_data-refactor-for-maintainability.patch
Patch9268: 0268-test-telemetry_data-add-test-cases-for-character-esc.patch
Patch9269: 0269-usertools-telemetry-add-JSON-pretty-print.patch
Patch9270: 0270-telemetry-move-include-after-guard.patch
Patch9271: 0271-ethdev-fix-telemetry-data-truncation.patch
Patch9272: 0272-mempool-fix-telemetry-data-truncation.patch
Patch9273: 0273-cryptodev-fix-telemetry-data-truncation.patch
Patch9274: 0274-mem-fix-telemetry-data-truncation.patch
Patch9275: 0275-telemetry-support-adding-integer-as-hexadecimal.patch
Patch9276: 0276-ethdev-get-capabilities-from-telemetry-in-hexadecima.patch
Summary: Data Plane Development Kit core
Group: System Environment/Libraries
@ -429,6 +442,14 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko
/usr/sbin/depmod
%changelog
* Fri Apr 21 2023 chenjiji <chenjiji09@163.com> - 21.11-41
- Telemetry: support display as hexadecimal
Sync some patchs from upstreaming for telemetry and modifies
are as follow:
1. Support dispaly integer as hexadecimal.
2. Fix data truncation for some u64 accept as int.
3. Add JSON pretty print.
* Tue Apr 11 2023 bigclouds99 <yuelg@chinaunicom.cn> - 21.11-40
- Create a softlink to dpdk default driver path