Commit graph

59 commits

Author SHA1 Message Date
Vladislav Vaintroub
905c3d61e1 MDEV-25870 followup - some Windows ARM64 improvements
- optimize atomic store64/load64 implementation.
- allow CRC32 optimization. Do not allow pmull yet, as this fails like in
  https://stackoverflow.com/questions/54048837/how-to-perform-polynomial-multiplication-using-arm64
2023-09-24 11:20:38 +02:00
Robert Bindar
e8392e58b2 MDEV-19696 - Cleanup gcc sync builtins
Since 10.4 requires C++11 capable compiler, gcc sync builtins became
dead code. Remove relevant cmake checks and cleanup include files.
2019-07-03 12:11:22 +03:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Marko Mäkelä
26a14ee130 Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
Vicențiu Ciorbaru
cb248f8806 Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
Vicențiu Ciorbaru
5543b75550 Update FSF Address
* Update wrong zip-code
2019-05-11 21:29:06 +03:00
Marko Mäkelä
34841d2305 Merge bb-10.2-ext into 10.3 2017-12-12 09:57:17 +02:00
Sergey Vojtovich
c60095a818 Faster atomic loads and stores on windows 2017-12-08 17:55:41 +04:00
Sergey Vojtovich
b3346c2f41 Restore LF_BACKOFF
Moved InnoDB UT_RELAX_CPU() to server. Restored cross-platform LF_BACKOFF
implementation basing on UT_RELAX_CPU().
2017-12-08 13:44:45 +02:00
Sergey Vojtovich
1029b22feb MDEV-13728 - Import MySQL 5.7 atomic operations for MSVC and Solaris
gcc_sync.h, solaris.h, generic-msvc.h copied verbatim.
2017-11-27 18:35:53 +04:00
Sergey Vojtovich
c10e523d78 MDEV-11212 - Clean-up MariaDB atomic operations
No more black magic for gcc atomic bultins. Fixes some warnings.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
81f280789b MDEV-11212 - Clean-up MariaDB atomic operations
Moved gcc specific code to gcc_builtins.h.
Moved intptr into the black magic code block.
Moved definition of atomic operations for "long" out of black magic code block.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
8ff3b892ae MDEV-11212 - Clean-up MariaDB atomic operations
Removed MY_ATOMIC_MODE_DUMMY and WITH_ATOMIC_OPS: MariaDB is not functional
without atomic operations anymore.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
bb9928160f MDEV-11212 - Clean-up MariaDB atomic operations
Removed MY_ATOMIC_HAS_8_16: never defined.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
1369e70b56 MDEV-11212 - Clean-up MariaDB atomic operations
Removed "somewhat broken native x86 implementation". Should never be used on
supported platforms.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
71e11bce34 MDEV-8791 - AIX: Unresolved Symbols during linking
Clean-up nolock.h: it doesn't serve any purpose anymore. Appropriate code moved
to x86-gcc.h and my_atomic.h.

If gcc sync bultins were detected, we want to make use of them independently of
__GNUC__ definition. E.g. XLC simulates those, but doesn't define __GNUC__.

HS/Spider: According to AIX manual alloca() returns char*, which cannot be
casted to any type with static_cast. Use explicit cast instead.

MDL: Removed namemangling pragma, which didn't let MariaDB build with XLC.

WSREP: _int64 seem to be conflicting name with XLC, replaced with _integer64.

CONNECT: RTLD_NOLOAD is GNU extention. Removed rather meaningless check if
library is loaded. Multiple dlopen()'s of the same library are permitted,
and it never gets closed anyway. Except for error, which was a bug: it may
close library, which can still be referenced by other subsystems.

InnoDB: __ppc_get_timebase() is GNU extention. Only use it when __GLIBC__ is
defined.

Based on contribution by flynn1973.
2016-10-31 12:18:23 +04:00
Sergei Golubchik
658992699b Merge tag 'mariadb-10.0.20' into 10.1 2015-06-27 20:35:26 +02:00
Sergei Golubchik
66fd45afce MDEV-7398 mysqld segfaults on FreeBSD 10.1 i386 when built with clang 3.4
in cmake tests let's treat clang like gcc (same options,
same builtins) in many cases.

* don't check the compiler when
  * testing for -fvisibility=hidden support
  * testing for HAVE_ABI_CXA_DEMANGLE
  * testing for HAVE_GCC_ATOMIC_BUILTINS
  * when removing options with string(replace)
  * when running ${CC} --version (ignore the error instead)
