From: Vsevolod Stakhov Date: Mon, 7 Dec 2015 15:24:41 +0000 (+0000) Subject: Add hyperscan initialization X-Git-Tag: 1.1.0~388 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=813685c8e0fa11bb1458823d396079c9c3470c7a;p=rspamd.git Add hyperscan initialization --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 96118f12d..2088e2776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,10 @@ OPTION(ENABLE_SNOWBALL "Enable snowball stemmer [default: ON]" OPTION(ENABLE_CLANG_PLUGIN "Enable clang static analysing plugin [default: OFF]" OFF) OPTION(ENABLE_HYPERSCAN "Enable hyperscan for fast regexp processing [default: OFF]" OFF) + +IF (ENABLE_HYPERSCAN MATCHES "ON") + ENABLE_LANGUAGE(CXX) +ENDIF() # Build optimized code for following CPU (default i386) #SET(CPU_TUNE "i686") @@ -891,6 +895,7 @@ TRY_RUN(_CAN_RUN _CAN_COMPILE CMAKE_FLAGS CMAKE_C_FLAGS="-pthread") IF(_CAN_RUN EQUAL 1) SET(HAVE_PTHREAD_PROCESS_SHARED 1 CACHE INTERNAL "") + SET(RSPAMD_REQUIRED_LIBRARIES "${RSPAMD_REQUIRED_LIBRARIES} -lpthread") ENDIF(_CAN_RUN EQUAL 1) IF(HAVE_PTHREAD_PROCESS_SHARED) MESSAGE(STATUS "pthread_mutexattr_setpshared is supported") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a99b6e7ac..acc91b673 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,6 +125,7 @@ TARGET_LINK_LIBRARIES(rspamd rspamd-actrie) IF (ENABLE_HYPERSCAN MATCHES "ON") TARGET_LINK_LIBRARIES(rspamd hs) + SET_TARGET_PROPERTIES(rspamd PROPERTIES LINKER_LANGUAGE CXX) ENDIF() TARGET_LINK_LIBRARIES(rspamd ${RSPAMD_REQUIRED_LIBRARIES}) diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 84f4bbc5d..8a6f37119 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -30,6 +30,9 @@ #include "libserver/url.h" #include "libserver/task.h" #include "libutil/util.h" +#ifdef WITH_HYPERSCAN +#include "hs.h" +#endif struct rspamd_re_class { guint64 id; @@ -38,6 +41,10 @@ struct rspamd_re_class { gsize type_len; GHashTable *re; gchar hash[rspamd_cryptobox_HASHBYTES * 2 + 1]; +#ifdef WITH_HYPERSCAN + hs_database_t *hs_db; + +#endif }; struct rspamd_re_cache { @@ -45,6 +52,9 @@ struct rspamd_re_cache { ref_entry_t ref; guint nre; guint max_re_data; +#ifdef WITH_HYPERSCAN + hs_platform_info_t plt; +#endif }; struct rspamd_re_runtime { @@ -208,6 +218,40 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache) rspamd_snprintf (re_class->hash, sizeof (re_class->hash), "%*xs", (gint)rspamd_cryptobox_HASHBYTES, hash_out); } + +#ifdef WITH_HYPERSCAN + const gchar *platform = "generic"; + rspamd_fstring_t *features = rspamd_fstring_new (); + + g_assert (hs_populate_platform (&cache->plt) == HS_SUCCESS); + + /* Now decode what we do have */ + switch (cache->plt.tune) { + case HS_TUNE_FAMILY_HSW: + platform = "haswell"; + break; + case HS_TUNE_FAMILY_SNB: + platform = "sandy"; + break; + case HS_TUNE_FAMILY_BDW: + platform = "broadwell"; + break; + case HS_TUNE_FAMILY_IVB: + platform = "ivy"; + break; + default: + break; + } + + if (cache->plt.cpu_features & HS_CPU_FEATURES_AVX2) { + features = rspamd_fstring_append (features, "AVX2", 4); + } + + msg_info ("loaded hyperscan engine witch cpu tune '%s' and features '%V'", + platform, features); + + rspamd_fstring_free (features); +#endif } struct rspamd_re_runtime * diff --git a/src/rspamadm/CMakeLists.txt b/src/rspamadm/CMakeLists.txt index 7d693c388..585e42628 100644 --- a/src/rspamadm/CMakeLists.txt +++ b/src/rspamadm/CMakeLists.txt @@ -20,5 +20,9 @@ TARGET_LINK_LIBRARIES(rspamadm rspamd-actrie) IF (NOT DEBIAN_BUILD) SET_TARGET_PROPERTIES(rspamadm PROPERTIES VERSION ${RSPAMD_VERSION}) ENDIF (NOT DEBIAN_BUILD) +IF (ENABLE_HYPERSCAN MATCHES "ON") + TARGET_LINK_LIBRARIES(rspamadm hs) + SET_TARGET_PROPERTIES(rspamadm PROPERTIES LINKER_LANGUAGE CXX) +ENDIF () -INSTALL(TARGETS rspamadm RUNTIME DESTINATION bin) \ No newline at end of file +INSTALL(TARGETS rspamadm RUNTIME DESTINATION bin)