1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
7 #include <rte_atomic.h>
9 #include <rte_launch.h>
10 #include <rte_lcore.h>
11 #include <rte_per_lcore.h>
12 #include <rte_common.h>
13 #include <rte_memory.h>
14 #include <eal_thread.h>
16 #include "eal_private.h"
18 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
19 RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY;
20 RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
23 * Send a message to a slave lcore identified by slave_id to call a
24 * function f with argument arg. Once the execution is done, the
25 * remote lcore switch in FINISHED state.
28 rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)
32 int m2s = lcore_config[slave_id].pipe_master2slave[1];
33 int s2m = lcore_config[slave_id].pipe_slave2master[0];
35 if (lcore_config[slave_id].state != WAIT)
38 lcore_config[slave_id].f = f;
39 lcore_config[slave_id].arg = arg;
43 while (n == 0 || (n < 0 && errno == EINTR))
44 n = _write(m2s, &c, 1);
46 rte_panic("cannot write on configuration pipe\n");
50 n = _read(s2m, &c, 1);
51 } while (n < 0 && errno == EINTR);
54 rte_panic("cannot read on configuration pipe\n");
60 eal_thread_init_master(unsigned int lcore_id)
62 /* set the lcore ID in per-lcore memory area */
63 RTE_PER_LCORE(_lcore_id) = lcore_id;
66 static inline pthread_t
69 return GetCurrentThreadId();
72 /* main loop of threads */
74 eal_thread_loop(void *arg __rte_unused)
78 unsigned int lcore_id;
81 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
83 thread_id = eal_thread_self();
85 /* retrieve our lcore_id from the configuration structure */
86 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
87 if (thread_id == lcore_config[lcore_id].thread_id)
90 if (lcore_id == RTE_MAX_LCORE)
91 rte_panic("cannot retrieve lcore id\n");
93 m2s = lcore_config[lcore_id].pipe_master2slave[0];
94 s2m = lcore_config[lcore_id].pipe_slave2master[1];
96 /* set the lcore ID in per-lcore memory area */
97 RTE_PER_LCORE(_lcore_id) = lcore_id;
99 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
100 lcore_id, (uintptr_t)thread_id, cpuset);
102 /* read on our pipe to get commands */
108 n = _read(m2s, &c, 1);
109 } while (n < 0 && errno == EINTR);
112 rte_panic("cannot read on configuration pipe\n");
114 lcore_config[lcore_id].state = RUNNING;
118 while (n == 0 || (n < 0 && errno == EINTR))
119 n = _write(s2m, &c, 1);
121 rte_panic("cannot write on configuration pipe\n");
123 if (lcore_config[lcore_id].f == NULL)
124 rte_panic("NULL function pointer\n");
126 /* call the function and store the return value */
127 fct_arg = lcore_config[lcore_id].arg;
128 ret = lcore_config[lcore_id].f(fct_arg);
129 lcore_config[lcore_id].ret = ret;
132 /* when a service core returns, it should go directly to WAIT
133 * state, because the application will not lcore_wait() for it.
135 if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
136 lcore_config[lcore_id].state = WAIT;
138 lcore_config[lcore_id].state = FINISHED;
142 /* function to create threads */
144 eal_thread_create(pthread_t *thread)
148 th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)eal_thread_loop,
149 NULL, 0, (LPDWORD)thread);
153 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
154 SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL);
160 rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
163 /* This is a stub, not the expected result */