DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	"Yigit, Ferruh" <ferruh.yigit@intel.com>,
	"hemant.agrawal@nxp.com" <hemant.agrawal@nxp.com>,
	Ajit Khaparde <ajit.khaparde@broadcom.com>,
	Jerin Jacob <jerinjacobk@gmail.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	Andrew Rybchenko <Andrew.Rybchenko@oktetlabs.ru>,
	"Min Hu (Connor)" <humin29@huawei.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"olivier.matz@6wind.com" <olivier.matz@6wind.com>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>,
	"jerinj@marvell.com" <jerinj@marvell.com>,
	"Richardson, Bruce" <bruce.richardson@intel.com>
Subject: Re: [dpdk-dev] Questions about API with no parameter check
Date: Wed, 5 May 2021 08:58:22 -0700	[thread overview]
Message-ID: <20210505155822.GA13051@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)
In-Reply-To: <DM6PR11MB449137056DE1D5CD27621E019A5A9@DM6PR11MB4491.namprd11.prod.outlook.com>

On Tue, May 04, 2021 at 09:36:24AM +0000, Ananyev, Konstantin wrote:
> 
> 
> > 
> > 2021-04-29 09:16 (UTC-0700), Tyler Retzlaff:
> > > On Wed, Apr 07, 2021 at 05:10:00PM +0100, Ferruh Yigit wrote:
> > > > On 4/7/2021 4:25 PM, Hemant Agrawal wrote:
> > > > >>+1
> > > > >>But are we going to check all parameters?
> > > > >
> > > > >+1
> > > > >
> > > > >It may be better to limit the number of checks.
> > > > >
> > > >
> > > > +1 to verify input for APIs.
> > > >
> > > > Why not do all, what is the downside of checking all input for control path APIs?
> > >
> > > why not assert them then, what is the purpose of returning an error to a
> > > caller for a api contract violation like a `parameter shall not be NULL`
> > >
> > > * assert.h/cassert can be compiled away for those pundits who don't want
> > >   to see extra branches in their code
> > >
> > > * when not compiled away it gives you an immediate stack trace or dump to operate
> > >   on immediately identifying the problem instead of having to troll
> > >   through hoaky inconsistently formatted logging.
> > >
> > > * it catches callers who don't bother to check for error from return of
> > >   the function (debug builds) instead of some arbitrary failure at some
> > >   unrelated part of the code where the corrupted program state is relied
> > >   upon.
> > >
> > > we aren't running in kernel, we can crash.
> > 
> > As library developers we can't assume stability requirements at call site.
> > There may be temporary files to clean up, for example,
> > or other threads in the middle of their work.
> > 
> > As an application developer I'd hate to get a crash inside a library and
> > having to debug it. Usually installed are release versions with assertions
> > compiled away.
> 
> I agree with Dmitry summary above.
> Asserting inside the library calls is bad programming practice,
> please keep it away from the project. 

i'm not advocating for asserts i'm advocating for users to have a
choice instead of being opted in to this change unconditionally.

asserts are an option that may be policy controlled as previously mentioned
either in this thread or another. so if you don't like them you can disable
them as a function of the policy. for a basic assert that means building
release instead of debug but a more sophisticated policy mechanism could be
employed if desired.

what you can't turn off is introduction of superfluous errors being
returned due to programming mistakes in the application which should be
handled yet have no sensible way to be handled. it just clutters the
calling code with unnecessary error handling, makes the errors returned
ambiguious and often indistinguishable from real errors.

by this logic we should modify rte_free to be

int rte_free(void * p) { if (p == NULL) return EINVAL; mem_free(p, true); }

which is about as useful as one can imagine.

this proposal has been pushed through too quickly without proper debate,
and the patch that introduces the superfluous errors breaks abi. tech
board should get involved before it goes further.

i'm not asking for asserts, i'm asking not to be opted in to an equally
harmful error handling pattern that makes application logic more error
prone and more complex negatively impacting quality.

thanks

      reply	other threads:[~2021-05-05 15:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 11:28 Min Hu (Connor)
2021-04-07 11:40 ` Thomas Monjalon
2021-04-07 11:48   ` Liang Ma
2021-04-07 11:53   ` Ananyev, Konstantin
2021-04-07 13:19     ` Jerin Jacob
2021-04-07 14:40       ` Ajit Khaparde
2021-04-07 15:25         ` Hemant Agrawal
2021-04-07 16:10           ` Ferruh Yigit
2021-04-07 16:26             ` Burakov, Anatoly
2021-04-08  1:06               ` Min Hu (Connor)
2021-04-08  8:22                 ` Thomas Monjalon
2021-04-08  9:00                   ` Min Hu (Connor)
2021-04-29 16:16             ` Tyler Retzlaff
2021-04-29 18:49               ` Dmitry Kozlyuk
2021-04-30  0:15                 ` Tyler Retzlaff
2021-05-03 15:19                   ` Morten Brørup
2021-05-04  9:36                 ` Ananyev, Konstantin
2021-05-05 15:58                   ` Tyler Retzlaff [this message]

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=20210505155822.GA13051@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
    --to=roretzla@linux.microsoft.com \
    --cc=Andrew.Rybchenko@oktetlabs.ru \
    --cc=ajit.khaparde@broadcom.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=humin29@huawei.com \
    --cc=jerinj@marvell.com \
    --cc=jerinjacobk@gmail.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=olivier.matz@6wind.com \
    --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).