]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/lib/librte_eal/freebsd/eal_thread.c
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"
28 RTE_DEFINE_PER_LCORE(unsigned, _lcore_id
) = LCORE_ID_ANY
;
29 RTE_DEFINE_PER_LCORE(unsigned, _socket_id
) = (unsigned)SOCKET_ID_ANY
;
30 RTE_DEFINE_PER_LCORE(rte_cpuset_t
, _cpuset
);
33 * Send a message to a slave lcore identified by slave_id to call a
34 * function f with argument arg. Once the execution is done, the
35 * remote lcore switch in FINISHED state.
38 rte_eal_remote_launch(int (*f
)(void *), void *arg
, unsigned slave_id
)
42 int m2s
= lcore_config
[slave_id
].pipe_master2slave
[1];
43 int s2m
= lcore_config
[slave_id
].pipe_slave2master
[0];
46 if (lcore_config
[slave_id
].state
!= WAIT
)
49 lcore_config
[slave_id
].f
= f
;
50 lcore_config
[slave_id
].arg
= arg
;
54 while (n
== 0 || (n
< 0 && errno
== EINTR
))
55 n
= write(m2s
, &c
, 1);
57 rte_panic("cannot write on configuration pipe\n");
62 } while (n
< 0 && errno
== EINTR
);
65 rte_panic("cannot read on configuration pipe\n");
69 rte_eal_trace_thread_remote_launch(f
, arg
, slave_id
, rc
);
73 /* set affinity for current thread */
75 eal_thread_set_affinity(void)
77 unsigned lcore_id
= rte_lcore_id();
79 /* acquire system unique id */
82 /* update EAL thread core affinity */
83 return rte_thread_set_affinity(&lcore_config
[lcore_id
].cpuset
);
86 void eal_thread_init_master(unsigned lcore_id
)
88 /* set the lcore ID in per-lcore memory area */
89 RTE_PER_LCORE(_lcore_id
) = lcore_id
;
91 /* set CPU affinity */
92 if (eal_thread_set_affinity() < 0)
93 rte_panic("cannot set affinity\n");
96 /* main loop of threads */
98 eal_thread_loop(__rte_unused
void *arg
)
105 char cpuset
[RTE_CPU_AFFINITY_STR_LEN
];
107 thread_id
= pthread_self();
109 /* retrieve our lcore_id from the configuration structure */
110 RTE_LCORE_FOREACH_SLAVE(lcore_id
) {
111 if (thread_id
== lcore_config
[lcore_id
].thread_id
)
114 if (lcore_id
== RTE_MAX_LCORE
)
115 rte_panic("cannot retrieve lcore id\n");
117 m2s
= lcore_config
[lcore_id
].pipe_master2slave
[0];
118 s2m
= lcore_config
[lcore_id
].pipe_slave2master
[1];
120 /* set the lcore ID in per-lcore memory area */
121 RTE_PER_LCORE(_lcore_id
) = lcore_id
;
123 /* set CPU affinity */
124 if (eal_thread_set_affinity() < 0)
125 rte_panic("cannot set affinity\n");
127 ret
= eal_thread_dump_affinity(cpuset
, sizeof(cpuset
));
129 RTE_LOG(DEBUG
, EAL
, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
130 lcore_id
, thread_id
, cpuset
, ret
== 0 ? "" : "...");
132 __rte_trace_mem_per_thread_alloc();
133 rte_eal_trace_thread_lcore_ready(lcore_id
, cpuset
);
135 /* read on our pipe to get commands */
141 n
= read(m2s
, &c
, 1);
142 } while (n
< 0 && errno
== EINTR
);
145 rte_panic("cannot read on configuration pipe\n");
147 lcore_config
[lcore_id
].state
= RUNNING
;
151 while (n
== 0 || (n
< 0 && errno
== EINTR
))
152 n
= write(s2m
, &c
, 1);
154 rte_panic("cannot write on configuration pipe\n");
156 if (lcore_config
[lcore_id
].f
== NULL
)
157 rte_panic("NULL function pointer\n");
159 /* call the function and store the return value */
160 fct_arg
= lcore_config
[lcore_id
].arg
;
161 ret
= lcore_config
[lcore_id
].f(fct_arg
);
162 lcore_config
[lcore_id
].ret
= ret
;
164 lcore_config
[lcore_id
].state
= FINISHED
;
168 /* pthread_exit(NULL); */
172 /* require calling thread tid by gettid() */
173 int rte_sys_gettid(void)
180 int rte_thread_setname(pthread_t id
, const char *name
)
182 /* this BSD function returns no error */
183 pthread_set_name_np(id
, name
);
187 int rte_thread_getname(pthread_t id
, char *name
, size_t len
)