* run ABI checks for clang
* use "canonical" gcc flags for clang
* fix groonga too

Also:

* add cmake detection for gcc __atomic_* builtins. they might be
  supported (__ATOMIC_SEQ_CST is defined), but not for all operand
  sizes. In particular, 64-bit atomic load is problematic on i386
* cache check results for Windows
* remove the test for HAVE_CXXABI_H (HAVE_ABI_CXA_DEMANGLE is
  suffifient)
2015-06-16 23:58:21 +02:00
Sergei Golubchik
e695db0f2d MDEV-7437 remove suport for "atomics" with rwlocks 2015-01-13 10:15:21 +01:00
Sergei Golubchik
4d4ce59d2b compilation fixes for WITH_ATOMIC_OPS=rwlocks 2014-09-08 12:59:57 +02:00
Sergey Vojtovich
9836fd5d13 MDEV-5766 - my_atomic_load does memory writes
my_atomic_load() is implemented as __sync_fetch_and_or(var, 0) which
writes or-ed value back to var. Memory writes as such have worse
performance and scalability than reads.

gcc 4.7 and up offers better facility for atomic loads/stores. Use it
whenever it is available.
2014-03-07 11:43:06 +04:00
Sergei Golubchik
009dee833c centos5 gcc 4.1 asm bug
include/atomic/x86-gcc.h:
  force %esi register, don't give gcc a choice.
  (otherwise it could choose %ebx, and 4.1 did)
2013-05-07 18:28:36 +02:00
Vladislav Vaintroub
257fd9d3d9 MDEV-417 - fix typo that prevented use of atomic instructions on Windows
use correct macro for Microsoft compiler. It is _MSC_VER , not _MSV_VER
2012-07-30 20:13:23 +02:00
Kent Boortz
02e07e3b51 Updated/added copyright headers 2011-06-30 17:46:53 +02:00
Davi Arnaut
cfe8acb198 Bug#56760: my_atomics failures on osx10.5-x86-64bit
The problem was due to a misuse of GCC asm constraints used to
implement a atomic load. On x86_64, the load was implemented
as a cmpxchg which implicitly uses the eax register as a
source and destination operand, yet the dummy value used for
comparison wasn't being properly loaded into eax (and other
problems).

The core problem is that cmpxchg is unnecessary as a load
on x86_64 as there are other simpler instructions such
as xadd. Even though, such instructions are only used to
have a memory barrier as load and stores are atomic by
definition. Hence, the solution is to explicitly issue the
required CPU and compiler barriers.

include/atomic/x86-gcc.h:
  Issue a synchronizing instruction before loading the value.
  Afterwards, issue a compiler barrier to prevent reordering.
2010-11-30 21:19:49 -02:00
Davi Arnaut
1d5209438c Bug#52419: x86 assembly based atomic CAS causes test failures
The problem was that the x86 assembly based atomic CAS
(compare and swap) implementation could copy the wrong
value to the ebx register, where the cmpxchg8b expects
to see part of the "comparand" value. Since the original
value in the ebx register is saved in the stack (that is,
the push instruction causes the stack pointer to change),
a wrong offset could be used if the compiler decides to
put the source of the comparand value in the stack.

The solution is to copy the comparand value directly from
memory. Since the comparand value is 64-bits wide, it is
copied in two steps over to the ebx and ecx registers.

include/atomic/x86-gcc.h:
  For reference, an excerpt from a faulty binary follows.
  
  It is a disassembly of my_atomic-t, compiled at -O3 with
  ICC 11.0. Most of the code deals with preparations for
  a atomic cmpxchg8b operation. This instruction compares
  the value in edx:eax with the destination operand. If the
  values are equal, the value in ecx:ebx is stored in the
  destination, otherwise the value in the destination operand
  is copied into edx:eax.
  
  In this case, my_atomic_add64 is implemented as a compare
  and exchange. The addition is done over temporary storage
  and loaded into the destination if the original term value
  is still valid.
  
    volatile int64 a64;
    int64 b=0x1000200030004000LL;
    a64=0;
        mov    0xfffffda8(%ebx),%eax
        xor    %ebp,%ebp
        mov    %ebp,(%eax)
        mov    %ebp,0x4(%eax)
    my_atomic_add64(&a64, b);
        mov    0xfffffda8(%ebx),%ebp      # Load address of a64
        mov    0x0(%ebp),%edx             # Copy value
        mov    0x4(%ebp),%ecx
        mov    %edx,0xc(%esp)             # Assign to tmp var in the stack
        mov    %ecx,0x10(%esp)
        add    $0x30004000,%edx           # Sum values
        adc    $0x10002000,%ecx
        mov    %edx,0x8(%esp)             # Save part of result for later
        mov    0x0(%ebp),%esi             # Copy value of a64 again
        mov    0x4(%ebp),%edi
        mov    0xc(%esp),%eax             # Load the value of a64 used
        mov    0x10(%esp),%edx            # for comparison
        mov    %esi,(%esp)
        mov    %edi,0x4(%esp)
        push   %ebx                       # Push %ebx into stack. Changes esp.
        mov    0x8(%esp),%ebx             # Wrong restore of the result.
        lock cmpxchg8b 0x0(%ebp)
        sete   %cl
        pop    %ebx
