I am using glibc 2.24 version. It has lock elision path included for pthread_mutex_lock implementation with Transactional Synchronization Extensions such as _xbegin() and _xend(). The hardware is supposed to support lock elision as hle CPU flag is for Hardware Lock Elision I think. The processor I am using is Intel(R) Xeon(R) Gold 6130 with Skylake architecture.
First I wanted to disable Lock elision but when I run the program that uses pthread_mutex_lock, with perf stat -T to monitor transactional cycles, I got 0. I assume this means pthread_mutex_lock does not use transactional path at all. After googling I found that it might be necessary to use export GLIBC_TUNABLES=glibc.elision.enable=1 first, to enable lock elision but after this step I still don't see any transactions with perf.
On the other hand when I include _xbegin(); and _xend(); directly in the process, I get some number of transactional cycles with perf stat -T, which should mean that I am looking for the right counters with perf, hopefully.
So any advice to how I can enable lock elision would be helpful. Or am I checking it incorrectly?
Update for TSX I'm using this two instructions in the main function, just like this:
_xbegin();
_xend();
I'm not sure which library it needs, I already have tens of them included. For compilation I'm using the following flags: -O3 -march=native -lpthread that are relevant for this example.
For locks I have mutex:
pthread_mutex_t * mutex;
mutex = (pthread_mutex_t *) malloc(10 * sizeof(pthread_mutex_t));
for(int k=0; k<10; k++){
pthread_mutex_init(&mutex[k], NULL);
}
Maybe for elision I should initialize it differently?
hle
andrtm
in/proc/cpuinfo
and make sure it's not been disabled using a microcode update (because it's buggy according to erratum SKX88). Also,glibc.elision.enable
is supported starting with glibc 2.27. You can check your glibc version usingldd --version
. Then we can see what to do. – Inflammableglibc.elision.enable
has no effect on versions older than 2.27. If I remember corrcetly, older versions of glibc have to be compiled with--enable-lock-elision=yes
for lock elision to work. – Inflammable--enable-lock-elision=yes
, not your code. In contrast, starting with glibc 2.27, your code has to be run withexport GLIBC_TUNABLES=glibc.elision.enable=1
. – Inflammable