From 1267a00b062d4a0dedccb37d8528948f29754126 Mon Sep 17 00:00:00 2001 From: Kit Chan Date: Mon, 20 Nov 2023 13:48:19 -0800 Subject: [PATCH] Add support to disable jit in using lua plugin in remap (#10818) --- doc/admin-guide/plugins/lua.en.rst | 10 ++++++++-- plugins/lua/ts_lua.cc | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/admin-guide/plugins/lua.en.rst b/doc/admin-guide/plugins/lua.en.rst index 0386e235d08..c4ad949832f 100644 --- a/doc/admin-guide/plugins/lua.en.rst +++ b/doc/admin-guide/plugins/lua.en.rst @@ -182,18 +182,24 @@ enabled. The default value of '0' means disabled. :: - map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/XXX/tslua.so @pparam=--ljgc=1 + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/XXX/tslua.so @pparam=--ljgc=1 @pparam=/script/test.lua Configuration for JIT mode ========================== -We can also turn off JIT mode for LuaJIT when it is acting as global plugin for Traffic Server. The default is on (1). We can write this in plugin.config to turn off JIT +We can also turn off JIT mode for LuaJIT for Traffic Server. The default is on (1). We can write this in plugin.config to turn off JIT :: tslua.so --jit=0 /etc/trafficserver/script/test_global_hdr.lua +An example when using the plugin in remap.config + +:: + + map http://a.tbcdn.cn/ http://inner.tbcdn.cn/ @plugin=/XXX/tslua.so @pparam=--jit=0 @pparam=/script/test.lua + Profiling ========= diff --git a/plugins/lua/ts_lua.cc b/plugins/lua/ts_lua.cc index 6c9cd1f24af..8ae8d481438 100644 --- a/plugins/lua/ts_lua.cc +++ b/plugins/lua/ts_lua.cc @@ -347,8 +347,10 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s int fn = 0; int states = ts_lua_max_state_count; int ljgc = 0; + int jit = 1; static const struct option longopt[] = { {"states", required_argument, 0, 's'}, + {"jit", required_argument, 0, 'j'}, {"inline", required_argument, 0, 'i'}, {"ljgc", required_argument, 0, 'g'}, {0, 0, 0, 0 }, @@ -367,6 +369,19 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s Dbg(dbg_ctl, "[%s] setting number of lua VMs [%d]", __FUNCTION__, states); // set state break; + case 'j': + jit = atoi(optarg); + if (jit == 0) { + Dbg(dbg_ctl, "[%s] disable JIT mode for remap plugin", __FUNCTION__); + for (int index = 0; index < ts_lua_max_state_count; ++index) { + ts_lua_main_ctx *const main_ctx = (ts_lua_main_ctx_array + index); + lua_State *const lstate = main_ctx->lua; + if (luaJIT_setmode(lstate, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF) == 0) { + TSError("[ts_lua][%s] Failed to disable JIT mode for remap plugin", __FUNCTION__); + } + } + } + break; case 'i': inline_script = optarg; break;