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 /* main loop of threads */
69 eal_thread_loop(void *arg __rte_unused)
73 unsigned int lcore_id;
76 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
78 thread_id = pthread_self();
80 /* retrieve our lcore_id from the configuration structure */
81 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
82 if (thread_id == lcore_config[lcore_id].thread_id)
85 if (lcore_id == RTE_MAX_LCORE)
86 rte_panic("cannot retrieve lcore id\n");
88 m2s = lcore_config[lcore_id].pipe_master2slave[0];
89 s2m = lcore_config[lcore_id].pipe_slave2master[1];
91 /* set the lcore ID in per-lcore memory area */
92 RTE_PER_LCORE(_lcore_id) = lcore_id;
94 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
95 lcore_id, (uintptr_t)thread_id, cpuset);
97 /* read on our pipe to get commands */
103 n = _read(m2s, &c, 1);
104 } while (n < 0 && errno == EINTR);
107 rte_panic("cannot read on configuration pipe\n");
109 lcore_config[lcore_id].state = RUNNING;
113 while (n == 0 || (n < 0 && errno == EINTR))
114 n = _write(s2m, &c, 1);
116 rte_panic("cannot write on configuration pipe\n");
118 if (lcore_config[lcore_id].f == NULL)
119 rte_panic("NULL function pointer\n");
121 /* call the function and store the return value */
122 fct_arg = lcore_config[lcore_id].arg;
123 ret = lcore_config[lcore_id].f(fct_arg);
124 lcore_config[lcore_id].ret = ret;
127 /* when a service core returns, it should go directly to WAIT
128 * state, because the application will not lcore_wait() for it.
130 if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
131 lcore_config[lcore_id].state = WAIT;
133 lcore_config[lcore_id].state = FINISHED;
137 /* function to create threads */
139 eal_thread_create(pthread_t *thread)
143 th = CreateThread(NULL, 0,
144 (LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
145 NULL, 0, (LPDWORD)thread);
149 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
150 SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL);
155 /* get current thread ID */
159 return GetCurrentThreadId();
163 rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
166 /* This is a stub, not the expected result */