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 73B66A0545; Thu, 15 Dec 2022 11:46:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1710F40684; Thu, 15 Dec 2022 11:46:13 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 075C440223 for ; Thu, 15 Dec 2022 11:46:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671101172; x=1702637172; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=NyfxOC5JfR3DtY/sU5SnuxN5tbcJc5ILnsYO8apZX4I=; b=enhPxE61iEidHuYQgamX4w39Bgx3sWbYUgLGOASAkMdh61wi9O9Ku5pz LP622Kmm/nOmyyCUkPEo5RB92tP9fIOl+u3kf8CvCGurmua2g6TCx4bnJ L+cdkmgddkg3ANI7azovaaU/gIsGJO58AyfZMfxocQDv0Mm8ZWRjz3s+B b3tHQ8zRYNDZVztudBs+I3KOBps52iLPXI6lSzdwPKHdvxkgyJAgHHBPo Qr/FY1p61Z7lSYdf+RBztFlSaS5B7p2qwgb91S2my1+Wj0n+tzI2KnvdA tWL0xefSVkc2uZDYUoiR6Ne/le+JLqxukOyKYnNjMJmXFUJ+OGRqJ2n22 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="382950593" X-IronPort-AV: E=Sophos;i="5.96,247,1665471600"; d="scan'208";a="382950593" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 02:46:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="627139444" X-IronPort-AV: E=Sophos;i="5.96,247,1665471600"; d="scan'208";a="627139444" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga006.jf.intel.com with ESMTP; 15 Dec 2022 02:46:10 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 15 Dec 2022 02:46:10 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Thu, 15 Dec 2022 02:46:10 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.42) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Thu, 15 Dec 2022 02:46:10 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mn+uw1pe6dPbvi125KDRUj4uDcGmO9Uh2opo3wOc8hWozJMMbvPM8DPyIxPaTuEIEd77yitc9T4U/7xqZiD94oZwBwukfHJy/COQWIicDI8fyLt+Ml5m1OXQqIWiMrEP4vSToZ6bk0bpm1wT4LULcCbgBUm7IGl+QnGN20hNe044POZeNEOlQP5TR5s3kuB90eeXrtv6+PezELXNN+DefbJxUM+ab0uX9g1KldVovOYkK68kqJxGSlrQY2AgAgaJq/rh7hgNhh38oxuWhKDYienhzQDwoIz+Ewf7D9vYxlZOuDrbmCvs0u2ejyOKWJZ+pwyqm03dxLPDZI7z4S9PwA== 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=8bpRWu6/sbfUXfs1bCrbJMWD9J8GXzHRE/9WS19VKZk=; b=Tz90dXQB28y7e0cSpyiKbqu9QefOHM3yNPJ/wjVq00QlDijPRYVDYpV7FFkcjXGO0oBtz2WdPKr+MUoeJEUKff1bm7r/HtrBpUQadUCfD9S0bQZ2yyZDu/qLUtl4mcTiVyG0EkeBbD6rcVUbFvyhxwauam8fS78fvB8MCj2os8KbtitJaV9WZ9z6Pe4vWBqf1I7+7Ho1TrlLtpBTa1ypijSjHLkftIU+fSkBoHN3or8bKJx3iVib3bko/1D21vDaX9JVDcBZR81q9fptwGya/M6uaYI29g0zEe9BlftMg6p4XafRZ76chIYyJruSSESxcGCXi+PW4rg6emkKHfr31w== 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 DM6PR11MB4561.namprd11.prod.outlook.com (2603:10b6:5:2ae::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Thu, 15 Dec 2022 10:46:09 +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; Thu, 15 Dec 2022 10:46:09 +0000 Date: Thu, 15 Dec 2022 10:46:02 +0000 From: Bruce Richardson To: Huisong Li CC: , , , , , Subject: Re: [PATCH V6 6/8] telemetry: support adding integer value as hexadecimal Message-ID: References: <20221208080540.62913-1-lihuisong@huawei.com> <20221215103146.816-1-lihuisong@huawei.com> <20221215103146.816-7-lihuisong@huawei.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221215103146.816-7-lihuisong@huawei.com> X-ClientProxiedBy: LO4P123CA0263.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::16) To MWHPR11MB1629.namprd11.prod.outlook.com (2603:10b6:301:d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR11MB1629:EE_|DM6PR11MB4561:EE_ X-MS-Office365-Filtering-Correlation-Id: 6fe999bc-3b0a-4a56-38bf-08dade899334 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XteHHm0BATTI4GVq/7xyj0zsaRGm+ohYS5LmX4xBSo5fdGN6PIdhaw1i+SLjytkKqpfAdOSEJAqZQciV9nDRXT1r2NfMM+tgqnbTqdjbSSCvfNiNMaKQ+k/p+vXBZWatd92zlb15z+NrdP2dpbine6XaeZLcMy26Kn1Jb5OEDdno5ZjD7lRWwBa1imGKNHhiojgftY9rRYFDCni/pPLS+iCq/vgnoYO0pyfH7VEOQLDvBztCOvdeshd1Kka+qMMaDjr+qOsmHdqzS+TXqPX1Ud26/3Na/fYvjwWKSMo7ilxTOE/aBytHIFSWBUulaAKDzzdrn+Jy4i/Y3DE1/lyrwg00lAtHFg2slYoPbCkm4HB9Djj8mS34H3dpoQyeztH0cZccHUYH8dFVrKwBRdTbatghazfTrGlt1inCfIZoSfWr4bxia5QoOqdzQGzWmPhMgJdZon8knUP2RHEuwnbNCpcmfBKVpgzgRvvuLEQhp7k1QC3gbdY+Ghy3mud4oXIDoSXolzzEQZkUsi94mVAiYSJec58bd0rp0YIaaM1MC5VLBmiZCJc8d6lclf4eO505MDdt8o2X121ZPbWtgBZuRPGvtEDgw+whQN3ZjVEzdmaHO+CXr7oNFPN2+Vltaxv3GGwxeRzM7CLOxx35xpI+VhK8I2vHMwfRtyqHhoejYaVMQ+Fns53TvQWnCJYmL4J/ 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)(346002)(366004)(39860400002)(136003)(396003)(376002)(451199015)(6512007)(6506007)(86362001)(38100700002)(66574015)(478600001)(186003)(82960400001)(83380400001)(6486002)(66476007)(4326008)(26005)(5660300002)(316002)(8936002)(8676002)(2906002)(66556008)(6916009)(44832011)(6666004)(66946007)(41300700001)(67856001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?X0DiFha/AjmrbjOTJfW2ZrdjgCXOm175TmG6meDtVnCqgQ4hi6Ib0frHDP?= =?iso-8859-1?Q?zFBxQbOuQheQ6ssLV469fteKKY5qMpesDWR18AroqXNHdguDHZPQXCIBmi?= =?iso-8859-1?Q?vfdByTudGUVdMMIWbiGdx3cuaVIFjCZPw5nYfKNBNbSBkaX9vG2lukpDCz?= =?iso-8859-1?Q?7PME+zz7G/jmLkZYf+AOU+64VRzJ1VtUJ3twhFiDTUttSQnltkD8OllC3K?= =?iso-8859-1?Q?v/4lSIGZw52RVd92zMOEVKg+bqrNw+LJXvI+MtVgyaSFTGnVySDbt4GgBN?= =?iso-8859-1?Q?pl7sXqrOYWGmZJZbrvivt78eGmfvg/6XPmm2MIbji8DdvLeQQK1rXQ/NxE?= =?iso-8859-1?Q?YaU0jDtnMkYTRIeOV1VpkmYDprdlu6gpeBAa3IIoUlvXjlKROF89E6+rWs?= =?iso-8859-1?Q?YkQU1YjuLN+7mQ8dfhNCa6LScfw5ApuE9bOW8s5c9quncaNFppyn5snNWz?= =?iso-8859-1?Q?BVWdLXLuqIZ9o+ycS8XDVoBb3ULtuCuMQyn8KL1/Jlkat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XGksRVWM+MiKRvqPXldjn2lQHcd1KAM88su8fAijGNhDWa96kHXhVL13h?= =?iso-8859-1?Q?zZy+lWe8qB3lUWKSsUZg7QiM+uOxu9y9b5iJV12qNACbsBW7ZWJhQmc92k?= =?iso-8859-1?Q?nEnBO+BiU6VbJmVn+iQGEKCl6X+6MPDnOQkpMaGHihWeI+Zlt1NXNgJDw/?= =?iso-8859-1?Q?FxPHvJ1omOq0NG3djY9smZFzhLwd4hLV3y0bLa18CrhsosLGEcjvTpeb4f?= =?iso-8859-1?Q?r9cgOXtSSzMu8U+OKUQo80JJ7KQ8fgjs8TV16c4L61agoAq6lm9bds08eY?= =?iso-8859-1?Q?d+bz7gpFpkCzhDNDkhM=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 6fe999bc-3b0a-4a56-38bf-08dade899334 X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1629.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2022 10:46:09.0561 (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: +IZ+izpB7AE3HBDVNiwA1BzJ3QYBCAF11yrEZHPLVLeLLheZQEltM8tXJYznBdq2x77mwEdZ0B27zVmDonAh+SIHLfAjACRSKmhBQQ5WvZ8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4561 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 Thu, Dec 15, 2022 at 06:31:44PM +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 | 72 ++++++++++++++++++++++++++++++++++ > lib/telemetry/version.map | 9 +++++ > 3 files changed, 128 insertions(+) > > +/* 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; > + This check is not sufficient, as display_bitwidth could be 0 for example, and the actual printed number have up to 16 characters. > + if (display_bitwidth != 0) { > + sprintf(format, "0x%%0%u" PRIx64, spec_hex_width); > + sprintf(buf, format, val); > + } else { > + sprintf(buf, "0x%" PRIx64, val); > + } > + snprintf should always be used when printing to the buffer so as to avoid overflow. The return value after snprintf should always be checked too. Thanks, /Bruce