[PATCH] MDEV-27936 hardware lock elision on ppc64{,le} failing to compile
There is only a very small range of gcc compiler versions
that allow the built_{htm} functions to be defined without -mhtm
being specified as a global C{,XX}FLAGS.
Because the design is centered around enable HTM only in the
functional blocks that use it, this breaks on the inclusion
of the htmxlintrin.h header that includes this.
As a partial mitigation, extented to GNU/clang compilers,
transaction functions gain the attribute "hot".
In general the use of htm is around the optimistic
transaction ability of the function. The key part of using the
hot attribute is to place these functions together so that
a maximization of icache, tlb and OS paging can ensure that
these can be ready to execute by any thread/cpu with the
minimium amount of overhead.
POWER is particulary affected here because the xbegin/xend
functions are not inline.
srw_lock.cc requires the -mhtm cflag, both in the storage
engine and the unittests.
As below, target htm sections don't enable the builtins
root@
0b49bb233a4d:/# gcc -o main main.c
main.c: In function 'f':
main.c:5:16: warning: implicit declaration of function '__builtin_tbegin'; did you mean '__builtin_asin'? [-Wimplicit-function-declaration]
5 | return __builtin_tbegin(0);
| ^~~~~~~~~~~~~~~~
| __builtin_asin
/usr/bin/ld: /tmp/ccaqLefJ.o: in function `f':
main.c:(.text+0x20): undefined reference to `__builtin_tbegin'
collect2: error: ld returned 1 exit status
root@
0b49bb233a4d:/# gcc -mhtm -o main main.c
root@
0b49bb233a4d:/# cat main.c
__attribute__((target("htm")))
int f()
{
return __builtin_tbegin(0);
}
int main()
{
return f();
}
root@
0b49bb233a4d:/# uname -a
Linux
0b49bb233a4d 5.17.0-0.rc6.109.fc37.x86_64 #1 SMP PREEMPT Mon Feb 28 15:48:52 UTC 2022 ppc64le GNU/Linux
Gbp-Pq: Name
1006527-fix-ppc64-ftbfs.patch