DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Bruce Richardson" <bruce.richardson@intel.com>,
	"Huisong Li" <lihuisong@huawei.com>
Cc: <dev@dpdk.org>, <ciara.power@intel.com>,
	<liudongdong3@huawei.com>, <huangdaode@huawei.com>,
	<fengchengwen@huawei.com>
Subject: RE: [PATCH V3 00/11] telemetry: add u32 value type and hex integer string API
Date: Tue, 13 Dec 2022 12:00:57 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D8758B@smartserver.smartshare.dk> (raw)
In-Reply-To: <Y5cbh0+glWByqm8X@bricha3-MOBL.ger.corp.intel.com>



Med venlig hilsen / Kind regards,
-Morten Brørup


> -----Original Message-----
> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Monday, 12 December 2022 13.16
> To: Morten Brørup
> Cc: Huisong Li; dev@dpdk.org; ciara.power@intel.com;
> liudongdong3@huawei.com; huangdaode@huawei.com; fengchengwen@huawei.com
> Subject: Re: [PATCH V3 00/11] telemetry: add u32 value type and hex
> integer string API
> 
> On Mon, Dec 12, 2022 at 01:03:52PM +0100, Morten Brørup wrote:
> > > From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> > > Sent: Monday, 12 December 2022 12.21
> > >
> > > On Mon, Dec 12, 2022 at 12:02:32PM +0100, Morten Brørup wrote:
> > > > > From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> > > > > Sent: Monday, 12 December 2022 11.32
> > > > >
> > > > > On Mon, Dec 12, 2022 at 02:42:55PM +0800, Huisong Li wrote:
> > > > > > Some lib telemetry interfaces add the 'u32' and 'u64' data by
> the
> > > > > > rte_tel_data_add_dict/array_int API. This may cause data
> > > conversion
> > > > > error
> > > > > > or data truncation.
> > > > > >
> > > > > > The 'u32' data can not be assigned to signed 32-bit integer.
> > > However,
> > > > > > assigning to u64 is very wasteful, after all, the buffer
> capacity
> > > of
> > > > > each
> > > > > > transfer is limited. So it is necessary for 'u32' data to add
> > > usigned
> > > > > > 32-bit integer type and a series of 'u32' operation APIs.
> > > > > >
> > > > > > This patchset uses the new 'u32' API to resolve the problem
> of
> > > data
> > > > > > conversion error, and use the 'u64' API to add 'u64' data.
> > > > > >
> > > > > > In addition, this patchset introduces two APIs to store u32
> and
> > > u64
> > > > > > values as hexadecimal encoded strings in telemetry library.
> > > > > >
> > > > > > --- -v3: fix a misspelling mistake in commit log.  -v2: - fix
> ABI
> > > > > break
> > > > > > warning.  - introduce two APIs to store u32 and u64 values as
> > > > > hexadecimal
> > > > > > encoded strings.
> > > > > >
> > > > > I'm not convinced about adding the u32 value generically to the
> > > > > telemetry
> > > > > lib - except in the case of having explicit function calls for
> u32
> > > vs
> > > > > u64
> > > > > hex strings. Having a u32 type doesn't gain us any space
> internally
> > > > > over a
> > > > > u64 value, since all values are in a union type. Also, for
> output
> > > as
> > > > > json,
> > > > > the numeric values are all output as decimal values, meaning
> that
> > > the
> > > > > value
> > > > > 1 appears as the same size in the output string whether it is a
> u32
> > > or
> > > > > u64
> > > > > type. Now, it may save space in a future binary output format,
> but
> > > even
> > > > > then it still may not do so.
> > > >
> > > > I agree that a u32 doesn't gain any space internally.
> > > >
> > > > However, many SNMP counters are unsigned 32 bit, and expected to
> wrap
> > > around as such.
> > > >
> > > > So I suppose the u32 type might be useful for SNMP, if obtained
> > > through the telemetry library.
> > > >
> > > > Alternatively, we could somehow reuse the u64 type and require
> the
> > > application to pass (value & UINT32_MAX) to the u64 functions. To
> make
> > > this easy to use, we should add some wrappers to do it for the
> > > application. And eventually we would probably end up with something
> > > very similar to this patch.
> > > >
> > >
> > > I think just using the u64 functions is probably simplest and best
> > > right
> > > now. If we add support for something like snmp then yes, it would
> make
> > > sense to explicitly add it, but it seems like a lot of extra code
> for
> > > little or no benefit until we support something like that.
> >
> > <rant>
> > If we wanted to fix this generally, we should rely on type promotion,
> so the existing _int function should be updated to take an int64_t
> value, and the _u64 function should be renamed to _uint (and still take
> an uint64_t value). However, that would break the ABI, and would need
> to go through some process for that. So let's not change this now.
> > </rant>
> 
> Yes, not making "int" an "i64" type was a poor design decision on my
> part
> in the earlier versions. Thankfully negative values are rarely needed
> beyond the range of 32-bits, but we should probably look to update this
> as
> you suggest at the next ABI break window.
> 
> >
> > I tend to agree with Bruce on this: Let's get rid of the new u32
> functions, and rely on the u64 functions for that instead.
> >
> > >
> > > > >
> > > > > Therefore, I'd tend to keep the existing u64 type as-is, and
> > > instead
> > > > > only
> > > > > add the functions for outputting hex values. Those hex output
> > > functions
> > > > > could take an additional parameter indicating the desired hex
> > > output
> > > > > length, as there could well be cases where we want just 16-bit
> hex
> > > > > value
> > > > > too.
> > > >
> > > > The way I read the patch series, the hex output length is not
> fixed,
> > > but an u64 value of 5 will be output as 0x5, not
> 0x0000000000000005.
> > > >
> > > > So the only benefit of having both u32_hex and u64_hex functions
> is
> > > to avoid type promotion from uint32_t to uint64_t on input for 32
> bit
> > > values.
> > > >
> > > > Instead of passing a 3rd parameter or adding u16_hex functions,
> we
> > > could consider just having one set of hex functions using uint64_t
> for
> > > the value, and rely on type promotion for 32 and 16 bit values.
> > > >
> > >
> > > +1 to having only a single hex function, and I think type promotion
> > > should
> > > work fine.
> > >
> > > However, I still think it might be worthwhile allowing the user to
> pass
> > > in
> > > a min output length parameter too. I find for many hex strings
> having
> > > the
> > > leading zeros to explicitly show the length can be useful. The
> value
> > > "0"
> > > could cover the current behaviour of no-padding, otherwise the
> > > parameter
> > > should indicate the number of bits to be displayed. (If we want to
> lock
> > > it
> > > down we can use an enum parameter rather than int to limit it to 0,
> 8,
> > > 16,
> > > 32 or 64 bit displayed values).
> >
> > An extra parameter for minimum output length (in number of input
> bits) would be very nice, and makes avoids a set of functions for each
> bit width.
> >
> > (I don't think it should be lock it down to some special bit lengths;
> there is no need to prevent 24 bit or other exotic bit widths.)
> >
> > Something like this:
> >
> > char str[64]; // Big enough length.
> > if (bits != 0) {
> >   char format[16]; // Big enough length.
> >   sprintf(format, "0x0%u%" PRIx64, (bits + 3) / 4);
> >   sprintf(str, format, value);
> > } else {
> >   sprintf(str, "0x%" PRIx64, value);
> > }
> >
> 
> LGTM.

