1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2020-2021 Xilinx, Inc.
8 #include <rte_common.h>
9 #include <rte_spinlock.h>
10 #include <rte_lcore.h>
11 #include <rte_service.h>
12 #include <rte_memory.h>
15 #include "sfc_service.h"
16 #include "sfc_debug.h"
18 static uint32_t sfc_service_lcore[RTE_MAX_NUMA_NODES];
19 static rte_spinlock_t sfc_service_lcore_lock = RTE_SPINLOCK_INITIALIZER;
21 RTE_INIT(sfc_service_lcore_init)
25 for (i = 0; i < RTE_DIM(sfc_service_lcore); ++i)
26 sfc_service_lcore[i] = RTE_MAX_LCORE;
30 sfc_find_service_lcore(int *socket_id)
32 uint32_t service_core_list[RTE_MAX_LCORE];
37 SFC_ASSERT(rte_spinlock_is_locked(&sfc_service_lcore_lock));
39 num = rte_service_lcore_list(service_core_list,
40 RTE_DIM(service_core_list));
42 SFC_GENERIC_LOG(WARNING, "No service cores available");
46 SFC_GENERIC_LOG(ERR, "Failed to get service core list");
50 for (i = 0; i < num; ++i) {
51 lcore_id = service_core_list[i];
53 if (*socket_id == SOCKET_ID_ANY) {
54 *socket_id = rte_lcore_to_socket_id(lcore_id);
56 } else if (rte_lcore_to_socket_id(lcore_id) ==
57 (unsigned int)*socket_id) {
63 SFC_GENERIC_LOG(WARNING,
64 "No service cores reserved at socket %d", *socket_id);
72 sfc_get_service_lcore(int socket_id)
74 uint32_t lcore_id = RTE_MAX_LCORE;
76 rte_spinlock_lock(&sfc_service_lcore_lock);
78 if (socket_id != SOCKET_ID_ANY) {
79 lcore_id = sfc_service_lcore[socket_id];
83 for (i = 0; i < RTE_DIM(sfc_service_lcore); ++i) {
84 if (sfc_service_lcore[i] != RTE_MAX_LCORE) {
85 lcore_id = sfc_service_lcore[i];
91 if (lcore_id == RTE_MAX_LCORE) {
92 lcore_id = sfc_find_service_lcore(&socket_id);
93 if (lcore_id != RTE_MAX_LCORE)
94 sfc_service_lcore[socket_id] = lcore_id;
97 rte_spinlock_unlock(&sfc_service_lcore_lock);