Browse Source

Add hyperscan initialization

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
813685c8e0
4 changed files with 55 additions and 1 deletions
  1. 5
    0
      CMakeLists.txt
  2. 1
    0
      src/CMakeLists.txt
  3. 44
    0
      src/libserver/re_cache.c
  4. 5
    1
      src/rspamadm/CMakeLists.txt

+ 5
- 0
CMakeLists.txt View 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")

+ 1
- 0
src/CMakeLists.txt View 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})

+ 44
- 0
src/libserver/re_cache.c View 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 *

+ 5
- 1
src/rspamadm/CMakeLists.txt View 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)
INSTALL(TARGETS rspamadm RUNTIME DESTINATION bin)

Loading…
Cancel
Save