title: Enable/Disable Hardware Lock Elision
body: <p>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 <em>hle</em> CPU flag is for Hardware Lock Elision I think. The processor I am using is Intel(R) Xeon(R) Gold 6130 with Skylake architecture.</p>
  
  <p>First I wanted to disable Lock elision but when I run the program that uses <strong>pthread_mutex_lock</strong>, with <strong>perf stat -T</strong> 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 <strong>export GLIBC_TUNABLES=glibc.elision.enable=1</strong> first, to enable lock elision but after this step I still don't see any transactions with perf. </p>
  
  <p>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.</p>
  
  <p>So any advice to how I can enable lock elision would be helpful. Or am I checking it incorrectly? </p>
  
  <p><strong>Update</strong> for TSX I'm using this two instructions in the main function, just like this:</p>
  
  <pre><code>_xbegin();
  _xend();
  </code></pre>
  
  <p>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. </p>
  
  <p>For locks I have mutex:</p>
  
  <pre><code>pthread_mutex_t * mutex;
  mutex = (pthread_mutex_t *) malloc(10 * sizeof(pthread_mutex_t));
  for(int k=0; k&lt;10; k++){
      pthread_mutex_init(&amp;mutex[k], NULL);
    }
  </code></pre>
  
  <p>Maybe for elision I should initialize it differently? </p>