Re: lock support for aarch64

Lists: pgsql-hackers
From: Mark Salter <msalter(at)redhat(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: lock support for aarch64
Date: 2013-05-13 12:39:18
Message-ID: 1368448758.23422.12.camel@t520.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I used the following patch to add lock support aarch64. It is just a
copy of the arm support based on gcc builtins. Postgresql built with
this patch passes the various tests.

diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index d4a783f..624a73b 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -335,6 +335,25 @@ tas(volatile slock_t *lock)
#endif /* __arm__ */


+/*
+ * Use gcc builtins for AArch64.
+ */
+#if defined(__aarch64__)
+#define HAS_TEST_AND_SET
+
+#define TAS(lock) tas(lock)
+
+typedef int slock_t;
+
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ return __sync_lock_test_and_set(lock, 1);
+}
+
+#define S_UNLOCK(lock) __sync_lock_release(lock)
+#endif /* __aarch64__ */
+
/* S/390 and S/390x Linux (32- and 64-bit zSeries) */
#if defined(__s390__) || defined(__s390x__)
#define HAS_TEST_AND_SET


From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Mark Salter <msalter(at)redhat(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 13:15:20
Message-ID: 5190E768.3000308@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 13.05.2013 15:39, Mark Salter wrote:
> I used the following patch to add lock support aarch64. It is just a
> copy of the arm support based on gcc builtins. Postgresql built with
> this patch passes the various tests.

I think this needs an "#ifdef HAVE_GCC_INT_ATOMICS", like the ARM codepath.

If we are to support aarch64, it would be good to have an aarch64
machine on the buildfarm. Could you arrange that? See
http://buildfarm.postgresql.org/

- Heikki


From: Mark Salter <msalter(at)redhat(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 13:48:37
Message-ID: 1368452917.23422.21.camel@t520.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2013-05-13 at 16:15 +0300, Heikki Linnakangas wrote:
> On 13.05.2013 15:39, Mark Salter wrote:
> > I used the following patch to add lock support aarch64. It is just a
> > copy of the arm support based on gcc builtins. Postgresql built with
> > this patch passes the various tests.
>
> I think this needs an "#ifdef HAVE_GCC_INT_ATOMICS", like the ARM codepath.

Yes. Would it be better to do something like:

+/*
+ * Use gcc builtins if available.
+ */
+#if !defined(HAS_TEST_AND_SET) && defined(HAVE_GCC_INT_ATOMICS)
+#define HAS_TEST_AND_SET
+
+#define TAS(lock) tas(lock)
+
+typedef int slock_t;
+
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ return __sync_lock_test_and_set(lock, 1);
+}
+
+#define S_UNLOCK(lock) __sync_lock_release(lock)
+#endif
+
/* Blow up if we didn't have any way to do spinlocks */
#ifndef HAS_TEST_AND_SET
#error PostgreSQL does not have native spinlock support on this platform. To continue the compilation, rerun configure using --disable-spinlocks. However, performance will be poor. Please report this to pgsql-bugs(at)postgresql(dot)org(dot)

>
> If we are to support aarch64, it would be good to have an aarch64
> machine on the buildfarm. Could you arrange that? See
> http://buildfarm.postgresql.org/
>

Right now, all we have is a simulator. It takes about 24hrs to build and
test the Fedora RPM. Hardware will start to be available soon. But yes,
I think we could arrange to add to the buildfarm.

--Mark


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Mark Salter <msalter(at)redhat(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 14:26:51
Message-ID: CAHyXU0zKJPA_gHFKmqOH8qihj+H39rRL0ePovaX1hb4TBXSvRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, May 13, 2013 at 8:15 AM, Heikki Linnakangas
<hlinnakangas(at)vmware(dot)com> wrote:
> On 13.05.2013 15:39, Mark Salter wrote:
>>
>> I used the following patch to add lock support aarch64. It is just a
>> copy of the arm support based on gcc builtins. Postgresql built with
>> this patch passes the various tests.
>
>
> I think this needs an "#ifdef HAVE_GCC_INT_ATOMICS", like the ARM codepath.

I'm starting to wonder why we don't always use gcc atomics if they are
available and assembly implementation is not (any maybe, even if it
is).

merlin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Salter <msalter(at)redhat(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 15:14:05
Message-ID: 4237.1368458045@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Salter <msalter(at)redhat(dot)com> writes:
> I used the following patch to add lock support aarch64. It is just a
> copy of the arm support based on gcc builtins. Postgresql built with
> this patch passes the various tests.

Couldn't we just do

-#if defined(__arm__) || defined(__arm)
+#if defined(__arm__) || defined(__arm) || defined(__aarch64__)

in the existing ARM code block?

regards, tom lane


From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Mark Salter <msalter(at)redhat(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 15:26:46
Message-ID: 51910636.30007@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 13.05.2013 17:26, Merlin Moncure wrote:
> I'm starting to wonder why we don't always use gcc atomics if they are
> available and assembly implementation is not (any maybe, even if it
> is).

That was discussed a while ago, but there were a lot of claims that
__sync_lock_test_and_set is broken on many various platforms:
http://www.postgresql.org/message-id/flat/5642(dot)1324482916(at)sss(dot)pgh(dot)pa(dot)us#5642(dot)1324482916@sss.pgh.pa.us.
The situation might've improved since, but I guess we should proceed
cautiously.

- Heikki


From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Mark Salter <msalter(at)redhat(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 15:36:55
Message-ID: 51910897.6070500@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 13.05.2013 18:14, Tom Lane wrote:
> Mark Salter<msalter(at)redhat(dot)com> writes:
>> I used the following patch to add lock support aarch64. It is just a
>> copy of the arm support based on gcc builtins. Postgresql built with
>> this patch passes the various tests.
>
> Couldn't we just do
>
> -#if defined(__arm__) || defined(__arm)
> +#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
>
> in the existing ARM code block?

That would imply falling back to swpb instruction also on aarch64, which
won't work.

- Heikki


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Mark Salter <msalter(at)redhat(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lock support for aarch64
Date: 2013-05-13 15:53:48
Message-ID: 5088.1368460428@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> writes:
> On 13.05.2013 18:14, Tom Lane wrote:
>> Couldn't we just do
>> -#if defined(__arm__) || defined(__arm)
>> +#if defined(__arm__) || defined(__arm) || defined(__aarch64__)

> That would imply falling back to swpb instruction also on aarch64, which
> won't work.

It doesn't work on current ARM32 chips either, but no one has complained
about the existing coding. At least on ARM64 there'd be a likelihood
that you'd get an assembler error rather than an executable that crashes
at launch.

I suppose we could consider adding

#ifdef __aarch64__
#error ...
#endif

in the section for not-HAVE_GCC_INT_ATOMICS, but I'm doubtful it's
worth the trouble.

regards, tom lane