From a000bd661e0459524bd146a803e17df813350d92 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 26 Oct 2013 13:09:59 +0200 Subject: 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. --- ChangeLog | 4 ++++ configure.ac | 8 ++++++++ runtime/rsyslog.h | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) 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... */ -- cgit v1.2.3 From 200b43431695d3d4cccadafb2a37373fc55af0bb Mon Sep 17 00:00:00 2001 From: Pavel Levshin Date: Sat, 26 Oct 2013 14:57:37 +0400 Subject: Make use of int64 json numbers, if available --- configure.ac | 4 ++++ grammar/rainerscript.c | 4 ++++ plugins/ommongodb/ommongodb.c | 5 ++++- runtime/msg.c | 8 ++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ebf35190..30c4559b 100644 --- a/configure.ac +++ b/configure.ac @@ -37,6 +37,10 @@ PKG_CHECK_MODULES([JSON_C], [json],, [ PKG_CHECK_MODULES([JSON_C], [json-c]) ]) +# if int64 is supported, use it +AC_CHECK_LIB(json-c, json_object_new_object,,) +AC_CHECK_FUNCS(json_object_new_int64,,) + case "${host}" in *-*-linux*) AC_DEFINE([OS_LINUX], [1], [Indicator for a Linux OS]) diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 4da49798..a2bed2bf 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1202,7 +1202,11 @@ var2Number(struct var *r, int *bSuccess) n = es_str2num(r->d.estr, bSuccess); } else { if(r->datatype == 'J') { +#ifdef HAVE_JSON_OBJECT_NEW_INT64 + n = (r->d.json == NULL) ? 0 : json_object_get_int64(r->d.json); +#else /* HAVE_JSON_OBJECT_NEW_INT64 */ n = (r->d.json == NULL) ? 0 : json_object_get_int(r->d.json); +#endif /* HAVE_JSON_OBJECT_NEW_INT64 */ } else { n = r->d.n; } diff --git a/plugins/ommongodb/ommongodb.c b/plugins/ommongodb/ommongodb.c index ecfd2518..a7c42010 100644 --- a/plugins/ommongodb/ommongodb.c +++ b/plugins/ommongodb/ommongodb.c @@ -311,8 +311,11 @@ BSONAppendJSONObject(bson *doc, const gchar *name, struct json_object *json) case json_type_int: { int64_t i; - /* FIXME: the future version will have get_int64 */ +#ifdef HAVE_JSON_OBJECT_NEW_INT64 + i = json_object_get_int64(json); +#else /* HAVE_JSON_OBJECT_NEW_INT64 */ i = json_object_get_int(json); +#endif /* HAVE_JSON_OBJECT_NEW_INT64 */ if (i >= INT32_MIN && i <= INT32_MAX) return bson_append_int32(doc, name, i); else diff --git a/runtime/msg.c b/runtime/msg.c index e30ff671..9f5bcde2 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -4140,7 +4140,11 @@ jsonDeepCopy(struct json_object *src) dst = json_object_new_double(json_object_get_double(src)); break; case json_type_int: +#ifdef HAVE_JSON_OBJECT_NEW_INT64 + dst = json_object_new_int64(json_object_get_int64(src)); +#else /* HAVE_JSON_OBJECT_NEW_INT64 */ dst = json_object_new_int(json_object_get_int(src)); +#endif /* HAVE_JSON_OBJECT_NEW_INT64 */ break; case json_type_string: dst = json_object_new_string(json_object_get_string(src)); @@ -4183,7 +4187,11 @@ msgSetJSONFromVar(msg_t *pMsg, uchar *varname, struct var *v) free(cstr); break; case 'N':/* number (integer) */ +#ifdef HAVE_JSON_OBJECT_NEW_INT64 + json = json_object_new_int64(v->d.n); +#else /* HAVE_JSON_OBJECT_NEW_INT64 */ json = json_object_new_int((int) v->d.n); +#endif /* HAVE_JSON_OBJECT_NEW_INT64 */ break; case 'J':/* native JSON */ json = jsonDeepCopy(v->d.json); -- cgit v1.2.3 From f5155a74696c4e1bf367541a093351f47c439b38 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 26 Oct 2013 15:42:18 +0200 Subject: doc: add enhancement to ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index b0b974e4..e3b18b8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ --------------------------------------------------------------------------- Version 7.5.6 [devel] 2013-10-?? +- RainerScript: make use of 64 bit for numbers where available + Thanks to Pavel Levshin for enhancement. - 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 -- cgit v1.2.3 From 4acf8e361aa68b3e753611c7c7e607c04dfd8d1a Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 26 Oct 2013 15:45:48 +0200 Subject: make rsyslog version output include the number of bits used for RainerScript --- tools/syslogd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/syslogd.c b/tools/syslogd.c index fba60df5..aaeb9866 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -1342,6 +1342,11 @@ static void printVersion(void) printf("\tuuid support:\t\t\t\tYes\n"); #else printf("\tuuid support:\t\t\t\tNo\n"); +#endif +#ifdef HAVE_JSON_OBJECT_NEW_INT64 + printf("\tNumber of Bits in RainerScript integers: 64\n"); +#else + printf("\tNumber of Bits in RainerScript integers: 32 (due to too-old json-c lib)\n"); #endif printf("\nSee http://www.rsyslog.com for more information.\n"); } -- cgit v1.2.3 From 6106c05fcfbb8fe744108e4c3a66948b66f560f8 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 26 Oct 2013 16:02:42 +0200 Subject: require libestr 0.1.9 --- ChangeLog | 2 ++ configure.ac | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 511c66b1..014dacc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ --------------------------------------------------------------------------- Version 7.4.6 [v7.4-stable] 2013-11-?? +- now requires libestr 0.1.9 as earlier versions lead to problems with + number handling in RainerScript - bugfix: memory leak in strlen() RainerScript function Thanks to Gregoire Seux for reportig this bug. closes: http://bugzilla.adiscon.com/show_bug.cgi?id=486 diff --git a/configure.ac b/configure.ac index c57df5f5..e253c916 100644 --- a/configure.ac +++ b/configure.ac @@ -32,7 +32,7 @@ AC_CANONICAL_HOST PKG_PROG_PKG_CONFIG # modules we require -PKG_CHECK_MODULES(LIBESTR, libestr >= 0.1.8) +PKG_CHECK_MODULES(LIBESTR, libestr >= 0.1.9) PKG_CHECK_MODULES([JSON_C], [json],, [ PKG_CHECK_MODULES([JSON_C], [json-c]) ]) -- cgit v1.2.3