|
From: <sv...@va...> - 2012-09-02 20:26:31
|
philippe 2012-09-02 21:26:23 +0100 (Sun, 02 Sep 2012)
New Revision: 12939
Log:
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).
Modified files:
trunk/callgrind/bbcc.c
trunk/callgrind/global.h
Modified: trunk/callgrind/global.h (+3 -3)
===================================================================
--- trunk/callgrind/global.h 2012-09-02 21:12:14 +01:00 (rev 12938)
+++ trunk/callgrind/global.h 2012-09-02 21:26:23 +01:00 (rev 12939)
@@ -843,8 +843,8 @@
#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 @@
}
#define CLG_ASSERT(cond) \
- if (!(cond)) { \
+ if (UNLIKELY(!(cond))) { \
CLG_(print_context)(); \
CLG_(print_bbno)(); \
tl_assert(cond); \
Modified: trunk/callgrind/bbcc.c (+6 -1)
===================================================================
--- trunk/callgrind/bbcc.c 2012-09-02 21:12:14 +01:00 (rev 12938)
+++ trunk/callgrind/bbcc.c 2012-09-02 21:26:23 +01:00 (rev 12939)
@@ -571,7 +571,12 @@
*/
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
|