[8/8] ethdev: telemetry convert capability related variable to hex

Message ID 20221208080540.62913-9-lihuisong@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series fix possible data truncation and conversion error |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build fail github build: failed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS

Commit Message

lihuisong (C) Dec. 8, 2022, 8:05 a.m. UTC
  The 'dev_flags', 'rx_offloads', 'tx_offloads' and 'rss_hf' are suitable
for hexadecimal display.

Like:
 -->old display by input /ethdev/info,0
      "dev_flags": 3,
      "rx_offloads": 524288,
      "tx_offloads": 65536,
      "ethdev_rss_hf": 9100

 --> now display
     "dev_flags": "0x3",
     "rx_offloads": "0x80000",
     "tx_offloads": "0x10000",
     "ethdev_rss_hf": "0x238c"

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/ethdev/rte_ethdev.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
  

Comments

Morten Brørup Dec. 8, 2022, 10:55 a.m. UTC | #1
+To: Bruce and Stephen might also have opinions on this.

> From: Huisong Li [mailto:lihuisong@huawei.com]
> Sent: Thursday, 8 December 2022 09.06
> 
> The 'dev_flags', 'rx_offloads', 'tx_offloads' and 'rss_hf' are suitable
> for hexadecimal display.
> 
> Like:
>  -->old display by input /ethdev/info,0
>       "dev_flags": 3,
>       "rx_offloads": 524288,
>       "tx_offloads": 65536,
>       "ethdev_rss_hf": 9100
> 
>  --> now display
>      "dev_flags": "0x3",
>      "rx_offloads": "0x80000",
>      "tx_offloads": "0x10000",
>      "ethdev_rss_hf": "0x238c"

This is certainly good for human consumption, but perhaps not for machine consumption (where a number type is more appropriate than a string type).

Unfortunately, the JSON format [RFC7159] does not allow hexadecimal numbers, so hexadecimal values (if supported) have to be passed as strings.

[RFC7159]: https://www.rfc-editor.org/rfc/rfc7159

This leaves us with the key question:

Do we want to provide integer values like these as hexadecimal encoded strings?

If we do, then the telemetry library should provide the functions to do it, rather than doing it here (and everywhere else, where relevant).
  
Bruce Richardson Dec. 8, 2022, 11:20 a.m. UTC | #2
On Thu, Dec 08, 2022 at 11:55:16AM +0100, Morten Brørup wrote:
> +To: Bruce and Stephen might also have opinions on this.
> 
> > From: Huisong Li [mailto:lihuisong@huawei.com]
> > Sent: Thursday, 8 December 2022 09.06
> > 
> > The 'dev_flags', 'rx_offloads', 'tx_offloads' and 'rss_hf' are suitable
> > for hexadecimal display.
> > 
> > Like:
> >  -->old display by input /ethdev/info,0
> >       "dev_flags": 3,
> >       "rx_offloads": 524288,
> >       "tx_offloads": 65536,
> >       "ethdev_rss_hf": 9100
> > 
> >  --> now display
> >      "dev_flags": "0x3",
> >      "rx_offloads": "0x80000",
> >      "tx_offloads": "0x10000",
> >      "ethdev_rss_hf": "0x238c"
> 
> This is certainly good for human consumption, but perhaps not for machine consumption (where a number type is more appropriate than a string type).
> 
> Unfortunately, the JSON format [RFC7159] does not allow hexadecimal numbers, so hexadecimal values (if supported) have to be passed as strings.
> 
> [RFC7159]: https://www.rfc-editor.org/rfc/rfc7159
> 
> This leaves us with the key question:
> 
> Do we want to provide integer values like these as hexadecimal encoded strings?
> 
> If we do, then the telemetry library should provide the functions to do it, rather than doing it here (and everywhere else, where relevant).
> 

My initial thought was "no, we shouldn't do that, and just treat numbers as
numbers", and let the end-user display software worry about formatting it
correctly. However, I have since changed my mind, in that:

* Although these are numbers, they are not used for computation, or
  comparison
* Having them as strings makes them more useful for "dumb-client"
  connections, like that of the telemetry script in DPDK
* If display software is aware of the significance of these values and does
  want to do additional parsing of the flags, e.g. to map them to named
  flags, converting a string back to a number is not a difficult task.
* These values are not changing between polls, so any convertion/processing
  of the flags to be done before display only needs to be done once (except
  in very rare circumstances of a port reconfiguration)

