Commit 36388503 authored by thakis's avatar thakis Committed by Commit bot

Revert of tcmalloc: Use C++11 atomics where appropriate. (patchset #8...

Revert of tcmalloc: Use C++11 atomics where appropriate. (patchset #8 id:140001 of https://codereview.chromium.org/1549913002/ )

Reason for revert:
Caused performance problems (see http://crbug.com/572525 and dupes)

Original issue's description:
> tcmalloc: Use C++11 atomics where appropriate.
>
> Ports these CLs to tcmalloc:
> https://codereview.chromium.org/636783002/
> https://codereview.chromium.org/1466833002/ (except mac)
>
> No intended behavior change, but it should remove
> the static initializer in atomicops_internals_x86_gcc.h
> on Linux.  It's also less code.
>
> BUG=94925,559247
>
> Committed: https://crrev.com/e13537fe418eff11d3cab9077f6a647d7c74f103
> Cr-Commit-Position: refs/heads/master@{#366904}

TBR=jfb@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=94925,559247

Review URL: https://codereview.chromium.org/1557433002

Cr-Commit-Position: refs/heads/master@{#367069}
parent 79388d00
...@@ -122,10 +122,14 @@ if (use_allocator == "tcmalloc") { ...@@ -122,10 +122,14 @@ if (use_allocator == "tcmalloc") {
"$tcmalloc_dir/src/base/abort.cc", "$tcmalloc_dir/src/base/abort.cc",
"$tcmalloc_dir/src/base/abort.h", "$tcmalloc_dir/src/base/abort.h",
"$tcmalloc_dir/src/base/arm_instruction_set_select.h", "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
"$tcmalloc_dir/src/base/atomicops-internals-arm-generic.h",
"$tcmalloc_dir/src/base/atomicops-internals-arm-v6plus.h",
"$tcmalloc_dir/src/base/atomicops-internals-linuxppc.h",
"$tcmalloc_dir/src/base/atomicops-internals-macosx.h", "$tcmalloc_dir/src/base/atomicops-internals-macosx.h",
"$tcmalloc_dir/src/base/atomicops-internals-windows.h", "$tcmalloc_dir/src/base/atomicops-internals-windows.h",
"$tcmalloc_dir/src/base/atomicops-internals-x86.cc",
"$tcmalloc_dir/src/base/atomicops-internals-x86.h",
"$tcmalloc_dir/src/base/atomicops.h", "$tcmalloc_dir/src/base/atomicops.h",
"$tcmalloc_dir/src/base/atomicops_internals_portable.h",
"$tcmalloc_dir/src/base/commandlineflags.h", "$tcmalloc_dir/src/base/commandlineflags.h",
"$tcmalloc_dir/src/base/cycleclock.h", "$tcmalloc_dir/src/base/cycleclock.h",
......
...@@ -104,9 +104,13 @@ ...@@ -104,9 +104,13 @@
'<(tcmalloc_dir)/src/base/abort.cc', '<(tcmalloc_dir)/src/base/abort.cc',
'<(tcmalloc_dir)/src/base/abort.h', '<(tcmalloc_dir)/src/base/abort.h',
'<(tcmalloc_dir)/src/base/arm_instruction_set_select.h', '<(tcmalloc_dir)/src/base/arm_instruction_set_select.h',
'<(tcmalloc_dir)/src/base/atomicops-internals-arm-generic.h',
'<(tcmalloc_dir)/src/base/atomicops-internals-arm-v6plus.h',
'<(tcmalloc_dir)/src/base/atomicops-internals-linuxppc.h',
'<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h', '<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h',
'<(tcmalloc_dir)/src/base/atomicops-internals-windows.h', '<(tcmalloc_dir)/src/base/atomicops-internals-windows.h',
'<(tcmalloc_dir)/src/base/atomicops_internals_portable.h', '<(tcmalloc_dir)/src/base/atomicops-internals-x86.cc',
'<(tcmalloc_dir)/src/base/atomicops-internals-x86.h',
'<(tcmalloc_dir)/src/base/atomicops.h', '<(tcmalloc_dir)/src/base/atomicops.h',
'<(tcmalloc_dir)/src/base/commandlineflags.h', '<(tcmalloc_dir)/src/base/commandlineflags.h',
'<(tcmalloc_dir)/src/base/cycleclock.h', '<(tcmalloc_dir)/src/base/cycleclock.h',
......
...@@ -100,4 +100,3 @@ Modifications: ...@@ -100,4 +100,3 @@ Modifications:
- Disabled HEAPPROFILE envvar unless ENABLE_PROFILING is defined - Disabled HEAPPROFILE envvar unless ENABLE_PROFILING is defined
- Add "ARMv8-a" to the supporting list of ARM architecture - Add "ARMv8-a" to the supporting list of ARM architecture
- Add generic.total_physical_bytes property to MallocExtension - Add generic.total_physical_bytes property to MallocExtension
- Replaced atomicops code with a portable implemenation based on C++11 <atomics>
/* Copyright (c) 2007, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ---
* This module gets enough CPU information to optimize the
* atomicops module on x86.
*/
#include "base/atomicops.h"
#include "base/basictypes.h"
#include "base/googleinit.h"
#include "base/logging.h"
#include <string.h>
// This file only makes sense with atomicops-internals-x86.h -- it
// depends on structs that are defined in that file. If atomicops.h
// doesn't sub-include that file, then we aren't needed, and shouldn't
// try to do anything.
#ifdef BASE_ATOMICOPS_INTERNALS_X86_H_
// Inline cpuid instruction. In PIC compilations, %ebx contains the address
// of the global offset table. To avoid breaking such executables, this code
// must preserve that register's value across cpuid instructions.
#if defined(__i386__)
#define cpuid(a, b, c, d, inp) \
asm ("mov %%ebx, %%edi\n" \
"cpuid\n" \
"xchg %%edi, %%ebx\n" \
: "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp))
#elif defined (__x86_64__)
#define cpuid(a, b, c, d, inp) \
asm ("mov %%rbx, %%rdi\n" \
"cpuid\n" \
"xchg %%rdi, %%rbx\n" \
: "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp))
#endif
#if defined(cpuid) // initialize the struct only on x86
// Set the flags so that code will run correctly and conservatively
// until InitGoogle() is called.
struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = {
false, // bug can't exist before process spawns multiple threads
false, // no SSE2
false, // no cmpxchg16b
};
// Initialize the AtomicOps_Internalx86CPUFeatures struct.
static void AtomicOps_Internalx86CPUFeaturesInit() {
uint32 eax;
uint32 ebx;
uint32 ecx;
uint32 edx;
// Get vendor string (issue CPUID with eax = 0)
cpuid(eax, ebx, ecx, edx, 0);
char vendor[13];
memcpy(vendor, &ebx, 4);
memcpy(vendor + 4, &edx, 4);
memcpy(vendor + 8, &ecx, 4);
vendor[12] = 0;
// get feature flags in ecx/edx, and family/model in eax
cpuid(eax, ebx, ecx, edx, 1);
int family = (eax >> 8) & 0xf; // family and model fields
int model = (eax >> 4) & 0xf;
if (family == 0xf) { // use extended family and model fields
family += (eax >> 20) & 0xff;
model += ((eax >> 16) & 0xf) << 4;
}
// Opteron Rev E has a bug in which on very rare occasions a locked
// instruction doesn't act as a read-acquire barrier if followed by a
// non-locked read-modify-write instruction. Rev F has this bug in
// pre-release versions, but not in versions released to customers,
// so we test only for Rev E, which is family 15, model 32..63 inclusive.
if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD
family == 15 &&
32 <= model && model <= 63) {
AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
} else {
AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
}
// edx bit 26 is SSE2 which we use to tell use whether we can use mfence
AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
// ecx bit 13 indicates whether the cmpxchg16b instruction is supported
AtomicOps_Internalx86CPUFeatures.has_cmpxchg16b = ((ecx >> 13) & 1);
}
REGISTER_MODULE_INITIALIZER(atomicops_x86, {
AtomicOps_Internalx86CPUFeaturesInit();
});
#endif
#endif /* ifdef BASE_ATOMICOPS_INTERNALS_X86_H_ */
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
* Author: Sanjay Ghemawat * Author: Sanjay Ghemawat
*/ */
// For atomic operations on statistics counters, see atomic_stats_counter.h.
// For atomic operations on sequence numbers, see atomic_sequence_num.h.
// For atomic operations on reference counts, see atomic_refcount.h.
// Some fast atomic operations -- typically with machine-dependent // Some fast atomic operations -- typically with machine-dependent
// implementations. This file may need editing as Google code is // implementations. This file may need editing as Google code is
// ported to different architectures. // ported to different architectures.
...@@ -79,14 +83,30 @@ ...@@ -79,14 +83,30 @@
// #else // #else
// # define AtomicWordCastType Atomic32 // # define AtomicWordCastType Atomic32
// #endif // #endif
// TODO(csilvers): figure out ARCH_PIII/ARCH_K8 (perhaps via ./configure?)
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
#include "base/arm_instruction_set_select.h"
// TODO(csilvers): match piii, not just __i386. Also, match k8
#if defined(__MACH__) && defined(__APPLE__) #if defined(__MACH__) && defined(__APPLE__)
#include "base/atomicops-internals-macosx.h" #include "base/atomicops-internals-macosx.h"
#elif defined(__GNUC__) && defined(ARMV6)
#include "base/atomicops-internals-arm-v6plus.h"
#elif defined(ARMV3)
#include "base/atomicops-internals-arm-generic.h"
#elif defined(_WIN32) #elif defined(_WIN32)
#include "base/atomicops-internals-windows.h" #include "base/atomicops-internals-windows.h"
#elif defined(__GNUC__) && (defined(__i386) || defined(__x86_64__))
#include "base/atomicops-internals-x86.h"
#elif defined(__linux__) && defined(__PPC__)
#include "base/atomicops-internals-linuxppc.h"
#else #else
#include "base/atomicops_internals_portable.h" // Assume x86 for now. If you need to support a new architecture and
// don't know how to implement atomic ops, you can probably get away
// with using pthreads, since atomicops is only used by spinlock.h/cc
//#error You need to implement atomic operations for this architecture
#include "base/atomicops-internals-x86.h"
#endif #endif
// Signed type that can hold a pointer and supports the atomic ops below, as // Signed type that can hold a pointer and supports the atomic ops below, as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment