DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>, <dev@dpdk.org>,
	<ciara.power@intel.com>, <david.marchand@redhat.com>,
	<thomas@monjalon.net>
Subject: Re: [PATCH 1/2] telemetry: use malloc instead of variable length array
Date: Wed, 5 Apr 2023 09:53:23 +0100	[thread overview]
Message-ID: <ZC03Aw7LQjWk8cb0@bricha3-MOBL.ger.corp.intel.com> (raw)
In-Reply-To: <20230404182004.43b3ff7e@hermes.local>

On Tue, Apr 04, 2023 at 06:20:04PM -0700, Stephen Hemminger wrote:
> On Tue, 4 Apr 2023 10:34:01 -0700
> Tyler Retzlaff <roretzla@linux.microsoft.com> 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

  reply	other threads:[~2023-04-05  8:54 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 16:30 [PATCH 0/2] improve code portability Tyler Retzlaff
2023-04-03 16:30 ` [PATCH 1/2] telemetry: use malloc instead of variable length array Tyler Retzlaff
2023-04-03 17:17   ` Tyler Retzlaff
2023-04-03 20:19   ` Stephen Hemminger
2023-04-03 20:40     ` Tyler Retzlaff
2023-04-04  8:47     ` Bruce Richardson
2023-04-04 16:24       ` Tyler Retzlaff
2023-04-04 16:28         ` Bruce Richardson
2023-04-04 16:44           ` Tyler Retzlaff
2023-04-04 17:25             ` Bruce Richardson
2023-04-04 17:34               ` Tyler Retzlaff
2023-04-05  1:20                 ` Stephen Hemminger
2023-04-05  8:53                   ` Bruce Richardson [this message]
2023-04-05  1:04       ` Stephen Hemminger
2023-04-05  8:54         ` Bruce Richardson
2023-04-05 15:25           ` Tyler Retzlaff
2023-04-05 15:30             ` Dmitry Kozlyuk
2023-04-05 15:37               ` Stephen Hemminger
2023-04-05 15:47             ` Bruce Richardson
2023-04-03 16:30 ` [PATCH 2/2] telemetry: use portable syntax to initialize array Tyler Retzlaff
2023-04-03 17:04 ` [PATCH 0/2] improve code portability Bruce Richardson
2023-04-03 17:35   ` Tyler Retzlaff
2023-04-03 18:47 ` [PATCH v2] " Tyler Retzlaff
2023-04-03 18:47   ` [PATCH v2] telemetry: use portable syntax to initialize array Tyler Retzlaff
2023-04-03 18:59 ` [PATCH v3] improve code portability Tyler Retzlaff
2023-04-03 18:59   ` [PATCH v3] telemetry: use portable syntax to initialize array Tyler Retzlaff
2023-04-04  8:51     ` Bruce Richardson
2023-04-04 15:54       ` Tyler Retzlaff
2023-04-04 16:08         ` Bruce Richardson
2023-04-04  9:01     ` Konstantin Ananyev
2023-04-04 15:59       ` Tyler Retzlaff
2023-04-04 16:19         ` Bruce Richardson
2023-04-04 16:28           ` Tyler Retzlaff
2023-04-04 18:09 ` [PATCH v4] improve code portability Tyler Retzlaff
2023-04-04 18:09   ` [PATCH v4] telemetry: remove non-portable array initialization syntax Tyler Retzlaff
2023-04-05  8:56     ` Bruce Richardson
2023-04-05 15:27       ` Tyler Retzlaff
2023-04-05 18:52 ` [PATCH v5] improve code portability Tyler Retzlaff
2023-04-05 18:52   ` [PATCH v5] telemetry: remove non-portable array initialization syntax Tyler Retzlaff
2023-05-24 20:54     ` 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=ZC03Aw7LQjWk8cb0@bricha3-MOBL.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=ciara.power@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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).