From: Tony Garnock-Jones <tonyg@leastfixedpoint.com>
To: 70474@debbugs.gnu.org
Subject: bug#70474: Just adding DMB doesn't help
Date: Mon, 22 Apr 2024 09:52:47 +0200 [thread overview]
Message-ID: <be393d49-cf57-4099-a75a-f540bb8c338d@leastfixedpoint.com> (raw)
In-Reply-To: <825897f1-19fa-4f6a-b459-8db93791d1c3@leastfixedpoint.com>
[-- Attachment #1: Type: text/plain, Size: 472 bytes --]
As an alternative to changing the JIT to produce SWPAL/CASAL, because I
wasn't sure if *all* aarch64 targets support these, I tried adding DMB
ISH or DMB SY to the end of the generated code sequences. Surprisingly,
this did not fix the issue! So there's perhaps something fishy about the
LDAXR-STLXR sequences themselves?
So for now I'll stick on my own machine with SWPAL/CASAL, since this
does seem to work well enough to let both my own code and fibers run.
Tony
[-- Attachment #2: add-dmb-does-not-help.patch --]
[-- Type: text/plain, Size: 1921 bytes --]
diff --git a/libguile/lightening/lightening/aarch64-cpu.c b/libguile/lightening/lightening/aarch64-cpu.c
index 13aa351e9..bff583e33 100644
--- a/libguile/lightening/lightening/aarch64-cpu.c
+++ b/libguile/lightening/lightening/aarch64-cpu.c
@@ -225,6 +225,7 @@ oxxrs(jit_state_t *_jit, int32_t Op,
#define A64_STLR 0xc89ffc00
#define A64_LDAXR 0xc85ffc00
#define A64_STLXR 0xc800fc00
+#define A64_DMB 0xd50330bf
#define A64_STRBI 0x39000000
#define A64_LDRBI 0x39400000
#define A64_LDRSBI 0x39800000
@@ -675,6 +676,31 @@ STLXR(jit_state_t *_jit, int32_t Rt, int32_t Rn, int32_t Rm)
return oxxx(_jit, A64_STLXR, Rt, Rn, Rm);
}
+static void
+DMB(jit_state_t *_jit, int32_t CRm)
+{
+ uint32_t inst = A64_DMB;
+ inst = write_unsigned_bitfield(inst, CRm, 4, 8);
+ emit_u32_with_pool(_jit, inst);
+}
+
+static void
+DMB_ISH(jit_state_t *_jit)
+{
+ DMB(_jit, 11);
+ // ^ 11 = ISH, "Inner Shareable". This is what Java apparently uses
+ // See
+ // - https://gist.github.com/RaasAhsan/8e3554a41e07068536425ca0de46c9e8
+ // - https://mail.openjdk.org/pipermail/hotspot-dev/2021-March/049694.html
+ // - https://bugs.openjdk.org/browse/JDK-8262519
+}
+
+static void
+DMB_SY(jit_state_t *_jit)
+{
+ DMB(_jit, 15);
+}
+
static void
LDRSB(jit_state_t *_jit, int32_t Rt, int32_t Rn, int32_t Rm)
{
@@ -2541,6 +2567,7 @@ swap_atomic(jit_state_t *_jit, int32_t dst, int32_t loc, int32_t val)
jit_patch_there(_jit, bnei(_jit, result, 0), retry);
if (dst == val) unget_temp_gpr(_jit);
unget_temp_gpr(_jit);
+ DMB_SY(_jit);
}
static void
@@ -2562,6 +2589,7 @@ cas_atomic(jit_state_t *_jit, int32_t dst, int32_t loc, int32_t expected,
jit_patch_here(_jit, bad);
movr(_jit, dst, dst_or_tmp);
unget_temp_gpr(_jit);
+ DMB_SY(_jit);
}
static void
next prev parent reply other threads:[~2024-04-22 7:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 10:54 bug#70474: Possible bug with `atomic-box-swap!` on OSX/M3 (?!?!) Tony Garnock-Jones
2024-04-19 12:14 ` bug#70474: Also manifests on an M1 running 14.1.1 and with newer Guile versions Tony Garnock-Jones
2024-04-19 13:19 ` bug#70474: Possible bug with `atomic-box-swap!` on OSX/M3 (?!?!) Christopher Baines
2024-04-19 20:46 ` bug#70474: [PATCH 1/2] Including the cast makes Apple clang 15.0.0 happy; without it, clang is sad Tony Garnock-Jones
2024-04-19 20:48 ` bug#70474: [PATCH 2/2] Replace aarch64 CAS and atomic-swap generated JIT code with CASAL and SWPAL instructions Tony Garnock-Jones
2024-04-22 7:52 ` Tony Garnock-Jones [this message]
2024-04-22 8:18 ` bug#70474: [PATCH] Move the spin loop target to the LDAXR instruction Tony Garnock-Jones
2024-04-22 11:23 ` Tony Garnock-Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be393d49-cf57-4099-a75a-f540bb8c338d@leastfixedpoint.com \
--to=tonyg@leastfixedpoint.com \
--cc=70474@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).