DPDK patches and discussions
 help / color / mirror / Atom feed
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Cc: "Smoczynski, MarcinX" <marcinx.smoczynski@intel.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"Richardson, Bruce" <bruce.richardson@intel.com>,
	"shahafs@mellanox.com" <shahafs@mellanox.com>,
	"gaetan.rivet@6wind.com" <gaetan.rivet@6wind.com>,
	"matan@mellanox.com" <matan@mellanox.com>
Subject: Re: [dpdk-dev] Using _XOPEN_SOURCE macros may break builds on FreeBSD
Date: Mon, 13 May 2019 15:14:42 +0200	[thread overview]
Message-ID: <20190513131442.GK4284@6wind.com> (raw)
Message-ID: <20190513131442.88QfKx2zWKR6aPmpCNkhzntoB7d6oMapcNgpNVRTL4k@z> (raw)
In-Reply-To: <2601191342CEEE43887BDE71AB9772580161631159@irsmsx105.ger.corp.intel.com>

Hey Konstantin,

On Mon, May 13, 2019 at 10:49:00AM +0000, Ananyev, Konstantin wrote:
> Hi Adrien,
> 
> > 
> > On Mon, May 13, 2019 at 09:51:24AM +0000, Smoczynski, MarcinX wrote:
> > > 10/05/2019 20:17, Thomas Monjalon:
> > > > 10/05/2019 19:14, Smoczynski, MarcinX:
> > > > > To summarize we have different visibility sets for Linux and BSD
> > > > > when using XOPEN_SOURCE or POSIX_C_SOURCE explicitly. To overcome
> > > > > this situation we can either remove problematic XOPEN macros from
> > > > > mk/meson rules (drivers/net/failsafe, drivers/net/mlx4,
> > > > > drivers/net/mlx5)
> > > >
> > > > What is the consequence of removing these macros in mlx and failsafe PMDs?
> > >
> > > The purpose of these *_SOURCE constants is to enable particular feature sets
> > > visibility. As long as we have GNU_SOURCE on Linux removing it won't have any
> > > consequences. On BSD it will unify feature sets visibility with the rest of
> > > sources. Can't think of any downsides here.
> > >
> > > I believe XOPEN_SOURCE was introduced to extend features not to restrict them.
> > 
> > I confirm that under Linux, all IPPROTO_* (POSIX/XOPEN/RFC1700) are defined
> > regardless (_GNU_SOURCE not even needed), while under FreeBSD, the non-POSIX
> > versions are only defined when __BSD_VISIBLE is set.
> > 
> > The FreeBSD behavior is more correct in this respect since the purpose of
> > _XOPEN_SOURCE and friends is also to let applications limit the risk of
> > redefinitions in case they were written for an earlier standard
> > (e.g. -D_XOPEN_SOURCE=500 vs. -D_XOPEN_SOURCE=600).
> 
> Still not sure why do you need it for failsafe and mlx PMDs?
> Would something in these PMDs be broken without  '-D_XOPEN_SOURCE=600'?

Well, not really. At least not anymore if they compile fine without it on
all supported targets. I don't mind if they are removed from PMDs.

_XOPEN_SOURCE=600 was originally added to mlx4 (later inherited by mlx5 and
failsafe) for the following reasons:

- Out fo habit, since a lot of stuff in unistd.h and fcntl.h depends on it
  to be exposed. Some affected definitions were likely needed at some point.

- Besides toggling C syntax extensions, forcing a C standard through the
  -std parameter (e.g. -std=c99) in order to guarantee a minimum level of
  C compliance disables the implicit presence of nonstandard definitions,
  which must be re-enabled as needed through the appropriate #defines.

For instance, including unistd.h for getsid() stops working as soon as you
use -std=c99. On Linux you can get it back through -std=gnu99 or by
combining -std=c99 with -D_GNU_SOURCE or -D_XOPEN_SOURCE. The latter was
chosen because it is the standard define supposed to work across OSes.

