diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-28 08:39:40 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-28 08:40:08 +0100 |
commit | 53478ca1ff6b3d1603cae2cc7d84a3d35dc815d7 (patch) | |
tree | 497c6cdbe9f0c91312c3c8b9764dd922f9a95d3d /src/lua/lua_config.c | |
parent | 41d5f05b86c4cebc4338c0a038d47c0db023ce71 (diff) | |
download | rspamd-53478ca1ff6b3d1603cae2cc7d84a3d35dc815d7.tar.gz rspamd-53478ca1ff6b3d1603cae2cc7d84a3d35dc815d7.zip |
[Feature] Allow to get CPU flags from Lua
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 916baa46e..398c9ed34 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -626,6 +626,17 @@ rspamd_config:set_peak_cb(function(ev_base, sym, mean, stddev, value, error) end) */ LUA_FUNCTION_DEF (config, set_peak_cb); +/*** + * @method rspamd_config:get_cpu_flags() + * Returns architecture dependent flags supported by the CPU + * Currently, only x86 flags are supported: + * - 'ssse3' + * - 'sse42' + * - 'avx' + * - 'avx2' + * @return {table} flag -> true table + */ +LUA_FUNCTION_DEF (config, get_cpu_flags); static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_module_opt), @@ -673,6 +684,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, add_doc), LUA_INTERFACE_DEF (config, add_example), LUA_INTERFACE_DEF (config, set_peak_cb), + LUA_INTERFACE_DEF (config, get_cpu_flags), {"__tostring", rspamd_lua_class_tostring}, {"__newindex", lua_config_newindex}, {NULL, NULL} @@ -2783,6 +2795,59 @@ lua_config_add_example (lua_State *L) } static gint +lua_config_get_cpu_flags (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L, 1); + struct rspamd_cryptobox_library_ctx *crypto_ctx; + + if (cfg != NULL) { + crypto_ctx = cfg->libs_ctx->crypto_ctx; + lua_newtable (L); + + if (crypto_ctx->cpu_config & CPUID_SSSE3) { + lua_pushstring (L, "ssse3"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_SSE41) { + lua_pushstring (L, "sse41"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_SSE42) { + lua_pushstring (L, "sse42"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_SSE2) { + lua_pushstring (L, "sse2"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_SSE3) { + lua_pushstring (L, "sse3"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_AVX) { + lua_pushstring (L, "avx"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + if (crypto_ctx->cpu_config & CPUID_AVX2) { + lua_pushstring (L, "avx2"); + lua_pushboolean (L, true); + lua_settable (L, -3); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint lua_monitored_alive (lua_State *L) { struct rspamd_monitored *m = lua_check_monitored (L, 1); |