From a higher level perspective, I'm wondering why passing an uint32_t as x to rte_tel_data_add_{dict|array}_int(struct rte_tel_data *d, int x) doesn't produce a compiler warning about risky type conversion. And similarly passing a signed value to the _u64 functions.

Wouldn't it make sense to wrap these functions in a macro, so -Wconversion could be enabled when they are used? (I guess -Wconversion is default disabled when building DPDK.)

-Morten


  reply	other threads:[~2022-12-13 11:01 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  8:05 [PATCH 0/8] fix possible data truncation and conversion error Huisong Li
2022-12-08  8:05 ` [PATCH 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-08  8:05 ` [PATCH 2/8] telemetry: add u32 telemetry data type API Huisong Li
2022-12-08  8:05 ` [PATCH 3/8] test: add test cases for u32 telemetry data API Huisong Li
2022-12-08  8:05 ` [PATCH 4/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-08  8:05 ` [PATCH 5/8] mempool: " Huisong Li
2022-12-08  8:05 ` [PATCH 6/8] cryptodev: fix possible data " Huisong Li
2022-12-08  8:05 ` [PATCH 7/8] mem: possible data truncation and " Huisong Li
2022-12-08  8:05 ` [PATCH 8/8] ethdev: telemetry convert capability related variable to hex Huisong Li
2022-12-08 10:55   ` Morten Brørup
2022-12-08 11:20     ` Bruce Richardson
2022-12-09  3:07       ` lihuisong (C)
2022-12-09 11:04 ` [PATCH V2 00/11] telemetry: add u32 value type and hex integer string API Huisong Li
2022-12-09 11:04   ` [PATCH V2 01/11] telemetry: move to header to controllable range Huisong Li
2022-12-09 11:04   ` [PATCH V2 02/11] telemetry: add u32 value type Huisong Li
2022-12-09 11:04   ` [PATCH V2 03/11] test: add test cases for adding u32 value API Huisong Li
2022-12-09 11:04   ` [PATCH V2 04/11] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-09 11:04   ` [PATCH V2 05/11] mempool: " Huisong Li
2022-12-09 11:04   ` [PATCH V2 06/11] cryptodev: fix possible data " Huisong Li
2022-12-09 11:04   ` [PATCH V2 07/11] mem: possible data truncation and " Huisong Li
2022-12-09 11:04   ` [PATCH V2 08/11] telemetry: refactor mapping betwween value and array type Huisong Li
2022-12-09 11:04   ` [PATCH V2 09/11] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-09 11:04   ` [PATCH V2 10/11] test: add test cases for adding hex integer values API Huisong Li
2022-12-09 11:04   ` [PATCH V2 11/11] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-09 18:24   ` [PATCH V2 00/11] telemetry: add u32 value type and hex integer string API Morten Brørup
2022-12-12  6:23     ` lihuisong (C)
2022-12-11  9:02   ` fengchengwen
2022-12-12  6:42 ` [PATCH V3 " Huisong Li
2022-12-12  6:42   ` [PATCH V3 01/11] telemetry: move to header to controllable range Huisong Li
2022-12-12  6:42   ` [PATCH V3 02/11] telemetry: add u32 value type Huisong Li
2022-12-12  6:42   ` [PATCH V3 03/11] test: add test cases for adding u32 value API Huisong Li
2022-12-12  6:42   ` [PATCH V3 04/11] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-12  6:43   ` [PATCH V3 05/11] mempool: " Huisong Li
2022-12-12  6:43   ` [PATCH V3 06/11] cryptodev: fix possible data " Huisong Li
2022-12-12  6:43   ` [PATCH V3 07/11] mem: possible data truncation and " Huisong Li
2022-12-12  6:43   ` [PATCH V3 08/11] telemetry: refactor mapping betwween value and array type Huisong Li
2022-12-12  6:43   ` [PATCH V3 09/11] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-12  6:43   ` [PATCH V3 10/11] test: add test cases for adding hex integer values API Huisong Li
2022-12-12  6:43   ` [PATCH V3 11/11] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-12 10:31   ` [PATCH V3 00/11] telemetry: add u32 value type and hex integer string API Bruce Richardson
2022-12-12 11:02     ` Morten Brørup
2022-12-12 11:20       ` Bruce Richardson
2022-12-12 12:03         ` Morten Brørup
2022-12-12 12:16           ` Bruce Richardson
2022-12-13 11:00             ` Morten Brørup [this message]
2022-12-13 17:12             ` Bruce Richardson
2022-12-13  3:02           ` lihuisong (C)
2022-12-13 10:15 ` [PATCH V4 0/9] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-13 10:15   ` [PATCH V4 1/9] telemetry: move to header to controllable range Huisong Li
2022-12-13 17:10     ` Bruce Richardson
2022-12-14  2:44       ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 2/9] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-13 10:15   ` [PATCH V4 3/9] mempool: " Huisong Li
2022-12-13 10:15   ` [PATCH V4 4/9] cryptodev: fix possible data " Huisong Li
2022-12-13 10:15   ` [PATCH V4 5/9] mem: possible data truncation and " Huisong Li
2022-12-13 10:15   ` [PATCH V4 6/9] telemetry: refactor mapping between value and array type Huisong Li
2022-12-13 16:57     ` Bruce Richardson
2022-12-14  2:46       ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 7/9] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-13 17:09     ` Bruce Richardson
2022-12-14  2:44       ` lihuisong (C)
2022-12-14  7:28         ` Morten Brørup
2022-12-14 12:17           ` lihuisong (C)
2022-12-13 10:15   ` [PATCH V4 8/9] test: add test cases for adding hex integer value API Huisong Li
2022-12-13 10:15   ` [PATCH V4 9/9] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-14 12:32 ` [PATCH V5 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-14 12:32   ` [PATCH V5 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-14 12:32   ` [PATCH V5 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-14 12:32   ` [PATCH V5 3/8] mempool: " Huisong Li
2022-12-14 12:32   ` [PATCH V5 4/8] cryptodev: fix possible data " Huisong Li
2022-12-14 12:32   ` [PATCH V5 5/8] mem: possible data truncation and " Huisong Li
2022-12-14 13:00     ` Morten Brørup
2022-12-15  1:11       ` lihuisong (C)
2022-12-15  7:04         ` Morten Brørup
2022-12-15  7:56           ` lihuisong (C)
2022-12-14 12:32   ` [PATCH V5 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-14 15:38     ` Bruce Richardson
2022-12-15  1:32       ` lihuisong (C)
2022-12-14 12:32   ` [PATCH V5 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-14 12:32   ` [PATCH V5 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-15 10:31 ` [PATCH V6 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-15 10:31   ` [PATCH V6 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-15 10:31   ` [PATCH V6 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-15 10:31   ` [PATCH V6 3/8] mempool: " Huisong Li
2022-12-15 10:31   ` [PATCH V6 4/8] cryptodev: fix possible data " Huisong Li
2022-12-15 10:31   ` [PATCH V6 5/8] mem: possible data truncation and " Huisong Li
2022-12-15 10:31   ` [PATCH V6 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-15 10:46     ` Bruce Richardson
2022-12-15 11:27       ` lihuisong (C)
2022-12-15 12:00         ` Morten Brørup
2022-12-15 12:15           ` Bruce Richardson
2022-12-15 12:24             ` Morten Brørup
2022-12-15 12:45               ` lihuisong (C)
2022-12-15 12:52                 ` Morten Brørup
2022-12-15 13:08                   ` Bruce Richardson
2022-12-16  1:15                     ` lihuisong (C)
2022-12-15 10:31   ` [PATCH V6 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-15 10:31   ` [PATCH V6 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-16  1:54 ` [PATCH V7 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-16  1:54   ` [PATCH V7 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-16  1:54   ` [PATCH V7 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-16  1:54   ` [PATCH V7 3/8] mempool: " Huisong Li
2022-12-16  1:54   ` [PATCH V7 4/8] cryptodev: fix possible data " Huisong Li
2022-12-16  1:54   ` [PATCH V7 5/8] mem: possible data truncation and " Huisong Li
2022-12-16  1:54   ` [PATCH V7 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-16  1:54   ` [PATCH V7 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-16  9:31     ` Bruce Richardson
2022-12-19  7:04       ` lihuisong (C)
2022-12-16  1:54   ` [PATCH V7 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2022-12-19  7:06 ` [PATCH V8 0/8] telemetry: fix data truncation and conversion error and add hex integer API Huisong Li
2022-12-19  7:06   ` [PATCH V8 1/8] telemetry: move to header to controllable range Huisong Li
2022-12-19  7:06   ` [PATCH V8 2/8] ethdev: fix possible data truncation and conversion error Huisong Li
2022-12-19  7:06   ` [PATCH V8 3/8] mempool: " Huisong Li
2022-12-19  7:06   ` [PATCH V8 4/8] cryptodev: fix possible data " Huisong Li
2022-12-19  7:06   ` [PATCH V8 5/8] mem: possible data truncation and " Huisong Li
2022-12-19  7:06   ` [PATCH V8 6/8] telemetry: support adding integer value as hexadecimal Huisong Li
2022-12-19  9:19     ` Bruce Richardson
2022-12-19  7:06   ` [PATCH V8 7/8] test: add test cases for adding hex integer value API Huisong Li
2022-12-19  7:06   ` [PATCH V8 8/8] ethdev: display capability values in hexadecimal format Huisong Li
2023-01-16 12:06   ` [PATCH V8 0/8] telemetry: fix data truncation and conversion error and add hex integer API lihuisong (C)
2023-01-30 10:39     ` lihuisong (C)
2023-02-05 20:43   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=98CBD80474FA8B44BF855DF32C47DC35D8758B@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=bruce.richardson@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=huangdaode@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=liudongdong3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).