Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Makefile: Link tcmalloc if present in the system

This patch links tcmalloc or tcmalloc_minimal libraries if the system has
libtcmalloc or libtcmalloc_minimal. Using tcmalloc reduces the time to run
EntryTest by 2%.

Before:

$ perf stat -r 10 -- ./jato -cp test/functional/ jvm/EntryTest

 Performance counter stats for './jato -cp test/functional/ jvm/EntryTest' (10 runs):

           743,314 cache-misses             #      0.914 M/sec   ( +-   2.399% )  (scaled from 33.38%)
        18,292,874 cache-references         #     22.493 M/sec   ( +-   1.037% )  (scaled from 33.57%)
         7,372,729 branch-misses            #      2.111 %       ( +-   1.053% )  (scaled from 33.80%)
       349,330,853 branches                 #    429.531 M/sec   ( +-   0.382% )  (scaled from 33.95%)
     1,871,598,945 instructions             #      1.161 IPC     ( +-   0.495% )  (scaled from 33.51%)
     1,611,909,200 cycles                   #   1981.977 M/sec   ( +-   0.241% )  (scaled from 33.16%)
             8,912 page-faults              #      0.011 M/sec   ( +-   0.003% )
                 0 CPU-migrations           #      0.000 M/sec   ( +-    -nan% )
               143 context-switches         #      0.000 M/sec   ( +-   0.865% )
        813.283612 task-clock-msecs         #      0.977 CPUs    ( +-   0.095% )

        0.832314016  seconds time elapsed   ( +-   0.131% )

After:

$ sync && perf stat -r 10 -- ./jato -cp test/functional/ jvm/EntryTest

 Performance counter stats for './jato -cp test/functional/ jvm/EntryTest' (10 runs):

           824,176 cache-misses             #      1.042 M/sec   ( +-   2.234% )  (scaled from 33.37%)
        18,027,516 cache-references         #     22.802 M/sec   ( +-   1.645% )  (scaled from 33.86%)
         6,414,001 branch-misses            #      1.961 %       ( +-   1.353% )  (scaled from 34.09%)
       327,051,906 branches                 #    413.671 M/sec   ( +-   0.356% )  (scaled from 33.55%)
     1,775,159,432 instructions             #      1.139 IPC     ( +-   0.560% )  (scaled from 33.12%)
     1,558,045,501 cycles                   #   1970.691 M/sec   ( +-   0.211% )  (scaled from 33.31%)
             9,631 page-faults              #      0.012 M/sec   ( +-   0.003% )
                 0 CPU-migrations           #      0.000 M/sec   ( +-    -nan% )
               138 context-switches         #      0.000 M/sec   ( +-   0.923% )
        790.608790 task-clock-msecs         #      0.976 CPUs    ( +-   0.087% )

        0.809892157  seconds time elapsed   ( +-   0.096% )

Signed-off-by: Ana Farcasi <farcasia@gmail.com>
[ penberg@kernel.org: cleanup, fix scripts/gcc-has-lib.sh ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
  • Loading branch information...
commit a7f249964e6b3f32ed2260175a1a55d8f5e20418 1 parent b2baae3
@farcasia farcasia authored committed
Showing with 22 additions and 0 deletions.
  1. +11 −0 Makefile
  2. +11 −0 scripts/gcc-has-lib.sh
View
11 Makefile
@@ -171,6 +171,17 @@ endif
DEFAULT_CFLAGS += $(ARCH_CFLAGS) -g -rdynamic -std=gnu99 -D_GNU_SOURCE -fstack-protector-all -D_FORTIFY_SOURCE=2
+HAS_TCMALLOC_MINIMAL:=$(shell scripts/gcc-has-lib.sh gcc tcmalloc_minimal)
+ifeq ($(HAS_TCMALLOC_MINIMAL),y)
+ TCMALLOC_CFLAGS += -ltcmalloc_minimal -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
+endif
+
+HAS_TCMALLOC:=$(shell scripts/gcc-has-lib.sh gcc tcmalloc)
+ifeq ($(HAS_TCMALLOC),y)
+ TCMALLOC_CFLAGS += -ltcmalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
+endif
+
+DEFAULT_CFLAGS += $(TCMALLOC_CFLAGS)
# boehmgc integration (see boehmgc/doc/README.linux)
DEFAULT_CFLAGS += -D_REENTRANT -DGC_LINUX_THREADS -DGC_USE_LD_WRAP
View
11 scripts/gcc-has-lib.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+GCC=$1
+LIB=$2
+
+echo "int main(int argc, char *argv[]) {return 0;}" | gcc -l$LIB -x c - > /dev/null 2>&1
+if [ "$?" -eq "0" ] ; then
+ echo y
+else
+ echo n
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.