1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 #include <pthread_np.h>
12 #include <sys/queue.h>
15 #include <rte_debug.h>
16 #include <rte_atomic.h>
17 #include <rte_launch.h>
19 #include <rte_memory.h>
20 #include <rte_per_lcore.h>
22 #include <rte_lcore.h>
23 #include <rte_eal_trace.h>
25 #include "eal_private.h"
26 #include "eal_thread.h"
29 * Send a message to a worker lcore identified by worker_id to call a
30 * function f with argument arg. Once the execution is done, the
31 * remote lcore switch in FINISHED state.
34 rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned worker_id)
38 int m2w = lcore_config[worker_id].pipe_main2worker[1];
39 int w2m = lcore_config[worker_id].pipe_worker2main[0];
42 if (lcore_config[worker_id].state != WAIT)
45 lcore_config[worker_id].f = f;
46 lcore_config[worker_id].arg = arg;
50 while (n == 0 || (n < 0 && errno == EINTR))
51 n = write(m2w, &c, 1);
53 rte_panic("cannot write on configuration pipe\n");
58 } while (n < 0 && errno == EINTR);
61 rte_panic("cannot read on configuration pipe\n");
65 rte_eal_trace_thread_remote_launch(f, arg, worker_id, rc);
69 /* main loop of threads */
71 eal_thread_loop(__rte_unused void *arg)
78 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
80 thread_id = pthread_self();
82 /* retrieve our lcore_id from the configuration structure */
83 RTE_LCORE_FOREACH_WORKER(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 m2w = lcore_config[lcore_id].pipe_main2worker[0];
91 w2m = lcore_config[lcore_id].pipe_worker2main[1];
93 __rte_thread_init(lcore_id, &lcore_config[lcore_id].cpuset);
95 ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
96 RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
97 lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
99 rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
101 /* read on our pipe to get commands */
107 n = read(m2w, &c, 1);
108 } while (n < 0 && errno == EINTR);
111 rte_panic("cannot read on configuration pipe\n");
113 lcore_config[lcore_id].state = RUNNING;
117 while (n == 0 || (n < 0 && errno == EINTR))
118 n = write(w2m, &c, 1);
120 rte_panic("cannot write on configuration pipe\n");
122 if (lcore_config[lcore_id].f == NULL)
123 rte_panic("NULL function pointer\n");
125 /* call the function and store the return value */
126 fct_arg = lcore_config[lcore_id].arg;
127 ret = lcore_config[lcore_id].f(fct_arg);
128 lcore_config[lcore_id].ret = ret;
130 lcore_config[lcore_id].state = FINISHED;
134 /* pthread_exit(NULL); */
138 /* require calling thread tid by gettid() */
139 int rte_sys_gettid(void)
146 int rte_thread_setname(pthread_t id, const char *name)
148 /* this BSD function returns no error */
149 pthread_set_name_np(id, name);
153 int rte_thread_getname(pthread_t id, char *name, size_t len)