All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 18/18] erlang: make libatomic_ops optional
Date: Mon, 1 Feb 2016 22:55:51 +0100	[thread overview]
Message-ID: <20160201225551.5bb70783@free-electrons.com> (raw)
In-Reply-To: <CA+-urNRdjP16nOm6ARH3WLgtopK61hhQB8PSm9FnYk_MdBUJJg@mail.gmail.com>

Frank,

On Mon, 25 Jan 2016 19:43:05 -0500, Frank Hunleth wrote:

> >> diff --git a/package/erlang/Config.in b/package/erlang/Config.in
> >> index 0ec01bb..9bd64ac 100644
> >> --- a/package/erlang/Config.in
> >> +++ b/package/erlang/Config.in
> >> @@ -7,8 +7,7 @@ config BR2_PACKAGE_ERLANG
> >>       bool "erlang"
> >>       depends on BR2_USE_MMU # fork()
> >>       depends on !BR2_STATIC_LIBS
> >> -     depends on BR2_PACKAGE_LIBATOMIC_ARCH_SUPPORTS
> >> -     select BR2_PACKAGE_LIBATOMIC_OPS
> >> +     depends on BR2_PACKAGE_LIBATOMIC_ARCH_SUPPORTS # erlang native atomics and libatomic_ops
> >
> > This shouldn't be here, since you no longer select libatomic_ops.
> 
> I'm having trouble addressing this one. It seems like some "depends
> on" clause should be here. The Erlang docs are vague on what all they
> support natively, so I was originally thinking that
> BR2_PACKAGE_LIBATOMIC_ARCH_SUPPORTS has a good list.

This one is easy: BR2_PACKAGE_xxx_ARCH_SUPPORTS options are meant to
more easily propagate the architecture dependencies of one package when
you select that package.

Remember that in Buildroot, when a package does:

	select BR2_PACKAGE_<foo>

It *must* replicate the "depends on" that exist in the defintion of
BR2_PACKAGE_<foo>.

For some packages, such dependencies are architecture dependencies,
like:

config BR2_PACKAGE_<foo>
	bool "foo"
	depends on BR2_arm || BR2_armeb || BR2_i386 || BR2_mips || ...

Then in all packages selecting BR2_PACKAGE_<foo>, we would have to
replicate this long "depends on" line. And when this "depends on"
changes, propagate to all reverse dependencies. Not nice.

Hence we rather do:

config BR2_PACKAGE_<foo>_ARCH_SUPPORTS
	bool
	default y if BR2_arm || BR2_armeb || BR2_i386 || BR2_mips || ...

config BR2_PACKAGE_<foo>
	bool "foo"
	depends on BR2_PACKAGE_<foo>_ARCH_SUPPORTS

This way, not only BR2_PACKAGE_<foo> uses
BR2_PACKAGE_<foo>_ARCH_SUPPORTS, but also all reverse dependencies of
the "foo" package.

So, if you are not selecting BR2_PACKAGE_<foo>, there is no reason to
use BR2_PACKAGE_<foo>_ARCH_SUPPORTS. Does that make sense ?

> 
> "Erlang/OTP itself provides implementations of native atomic memory operations
> that can be used when compiling with a `gcc` compatible compiler for 32/64-bit
> x86, 32/64-bit SPARC V9, 32-bit PowerPC, or 32-bit Tile. When compiling with
> a `gcc` compatible compiler for other architectures, the VM may be able to make
> use of native atomic operations using the `__atomic_*` builtins (may be
> available when using a `gcc` of at least version 4.7) and/or using the
> `__sync_*` builtins (may be available when using a `gcc` of at least version
> 4.1). If only the `gcc`'s `__sync_*` builtins are available, the performance
> will suffer. Such a configuration should only be used as a last resort. When
> compiling on Windows using a MicroSoft Visual C++ compiler native atomic
> memory operations are provided by Windows APIs.
> 
> Native atomic implementation in the order preferred:
> 1.  The implementation provided by Erlang/OTP.
> 2.  The API provided by Windows.
> 3.  The implementation based on the `gcc` `__atomic_*` builtins.
> 4.  If none of the above are available for your architecture/compiler, you
>     are recommended to build and install [libatomic_ops][] before building
>     Erlang/OTP. The `libatomic_ops` library provides native atomic memory
>     operations for a variety of architectures and compilers. When building
>     Erlang/OTP you need to inform the build system of where the
>     `libatomic_ops` library is installed using the
>     `--with-libatomic_ops=PATH` `configure` switch.
> 5.  As a last resort, the implementation solely based on the `gcc`
>     `__sync_*` builtins. This will however cause lots of expensive and
>     unnecessary memory barrier instructions to be issued. That is,
>     performance will suffer. The `configure` script will warn at the end
>     of its execution if it cannot find any other alternative than this.
> "

