diff mbox series

[11/20] net/sfc: add NUMA-aware registry of service logical cores

Message ID 20210527152510.1551026-12-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Superseded, archived
Headers show
Series net/sfc: support flow API COUNT action | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko May 27, 2021, 3:25 p.m. UTC
The driver requires service cores for housekeeping. Share these
cores for many adapters and various purposes to avoid extra CPU
overhead.

Since housekeeping services will talk to NIC, it should be possible
to choose logical core on matching NUMA node.

Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 drivers/net/sfc/meson.build   |  1 +
 drivers/net/sfc/sfc_service.c | 99 +++++++++++++++++++++++++++++++++++
 drivers/net/sfc/sfc_service.h | 20 +++++++
 3 files changed, 120 insertions(+)
 create mode 100644 drivers/net/sfc/sfc_service.c
 create mode 100644 drivers/net/sfc/sfc_service.h
diff mbox series

Patch

diff --git a/drivers/net/sfc/meson.build b/drivers/net/sfc/meson.build
index ccf5984d87..4ac97e8d43 100644
--- a/drivers/net/sfc/meson.build
+++ b/drivers/net/sfc/meson.build
@@ -62,4 +62,5 @@  sources = files(
         'sfc_ef10_tx.c',
         'sfc_ef100_rx.c',
         'sfc_ef100_tx.c',
+        'sfc_service.c',
 )
diff --git a/drivers/net/sfc/sfc_service.c b/drivers/net/sfc/sfc_service.c
new file mode 100644
index 0000000000..9c89484406
--- /dev/null
+++ b/drivers/net/sfc/sfc_service.c
@@ -0,0 +1,99 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020-2021 Xilinx, Inc.
+ */
+
+#include <stdint.h>
+
+#include <rte_common.h>
+#include <rte_spinlock.h>
+#include <rte_lcore.h>
+#include <rte_service.h>
+#include <rte_memory.h>
+
+#include "sfc_log.h"
+#include "sfc_service.h"
+#include "sfc_debug.h"
+
+static uint32_t sfc_service_lcore[RTE_MAX_NUMA_NODES];
+static rte_spinlock_t sfc_service_lcore_lock = RTE_SPINLOCK_INITIALIZER;
+
+RTE_INIT(sfc_service_lcore_init)
+{
+	size_t i;
+
+	for (i = 0; i < RTE_DIM(sfc_service_lcore); ++i)
+		sfc_service_lcore[i] = RTE_MAX_LCORE;
+}
+
+static uint32_t
+sfc_find_service_lcore(int *socket_id)
+{
+	uint32_t service_core_list[RTE_MAX_LCORE];
+	uint32_t lcore_id;
+	int num;
+	int i;
+
+	SFC_ASSERT(rte_spinlock_is_locked(&sfc_service_lcore_lock));
+
+	num = rte_service_lcore_list(service_core_list,
+				    RTE_DIM(service_core_list));
+	if (num == 0) {
+		SFC_GENERIC_LOG(WARNING, "No service cores available");
+		return RTE_MAX_LCORE;
+	}
+	if (num < 0) {
+		SFC_GENERIC_LOG(ERR, "Failed to get service core list");
+		return RTE_MAX_LCORE;
+	}
+
+	for (i = 0; i < num; ++i) {
+		lcore_id = service_core_list[i];
+
+		if (*socket_id == SOCKET_ID_ANY) {
+			*socket_id = rte_lcore_to_socket_id(lcore_id);
+			break;
+		} else if (rte_lcore_to_socket_id(lcore_id) ==
+			   (unsigned int)*socket_id) {
+			break;
+		}
+	}
+
+	if (i == num) {
+		SFC_GENERIC_LOG(WARNING,
+			"No service cores reserved at socket %d", *socket_id);
+		return RTE_MAX_LCORE;
+	}
+
+	return lcore_id;
+}
+
+uint32_t
+sfc_get_service_lcore(int socket_id)
+{
+	uint32_t lcore_id = RTE_MAX_LCORE;
+
+	rte_spinlock_lock(&sfc_service_lcore_lock);
+
+	if (socket_id != SOCKET_ID_ANY) {
+		lcore_id = sfc_service_lcore[socket_id];
+	} else {
+		size_t i;
+
+		for (i = 0; i < RTE_DIM(sfc_service_lcore); ++i) {
+			if (sfc_service_lcore[i] != RTE_MAX_LCORE) {
+				lcore_id = sfc_service_lcore[i];
+				break;
+			}
+		}
+	}
+
+	if (lcore_id == RTE_MAX_LCORE) {
+		lcore_id = sfc_find_service_lcore(&socket_id);
+		if (lcore_id != RTE_MAX_LCORE)
+			sfc_service_lcore[socket_id] = lcore_id;
+	}
+
+	rte_spinlock_unlock(&sfc_service_lcore_lock);
+	return lcore_id;
+}
diff --git a/drivers/net/sfc/sfc_service.h b/drivers/net/sfc/sfc_service.h
new file mode 100644
index 0000000000..bbcce28479
--- /dev/null
+++ b/drivers/net/sfc/sfc_service.h
@@ -0,0 +1,20 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright(c) 2020-2021 Xilinx, Inc.
+ */
+
+#ifndef _SFC_SERVICE_H
+#define _SFC_SERVICE_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint32_t sfc_get_service_lcore(int socket_id);
+
+#ifdef __cplusplus
+}
+#endif
+#endif  /* _SFC_SERVICE_H */