Re: better atomics - v0.6

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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 16:00:47
Message-ID: 20140924160047.GR2521@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-09-24 18:55:51 +0300, Heikki Linnakangas wrote:
> On 09/24/2014 03:37 PM, Andres Freund wrote:
> >>>> >+/*
> >>>> >+ * pg_fetch_add_until_u32 - saturated addition to variable
> >>>> >+ *
> >>>> >+ * Returns the the value of ptr after the arithmetic operation.
> >>>> >+ *
> >>>> >+ * Full barrier semantics.
> >>>> >+ */
> >>>> >+STATIC_IF_INLINE uint32
> >>>> >+pg_atomic_fetch_add_until_u32(volatile pg_atomic_uint32 *ptr, int32 add_,
> >>>> >+ uint32 until)
> >>>> >+{
> >>>> >+ CHECK_POINTER_ALIGNMENT(ptr, 4);
> >>>> >+ return pg_atomic_fetch_add_until_u32_impl(ptr, add_, until);
> >>>> >+}
> >>>> >+
> >>>
> >>>This was a surprise to me, I don't recall discussion of an "fetch-add-until"
> >>>operation, and hadn't actually ever heard of it before.
> >It was included from the first version on, and I'd mentioned it a couple
> >times.
>
> 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?

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-09-24 16:18:48 Re: identify_locking_dependencies is broken for schema-only dumps
Previous Message Heikki Linnakangas 2014-09-24 15:55:51 Re: better atomics - v0.6