Skip to content

Commit

Permalink
* Enhance cycleclock on ARM v6 and above (sanek)
Browse files Browse the repository at this point in the history
	* Reduce object copying by using a reference (nherring)
	* Modified lock annotations a bit (lcwu)
	* Make debugallocation test a bit more forgiving (csilvers)
	* Count .dll/.dylib as shared libs in heapchecker (csilvers)
	* Disable sys_futex for arm (sanek)
	* Don't use macros as much in windows/port.h (andrey.s...)
	* Update #includes in case malloc.h is in weird places (csilvers)
	* Turn off some not-so-useful warnings in gcc 4 (csilvers)
	* Do some casting to make solaris happier about types (csilvers)
	* Disable debugallocation_test in 'minimal' mode (csilvers)
	* Rewrite debugallocation to be more modular (csilvers)
        * We can't run the heap-checker under valgrind (ppluzhnikov)


git-svn-id: http://gperftools.googlecode.com/svn/trunk@106 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
  • Loading branch information
csilvers committed Mar 2, 2011
1 parent c1abbfa commit 7558413
Show file tree
Hide file tree
Showing 26 changed files with 921 additions and 612 deletions.
8 changes: 7 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ AM_CXXFLAGS =
# builtins now in any case, but it's best to be explicit in case that
# changes one day. gcc ignores functions it doesn't understand.
if GCC
AM_CXXFLAGS += -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare \
AM_CXXFLAGS += -Wall -Wwrite-strings -Woverloaded-virtual \
-Wno-sign-compare -Wno-unused-result \
-fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc \
-fno-builtin-calloc -fno-builtin-cfree \
-fno-builtin-memalign -fno-builtin-posix_memalign \
Expand Down Expand Up @@ -162,6 +163,7 @@ SYSINFO_INCLUDES = src/base/sysinfo.h \
src/base/logging.h \
src/base/commandlineflags.h \
src/base/cycleclock.h \
src/base/arm_instruction_set_select.h \
src/base/basictypes.h
noinst_LTLIBRARIES += libsysinfo.la
libsysinfo_la_SOURCES = src/base/sysinfo.cc \
Expand Down Expand Up @@ -716,6 +718,9 @@ realloc_debug_unittest_CXXFLAGS = $(realloc_unittest_CXXFLAGS)
realloc_debug_unittest_LDFLAGS = $(realloc_unittest_LDFLAGS)
realloc_debug_unittest_LDADD = libtcmalloc_minimal_debug.la $(PTHREAD_LIBS)

# debugallocation_test checks that we print a proper stacktrace when
# debug-allocs fail, so we can't run it if we don't have stacktrace info.
if WITH_STACK_TRACE
TESTS += debugallocation_test.sh$(EXEEXT)
debugallocation_test_sh_SOURCES = src/tests/debugallocation_test.sh
noinst_SCRIPTS += $(debugallocation_test_sh_SOURCES)
Expand All @@ -730,6 +735,7 @@ debugallocation_test_SOURCES = src/tests/debugallocation_test.cc
debugallocation_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
debugallocation_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
debugallocation_test_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS)
endif WITH_STACK_TRACE

endif WITH_DEBUGALLOC

Expand Down
184 changes: 98 additions & 86 deletions Makefile.in

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -15004,6 +15004,30 @@ fi

done
# some systems define stuff there, others not
for ac_header in sys/malloc.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "sys/malloc.h" "ac_cv_header_sys_malloc_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_malloc_h" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_SYS_MALLOC_H 1
_ACEOF

fi

done
# where some versions of OS X put malloc.h
for ac_header in malloc/malloc.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "malloc/malloc.h" "ac_cv_header_malloc_malloc_h" "$ac_includes_default"
if test "x$ac_cv_header_malloc_malloc_h" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_MALLOC_MALLOC_H 1
_ACEOF

fi

