]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Improve callgrind performance by 4 to 8% using UNLIKELY
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 2 Sep 2012 20:26:23 +0000 (20:26 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 2 Sep 2012 20:26:23 +0000 (20:26 +0000)
Performance improvements from 4 to 8% obtained on amd64 on the perf tests by:
1. using UNLIKELY inside tracing macros
2. avoid calling CLG_(switch_thread)(tid) on the hot patch setup_bbcc
   unless tid differs from CLG_(current_tid).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12939

callgrind/bbcc.c
callgrind/global.h

index 22dc16f6e0baa718e0d2d9689066bf78784ca5ac..ad8a76d4908f1cfb785341981af61e476c33e5b6 100644 (file)
@@ -571,7 +571,12 @@ void CLG_(setup_bbcc)(BB* bb)
    */
   tid = VG_(get_running_tid)();
 #if 1
-  CLG_(switch_thread)(tid);
+  /* CLG_(switch_thread) is a no-op when tid is equal to CLG_(current_tid).
+   * As this is on the hot path, we only call CLG_(switch_thread)(tid)
+   * if tid differs from the CLG_(current_tid).
+   */
+  if (UNLIKELY(tid != CLG_(current_tid)))
+     CLG_(switch_thread)(tid);
 #else
   CLG_ASSERT(VG_(get_running_tid)() == CLG_(current_tid));
 #endif
index b10165d9264b30f9d78d34284960ffaf1351181e..a848d4c0aa009b6c7f75f515d41ff367ed8382bd 100644 (file)
@@ -843,8 +843,8 @@ extern ThreadId   CLG_(current_tid);
 #if CLG_ENABLE_DEBUG
 
 #define CLG_DEBUGIF(x) \
-  if ( (CLG_(clo).verbose >x) && \
-       (CLG_(stat).bb_executions >= CLG_(clo).verbose_start))
+  if (UNLIKELY( (CLG_(clo).verbose >x) && \
+                (CLG_(stat).bb_executions >= CLG_(clo).verbose_start)))
 
 #define CLG_DEBUG(x,format,args...)   \
     CLG_DEBUGIF(x) {                  \
@@ -853,7 +853,7 @@ extern ThreadId   CLG_(current_tid);
     }
 
 #define CLG_ASSERT(cond)              \
-    if (!(cond)) {                    \
+    if (UNLIKELY(!(cond))) {          \
       CLG_(print_context)();          \
       CLG_(print_bbno)();            \
       tl_assert(cond);                \