2010-09-17 17:34:15 -03:00
Davi Arnaut
8ee568cde7 Bug#52261: 64 bit atomic operations do not work on Solaris i386 ..
Workaround a interface problem with the atomic macros that was
causing warnings. The correct type is retrieved using typeof if
compiling with GCC.
2010-07-27 10:25:11 -03:00
Davi Arnaut
93e38e8a3e Bug#22320: my_atomic-t unit test fails
Bug#52261: 64 bit atomic operations do not work on Solaris i386
           gcc in debug compilation

One of the various problems was that the source operand to
CMPXCHG8b was marked as a input/output operand, causing GCC
to use the EBX register as the destination register for the
CMPXCHG8b instruction. This could lead to crashes as the EBX
register is also implicitly used by the instruction, causing
the value to be potentially garbaged and a protection fault
once the value is used to access a position in memory.

Another problem was the lack of proper clobbers for the atomic
operations and, also, a discrepancy between the implementations
for the Compare and Set operation. The specific problems are
described and fixed by Kristian Nielsen patches:

Patch: 1

Fix bugs in my_atomic_cas*(val,cmp,new) that *cmp is accessed
after CAS succeds.

In the gcc builtin implementation, problem was that *cmp was
read again after atomic CAS to check if old *val == *cmp;
this fails if CAS is successful and another thread modifies
*cmp in-between.

In the x86-gcc implementation, problem was that *cmp was set
also in the case of successful CAS; this means there is a
window where it can clobber a value written by another thread
after successful CAS.

Patch 2:

Add a GCC asm "memory" clobber to primitives that imply a
memory barrier.

This signifies to GCC that any potentially aliased memory
must be flushed before the operation, and re-read after the
operation, so that read or modification in other threads of
such memory values will work as intended.

In effect, it makes these primitives work as memory barriers
for the compiler as well as the CPU. This is better and more
correct than adding "volatile" to variables.

include/atomic/gcc_builtins.h:
  Do not read from *cmp after the operation as it might be
  already gone if the operation was successful.
include/atomic/nolock.h:
  Prefer system provided atomics over the broken x86 asm.
include/atomic/x86-gcc.h:
  Do not mark source operands as input/output operands.
  Add proper memory clobbers.
include/my_atomic.h:
  Add notes about my_atomic_add and my_atomic_cas behaviors.
unittest/mysys/my_atomic-t.c:
  Remove work around, if it fails, there is either a problem
  with the atomic operations code or the specific compiler
  version should be black-listed.
2010-07-23 09:37:10 -03:00
Davi Arnaut
cd41cd953d Bug#22320: my_atomic-t unit test fails
The atomic operations implementation on 5.1 has a few problems,
which might cause tests to abort randomly. Since no code in 5.1
uses atomic operations, simply remove the code.
2010-07-05 09:00:39 -03:00
Konstantin Osipov
fcc9c8627a Fix compiler warnings in my_atomic.h
include/atomic/x86-gcc.h:
  Fix a warning about empty while loop body.
include/my_atomic.h:
  Fix a warning about empty while loop body.
