Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numa: export mtl_get_numa_id to get the numa id for one NIC port #901

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions include/mtl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ enum st21_tx_pacing_way {

/** MTL init flag */
enum mtl_init_flag {
/** lib will bind all process threads to NIC numa socket, default behavior */
/** lib will bind all MTL threads to NIC numa socket, default behavior */
MTL_FLAG_BIND_NUMA = (MTL_BIT64(0)),
/** Enable built-in PTP implementation */
MTL_FLAG_PTP_ENABLE = (MTL_BIT64(1)),
Expand Down Expand Up @@ -397,7 +397,7 @@ enum mtl_init_flag {
MTL_FLAG_NO_MULTICAST = (MTL_BIT64(19)),
/** Dedicated lcore for system CNI tasks. */
MTL_FLAG_DEDICATED_SYS_LCORE = (MTL_BIT64(20)),
/** not bind all process threads to NIC numa socket */
/** not bind all MTL threads to NIC numa socket */
MTL_FLAG_NOT_BIND_NUMA = (MTL_BIT64(21)),

/**
Expand Down Expand Up @@ -459,6 +459,8 @@ enum mtl_init_flag {
* streams have unique UDP port numbers.
*/
MTL_FLAG_RX_UDP_PORT_ONLY = (MTL_BIT64(46)),
/** not bind current process to NIC numa socket */
MTL_FLAG_NOT_BIND_PROCESS_NUMA = (MTL_BIT64(47)),
};

/** MTL port init flag */
Expand Down Expand Up @@ -782,6 +784,19 @@ int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status
*/
int mtl_reset_port_stats(mtl_handle mt, enum mtl_port port);

/**
* Get the numa socket id for a MTL port.
*
* @param mt
* The handle to MTL instance.
* @param port
* The port index.
* @return
* >= 0 The numa socket ID.
* - <0: Error code if fail.
*/
int mtl_get_numa_id(mtl_handle mt, enum mtl_port port);

/** Helper to set the port for struct mtl_init_params */
int mtl_para_port_set(struct mtl_init_params* p, enum mtl_port port, char* name);
/** Helper to set the sip for struct mtl_init_params */
Expand Down
18 changes: 17 additions & 1 deletion lib/src/mt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ mtl_handle mtl_init(struct mtl_init_params* p) {
#ifndef WINDOWSENV
int numa_nodes = 0;
if (numa_available() >= 0) numa_nodes = numa_max_node() + 1;
if (!(p->flags & MTL_FLAG_NOT_BIND_NUMA) && (numa_nodes > 1)) {
if (!(p->flags & MTL_FLAG_NOT_BIND_PROCESS_NUMA) && (numa_nodes > 1)) {
/* bind current thread and its children to socket node */
struct bitmask* mask = numa_bitmask_alloc(numa_nodes);

Expand Down Expand Up @@ -1335,3 +1335,19 @@ int mtl_para_port_set(struct mtl_init_params* p, enum mtl_port port, char* name)
int mtl_para_dma_port_set(struct mtl_init_params* p, enum mtl_port port, char* name) {
return snprintf(p->dma_dev_port[port], MTL_PORT_MAX_LEN, "%s", name);
}

int mtl_get_numa_id(mtl_handle mt, enum mtl_port port) {
struct mtl_main_impl* impl = mt;

if (impl->type != MT_HANDLE_MAIN) {
err("%s, invalid type %d\n", __func__, impl->type);
return -EIO;
}
if (port >= mt_num_ports(impl)) {
err("%s, invalid port %d\n", __func__, port);
return -EIO;
}

struct mt_interface* inf = mt_if(impl, port);
return inf->socket_id;
}
17 changes: 17 additions & 0 deletions tests/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,23 @@ TEST(Misc, log_level) {
EXPECT_GE(ret, 0);
}

TEST(Misc, get_numa_id) {
auto ctx = (struct st_tests_context*)st_test_ctx();
auto handle = ctx->handle;
int ret;

ret = mtl_get_numa_id(handle, MTL_PORT_P);
EXPECT_GE(ret, 0);

if (ctx->para.num_ports > 1) {
ret = mtl_get_numa_id(handle, MTL_PORT_R);
EXPECT_GE(ret, 0);
}

ret = mtl_get_numa_id(handle, (enum mtl_port)MTL_PORT_MAX);
EXPECT_LT(ret, 0);
}

static void st10_timestamp_test(uint32_t sampling_rate) {
auto ctx = (struct st_tests_context*)st_test_ctx();
auto handle = ctx->handle;
Expand Down
Loading