Commit 479507e8 authored by Jim Harris's avatar Jim Harris Committed by Ben Walker
Browse files

env: add NUMA node ID enumeration functions



spdk_env_get_first_numa_id()
spdk_env_get_last_numa_id()
spdk_env_get_next_numa_id()
SPDK_ENV_FOREACH_NUMA_ID()

These follow the same pattern as the enumeration functions for
CPU core IDs.

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


Reviewed-by: default avatarBen Walker <ben@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 44970291
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -526,6 +526,37 @@ int32_t spdk_env_get_numa_id(uint32_t core);
 */
uint32_t spdk_env_get_socket_id(uint32_t core);

/**
 * Get the ID of the first NUMA node on this system.
 *
 * \return the ID of the first NUMA node
 */
int32_t spdk_env_get_first_numa_id(void);

/**
 * Get the ID of the last NUMA node on this system.
 *
 * \return the ID of the last NUMA node
 */
int32_t spdk_env_get_last_numa_id(void);

/**
 * Get the index of the next NUMA node on this system.
 *
 * If there is no next NUMA ID, or the passed prev_numa_id is not a
 * valid NUMA ID, return INT32_MAX.
 *
 * \param prev_numa_id Index of previous NUMA ID.
 *
 * \return the index of the next NUMA ID, or INT32_MAX if there is no next one
 */
int32_t spdk_env_get_next_numa_id(int32_t prev_numa_id);

#define SPDK_ENV_FOREACH_NUMA_ID(i)			\
	for (i = spdk_env_get_first_numa_id();		\
	     i < INT32_MAX;				\
	     i = spdk_env_get_next_numa_id(i))

struct spdk_cpuset;

/**
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@
	spdk_env_get_next_core;
	spdk_env_get_socket_id;
	spdk_env_get_numa_id;
	spdk_env_get_first_numa_id;
	spdk_env_get_last_numa_id;
	spdk_env_get_next_numa_id;
	spdk_env_get_cpuset;
	spdk_env_core_get_smt_cpuset;
	spdk_env_thread_launch_pinned;
+34 −0
Original line number Diff line number Diff line
@@ -85,6 +85,40 @@ spdk_env_get_socket_id(uint32_t core)
	return spdk_env_get_numa_id(core);
}

int32_t
spdk_env_get_first_numa_id(void)
{
	assert(rte_socket_count() > 0);

	return rte_socket_id_by_idx(0);
}

int32_t
spdk_env_get_last_numa_id(void)
{
	assert(rte_socket_count() > 0);

	return rte_socket_id_by_idx(rte_socket_count() - 1);
}

int32_t
spdk_env_get_next_numa_id(int32_t prev_numa_id)
{
	uint32_t i;

	for (i = 0; i < rte_socket_count(); i++) {
		if (rte_socket_id_by_idx(i) == prev_numa_id) {
			break;
		}
	}

	if ((i + 1) < rte_socket_count()) {
		return rte_socket_id_by_idx(i + 1);
	} else {
		return INT32_MAX;
	}
}

void
spdk_env_get_cpuset(struct spdk_cpuset *cpuset)
{