From: Willy Tarreau Date: Fri, 2 Apr 2021 12:57:42 +0000 (+0200) Subject: ADMIN: halog: automatically enable USE_MEMCHR on the right glibc version X-Git-Tag: v2.4-dev15~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4710e14fecea09ea52c349bc6cbb09ed5464548;p=thirdparty%2Fhaproxy.git ADMIN: halog: automatically enable USE_MEMCHR on the right glibc version There has been a USE_MEMCHR option for ages that was mostly never enabled because it was unclear when glibc became faster. A quick look at the code indicates that this arrived with the SSE implementation of memchr() which arrived at commit 093ecf92998de2 between 2.14 and 2.15, so let's automatically turn this on on x86_64 with glibc >= 2.15. This results in ~6GB of logs read per second (20 million lines) and ~2.5GB/s (8 million lines) parsed for errors or status codes classification, or 1 GB/s (3 million lines) for time percentiles. --- diff --git a/admin/halog/fgets2.c b/admin/halog/fgets2.c index 776a91538e..3634f5576a 100644 --- a/admin/halog/fgets2.c +++ b/admin/halog/fgets2.c @@ -34,6 +34,11 @@ #define FGETS2_BUFSIZE (256*1024) #endif +/* memchr() is faster in glibc with SSE since commit 093ecf92998de2 */ +#if defined(__x86_64__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 15)) +#define USE_MEMCHR +#endif + /* return non-zero if the integer contains at least one zero byte */ static inline __attribute__((unused)) unsigned int has_zero32(unsigned int x) {