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 02EA9A0543; Wed, 14 Dec 2022 16:39:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D40E34021D; Wed, 14 Dec 2022 16:39:10 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id F0545400D6 for ; Wed, 14 Dec 2022 16:39:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671032349; x=1702568349; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=aq7uW2T+yWNOHvzF02akppDUVff1v2JyLawnHI09aJE=; b=kX2WzlTTzkTDIIF+1uTT4sPVRq+EoruKZ/2zIW4Zm8t178+31U1BkVi+ bjtahbLu62rL0sEaIYOE/So0yLdvGX5FGG5nfv/n4Vcz4Dkj35CnkdSco NmyCHBQ05tbSsj3PVmYxT0vLe3II1URKSUdhCusugt54QQ9Q37OZ5VIRt CGehYg4CUkfIHYzDSX3s2w4jp6sec6cSzMsBlY+YD+x12PsxRUFNMwCTQ roUeGZeKQZX9c/DPQnGqiEcoSpjmxyKwi6XGyijKd60K0nMdlZOnA2+ek jDpwGwyMH/FwNNYbVK4lJ5ITMiVivRx2wV3CP0RiColVKryuv+ig60Kvl A==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="382735635" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="382735635" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 07:38:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="626767969" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="626767969" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga006.jf.intel.com with ESMTP; 14 Dec 2022 07:38:55 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 14 Dec 2022 07:38:54 -0800 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 14 Dec 2022 07:38:54 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Wed, 14 Dec 2022 07:38:54 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Wed, 14 Dec 2022 07:38:54 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YjX91Zrq4qpu2pb8bf+6wSNxMqtr2uDerc70BU9C4hkvpSnjnL+K+jdE3tz9NyAnUlLPct9MTv9qhbP/jE/mr/D9VXaTkc42tCG2PKUARyqhouExJJgZyjjngG/8K0eNWVnMyFZsNxCdaGGele2CkMxJWMq9EvUerew9Ba0hD3wz8CNoDtYyaa+08KnpPKYWWSSLU6oEIPPm2F55Woah9pTd3aHk+83q65SB6ATf98Ktwm5Hir/gcRgo8Gq23Fr+eXJSDBtqJ+eRqHXYFZyXc5fYMDDLy/eCl+sAXTUgRMSIZMo5I6EYIJWHNKsApJlMr14/xIqQXHkL27TpElmxBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7tKvAKWUx2AkmgH21W8VNrvXoTsPQbRbhF6DiANzuHo=; b=VMSzlaWY64bTdgphJ3/BA3vYr1AMWfyGgUQmDMuKsbkvxAzsG3k0FjoiBewfevtMACm+Ip8yPX0EAfvBSneT34b4DnPKvOsvibl9ImHadhDv8PTM3shRe66mxtbop1Hn2OGstkWN6rbDbMI51jcAf0lZwzyY+FlIa/7SqjVmnhhsogoVZ17Jn0e4X425kVy+ZHaRD1Jlx+3FEmLpAkY7+vDbxjcUeqSGyzuFHs6mWn/0ijCoTi6yaTC6g+/w2Ve+MrrmMeChTbLk3b9+JW8XUetqeYcEQ+c8yelYdUbV6dkbnl0xMpTW9dS9zDonsFcpBxI/62VcSnczWIkUNR0ElQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MWHPR11MB1629.namprd11.prod.outlook.com (2603:10b6:301:d::21) by PH7PR11MB6554.namprd11.prod.outlook.com (2603:10b6:510:1a8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Wed, 14 Dec 2022 15:38:52 +0000 Received: from MWHPR11MB1629.namprd11.prod.outlook.com ([fe80::18bd:edae:ad31:a228]) by MWHPR11MB1629.namprd11.prod.outlook.com ([fe80::18bd:edae:ad31:a228%3]) with mapi id 15.20.5924.011; Wed, 14 Dec 2022 15:38:52 +0000 Date: Wed, 14 Dec 2022 15:38:45 +0000 From: Bruce Richardson To: Huisong Li CC: , , , , , Subject: Re: [PATCH V5 6/8] telemetry: support adding integer value as hexadecimal Message-ID: References: <20221208080540.62913-1-lihuisong@huawei.com> <20221214123253.29549-1-lihuisong@huawei.com> <20221214123253.29549-7-lihuisong@huawei.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221214123253.29549-7-lihuisong@huawei.com> X-ClientProxiedBy: LO4P265CA0088.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bc::7) To MWHPR11MB1629.namprd11.prod.outlook.com (2603:10b6:301:d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR11MB1629:EE_|PH7PR11MB6554:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f1bdb43-6a2b-4481-e5f0-08dadde94d37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jzYxSTE0Y6xqnTLb4H48kKadij+K5VyLks1HE1rjZ+NohEDlp41Cg0o4+t65rq5xFlbk4dsBSNM1VPk0QQ5VNWGDsDt2YroZewk0tblhPnzPiSCH/L+RL/Gyk5B8HIX9GMoeZjvBH/+Xks6YIJxqsd2vCwsBOXDj9v3fNqGPfPkAJ9N+4530U5kM9gII70yLcZX0POxAlrJNcTnbXByqs3JcwSQmL/zIXCMg7tFjRmIHpoa/hSjwqztdlghtrhWp4uYRwuoe/QoLeAyW+6sevs3X+p2oLmAkISz6e6BStAduTt1XcpeDXxrlhWQX23xXFRhOodlDKGDFVHrUbRTQlxgEqs6KRPbc5NmSS1H4PnSMBVVqrwGJOZRVd7MqOC96lzEF4JKwJZmfEAEEjbQSSZFNZHFAPlUcVauK7HgXKx5s0l1fsafWWsl1BZM4QMK9qqtbrzbpbqNkWPIZJWLgAnODEhhuFMIIxXGM4G35U2wDJIy0vIVJ7hiICBUtlBJxn2K7H1Grte2mFg1zdEm+iXa+CUp3zH/iyoYOJz5Bgsef3Glt/d+/lQ7jwq1/H1fycYItqi2WxiuX3m/QuONXt6VLdgx2+P+0+QU+ZIRhqgNn9CZ7O2utp7kHOdlZav8xmSML4lTRgKj34XppVTeUhg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR11MB1629.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(366004)(136003)(346002)(376002)(39860400002)(396003)(451199015)(86362001)(6512007)(5660300002)(2906002)(66574015)(6666004)(6506007)(41300700001)(4326008)(83380400001)(316002)(8676002)(6916009)(66556008)(66946007)(66476007)(82960400001)(186003)(26005)(8936002)(44832011)(38100700002)(6486002)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?yENhM99Bm6jxH9P6hErLFjvjcOH+lI5Ie8E9c+d1w0NfhOSBwVeAS33Opm?= =?iso-8859-1?Q?c43D4r1sJtXRiw7Z0sS4Dl/MeDEoAU13y3x/hiT//zlPkqJGWKcwPH+Kwx?= =?iso-8859-1?Q?L44lWi0reWHrXlveMrP+kBtpbQ31LHN6m3b2j7uUlCpgHfhhyrAoJmaWJ8?= =?iso-8859-1?Q?GMSJOJ+IPidZEVrCbM23A+Q1w1RN8ZzqjA6aRmRwOYCIfFGSAzG5OiTzEK?= =?iso-8859-1?Q?DAs7Gfegji9GV4emfFsQuWP5/sqLmlONLx7fbnxkyCpsFeIFiDwU6MrPXI?= =?iso-8859-1?Q?bH9Aq9q9fWGu2rclPQJ5le27yi+OJbKsM0oMRH4F67rwGNyN+haCTZ+e4I?= =?iso-8859-1?Q?FgnBjugeVI6ncgFm1Lte7403w/PUMZN0U0oLLiKMoPzkk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mPKm74+8LGy90+/WYzOptbJK/d5HqKaij25ld5TcNxzuyLjtQmaP/snqpX?= =?iso-8859-1?Q?oRSXmYsHgnxlPUES5tg5oU/2XQ+D9FKRScUiJF/K12yZdxeNCd0Vm9TfLo?= =?iso-8859-1?Q?NFaCWgqTwIno8X0Z19POWVR2DoS6+IwIc5feX5l5yQPYwETNE+OJUZ5A7n?= =?iso-8859-1?Q?GJt21QQcoJPUFRk8keBW+X7Jo+uqa8kZw/xQ8UngoyT3vxzGco2F3TNiq3?= =?iso-8859-1?Q?vgNGrt+BUkcdV7s95YuM+WSlozzyVKMRhKGnMfCb7n84o/V/QTBE+Hj4IO?= =?iso-8859-1?Q?YKNbA9kP5YwE9j6moYw1cuQ90kjNTV4zgycHykcdSP3y72Skn3BeaWwT78?= =?iso-8859-1?Q?V8x9TCxzmH0nJ0ueQooRsNwpR47RZ9Cj7a7xcIrR63JZtBcekAIwfmLU6B?= =?iso-8859-1?Q?P1BideV/BxFp8Wxr85U=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 7f1bdb43-6a2b-4481-e5f0-08dadde94d37 X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1629.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 15:38:52.1317 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: v/I6sO8747OC470fKSzm08PhlOlSflyPJDez36aVtJrSho6MXRkWPOUPAK7MzRnsgHa/FPLgnSdZjjVNUQyq6HVQiODgYA+ToFvJcj32kA8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6554 X-OriginatorOrg: intel.com 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 On Wed, Dec 14, 2022 at 08:32:51PM +0800, Huisong Li wrote: > Sometimes displaying a 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 padding to the specified width. > > Signed-off-by: Huisong Li > Acked-by: Morten Brørup > Acked-by: Chengwen Feng > --- > lib/telemetry/rte_telemetry.h | 47 +++++++++++++++++++++ > lib/telemetry/telemetry_data.c | 74 ++++++++++++++++++++++++++++++++++ > lib/telemetry/version.map | 9 +++++ > 3 files changed, 130 insertions(+) > > diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h > index 40e9a3bf9d..b24f0310ea 100644 > --- a/lib/telemetry/rte_telemetry.h > +++ b/lib/telemetry/rte_telemetry.h > @@ -10,6 +10,7 @@ extern "C" { > #endif > > #include > +#include > > /** 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 a 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 a 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 34366ecee3..14cb56d680 100644 > --- a/lib/telemetry/telemetry_data.c > +++ b/lib/telemetry/telemetry_data.c > @@ -4,6 +4,7 @@ > > #include > #include > +#include > > #undef RTE_USE_LIBBSD > #include > @@ -12,6 +13,8 @@ > > #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) > { > @@ -97,6 +100,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, uint16_t len, uint64_t val, > + uint8_t display_bitwidth) > +{ > +#define RTE_TEL_UINT_HEX_FORMAT_LEN 16 > + > + uint8_t spec_hex_width = (display_bitwidth + 3) / 4; > + char format[RTE_TEL_UINT_HEX_FORMAT_LEN]; > + > + /* Buffer needs to have room to contain the prefix '0x' and '\0'. */ > + if (len < spec_hex_width + 3) > + return -EINVAL; > + > + if (display_bitwidth != 0) { > + sprintf(format, "0x%%0%u" PRIx64, spec_hex_width); > + sprintf(buf, format, val); > + } else { > + sprintf(buf, "0x%" PRIx64, val); > + } > + > + 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); Small nit - the indentation here - and in a few other places does not match that in the rest of the file. The existing file only uses tabs for indent, and does not align continuations on brackets, it just double-indents. /Bruce