Historically mlx4 had to enable -std=c99 to be able to use various features
not present when GCC defaulted to -std=gnu90. It was later transformed to
-std=c11 for similar reasons (anonymous members in structs/unions if memory
serves me right).

> > DPDK applications may also define _XOPEN_SOURCE for their own needs. They
> > should still be able to use rte_ip.h afterward.
> 
> I suppose they can, they would just have (on FreeBSD) to add '-D __BSD_VISIBLE'
> themselves. 

Of course, but public headers should be as self sufficient as possible.
Unless they provide really insane compiler flags, if user applications get
compilation errors after including some header we install on the system,
I think the blame is on DPDK.

> > I think this reason is
> > enough to go with -D__BSD_VISIBLE under FreeBSD without removing
> > _XOPEN_SOURCE, as it should work regardless.
> 
> So do you suggest to add '-D __BSD_VISIBLE'  into
> mlx/failsafe PMDs Makefiles/meson.build, or ... ?

Since headers of our public API potentially require it, it must be defined
globally (unlike _XOPEN_SOURCE which is only local to a few PMDs):
app/meson.build, lib/meson.build, mk/target/generic/rte.vars.mk, alongside
-D_GNU_SOURCE.

Add it to mlx*/failsafe only if that's not enough. Just make sure
applications inherit this flag.

> > Looking at the patch [1], I also think there's another, simpler approach:
> > unless really performance critical, defining rte_ipv6_get_next_ext() in
> > rte_net.c instead of a static inline in rte_ip.h should address this issue.
> 
> It is performance critical, and I think that 
> function call for each ext header is a way too expensive approach.
> Will prefer to keep that function inline.

OK, a bit cumbersome but since we're heading this way [2], how about
defining our own instead of all the above?

 #define RTE_IPPROTO_HOPOPTS 0
 #define RTE_IPPROTO_ROUTING 43
 ...

Which could prove handy later as it appears Linux and FreeBSD don't have the
same set of available IPPROTO_* definitions.

Thoughts?

[2] "[RFC v2 00/14] prefix network structures"
    https://mails.dpdk.org/archives/dev/2019-April/129752.html

-- 
Adrien Mazarguil
6WIND

  parent reply	other threads:[~2019-05-13 13:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-10 17:14 Smoczynski, MarcinX
2019-05-10 17:14 ` Smoczynski, MarcinX
2019-05-10 18:17 ` Thomas Monjalon
2019-05-10 18:17   ` Thomas Monjalon
2019-05-10 18:23   ` Thomas Monjalon
2019-05-10 18:23     ` Thomas Monjalon
2019-05-13  9:51     ` Smoczynski, MarcinX
2019-05-13  9:51       ` Smoczynski, MarcinX
2019-05-13 10:25       ` Adrien Mazarguil
2019-05-13 10:25         ` Adrien Mazarguil
2019-05-13 10:49         ` Ananyev, Konstantin
2019-05-13 10:49           ` Ananyev, Konstantin
2019-05-13 13:14           ` Adrien Mazarguil [this message]
2019-05-13 13:14             ` Adrien Mazarguil
2019-05-13 16:24             ` Ananyev, Konstantin
2019-05-13 16:24               ` Ananyev, Konstantin
2019-05-14  8:58               ` Smoczynski, MarcinX
2019-05-14  8:58                 ` Smoczynski, MarcinX
2019-05-14  9:16                 ` Adrien Mazarguil
2019-05-14  9:16                   ` Adrien Mazarguil
2019-05-14 10:29                   ` Ananyev, Konstantin
2019-05-14 10:29                     ` Ananyev, Konstantin

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=20190513131442.GK4284@6wind.com \
    --to=adrien.mazarguil@6wind.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=gaetan.rivet@6wind.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=marcinx.smoczynski@intel.com \
    --cc=matan@mellanox.com \
    --cc=shahafs@mellanox.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).