]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/lib/librte_eal/linuxapp/eal/eal_thread.c
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/queue.h>
42 #include <sys/syscall.h>
44 #include <rte_debug.h>
45 #include <rte_atomic.h>
46 #include <rte_launch.h>
48 #include <rte_memory.h>
49 #include <rte_memzone.h>
50 #include <rte_per_lcore.h>
52 #include <rte_per_lcore.h>
53 #include <rte_lcore.h>
55 #include "eal_private.h"
56 #include "eal_thread.h"
58 RTE_DEFINE_PER_LCORE(unsigned, _lcore_id
) = LCORE_ID_ANY
;
59 RTE_DEFINE_PER_LCORE(unsigned, _socket_id
) = (unsigned)SOCKET_ID_ANY
;
60 RTE_DEFINE_PER_LCORE(rte_cpuset_t
, _cpuset
);
63 * Send a message to a slave lcore identified by slave_id to call a
64 * function f with argument arg. Once the execution is done, the
65 * remote lcore switch in FINISHED state.
68 rte_eal_remote_launch(int (*f
)(void *), void *arg
, unsigned slave_id
)
72 int m2s
= lcore_config
[slave_id
].pipe_master2slave
[1];
73 int s2m
= lcore_config
[slave_id
].pipe_slave2master
[0];
75 if (lcore_config
[slave_id
].state
!= WAIT
)
78 lcore_config
[slave_id
].f
= f
;
79 lcore_config
[slave_id
].arg
= arg
;
83 while (n
== 0 || (n
< 0 && errno
== EINTR
))
84 n
= write(m2s
, &c
, 1);
86 rte_panic("cannot write on configuration pipe\n");
91 } while (n
< 0 && errno
== EINTR
);
94 rte_panic("cannot read on configuration pipe\n");
99 /* set affinity for current EAL thread */
101 eal_thread_set_affinity(void)
103 unsigned lcore_id
= rte_lcore_id();
105 /* acquire system unique id */
108 /* update EAL thread core affinity */
109 return rte_thread_set_affinity(&lcore_config
[lcore_id
].cpuset
);
112 void eal_thread_init_master(unsigned lcore_id
)
114 /* set the lcore ID in per-lcore memory area */
115 RTE_PER_LCORE(_lcore_id
) = lcore_id
;
117 /* set CPU affinity */
118 if (eal_thread_set_affinity() < 0)
119 rte_panic("cannot set affinity\n");
122 /* main loop of threads */
123 __attribute__((noreturn
)) void *
124 eal_thread_loop(__attribute__((unused
)) void *arg
)
131 char cpuset
[RTE_CPU_AFFINITY_STR_LEN
];
133 thread_id
= pthread_self();
135 /* retrieve our lcore_id from the configuration structure */
136 RTE_LCORE_FOREACH_SLAVE(lcore_id
) {
137 if (thread_id
== lcore_config
[lcore_id
].thread_id
)
140 if (lcore_id
== RTE_MAX_LCORE
)
141 rte_panic("cannot retrieve lcore id\n");
143 m2s
= lcore_config
[lcore_id
].pipe_master2slave
[0];
144 s2m
= lcore_config
[lcore_id
].pipe_slave2master
[1];
146 /* set the lcore ID in per-lcore memory area */
147 RTE_PER_LCORE(_lcore_id
) = lcore_id
;
149 /* set CPU affinity */
150 if (eal_thread_set_affinity() < 0)
151 rte_panic("cannot set affinity\n");
153 ret
= eal_thread_dump_affinity(cpuset
, RTE_CPU_AFFINITY_STR_LEN
);
155 RTE_LOG(DEBUG
, EAL
, "lcore %u is ready (tid=%x;cpuset=[%s%s])\n",
156 lcore_id
, (int)thread_id
, cpuset
, ret
== 0 ? "" : "...");
158 /* read on our pipe to get commands */
164 n
= read(m2s
, &c
, 1);
165 } while (n
< 0 && errno
== EINTR
);
168 rte_panic("cannot read on configuration pipe\n");
170 lcore_config
[lcore_id
].state
= RUNNING
;
174 while (n
== 0 || (n
< 0 && errno
== EINTR
))
175 n
= write(s2m
, &c
, 1);
177 rte_panic("cannot write on configuration pipe\n");
179 if (lcore_config
[lcore_id
].f
== NULL
)
180 rte_panic("NULL function pointer\n");
182 /* call the function and store the return value */
183 fct_arg
= lcore_config
[lcore_id
].arg
;
184 ret
= lcore_config
[lcore_id
].f(fct_arg
);
185 lcore_config
[lcore_id
].ret
= ret
;
187 lcore_config
[lcore_id
].state
= FINISHED
;
191 /* pthread_exit(NULL); */
195 /* require calling thread tid by gettid() */
196 int rte_sys_gettid(void)
198 return (int)syscall(SYS_gettid
);
201 int rte_thread_setname(pthread_t id
, const char *name
)
204 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
205 #if __GLIBC_PREREQ(2, 12)
206 ret
= pthread_setname_np(id
, name
);