From: Philippe Waroquiers Date: Sun, 2 Sep 2012 20:26:23 +0000 (+0000) Subject: Improve callgrind performance by 4 to 8% using UNLIKELY X-Git-Tag: svn/VALGRIND_3_9_0~710 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=613012246f2fb83e2188398a424c8522e08ed841;p=thirdparty%2Fvalgrind.git Improve callgrind performance by 4 to 8% using UNLIKELY 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 --- diff --git a/callgrind/bbcc.c b/callgrind/bbcc.c index 22dc16f6e0..ad8a76d490 100644 --- a/callgrind/bbcc.c +++ b/callgrind/bbcc.c @@ -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 diff --git a/callgrind/global.h b/callgrind/global.h index b10165d926..a848d4c0aa 100644 --- a/callgrind/global.h +++ b/callgrind/global.h @@ -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); \