2010-02-19 17:20:29 +03:00
Sergei Golubchik
56deea0dd7 merged 2009-12-24 21:18:53 +01:00
Sergei Golubchik
3bfb8797d0 fix atomic/solaris.h to conform
remove duplicated boilerplate code
2009-12-23 09:27:41 +01:00
Mikael Ronstrom
ec93c3ed23 Force use of c-register in CAS instruction on x86-32 bit architecture, b-register used for push and pop, so don't want to give compile the chance to choose the wrong register 2009-12-21 14:08:11 +01:00
Mikael Ronstrom
3b103b4897 Increase probability of correct atomics implementation by choosing stable implementations first 2009-12-19 08:54:05 +01:00
Mikael Ronstrom
eddd1a94a7 Make choices of atomic implementation based on highest stability 2009-12-19 08:46:37 +01:00
Mikael Ronstrom
45e62fba06 Fixed Solaris Atomics build issues 2009-12-18 11:15:21 +01:00
Mikael Ronstrom
3ad70924c9 Added extra checks of 64-bit atomic support on GCC and Solaris, also added 64-bit support in solaris.h which was missing 2009-12-18 09:29:18 +01:00
Mikael Ronstrom
a893a64e23 Fix for Windows atomics 2009-12-16 00:33:15 +01:00
Mikael Ronstrom
0fb1c286d7 Fixed complex gcc assembler issues with 64-bit operations on 32-bit platforms using PIC codes, commented x86-gcc.h a lot more 2009-12-15 22:15:48 +01:00
Mikael Ronstrom
6b0bb05068 Include windows.h in atomics framework for windows 2009-12-15 18:12:49 +01:00
Mikael Ronstrom
0d28ae37e5 Fixed 64-bit atomics on Win x86 and removed support for 8 and 16-bit atomic operations 2009-12-15 17:07:43 +01:00
Mikael Ronstrom
e74991d4a6 Fixed atomic instruction headers for Windows and x86-gcc 2009-12-15 15:40:08 +01:00
Mikael Ronstrom
566bcab328 Merge WL#5138 to mysql-next-mr 2009-11-27 18:11:05 +01:00
Mikael Ronstrom
b6c1ecb37f WL#5138 merged to mysql-next-mr 2009-11-20 16:23:32 +01:00
Marc Alff
7b9fd341a0 Misc cleanup 2009-11-17 17:36:39 -07:00
Marc Alff
382ae22290 WL#2595 kernel-independent atomic operations
Backport from 6.0.14 to 5.6.0

Original code from Sergei Golubchik
2009-11-17 17:11:32 -07:00
Luis Soares
f1bb8c3c55 manual merge: mysql-5.1-rep+2-delivery1 --> mysql-5.1-rpl-merge
Conflicts
=========

Text conflict in .bzr-mysql/default.conf
Text conflict in libmysqld/CMakeLists.txt
Text conflict in libmysqld/Makefile.am
Text conflict in mysql-test/collections/default.experimental
Text conflict in mysql-test/extra/rpl_tests/rpl_row_sp006.test
Text conflict in mysql-test/suite/binlog/r/binlog_tmp_table.result
Text conflict in mysql-test/suite/rpl/r/rpl_loaddata.result
Text conflict in mysql-test/suite/rpl/r/rpl_loaddata_fatal.result
Text conflict in mysql-test/suite/rpl/r/rpl_row_create_table.result
Text conflict in mysql-test/suite/rpl/r/rpl_row_sp006_InnoDB.result
Text conflict in mysql-test/suite/rpl/r/rpl_stm_log.result
Text conflict in mysql-test/suite/rpl_ndb/r/rpl_ndb_circular_simplex.result
Text conflict in mysql-test/suite/rpl_ndb/r/rpl_ndb_sp006.result
Text conflict in mysql-test/t/mysqlbinlog.test
Text conflict in sql/CMakeLists.txt
Text conflict in sql/Makefile.am
Text conflict in sql/log_event_old.cc
Text conflict in sql/rpl_rli.cc
Text conflict in sql/slave.cc
Text conflict in sql/sql_binlog.cc
Text conflict in sql/sql_lex.h
21 conflicts encountered.

NOTE
====
 mysql-5.1-rpl-merge has been made a mirror of mysql-next-mr:
 - "mysql-5.1-rpl-merge$ bzr pull ../mysql-next-mr"

 This is the first cset (merge/...) committed after pulling 
 from mysql-next-mr.
2009-10-22 23:30:28 +01:00
Mikael Ronstrom
bae553cfcd Backported my_atomic from 6.0-codebase and added support for 64-bit atomics to enable removal of LOCK_thread_count from every query, removed LOCK_thread_count from use in dispatch_command and close of query which is used in every query, now uses atomic increments/decrements instead 2009-10-12 11:00:39 +02:00
Mikael Ronstrom
a4785fc4a2 Moved atomics from 6.0 codebase to prepare for using atomic increments in places where LOCK_thread_count previously was used 2009-10-09 14:21:29 +02:00
Mats Kindahl
d47710c8dc WL#5016: Fix header file include guards
Adding header include file guards to files that are missing such.
2009-09-23 23:32:31 +02:00