summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-10-26 13:09:59 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-10-26 13:09:59 +0200
commita000bd661e0459524bd146a803e17df813350d92 (patch)
treef737c83b8d532490590011fef17f4220157e2b60
parent244e4571849aef4ea0c26c398ba056ea7d641592 (diff)
downloadrsyslog-a000bd661e0459524bd146a803e17df813350d92.tar.gz
rsyslog-a000bd661e0459524bd146a803e17df813350d92.tar.bz2
rsyslog-a000bd661e0459524bd146a803e17df813350d92.zip
slight performance optimization if GCC is used
We give branch prediction hints for the frequent RETiRet macro which is used for error handling. Some slight performance gain is to be expected from that.
-rw-r--r--ChangeLog4
-rw-r--r--configure.ac8
-rw-r--r--runtime/rsyslog.h7
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ca88982f..b0b974e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
---------------------------------------------------------------------------
Version 7.5.6 [devel] 2013-10-??
+- slight performance optimization if GCC is used
+ We give branch prediction hints for the frequent RETiRet macro which is
+ used for error handling. Some slight performance gain is to be expected
+ from that.
- removed global variable support
The original idea was not well thought out and global variables, as
implemented, worked far different from what anybody would expect. As
diff --git a/configure.ac b/configure.ac
index 2f23147b..ebf35190 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,6 +153,14 @@ AC_TRY_COMPILE([
AC_MSG_RESULT(no; defined as 64)
)
+# Check for __builtin_expect()
+AC_MSG_CHECKING([for __builtin_expect()])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, return __builtin_expect(main != 0, 1))],
+ [AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
+ Define to 1 if compiler supports __builtin_expect)
+ AC_MSG_RESULT([yes])],
+ [AC_MSG_RESULT([no])])
+
# check for availability of atomic operations
RS_ATOMIC_OPERATIONS
RS_ATOMIC_OPERATIONS_64BIT
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 71849bec..85381b8d 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -445,7 +445,12 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
* Be sure to call the to-be-returned variable always "iRet" and
* the function finalizer always "finalize_it".
*/
-#define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
+#if HAVE_BUILTIN_EXCEPT
+# define CHKiRet(code) if(__builtin_expect(((iRet = code) != RS_RET_OK), 0)) goto finalize_it
+#else
+# define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
+#endif
+
/* macro below is to be used if we need our own handling, eg for cleanup */
#define CHKiRet_Hdlr(code) if((iRet = code) != RS_RET_OK)
/* macro below is to handle failing malloc/calloc/strdup... which we almost always handle in the same way... */