done
# another place OS X puts malloc.h (?)
for ac_header in glob.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "glob.h" "ac_cv_header_glob_h" "$ac_includes_default"
Expand Down Expand Up @@ -16996,7 +17020,7 @@ fi


# Write generated configuration file
ac_config_files="$ac_config_files Makefile src/google/tcmalloc.h"
ac_config_files="$ac_config_files Makefile src/google/tcmalloc.h src/windows/google/tcmalloc.h"

cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
Expand Down Expand Up @@ -18115,6 +18139,7 @@ do
"libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"src/google/tcmalloc.h") CONFIG_FILES="$CONFIG_FILES src/google/tcmalloc.h" ;;
"src/windows/google/tcmalloc.h") CONFIG_FILES="$CONFIG_FILES src/windows/google/tcmalloc.h" ;;

*) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory
AC_CHECK_FUNCS(geteuid) # for turning off services when run as root
AC_CHECK_HEADERS(features.h) # for vdso_support.h
AC_CHECK_HEADERS(malloc.h) # some systems define stuff there, others not
AC_CHECK_HEADERS(sys/malloc.h) # where some versions of OS X put malloc.h
AC_CHECK_HEADERS(malloc/malloc.h) # another place OS X puts malloc.h (?)
AC_CHECK_HEADERS(glob.h) # for heap-profile-table (cleaning up profiles)
AC_CHECK_HEADERS(execinfo.h) # for stacktrace? and heapchecker_unittest
AC_CHECK_HEADERS(libunwind.h) # for stacktrace
Expand Down Expand Up @@ -359,5 +361,5 @@ AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \
"$enable_heap_checker" = yes)

# Write generated configuration file
AC_CONFIG_FILES([Makefile src/google/tcmalloc.h])
AC_CONFIG_FILES([Makefile src/google/tcmalloc.h src/windows/google/tcmalloc.h])
AC_OUTPUT
79 changes: 79 additions & 0 deletions src/base/arm_instruction_set_select.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2011, 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.
//
// Author: Alexander Levitskiy
//
// Generalizes the plethora of ARM flavors available to an easier to manage set
// Defs reference is at https://wiki.edubuntu.org/ARM/Thumb2PortingHowto

#ifndef ARM_INSTRUCTION_SET_SELECT_H_
#define ARM_INSTRUCTION_SET_SELECT_H_

#if defined(__ARM_ARCH_7__) || \
defined(__ARM_ARCH_7R__) || \
defined(__ARM_ARCH_7A__)
# define ARMV7 1
#endif

#if defined(ARMV7) || \
defined(__ARM_ARCH_6__) || \
defined(__ARM_ARCH_6J__) || \
defined(__ARM_ARCH_6K__) || \
defined(__ARM_ARCH_6Z__) || \
defined(__ARM_ARCH_6T2__) || \
defined(__ARM_ARCH_6ZK__)
# define ARMV6 1
#endif

#if defined(ARMV6) || \
defined(__ARM_ARCH_5T__) || \
defined(__ARM_ARCH_5E__) || \
defined(__ARM_ARCH_5TE__) || \
defined(__ARM_ARCH_5TEJ__)
# define ARMV5 1
#endif

#if defined(ARMV5) || \
defined(__ARM_ARCH_4__) || \
defined(__ARM_ARCH_4T__)
# define ARMV4 1
#endif

#if defined(ARMV4) || \
defined(__ARM_ARCH_3__) || \
defined(__ARM_ARCH_3M__)
# define ARMV3 1
#endif

#if defined(ARMV3) || \
defined(__ARM_ARCH_2__)
# define ARMV2 1
#endif

#endif // ARM_INSTRUCTION_SET_SELECT_H_
35 changes: 22 additions & 13 deletions src/base/cycleclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
#define GOOGLE_BASE_CYCLECLOCK_H_

