From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B27E0A0540; Tue, 13 Dec 2022 12:01:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A52EE4021D; Tue, 13 Dec 2022 12:01:02 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 2C2DC40146 for ; Tue, 13 Dec 2022 12:01:01 +0100 (CET) Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: RE: [PATCH V3 00/11] telemetry: add u32 value type and hex integer string API Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Tue, 13 Dec 2022 12:00:57 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D8758B@smartserver.smartshare.dk> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH V3 00/11] telemetry: add u32 value type and hex integer string API Thread-Index: AdkOI5EzAjfI05vjRkiBgZbM9SQevgAvSrbQ References: <20221208080540.62913-1-lihuisong@huawei.com> <20221212064306.39232-1-lihuisong@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35D87585@smartserver.smartshare.dk> <98CBD80474FA8B44BF855DF32C47DC35D87586@smartserver.smartshare.dk> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Bruce Richardson" , "Huisong Li" Cc: , , , , 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 Med venlig hilsen / Kind regards, -Morten Br=F8rup > -----Original Message----- > From: Bruce Richardson [mailto:bruce.richardson@intel.com] > Sent: Monday, 12 December 2022 13.16 > To: Morten Br=F8rup > 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 >=20 > On Mon, Dec 12, 2022 at 01:03:52PM +0100, Morten Br=F8rup 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=F8rup 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. > > > > > > 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. > > >=20 > 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. >=20 > > > > 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 !=3D 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); > > } > > >=20 > 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