Re: Broken atomics code on PPC with FreeBSD 10.3

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Broken atomics code on PPC with FreeBSD 10.3
Date: 2016-12-30 16:06:24
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On December 30, 2016 4:48:22 PM GMT+01:00, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>Andres Freund <andres(at)anarazel(dot)de> writes:
>> On 2016-12-30 00:44:33 -0500, Tom Lane wrote:
>>> Perhaps it could be argued that there's a FreeBSD compiler bug here,
>>> but what I'm wondering is why configure believes that this:
>>> [char lock = 0;
>>> __sync_lock_test_and_set(&lock, 1);
>>> __sync_lock_release(&lock);])],
>>> is going to draw a hard error on platforms without byte-wide
>>> My sense of C semantics is that the best you could hope for is a
>>> warning
>> Well, in theory these aren't actual functions but intrinsics with
>> special behaviour ("by being overloaded so that they work on multiple
>> types."). The compiler is supposed to warn and link to an external
>> function if a certain operation is not available:
>Yeah, I read that. But configure tests don't normally notice warnings.

IIRC those functions are *not* supposed to be provided, I.e. they should result in a linker error.

BTW, it's unclear why there's no 1 byte atomics support in that compiler, isn't it? On a ll/sc arch like ppc it should (and IIRC is) be supported efficiently. As you suggest, using a lwarx should just work.

> I'm not very good at reading
PPC assembler, but I think what is happening in the "char" case is that
gcc is trying to emulate a byte-wide operation using a word-wide one,
ie an lwarx/stwcx. loop. Even if that works (and apparently it does not),
we would not want to use it since it implies contention between adjacent
atomic flags.

That's the case as long as they're on a single cache line. Whether it's the same word, double/half word shouldn't matter.

Sent from my Android device with K-9 Mail. Please excuse my brevity.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2016-12-30 16:06:27 Re: proposal: session server side variables
Previous Message Erik Rijkers 2016-12-30 15:55:08 Re: Logical Replication WIP