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 <eal_thread.h>
16 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
19 * Send a message to a slave lcore identified by slave_id to call a
20 * function f with argument arg. Once the execution is done, the
21 * remote lcore switch in FINISHED state.
24 rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)
28 int m2s = lcore_config[slave_id].pipe_master2slave[1];
29 int s2m = lcore_config[slave_id].pipe_slave2master[0];
31 if (lcore_config[slave_id].state != WAIT)
34 lcore_config[slave_id].f = f;
35 lcore_config[slave_id].arg = arg;
39 while (n == 0 || (n < 0 && errno == EINTR))
40 n = _write(m2s, &c, 1);
42 rte_panic("cannot write on configuration pipe\n");
46 n = _read(s2m, &c, 1);
47 } while (n < 0 && errno == EINTR);
50 rte_panic("cannot read on configuration pipe\n");
56 eal_thread_init_master(unsigned int lcore_id)
58 /* set the lcore ID in per-lcore memory area */
59 RTE_PER_LCORE(_lcore_id) = lcore_id;
62 static inline pthread_t
65 return GetCurrentThreadId();
68 /* main loop of threads */
70 eal_thread_loop(void *arg __rte_unused)
74 unsigned int lcore_id;
77 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
79 thread_id = eal_thread_self();
81 /* retrieve our lcore_id from the configuration structure */
82 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
83 if (thread_id == lcore_config[lcore_id].thread_id)
86 if (lcore_id == RTE_MAX_LCORE)
87 rte_panic("cannot retrieve lcore id\n");
89 m2s = lcore_config[lcore_id].pipe_master2slave[0];
90 s2m = lcore_config[lcore_id].pipe_slave2master[1];
92 /* set the lcore ID in per-lcore memory area */
93 RTE_PER_LCORE(_lcore_id) = lcore_id;
95 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
96 lcore_id, (uintptr_t)thread_id, cpuset);
98 /* read on our pipe to get commands */
104 n = _read(m2s, &c, 1);
105 } while (n < 0 && errno == EINTR);
108 rte_panic("cannot read on configuration pipe\n");
110 lcore_config[lcore_id].state = RUNNING;
114 while (n == 0 || (n < 0 && errno == EINTR))
115 n = _write(s2m, &c, 1);
117 rte_panic("cannot write on configuration pipe\n");
119 if (lcore_config[lcore_id].f == NULL)
120 rte_panic("NULL function pointer\n");
122 /* call the function and store the return value */
123 fct_arg = lcore_config[lcore_id].arg;
124 ret = lcore_config[lcore_id].f(fct_arg);
125 lcore_config[lcore_id].ret = ret;
128 /* when a service core returns, it should go directly to WAIT
129 * state, because the application will not lcore_wait() for it.
131 if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
132 lcore_config[lcore_id].state = WAIT;
134 lcore_config[lcore_id].state = FINISHED;
138 /* function to create threads */
140 eal_thread_create(pthread_t *thread)
144 th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)eal_thread_loop,
145 NULL, 0, (LPDWORD)thread);
149 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
150 SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL);