Skip to content

Commit d208208

Browse files
committed
gt: correct NUMA node of LPM tables
The Lua states that run policies are created during the initialization of Grantor, and during policy reloads. In the former case, the creation is done on the master lcore. In the latter case, on the lcore of the dynamic configuration block. Thus, the code has to guess the lcore that actually runs the policy while creating LPM tables. This patch avoids the guessing by adding the running lcore ID to the registry of the lua states, and making the Lua LPM library to use this information.
1 parent 2c46517 commit d208208

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

gt/lua_lpm.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "gatekeeper_net.h"
2727
#include "gatekeeper_lpm.h"
2828
#include "gatekeeper_fib.h"
29+
#include "gatekeeper_gt.h"
2930

3031
static int
3132
l_str_to_prefix(lua_State *l)
@@ -91,6 +92,7 @@ l_new_lpm(lua_State *l)
9192
struct rte_lpm_config lpm_conf;
9293
struct rte_lpm **p_lpm;
9394
static rte_atomic32_t identifier = RTE_ATOMIC32_INIT(0);
95+
unsigned int lcore_id;
9496

9597
memset(&lpm_conf, 0, sizeof(lpm_conf));
9698

@@ -104,9 +106,13 @@ l_new_lpm(lua_State *l)
104106
luaL_error(l, "Expected two arguments, however it got %d arguments",
105107
lua_gettop(l));
106108

109+
lua_getfield(l, LUA_REGISTRYINDEX, GT_LUA_LCORE_ID_NAME);
110+
lcore_id = lua_tonumber(l, -1);
111+
107112
p_lpm = lua_newuserdata(l, sizeof(struct rte_lpm *));
108-
*p_lpm = init_ipv4_lpm("gt_", &lpm_conf, rte_socket_id(),
109-
rte_lcore_id(), rte_atomic32_add_return(&identifier, 1));
113+
*p_lpm = init_ipv4_lpm("gt_", &lpm_conf,
114+
rte_lcore_to_socket_id(lcore_id), lcore_id,
115+
rte_atomic32_add_return(&identifier, 1));
110116
if (unlikely(*p_lpm == NULL))
111117
luaL_error(l, "gt: failed to initialize the IPv4 LPM table for Lua policies");
112118

@@ -255,6 +261,7 @@ l_new_lpm6(lua_State *l)
255261
struct rte_lpm6_config lpm6_conf;
256262
struct rte_lpm6 **p_lpm6;
257263
static rte_atomic32_t identifier6 = RTE_ATOMIC32_INIT(0);
264+
unsigned int lcore_id;
258265

259266
memset(&lpm6_conf, 0, sizeof(lpm6_conf));
260267

@@ -268,9 +275,13 @@ l_new_lpm6(lua_State *l)
268275
luaL_error(l, "Expected two arguments, however it got %d arguments",
269276
lua_gettop(l));
270277

278+
lua_getfield(l, LUA_REGISTRYINDEX, GT_LUA_LCORE_ID_NAME);
279+
lcore_id = lua_tonumber(l, -1);
280+
271281
p_lpm6 = lua_newuserdata(l, sizeof(struct rte_lpm6 *));
272-
*p_lpm6 = init_ipv6_lpm("gt", &lpm6_conf, rte_socket_id(),
273-
rte_lcore_id(), rte_atomic32_add_return(&identifier6, 1));
282+
*p_lpm6 = init_ipv6_lpm("gt", &lpm6_conf,
283+
rte_lcore_to_socket_id(lcore_id), lcore_id,
284+
rte_atomic32_add_return(&identifier6, 1));
274285
if (unlikely(*p_lpm6 == NULL))
275286
luaL_error(l, "gt: failed to initialize the IPv6 LPM table for Lua policies");
276287

gt/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,8 +1822,7 @@ alloc_lua_mem_in_dpdk(void *ud, void *ptr,
18221822
#endif
18231823

18241824
static lua_State *
1825-
alloc_and_setup_lua_state(struct gt_config *gt_conf,
1826-
__attribute__((unused))unsigned int lcore_id)
1825+
alloc_and_setup_lua_state(struct gt_config *gt_conf, unsigned int lcore_id)
18271826
{
18281827
int ret;
18291828
char lua_entry_path[128];
@@ -1849,6 +1848,11 @@ alloc_and_setup_lua_state(struct gt_config *gt_conf,
18491848
goto out;
18501849
}
18511850

1851+
/* Add lcore_id information to the registry of @lua_state. */
1852+
lua_pushstring(lua_state, GT_LUA_LCORE_ID_NAME);
1853+
lua_pushnumber(lua_state, lcore_id);
1854+
lua_settable(lua_state, LUA_REGISTRYINDEX);
1855+
18521856
luaL_openlibs(lua_state);
18531857
lualpm_openlib(lua_state);
18541858
set_lua_path(lua_state, gt_conf->lua_base_directory);

include/gatekeeper_gt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,10 @@ gt_conf_hold(struct gt_config *gt_conf)
234234
rte_atomic32_inc(&gt_conf->ref_cnt);
235235
}
236236

237+
/*
238+
* Key in the registry of a Lua state used to run policies that points to
239+
* the lcore_id where the policy runs.
240+
*/
241+
#define GT_LUA_LCORE_ID_NAME "lcore_id"
242+
237243
#endif /* _GATEKEEPER_GT_H_ */

0 commit comments

Comments
 (0)