Commit 72c41fdd authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

sock: add spdk_sock_get_numa_socket_id



Elsewhere in SPDK/DPDK, we always just say "socket_id", but since
this is the sock module for TCP sockets, we clarify the name with
"numa".

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: I792c29e4db5094c88b6ced5f5e017cdee31c8fb8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24124


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent dfef7970
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -374,6 +374,16 @@ struct spdk_sock *spdk_sock_accept(struct spdk_sock *sock);
 */
const char *spdk_sock_get_interface_name(struct spdk_sock *sock);


/**
 * Gets the NUMA socket ID for the network interface of the local port for the TCP socket.
 *
 * \param sock TCP socket to find the NUMA socket ID for
 *
 * \return NUMA socket ID, or SPDK_ENV_SOCKET_ID_ANY if the NUMA socket ID is unknown
 */
uint32_t spdk_sock_get_numa_socket_id(struct spdk_sock *sock);

/**
 * Close a socket.
 *
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ struct spdk_net_impl {
	int (*getaddr)(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport, char *caddr,
		       int clen, uint16_t *cport);
	const char *(*get_interface_name)(struct spdk_sock *sock);
	uint32_t (*get_numa_socket_id)(struct spdk_sock *sock);
	struct spdk_sock *(*connect)(const char *ip, int port, struct spdk_sock_opts *opts);
	struct spdk_sock *(*listen)(const char *ip, int port, struct spdk_sock_opts *opts);
	struct spdk_sock *(*accept)(struct spdk_sock *sock);
+10 −0
Original line number Diff line number Diff line
@@ -242,6 +242,16 @@ spdk_sock_get_interface_name(struct spdk_sock *sock)
	}
}

uint32_t
spdk_sock_get_numa_socket_id(struct spdk_sock *sock)
{
	if (sock->net_impl->get_numa_socket_id) {
		return sock->net_impl->get_numa_socket_id(sock);
	} else {
		return SPDK_ENV_SOCKET_ID_ANY;
	}
}

const char *
spdk_sock_get_impl_name(struct spdk_sock *sock)
{
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
	spdk_sock_get_default_opts;
	spdk_sock_getaddr;
	spdk_sock_get_interface_name;
	spdk_sock_get_numa_socket_id;
	spdk_sock_connect;
	spdk_sock_connect_ext;
	spdk_sock_listen;
+24 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "spdk/util.h"
#include "spdk/string.h"
#include "spdk/net.h"
#include "spdk/file.h"
#include "spdk_internal/sock.h"
#include "spdk/net.h"

@@ -255,6 +256,27 @@ posix_sock_get_interface_name(struct spdk_sock *_sock)
	return sock->interface_name;
}

static uint32_t
posix_sock_get_numa_socket_id(struct spdk_sock *sock)
{
	const char *interface_name;
	uint32_t numa_socket_id;
	int rc;

	interface_name = posix_sock_get_interface_name(sock);
	if (interface_name == NULL) {
		return SPDK_ENV_SOCKET_ID_ANY;
	}

	rc = spdk_read_sysfs_attribute_uint32(&numa_socket_id,
					      "/sys/class/net/%s/device/numa_node", interface_name);
	if (rc == 0) {
		return numa_socket_id;
	} else {
		return SPDK_ENV_SOCKET_ID_ANY;
	}
}

enum posix_sock_create_type {
	SPDK_SOCK_CREATE_LISTEN,
	SPDK_SOCK_CREATE_CONNECT,
@@ -2188,6 +2210,7 @@ static struct spdk_net_impl g_posix_net_impl = {
	.name		= "posix",
	.getaddr	= posix_sock_getaddr,
	.get_interface_name = posix_sock_get_interface_name,
	.get_numa_socket_id = posix_sock_get_numa_socket_id,
	.connect	= posix_sock_connect,
	.listen		= posix_sock_listen,
	.accept		= posix_sock_accept,
@@ -2240,6 +2263,7 @@ static struct spdk_net_impl g_ssl_net_impl = {
	.name		= "ssl",
	.getaddr	= posix_sock_getaddr,
	.get_interface_name = posix_sock_get_interface_name,
	.get_numa_socket_id = posix_sock_get_numa_socket_id,
	.connect	= ssl_sock_connect,
	.listen		= ssl_sock_listen,
	.accept		= ssl_sock_accept,
Loading