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"
17 #include "eal_windows.h"
19 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
20 RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY;
21 RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
24 * Send a message to a slave lcore identified by slave_id to call a
25 * function f with argument arg. Once the execution is done, the
26 * remote lcore switch in FINISHED state.
29 rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)
33 int m2s = lcore_config[slave_id].pipe_master2slave[1];
34 int s2m = lcore_config[slave_id].pipe_slave2master[0];
36 if (lcore_config[slave_id].state != WAIT)
39 lcore_config[slave_id].f = f;
40 lcore_config[slave_id].arg = arg;
44 while (n == 0 || (n < 0 && errno == EINTR))
45 n = _write(m2s, &c, 1);
47 rte_panic("cannot write on configuration pipe\n");
51 n = _read(s2m, &c, 1);
52 } while (n < 0 && errno == EINTR);
55 rte_panic("cannot read on configuration pipe\n");
61 eal_thread_init_master(unsigned int lcore_id)
63 /* set the lcore ID in per-lcore memory area */
64 RTE_PER_LCORE(_lcore_id) = lcore_id;
67 static inline pthread_t
70 return GetCurrentThreadId();
73 /* main loop of threads */
75 eal_thread_loop(void *arg __rte_unused)
79 unsigned int lcore_id;
82 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
84 thread_id = eal_thread_self();
86 /* retrieve our lcore_id from the configuration structure */
87 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
88 if (thread_id == lcore_config[lcore_id].thread_id)
91 if (lcore_id == RTE_MAX_LCORE)
92 rte_panic("cannot retrieve lcore id\n");
94 m2s = lcore_config[lcore_id].pipe_master2slave[0];
95 s2m = lcore_config[lcore_id].pipe_slave2master[1];
97 /* set the lcore ID in per-lcore memory area */
98 RTE_PER_LCORE(_lcore_id) = lcore_id;
100 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
101 lcore_id, (uintptr_t)thread_id, cpuset);
103 /* read on our pipe to get commands */
109 n = _read(m2s, &c, 1);
110 } while (n < 0 && errno == EINTR);
113 rte_panic("cannot read on configuration pipe\n");
115 lcore_config[lcore_id].state = RUNNING;
119 while (n == 0 || (n < 0 && errno == EINTR))
120 n = _write(s2m, &c, 1);
122 rte_panic("cannot write on configuration pipe\n");
124 if (lcore_config[lcore_id].f == NULL)
125 rte_panic("NULL function pointer\n");
127 /* call the function and store the return value */
128 fct_arg = lcore_config[lcore_id].arg;
129 ret = lcore_config[lcore_id].f(fct_arg);
130 lcore_config[lcore_id].ret = ret;
133 /* when a service core returns, it should go directly to WAIT
134 * state, because the application will not lcore_wait() for it.
136 if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
137 lcore_config[lcore_id].state = WAIT;
139 lcore_config[lcore_id].state = FINISHED;
143 /* function to create threads */
145 eal_thread_create(pthread_t *thread)
149 th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)eal_thread_loop,
150 NULL, 0, (LPDWORD)thread);
154 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
155 SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL);
161 rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
164 /* This is a stub, not the expected result */