Ah, at least the Erlang documentation is quite verbose and actually
useful. So, let's take this point by point:

 (1) According to their documentation, this is only available on x86
     (not sure 32 bits or 64 bits, let's assume both), SPARC v9,
     PowerPC and Tile (we don't care about Tile).

 (2) We don't care.

 (3) __atomic_*() built-ins are available on *all* architectures,
     provided you link with -latomic.

 (4) libatomic_ops is available on architectures listed in
     BR2_PACKAGE_LIBATOMIC_OPS_ARCH_SUPPORTS

 (5) The availability of __sync_*() operations depend on the
     architectures. See
     http://lists.busybox.net/pipermail/buildroot/2016-January/150744.html
     for the lengthy details. We would actually need to know which
     __sync_*() built-ins Erlang is using. According to
     http://autobuild.buildroot.org/results/209/2090874eee165af3349cf2d597657fc1b4ca1012/build-end.log,
     it needs the 4-byte and 8-byte version.

So, with this in hand, here is how we could encode the architecture
dependency of Erlang:

config BR2_PACKAGE_ERLANG_ARCH_SUPPORTS
	bool
	default y if BR2_i386 || BR2_x86_64 || BR2_powerpc || BR2_sparc_v9 # case (1)
	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 # case (3)
	default y if BR2_PACKAGE_LIBATOMIC_OPS_ARCH_SUPPORTS # case (4)
	default y if BR2_TOOLCHAIN_HAS_SYNC_4 && BR2_TOOLCHAIN_HAS_SYNC_8 # case (5)

Of course, this should come with a pretty fat comment on top of it that
replicates the good explanation of the Erlang documentation. *And* in
order for case (3) to work, you must make sure that Erlang links with
-latomic.

> >> +ifeq ($(BR2_PACKAGE_ERLANG_USE_LIBATOMIC_OPS),y)
> >>  ERLANG_DEPENDENCIES += libatomic_ops
> >>  ERLANG_CONF_OPTS += --with-libatomic_ops=$(STAGING_DIR)/usr LIBS=-latomic_ops
> >> +endif
> >
> > Can you add a "else" clause to explicitly disable libatomic_ops
> > support? Otherwise, libatomic_ops may be enabled in the Buildroot
> > configuration, built before erlang, and detected automatically by
> > erlang configure script.
> 
> The configure script doesn't provide a --without-libatomic_ops or a
> --only-use-native-atomic-ops or anything that I can tell can be used
> to disable use of libatomic_ops. Based on my tests, the configure
> script does not use libatomic_ops even if present. It's also low down
> on their priority list for the atomics implementation to use, so I
> think this was intentional.

OK, so what you did is good. Maybe just add a comment on top of it.

Also, are you sure LIBS=-latomic_ops is needed ? This seems weird, I
believe Erlang should automatically link against libatomic_ops.

One last thing: do not confuse libatomic and libatomic_ops. They are
completely different things!

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

  reply	other threads:[~2016-02-01 21:55 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-23  1:10 [Buildroot] [PATCH 00/18] Erlang 18 and native atomic ops Frank Hunleth
2016-01-23  1:10 ` [Buildroot] [PATCH 01/18] erlang: bump to version 18.2.1 Frank Hunleth
2016-02-01 20:47   ` Romain Naour
2016-01-23  1:10 ` [Buildroot] [PATCH 02/18] pkg-rebar.mk: pass C++ compiler path and options Frank Hunleth
2016-01-23  1:10 ` [Buildroot] [PATCH 03/18] erlang-goldrush: bump to version 0.1.8 Frank Hunleth
2016-01-23  1:10 ` [Buildroot] [PATCH 04/18] erlang-lager: bump to version 2.2.0 Frank Hunleth
2016-01-23  1:10 ` [Buildroot] [PATCH 05/18] erlang-rebar: bump to version 2.6.1 Frank Hunleth
2016-01-23  1:10 ` [Buildroot] [PATCH 06/18] erlang-fast_tls: new package Frank Hunleth
2016-01-23  8:20   ` Thomas Petazzoni
2016-02-01 20:38     ` Romain Naour
2016-01-23  1:11 ` [Buildroot] [PATCH 07/18] erlang-p1-cache-tab: bump to version 1.0.1 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 08/18] erlang-p1-iconv: bump to version 0.9.0 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 09/18] erlang-p1-stringprep: bump to version 1.0.0 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 10/18] erlang-p1_stun: bump to version 0.9.0 Frank Hunleth
2016-01-23  8:21   ` Thomas Petazzoni
2016-01-23  1:11 ` [Buildroot] [PATCH 11/18] erlang-p1-sip: bump to version 1.0.0 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 12/18] erlang-p1-tls: " Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 13/18] erlang-p1-utils: bump to version 1.0.3 Frank Hunleth
2016-02-01 21:04   ` Romain Naour
2016-01-23  1:11 ` [Buildroot] [PATCH 14/18] erlang-p1-xml: bump to version 1.1.1 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 15/18] erlang-p1-yaml: bump to version 1.0.0 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 16/18] erlang-p1-zlib: " Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 17/18] ejabberd: bump to version 16.01 Frank Hunleth
2016-01-23  1:11 ` [Buildroot] [PATCH 18/18] erlang: make libatomic_ops optional Frank Hunleth
2016-01-23  8:25   ` Thomas Petazzoni
2016-01-26  0:43     ` Frank Hunleth
2016-02-01 21:55       ` Thomas Petazzoni [this message]
2016-02-02 19:57   ` [Buildroot] [PATCH v2 00/18] Erlang 18 and native atomic ops Frank Hunleth
2016-02-02 19:57     ` [Buildroot] [PATCH v2 01/18] erlang: bump to version 18.2.1 Frank Hunleth
2016-02-06 22:28       ` Romain Naour
2016-02-20 18:22       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 02/18] pkg-rebar.mk: pass C++ compiler path and options Frank Hunleth
2016-02-06 22:34       ` Romain Naour
2016-02-09  1:45         ` Frank Hunleth
2016-02-20 18:23       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 03/18] erlang-goldrush: bump to version 0.1.8 Frank Hunleth
2016-02-06 22:35       ` Romain Naour
2016-02-20 18:23       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 04/18] erlang-lager: bump to version 2.2.0 Frank Hunleth
2016-02-06 22:36       ` Romain Naour
2016-02-20 18:24       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 05/18] erlang-rebar: bump to version 2.6.1 Frank Hunleth
2016-02-06 22:39       ` Romain Naour
2016-02-09  1:58         ` Frank Hunleth
2016-02-20 17:37         ` Thomas Petazzoni
2016-02-20 18:08           ` Yann E. MORIN
2016-02-20 23:05             ` Arnout Vandecappelle
2016-02-20 23:19               ` Yann E. MORIN
2016-02-21  0:02                 ` Arnout Vandecappelle
2016-02-21  8:37                   ` Peter Korsgaard
2016-02-20 18:24       ` Thomas Petazzoni
2016-02-20 18:31         ` Frank Hunleth
2016-02-20 22:54           ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 06/18] erlang-fast_tls: new package Frank Hunleth
2016-02-06 22:42       ` Romain Naour
2016-02-20 18:25       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 07/18] erlang-p1-cache-tab: bump to version 1.0.1 Frank Hunleth
2016-02-06 22:43       ` Romain Naour
2016-02-20 18:26       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 08/18] erlang-p1-iconv: bump to version 0.9.0 Frank Hunleth
2016-02-06 22:45       ` Romain Naour
2016-02-20 18:26       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 09/18] erlang-p1-stringprep: bump to version 1.0.0 Frank Hunleth
2016-02-06 22:47       ` Romain Naour
2016-02-20 22:28       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 10/18] erlang-p1_stun: bump to version 0.9.0 Frank Hunleth
2016-02-06 22:52       ` Romain Naour
2016-02-09  2:23         ` Frank Hunleth
2016-02-20 22:30       ` Thomas Petazzoni
2016-02-20 23:09         ` Frank Hunleth
2016-02-20 23:12           ` Thomas Petazzoni
2016-02-21 22:16             ` Frank Hunleth
2016-02-02 19:57     ` [Buildroot] [PATCH v2 11/18] erlang-p1-sip: bump to version 1.0.0 Frank Hunleth
2016-02-06 22:58       ` Romain Naour
2016-02-20 22:31       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 12/18] erlang-p1-tls: " Frank Hunleth
2016-02-06 23:01       ` Romain Naour
2016-02-20 22:31       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 13/18] erlang-p1-utils: bump to version 1.0.3 Frank Hunleth
2016-02-06 23:02       ` Romain Naour
2016-02-20 22:34       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 14/18] erlang-p1-xml: bump to version 1.1.1 Frank Hunleth
2016-02-06 23:07       ` Romain Naour
2016-02-20 22:35       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 15/18] erlang-p1-yaml: bump to version 1.0.0 Frank Hunleth
2016-02-06 23:10       ` Romain Naour
2016-02-20 22:35       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 16/18] erlang-p1-zlib: " Frank Hunleth
2016-02-06 23:13       ` Romain Naour
2016-02-20 22:52       ` Thomas Petazzoni
2016-02-02 19:57     ` [Buildroot] [PATCH v2 17/18] ejabberd: bump to version 16.01 Frank Hunleth
2016-02-06 23:24       ` Romain Naour
2016-02-02 19:57     ` [Buildroot] [PATCH v2 18/18] erlang: support choosing atomic ops Frank Hunleth
2016-02-07 12:49       ` Romain Naour
2016-02-07 13:15         ` Thomas Petazzoni

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=20160201225551.5bb70783@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=buildroot@busybox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.