#include "base/basictypes.h" // make sure we get the def for int64
#include "base/arm_instruction_set_select.h"
#if defined(__MACH__) && defined(__APPLE__)
# include <mach/mach_time.h>
#elif defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_3__)
# include <sys/time.h>
#endif
#include <sys/time.h>

// NOTE: only i386 and x86_64 have been well tested.
// PPC, sparc, alpha, and ia64 are based on
Expand Down Expand Up @@ -99,20 +99,29 @@ struct CycleClock {
return itc;
#elif defined(_MSC_VER) && defined(_M_IX86)
_asm rdtsc

// If none of the above cases trigger, we use a solution based on
// a system call (gettimeofday or similar). We do these in order
// from fastest to slowest. We do not have an '#else' catch-all
// case here that just calls gettimeofday(); that system call is
// slow, and this function is expected to be fast, so we don't want
// to use it without an explicit decision that it's the only way.
#elif defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_3__)
#elif defined(ARMV3)
#if defined(ARMV6) // V6 is the earliest arch that has a standard cyclecount
uint32 pmccntr;
uint32 pmuseren;
uint32 pmcntenset;
// Read the user mode perf monitor counter access permissions.
asm("mrc p15, 0, %0, c9, c14, 0" : "=r" (pmuseren));
if (pmuseren & 1) { // Allows reading perfmon counters for user mode code.
asm("mrc p15, 0, %0, c9, c12, 1" : "=r" (pmcntenset));
if (pmcntenset & 0x80000000ul) { // Is it counting?
asm("mrc p15, 0, %0, c9, c13, 0" : "=r" (pmccntr));
// The counter is set up to count every 64th cycle
return static_cast<int64>(pmccntr) * 64; // Should optimize to << 6
}
}
#endif
struct timeval tv;
gettimeofday(&tv, NULL);
return static_cast<uint64>(tv.tv_sec) * 1000000 + tv.tv_usec;
return static_cast<int64>(tv.tv_sec) * 1000000 + tv.tv_usec;
#else
// We could define __alpha here as well, but it only has a 32-bit
// timer (good for like 4 seconds), which isn't very useful.
// The soft failover to a generic implementation is automatic only for ARM.
// For other platforms the developer is expected to make an attempt to create
// a fast implementation and use generic version if nothing better is available.
#error You need to define CycleTimer for your O/S and CPU
#endif
}
Expand Down
11 changes: 10 additions & 1 deletion src/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
#define WRITE_TO_STDERR(buf, len) write(STDERR_FILENO, buf, len)
#endif

// MSVC and mingw define their own, safe version of vnsprintf (the
// windows one in broken) in port.cc. Everyone else can use the
// version here. We had to give it a unique name for windows.
#ifndef _WIN32
# define perftools_vsnprintf vsnprintf
#endif


