net/sfc: add NUMA-aware registry of service logical cores
authorAndrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Fri, 2 Jul 2021 08:39:39 +0000 (11:39 +0300)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 20 Jul 2021 10:20:31 +0000 (12:20 +0200)
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
drivers/net/sfc/sfc_service.c [new file with mode: 0644]
drivers/net/sfc/sfc_service.h [new file with mode: 0644]

index 18e7edb..22c3f6d 100644 (file)
@@ -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 (file)
index 0000000..9c89484
--- /dev/null
@@ -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 (file)
index 0000000..bbcce28
--- /dev/null
@@ -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 */