]> source.dussan.org Git - rspamd.git/commitdiff
Add hyperscan initialization
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Dec 2015 15:24:41 +0000 (15:24 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Dec 2015 15:24:41 +0000 (15:24 +0000)
CMakeLists.txt
src/CMakeLists.txt
src/libserver/re_cache.c
src/rspamadm/CMakeLists.txt

index 96118f12d64578f52be571920813067a1fea20ca..2088e277637d2f573c3f5d1a30280d0c346ecd69 100644 (file)
@@ -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")
index a99b6e7ac936f308a406550944d0385446803a50..acc91b673d199ce33a4497b97d28fe19c0516acb 100644 (file)
@@ -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})
index 84f4bbc5d6306dab3c6ff93dceac6b4973b46025..8a6f371191c8f34b6528dd6f268f6954c0badac7 100644 (file)
@@ -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 *
index 7d693c388895523f6ee7e3e7fa1155a961f30f90..585e42628e7451da99c7d75ecc6464c360226f2f 100644 (file)
@@ -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)