[PATCH] Add loongarch64 native spin lock.

Started by YANG Xudongover 3 years ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t47861
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 28, 2026 at 12:40 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t47861_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t47861_1 && git checkout t47861_1

Patchset v1 (message #1) is on t47861_1

Jump to latest
#1YANG Xudong
yangxudong@ymatrix.cn

Hi,

This patch set tries to add loongarch64 native spin lock to postgresql.

- [PATCH 1/2] implements a loongarch64 native spin lock.
- [PATCH 2/2] fixes s_lock_test to make it runnable via `make check'.

The patch set is tested on my Loongson 3A5000 machine with Loong Arch
Linux and GCC 13.1.0 with default ./configure with no options.

Output of `make check' in src/backend/storage/lmgr is attached.

See:
[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#atomic-memory-access-instructions
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#atomic-memory-access-instructions
[2]: https://github.com/torvalds/linux/blob/f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6/arch/loongarch/include/asm/cmpxchg.h#L12
https://github.com/torvalds/linux/blob/f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6/arch/loongarch/include/asm/cmpxchg.h#L12

----
YANG Xudong

Attachments:

t47861_1
0001-Implement-loongarch64-native-spinlock-with-TAS.patchtext/plain; charset=UTF-8; name=0001-Implement-loongarch64-native-spinlock-with-TAS.patchDownload+39-1
0002-Make-s_lock_test-work.patchtext/plain; charset=UTF-8; name=0002-Make-s_lock_test-work.patchDownload+5-2
output.txttext/plain; charset=UTF-8; name=output.txtDownload
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: YANG Xudong (#1)
Re: [PATCH] Add loongarch64 native spin lock.

YANG Xudong <yangxudong@ymatrix.cn> writes:

This patch set tries to add loongarch64 native spin lock to postgresql.

This came up before, and our response was

https://git.postgresql.org/gitweb/?p=postgresql.git&amp;a=commitdiff&amp;h=1c72d82c2

In principle, at least, there is no longer any need for
machine-specific s_lock.h additions. Is there a strong reason
why the __sync_lock_test_and_set solution isn't good enough?

regards, tom lane

#3YANG Xudong
yangxudong@ymatrix.cn
In reply to: Tom Lane (#2)
Re: [PATCH] Add loongarch64 native spin lock.

Thanks for the information.

I checked the assembly code of __sync_lock_test_and_set generated by GCC
for loongarch64. It is exactly the same as this patch.

I guess this patch is not necessary any more.

Regards

Show quoted text

On 2023/5/17 20:37, Tom Lane wrote:

YANG Xudong <yangxudong@ymatrix.cn> writes:

This patch set tries to add loongarch64 native spin lock to postgresql.

This came up before, and our response was

https://git.postgresql.org/gitweb/?p=postgresql.git&amp;a=commitdiff&amp;h=1c72d82c2

In principle, at least, there is no longer any need for
machine-specific s_lock.h additions. Is there a strong reason
why the __sync_lock_test_and_set solution isn't good enough?

regards, tom lane