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>
15 #include "eal_private.h"
17 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
20 * Send a message to a slave lcore identified by slave_id to call a
21 * function f with argument arg. Once the execution is done, the
22 * remote lcore switch in FINISHED state.
25 rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)
29 int m2s = lcore_config[slave_id].pipe_master2slave[1];
30 int s2m = lcore_config[slave_id].pipe_slave2master[0];
32 if (lcore_config[slave_id].state != WAIT)
35 lcore_config[slave_id].f = f;
36 lcore_config[slave_id].arg = arg;
40 while (n == 0 || (n < 0 && errno == EINTR))
41 n = _write(m2s, &c, 1);
43 rte_panic("cannot write on configuration pipe\n");
47 n = _read(s2m, &c, 1);
48 } while (n < 0 && errno == EINTR);
51 rte_panic("cannot read on configuration pipe\n");
57 eal_thread_init_master(unsigned int lcore_id)
59 /* set the lcore ID in per-lcore memory area */
60 RTE_PER_LCORE(_lcore_id) = lcore_id;
63 static inline pthread_t
66 return GetCurrentThreadId();
69 /* main loop of threads */
71 eal_thread_loop(void *arg __rte_unused)
75 unsigned int lcore_id;
78 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
80 thread_id = eal_thread_self();
82 /* retrieve our lcore_id from the configuration structure */
83 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
84 if (thread_id == lcore_config[lcore_id].thread_id)
87 if (lcore_id == RTE_MAX_LCORE)
88 rte_panic("cannot retrieve lcore id\n");
90 m2s = lcore_config[lcore_id].pipe_master2slave[0];
91 s2m = lcore_config[lcore_id].pipe_slave2master[1];
93 /* set the lcore ID in per-lcore memory area */
94 RTE_PER_LCORE(_lcore_id) = lcore_id;
96 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
97 lcore_id, (uintptr_t)thread_id, cpuset);
99 /* read on our pipe to get commands */
105 n = _read(m2s, &c, 1);
106 } while (n < 0 && errno == EINTR);
109 rte_panic("cannot read on configuration pipe\n");
111 lcore_config[lcore_id].state = RUNNING;
115 while (n == 0 || (n < 0 && errno == EINTR))
116 n = _write(s2m, &c, 1);
118 rte_panic("cannot write on configuration pipe\n");
120 if (lcore_config[lcore_id].f == NULL)
121 rte_panic("NULL function pointer\n");
123 /* call the function and store the return value */
124 fct_arg = lcore_config[lcore_id].arg;
125 ret = lcore_config[lcore_id].f(fct_arg);
126 lcore_config[lcore_id].ret = ret;
129 /* when a service core returns, it should go directly to WAIT
130 * state, because the application will not lcore_wait() for it.
132 if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
133 lcore_config[lcore_id].state = WAIT;
135 lcore_config[lcore_id].state = FINISHED;
139 /* function to create threads */
141 eal_thread_create(pthread_t *thread)
145 th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)eal_thread_loop,
146 NULL, 0, (LPDWORD)thread);
150 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
151 SetThreadPriority(th, THREAD_PRIORITY_TIME_CRITICAL);