[Patch] nginx to use libatomic_ops

Igor Sysoev is at rambler-co.ru
Fri Oct 9 17:02:41 MSD 2009

On Fri, Oct 09, 2009 at 11:57:24AM +0200, W-Mark Kubacki wrote:

> 2009/10/8 Igor Sysoev <is at rambler-co.ru>:
> > On Tue, Sep 29, 2009 at 12:26:43PM +0200, W-Mark Kubacki wrote:
> >
> >> [...]
> >> What do you think about the compromise using GCC builtins if
> >> --with-libatomic is not set?
> >> Only architectures not covered by the #ifs would be affected and you
> >> could remove lock_file code entirely in future.
> >
> > On i386/amd64 gcc builtins are just inlines and do not require libgcc.
> > As to libatomic, I'm not sure now. I prefer to use complex libraries
> > such as OpenSSL, zlib, etc.
> On x86/amd64 the shipped assembler code works fine, and my libatomic
> patch was intended for 'other' architectures.
> Despite of the latter I believe reinventing the wheel (as did php-fpm)
> is no good engineering - and you need to maintain that code yourself
> rather than have the 'community' do that for you (and other projects).
> Unfortunately I don't know the "complex" libraries good enough to tell
> whether they contain atomic ops nor whether they export it.
> Igor, if it was my project I would have deleted the asm part
> completely and used GCC atomics (the same goes for php-fpm) where
> available, and libatomic (or any better replacement, I am not dogmatic
> here) else. As far as I can tell the latter are inlined, too.
> In the meantime I've created modified Gentoo ebuilds [1] (for all
> archs) and binaries [2] (for ARM) - with the option for libatomic.
> Find it attached as the link mentioned previously does not work
> anymore because I replaced subversion by GIT.
> -- 
> W-Mark Kubacki
> http://mark.ossdl.de/
> [1] http://git.ossdl.de/?p=ossdl-overlay.git;a=summary
> [2] http://binhost.ossdl.de/armv5tel-softfloat-linux-gnueabi/
>      (set this as binhost in Gentoo and the packages will be pulled
> automatically)

I agree that reinventing wheel is not good engineering and I prefer
to use libraries, however, in reason. I want to minimize external
dependances for general usage as much as possible. nginx may depend on
OpenSSL, libXSLT/libXML, perl, libGD, GeoIP, but usually it requires
just zlib and PCRE. And you can build nginx even without these libraries.

I'm not sure that community maintenance is always better.
PCRE and zlib support is certainly very good, however, I can say
this about any library.

As to gcc 4.1 builtin/libatomic only solution, now nginx can be built
by gcc 2.8 and 2.95, and I do not think that installing libatomic
on FreeBSD 4 (gcc 2.95) is necessary thing to run nginx.
Besides, for example, MacOSX/Darwin has atomic(3) and barrier(3) operations
optimized at run-time for UP and SMP (they does to use lock on UP).

I will add libatomic as last resort (gcc4.1 built-ins, my atomic code,
libatomic) and will add building procedures since it seems Linux
distributions are the only platform that has libatomic package.

BTW, could you please show coredump backtrace of segfault without atomic
ops ? I still want to fix the bug to allow nginx run even on platforms
without atomic ops at all.

Igor Sysoev

More information about the nginx mailing list