Re: [PATCH] loongarch: expose LAMCAS existence via cpuinfo and hwcap
From: Xi Ruoyao
Date: Sat Sep 05 2026 - 04:58:37 EST
On Sat, 2026-09-05 at 12:58 +0800, Rong Bao wrote:
> Hi Huacai,
>
>
> On 2026-09-05 12:46, Huacai Chen wrote:
> > [...]
> > > Features : cpucfg lam lam_bh scq ual fpu lsx lasx
> > > crc32 complex crypto lspw lvz lbt_x86 lbt_arm lbt_mips
> > > Hardware Watchpoint : yes, iwatch count: 8, dwatch count: 4
> > >
> > > ... while the CPUCFG 2 instruction reads "0x7e7ccfcf", whose bit 28 is 1,
> > > indicating the actual presence of LAMCAS.
> > Can we use LAM_CAS in the code, which is similar to LAM_BH?
>
>
> I originally chose "LAMCAS" and not "LAM_CAS" deliberately to match the
> manual spelling. For example, in "LoongArch Reference Manual, Volume 1
> (version 1.10)"[^0], Table 3 reads as follows:
>
> > 27 LAM_BH 1 indicates support AM{SWAP/ADD}[_DB].{B/H}.
> > 28 LAMCAS 1 indicates support AMCAS[_DB].{B/H/W/D}.
>
> Also, in "Toolchain Conventions of the LoongArch(tm) Architecture,
> Version 1.2"[^1], these two extensions are also stylized with different
> hyphenation:
>
> > -mlam-bh -m[no-]lam-bh Enable atomic operations
> am{swap/add}[_db].{b/h}. LoongArch V1.1
> > -mlamcas -m[no-]lamcas Enable atomic compare-and-swap instructions
> amcas[_db].{b/h/w/d}. LoongArch V1.1
I wrote them for GCC and I just verbatim copied the identifiers from the
reference manual.
But IIRC we've once discussed this and concluded that the user space
should just use cpucfg unless the feature requires kernel support (i.e.
LSX, LASX, and LBT must be checked via HWCAP instead of cpucfg as they
require the kernel to enable the hardware unit and manage the context
switch)?
Maybe using HWCAP instead of cpucfg can be useful as well when the
kernel can detect a hardware/firmware bug and remove the corresponding
bit from HWCAP, but the previous discussion about buggy LA364E firmware
implementation (causing sc.q semantic error) concluded that the kernel
will be very unlikely to ship such a work around. And AFAIK there's no
such a bug reported for LAMCAS ever...
--
Xi Ruoyao <xry111@xxxxxxxxxxx>