So overall, I would tend to agree with your proposal, in that it would be
good for telemetry lib to provide this functionality.

Regards,
/Bruce
  
lihuisong (C) Dec. 9, 2022, 3:07 a.m. UTC | #3
在 2022/12/8 19:20, Bruce Richardson 写道:
> On Thu, Dec 08, 2022 at 11:55:16AM +0100, Morten Brørup wrote:
>> +To: Bruce and Stephen might also have opinions on this.
>>
>>> From: Huisong Li [mailto:lihuisong@huawei.com]
>>> Sent: Thursday, 8 December 2022 09.06
>>>
>>> The 'dev_flags', 'rx_offloads', 'tx_offloads' and 'rss_hf' are suitable
>>> for hexadecimal display.
>>>
>>> Like:
>>>   -->old display by input /ethdev/info,0
>>>        "dev_flags": 3,
>>>        "rx_offloads": 524288,
>>>        "tx_offloads": 65536,
>>>        "ethdev_rss_hf": 9100
>>>
>>>   --> now display
>>>       "dev_flags": "0x3",
>>>       "rx_offloads": "0x80000",
>>>       "tx_offloads": "0x10000",
>>>       "ethdev_rss_hf": "0x238c"
>> This is certainly good for human consumption, but perhaps not for machine consumption (where a number type is more appropriate than a string type).
>>
>> Unfortunately, the JSON format [RFC7159] does not allow hexadecimal numbers, so hexadecimal values (if supported) have to be passed as strings.
>>
>> [RFC7159]: https://www.rfc-editor.org/rfc/rfc7159
>>
>> This leaves us with the key question:
>>
>> Do we want to provide integer values like these as hexadecimal encoded strings?
>>
>> If we do, then the telemetry library should provide the functions to do it, rather than doing it here (and everywhere else, where relevant).
>>
> My initial thought was "no, we shouldn't do that, and just treat numbers as
> numbers", and let the end-user display software worry about formatting it
> correctly. However, I have since changed my mind, in that:
>
> * Although these are numbers, they are not used for computation, or
>    comparison
> * Having them as strings makes them more useful for "dumb-client"
>    connections, like that of the telemetry script in DPDK
> * If display software is aware of the significance of these values and does
>    want to do additional parsing of the flags, e.g. to map them to named
>    flags, converting a string back to a number is not a difficult task.
> * These values are not changing between polls, so any convertion/processing
>    of the flags to be done before display only needs to be done once (except
>    in very rare circumstances of a port reconfiguration)
>
> So overall, I would tend to agree with your proposal, in that it would be
> good for telemetry lib to provide this functionality.
All right. Thanks for your suggestion. I will do it in V2.
>
> Regards,
> /Bruce
> .
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index dfb269970e..a496846ba4 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -5999,6 +5999,9 @@  eth_dev_handle_port_info(const char *cmd __rte_unused,
 		const char *params,
 		struct rte_tel_data *d)
 {
+#define RTE_ETH_DEV_MAX_HEX_BUFFER_LEN (sizeof(uint64_t) + 3)\
+
+	char hex_buf[RTE_ETH_DEV_MAX_HEX_BUFFER_LEN];
 	struct rte_tel_data *rxq_state, *txq_state;
 	char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
 	struct rte_eth_dev *eth_dev;
@@ -6068,13 +6071,18 @@  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_u32(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);
+	snprintf(hex_buf, RTE_ETH_DEV_MAX_HEX_BUFFER_LEN, "0x%x",
+		 eth_dev->data->dev_flags);
+	rte_tel_data_add_dict_string(d, "dev_flags", hex_buf);
+	snprintf(hex_buf, RTE_ETH_DEV_MAX_HEX_BUFFER_LEN, "0x%"PRIx64"",
+		 eth_dev->data->dev_conf.rxmode.offloads);
+	rte_tel_data_add_dict_string(d, "rx_offloads", hex_buf);
+	snprintf(hex_buf, RTE_ETH_DEV_MAX_HEX_BUFFER_LEN, "0x%"PRIx64"",
+		 eth_dev->data->dev_conf.txmode.offloads);
+	rte_tel_data_add_dict_string(d, "tx_offloads", hex_buf);
+	snprintf(hex_buf, RTE_ETH_DEV_MAX_HEX_BUFFER_LEN, "0x%"PRIx64"",
+		 eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
+	rte_tel_data_add_dict_string(d, "ethdev_rss_hf", hex_buf);
 
 	return 0;
 }