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 6FEF5428AF; Wed, 5 Apr 2023 10:54:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D2D641153; Wed, 5 Apr 2023 10:54:02 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 579B041151 for ; Wed, 5 Apr 2023 10:54:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680684840; x=1712220840; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=wCYJnheFQKlosjtjHz/5qfvTZaVLf1w6NbP4aqSd8n8=; b=QX4XXM8ItWxy/a40s51y1Wb9JLbbQ2ex+epojFjmGCdcJYO47gajR+Yc OWv+w1i/DyxHua3SyTbO6+R4VlmhcYj3UycmOQmE5eCdhe6OrPyJG9jBJ ACzveAyXB+iqZcJ6DeQ/vl4Vv5SFKsnFcKY20EvVx4eeG06gnu4hiZwx5 /8mQhZuTmOMH/Ttq62tZL5IGx+X4X1CBsAFSwFcCnLClf3/2H6gsFaIA+ 3oYnufplQt5MKW0d2gQn/WCJI+Ub9hpXs6RO2eTCeEEv7MerfAMYstVGg gyEGYcgiIeDBF6/MWpMaK1R1W4plHV2B/qekHofEfwd+9Ae8L7B5Dip0E Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="428689242" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="428689242" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 01:53:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="830292054" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="830292054" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga001.fm.intel.com with ESMTP; 05 Apr 2023 01:53:38 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 5 Apr 2023 01:53:38 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 5 Apr 2023 01:53:37 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Wed, 5 Apr 2023 01:53:37 -0700 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.21; Wed, 5 Apr 2023 01:53:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HhWRUVLgADgS7rE8rXL8agxA+2fLzEWLebCkgrHfn8saF37lDSS/XbWG7F6caMo6Uy8Pcstvd+coKcTcXfxqkkRuy8aUJFZbYGRK+YrUZrtVovT9V1Ia7vniphrxd2oqyJQfLh0FpJ6Kl7aCNj/KxzzG7G5b6gSxIIT4CEomJbg70yp63HIO+nOKH5hfyEWU3aqRLNK826211z59u956v8VCk5/W6bg04jYQlfO8J6HmmO0O53zim7evrYWe4f2YVmtbv2Q07pfXVFttCNqsLw8zuC/Qi6Fia8YTmFRBIIBFVkM/YsO8ZrSxBIABOJg6YPE2kvkT7y8DUUq5oZRxNA== 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=SCfLKYtzvo8iuWU4ys/cGqfWDTBj+7QrFPKo3Y+H+AU=; b=E5IV/+75rWeRDvO3RhkOpxr3pkxS4FQFJbQOVIekwgf7nmsIrhFBQg4eSuRHlKI+RbE/rxxknd1NjJW+yk0fvJopp5J/HQnUYBAetu6QzQy9p9+oEk7jrn5YGOwVnqjvgr1SUL/zB5StBBwlgvSBIZQXrQUkSvzNnEKcVdyWouw5iR9arfhfFyAGnRXt6pHTAHg4zytaE6OXu+PDIV/x3u4O2hHXeZr7BkD2QqUUTU5196H9XS8b11QyqJJuV1j9Sr3sx0TcS1/l1L8cC6PnMrFMYiKiV+HJqTdoj1ZhFGGh7wN8JRtQwzsLejKarJ9/AGGbd0O6+tz63gnZH6nPEA== 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 DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by CH0PR11MB5491.namprd11.prod.outlook.com (2603:10b6:610:d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Wed, 5 Apr 2023 08:53:31 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c%6]) with mapi id 15.20.6254.035; Wed, 5 Apr 2023 08:53:30 +0000 Date: Wed, 5 Apr 2023 09:53:23 +0100 From: Bruce Richardson To: Stephen Hemminger CC: Tyler Retzlaff , , , , Subject: Re: [PATCH 1/2] telemetry: use malloc instead of variable length array Message-ID: References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com> <1680539424-20255-2-git-send-email-roretzla@linux.microsoft.com> <20230403131913.0aec54ce@hermes.local> <20230404162444.GB18560@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20230404164446.GF18560@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20230404173401.GA32118@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20230404182004.43b3ff7e@hermes.local> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20230404182004.43b3ff7e@hermes.local> X-ClientProxiedBy: LO4P265CA0244.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:350::10) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|CH0PR11MB5491:EE_ X-MS-Office365-Filtering-Correlation-Id: d16a9c46-40fb-4e82-c63a-08db35b33aa0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QVgMNkgnJF+Ggvj75hjj0gy8QsEkrXicecMccto8plCo130tb6+1c8IHQuYHedXiPga5IQre8bJCf0OJZGQljT3RwPPhCweFV8mlgBl2a6ndvlWjckOKaTrOw93aKbqecD/Z1hb9ejzwoaJ2DrmMAY0K9lomg/HmwIu7QJnbwrClDSNwqVWh19kxginsjkJkns9n9u6FXEbH5CI1XBUNM5P2g8uxuYqhaswrXDICFXeUOEvpFeJpt2Isw1llY5mnqSDBUy3OXYLN5IrwkR3wscMui/0twJgw5W478+6kv3zdpNh8U+5wWCcwpPF/LJeIe/sqp0wmaGJMYEcNqHOgHiufhnkATzmqE15ozIXpg4SeD48YMZC0cV6ld3ORwEUIuiJ/SsXZxNx1AvLbP/bxAVJHolWrSI/A9H0HKW4PA858j60T1cvAzbLn49/kEjmkYv6VAOila4RAbdTYzmFBB6wkD2UxgH5GnhevUB1dYqePUfJasTA/ViD50r/aMS71cpatvhYL9GMfdrNfJImnTqNfPWeKpcHfYWDdHhi9J0mDAibCjCC8e1Rl1HFzchCH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(396003)(366004)(39860400002)(376002)(346002)(136003)(451199021)(6666004)(186003)(26005)(83380400001)(66946007)(8676002)(6512007)(478600001)(41300700001)(316002)(6506007)(6916009)(4326008)(82960400001)(66476007)(66556008)(6486002)(38100700002)(86362001)(5660300002)(2906002)(44832011)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zNXkHHjIAC4naehG/3shZt3tSzQXsmViQXTCC7p+/PzJ6zZbi7Kg7Q6Gz9FQ?= =?us-ascii?Q?EXRhtEMobh/2BS4622Md0mZBEv3m5mlHsEU1utS3m0x9+3nZnL7u7mrXG6cT?= =?us-ascii?Q?mHlQLby/uyxyznx4taxLYj9FXJAQDIkJL8MpQlH36CQOsVdAxEE8QVGxxtS2?= =?us-ascii?Q?xS4akxLZLLKmioH1bDoHHHzu1v0qoJ8BW8d1AuyYa3igY0QjX8a4IB4C8kTq?= =?us-ascii?Q?c8T86HjLqnRvMPvOTUsNvm4+3TwCWehzGBkfIxAOAWIOG6yJVQljGLskKvVY?= =?us-ascii?Q?MQFtM1jQUfB3HIL0igi1Y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ra74iZXYTWG?= =?us-ascii?Q?2o0uZB8l8uvBmI2uL/qZRdCz69vImLEyCBj8UiEt/IGEaHxOI4oUl5b3ZOdn?= =?us-ascii?Q?z4vJe0tJYKuxBMwXm4bpzCVXiba2dSCh4ekoBAEzXM9Ya0sl11ojdfEvsTIC?= =?us-ascii?Q?U2YydzbFnlNd3CtVHK2m2Zt6gksyrGm1c8MeRx2GPZ2l5bLXHWML2QkUyRWM?= =?us-ascii?Q?iECFECVLi0UaJLK5S37jmcQy2Ozl5arpFYliPj7xt3XWhYoC6db+MqgXEHg5?= =?us-ascii?Q?qUD8YtuJAxOWRzcF3yGXi04jO0myx/rm33Uj2LOXtEri6lYft+17ETnS1nHa?= =?us-ascii?Q?A/90CyX8LnIPe2tBUVKlzJwS7rCXS5lZC6QvKkvdxJ3y7yGw62NHz8IHXJtj?= =?us-ascii?Q?V7KHCvz37QU2uT83ohX+tXdfchbGzyQBwIcTUBhBb0hwgo26sXIW+UOya2Hq?= =?us-ascii?Q?dw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: d16a9c46-40fb-4e82-c63a-08db35b33aa0 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2023 08:53:30.4790 (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: OrB0iN1XiJ/GJ1X9XOGMS/OPP1FAUhzAXf4vGxB5O9KUTDMazw9Ml6aW9rAz+1RY4dYfqNgwgIOo/W7as3/XThrJnmOuaIR1eh9X+UzKkus= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5491 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 Tue, Apr 04, 2023 at 06:20:04PM -0700, Stephen Hemminger wrote: > On Tue, 4 Apr 2023 10:34:01 -0700 > Tyler Retzlaff wrote: > > > > > > I think suggestion #2 above should cover most cases, in which case using > > > > > your original suggestion of malloc would be ok too for the rare case (if > > > > > ever) where we don't just have one terminator on the end. > > > > > > > > maybe a dumb'd down compromise is to have a fixed stack limit and then > > > > if it is exceeded always just go to malloc/free? > > > > > > > Perhaps. If you like, I have have a try at implementing my own suggestions > > > above tomorrow. I'd like if we can get the "single-character-saving" option > > > working, because that would be the most efficient method of all. > > > > that would be great, i'll take the help i can get. > > > For the json print library in iproute2, it streams output using > stdio, which avoids lots of string processing issues. Well, it moves them > to be standard library. Yes, but it does have a number of downsides: * streaming means that we have to worry about message boundaries when transferring across sockets like in the telemetry case. With telemetry we have a packet-based (message based) interface, so we need to buffer all output to a string anyway. If we ever add a streaming (socket or fifo) interface, then the iproute2 implementation may be a better fit. * Last I looked at the iproute2 json implementation, it requires the user to track how many outstanding closing brackets of what type are needed, meaning that you have invalid json at intermediate stages, and makes it awkward if you run out of space in a buffer, i.e. no room for terminators. The implementation here, on the other hand, ensures that the output is always valid json, so for example, when adding a second string to an array of strings we go from ["str1"] to ["str1","str2"] directly - or in the case of insufficient space we leave the original version unmodified. For working with the case where we have a fixed buffer, this is a massive benefit. /Bruce