Re: better atomics - v0.6

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Geoghegan <pg(at)heroku(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Ants Aasma <ants(at)cybertec(dot)at>
Subject: Re: better atomics - v0.6
Date: 2014-09-24 18:19:06
Message-ID: 54230B1A.5000605@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 09/24/2014 07:57 PM, Andres Freund wrote:
> On 2014-09-24 12:44:09 -0400, Tom Lane wrote:
>> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>>> On 2014-09-24 18:55:51 +0300, Heikki Linnakangas wrote:
>>>> There doesn't seem to be any hardware implementations of that in the patch.
>>>> Is there any architecture that has an instruction or compiler intrinsic for
>>>> that?
>>
>>> You can implement it rather efficiently on ll/sc architectures. But I
>>> don't really think it matters. I prefer add_until (I've seen it named
>>> saturated add before as well) to live in the atomics code, rather than
>>> reimplement it in atomics employing code. I guess you see that
>>> differently?
>>
>> I think the question is more like "what in the world happened to confining
>> ourselves to a small set of atomics".
>
> I fail to see why the existance of a wrapper around compare-exchange
> (which is one of the primitives we'd agreed upon) runs counter to
> the agreement that we'll only rely on a limited number of atomics on the
> hardware level?

It might be a useful function, but if there's no hardware implementation
for it, it doesn't belong in atomics.h. We don't want to turn it into a
general library of useful little functions.

>> I doubt either that this exists
>> natively anywhere, or ethat it's so useful that we should expect platforms
>> to have efficient implementations.

Googling around, ARM seems to have a QADD instruction that does that.
But AFAICS it's not an atomic instruction that you could use for
synchronization purposes, just a regular instruction.

> It's useful for my work to get rid of most LockBufHdr() calls (to
> manipulate usagecount locklessly). That's why I added it. We can delay
> it till that patch is ready, but I don't really see the benefit.

Yeah, please leave it out for now, we can argue about it later. Even if
we want it in the future, it would be just dead, untested code now.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2014-09-24 18:24:42 Re: add modulo (%) operator to pgbench
Previous Message Tom Lane 2014-09-24 17:53:42 Re: add modulo (%) operator to pgbench