Fast, Reliable, Proven transactional storage for MySQL

InnoDB Plugin: Enabling GCC atomic built-in functions for InnoDB rw-locks

Beginning with InnoDB Plugin 1.0.3, InnoDB will automatically take advantage of your platform’s capabilities for more efficient locking and mutexing. On platforms that support doing so, InnoDB will implement mutexes and read/write locks with the GNU Compiler Collection (GCC) built-in functions for atomic memory access instead of the previous approach that used Pthreads (pthread_mutex_t).

When the InnoDB Plugin starts, it will write a message to the log file to indicate whether atomic instructions will be used for mutexes, for both mutexes and read/write locks, or not at all. See Section 7.2 of the documentation for more information.

To enable this enhancement, the InnoDB Plugin must be compiled with GCC version 4.1.2 or newer. Also, the target CPU must support the required atomic instructions. Furthermore, the implementation of InnoDB rw-locks with GCC atomic builtins requires that the compare-and-swap atomic builtin works on thread identifiers (pthread_t).

This would best be checked by the ./configure script at compilation time. However, because that script is distributed by MySQL and generating the script requires some extra tools, we implement the check for pthread_t at make time. If you re-generate the ./configure script and the file storage/innobase/Makefile.in, the check will be performed when you run ./configure.

On the x86 class of processors, the machine instructions needed for atomic builtins were introduced in the Intel 80486 (i486). If the compiler has been configured with i386 as the default target, the atomic builtins will be unavailable unless you specify -march=i486 or something similar in CFLAGS and CXXFLAGS. An example:

./configure --with-plugins=innobase CFLAGS=-march=i486 CXXFLAGS=-march=i486
make

Note that although the Intel Pentium Pro was introduced in 1995, it may not be wise to specify -march=i686, because some non-Intel processors do not implement the whole Pentium Pro instruction set. We have used appropriate compiler flags for the binaries we provide, to ensure maximum compatibility with current hardware and the compiler flags used by MySQL, as well as to utilize the atomic instructions where they are available. Therefore, we provide binaries built for i386 or i486 or other cpu type as appropriate. See the download page for specifics for your platform.

When mysqld starts, the InnoDB Plugin 1.0.3 will report in the log file one of the following:

InnoDB: Mutexes and rw_locks use GCC atomic builtins.
This is the most efficient setting.
InnoDB: Mutexes use GCC atomic builtins, rw_locks do not.
Some operating systems define pthread_t as a structure that cannot be used in atomic compare-and-swap operations.
InnoDB: Neither mutexes nor rw_locks use GCC atomic builtins.
Either the code was not compiled with GCC 4.1.2 or later, or the target system does not support the atomic builtins. See the note about -march=i486 above.