// We log all messages at this log-level and below.
// INFO == -1, WARNING == -2, ERROR == -3, FATAL == -4
Expand Down Expand Up @@ -191,7 +198,7 @@ inline void LogPrintf(int severity, const char* pat, va_list ap) {
// We write directly to the stderr file descriptor and avoid FILE
// buffering because that may invoke malloc()
char buf[600];
vsnprintf(buf, sizeof(buf)-1, pat, ap);
perftools_vsnprintf(buf, sizeof(buf)-1, pat, ap);
if (buf[0] != '\0' && buf[strlen(buf)-1] != '\n') {
assert(strlen(buf)+1 < sizeof(buf));
strcat(buf, "\n");
Expand Down Expand Up @@ -233,7 +240,9 @@ inline void LOG_IF(int lvl, bool cond, const char* pat, ...) {
// Like other "raw" routines, these functions are best effort, and
// thus don't return error codes (except RawOpenForWriting()).
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__)
#ifndef NOMINMAX
#define NOMINMAX // @#!$& windows
#endif
#include <windows.h>
typedef HANDLE RawFD;
const RawFD kIllegalRawFD = INVALID_HANDLE_VALUE;
Expand Down
4 changes: 2 additions & 2 deletions src/base/low_level_alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static const intptr_t kMagicAllocated = 0x4c833e95;
static const intptr_t kMagicUnallocated = ~kMagicAllocated;

namespace {
class ArenaLock {
class SCOPED_LOCKABLE ArenaLock {
public:
explicit ArenaLock(LowLevelAlloc::Arena *arena)
EXCLUSIVE_LOCK_FUNCTION(arena->mu)
Expand All @@ -233,7 +233,7 @@ namespace {
this->arena_->mu.Lock();
}
~ArenaLock() { RAW_CHECK(this->left_, "haven't left Arena region"); }
void Leave() UNLOCK_FUNCTION(arena_->mu) {
void Leave() UNLOCK_FUNCTION() {
this->arena_->mu.Unlock();
#if 0
if (this->mask_valid_) {
Expand Down
5 changes: 5 additions & 0 deletions src/base/spinlock_linux-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ static struct InitModule {
int x = 0;
// futexes are ints, so we can use them only when
// that's the same size as the lockword_ in SpinLock.
#ifdef __arm__
// ARM linux doesn't support sys_futex1(void*, int, int, struct timespec*);
have_futex = 0;
#else
have_futex = (sizeof (Atomic32) == sizeof (int) &&
sys_futex(&x, FUTEX_WAKE, 1, 0) >= 0);
#endif
if (have_futex &&
sys_futex(&x, FUTEX_WAKE | futex_private_flag, 1, 0) < 0) {
futex_private_flag = 0;
Expand Down
1 change: 0 additions & 1 deletion src/base/stl_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <stddef.h> // for ptrdiff_t
#include <limits>

#include "base/basictypes.h"
#include "base/logging.h"

// Generic allocator class for STL objects
Expand Down
8 changes: 6 additions & 2 deletions src/base/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ static int64 EstimateCyclesPerSecond(const int estimate_time_ms) {
return guess;
}

// ReadIntFromFile is only called on linux and cygwin platforms.
#if defined(__linux__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
// Helper function for reading an int from a file. Returns true if successful
// and the memory location pointed to by value is set to the value read.
static bool ReadIntFromFile(const char *file, int *value) {
Expand All @@ -250,6 +252,7 @@ static bool ReadIntFromFile(const char *file, int *value) {
}
return ret;
}
#endif

// WARNING: logging calls back to InitializeSystemInfo() so it must
// not invoke any logging code. Also, InitializeSystemInfo() can be
Expand Down Expand Up @@ -491,7 +494,7 @@ static void ConstructFilename(const char* spec, pid_t pid,
char* buf, int buf_size) {
CHECK_LT(snprintf(buf, buf_size,
spec,
pid ? pid : getpid()), buf_size);
static_cast<int>(pid ? pid : getpid())), buf_size);
}
#endif

Expand Down Expand Up @@ -804,7 +807,8 @@ bool ProcMapsIterator::NextExt(uint64 *start, uint64 *end, char **flags,
Buffer::kBufSize);
} else {
CHECK_LT(snprintf(object_path.buf_, Buffer::kBufSize,
"/proc/%d/path/%s", pid_, mapinfo->pr_mapname),
"/proc/%d/path/%s",
static_cast<int>(pid_), mapinfo->pr_mapname),
Buffer::kBufSize);
}
ssize_t len = readlink(object_path.buf_, current_filename_, PATH_MAX);
Expand Down
6 changes: 6 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H

/* Define to 1 if you have the <malloc/malloc.h> header file. */
#undef HAVE_MALLOC_MALLOC_H

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

Expand Down Expand Up @@ -119,6 +122,9 @@
/* Define to 1 if the system has the type `struct mallinfo'. */
#undef HAVE_STRUCT_MALLINFO

/* Define to 1 if you have the <sys/malloc.h> header file. */
#undef HAVE_SYS_MALLOC_H

/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H

Expand Down
Loading

0 comments on commit 7558413

Please sign in to comment.