#include <rte_lcore.h>
/**
- * basic loop of thread, called for each thread by eal_init().
+ * Basic loop of EAL thread, called for each worker thread by rte_eal_init().
*
* @param arg
- * opaque pointer
+ * The lcore_id (passed as an integer) of this worker thread.
*/
__rte_noreturn void *eal_thread_loop(void *arg);
/* create a thread for each lcore */
ret = pthread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ eal_thread_loop, (void *)(uintptr_t)i);
if (ret != 0)
rte_panic("Cannot create thread\n");
/* main loop of threads */
__rte_noreturn void *
-eal_thread_loop(__rte_unused void *arg)
+eal_thread_loop(void *arg)
{
+ unsigned int lcore_id = (uintptr_t)arg;
char c;
int n, ret;
unsigned lcore_id;
- pthread_t thread_id;
int m2w, w2m;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- thread_id = pthread_self();
-
- /* retrieve our lcore_id from the configuration structure */
- RTE_LCORE_FOREACH_WORKER(lcore_id) {
- if (thread_id == lcore_config[lcore_id].thread_id)
- break;
- }
- if (lcore_id == RTE_MAX_LCORE)
- rte_panic("cannot retrieve lcore id\n");
-
m2w = lcore_config[lcore_id].pipe_main2worker[0];
w2m = lcore_config[lcore_id].pipe_worker2main[1];
ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
- lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
+ lcore_id, pthread_self(), cpuset, ret == 0 ? "" : "...");
rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
/* create a thread for each lcore */
ret = pthread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ eal_thread_loop, (void *)(uintptr_t)i);
if (ret != 0)
rte_panic("Cannot create thread\n");
/* main loop of threads */
__rte_noreturn void *
-eal_thread_loop(__rte_unused void *arg)
+eal_thread_loop(void *arg)
{
+ unsigned int lcore_id = (uintptr_t)arg;
char c;
int n, ret;
- unsigned lcore_id;
- pthread_t thread_id;
int m2w, w2m;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- thread_id = pthread_self();
-
- /* retrieve our lcore_id from the configuration structure */
- RTE_LCORE_FOREACH_WORKER(lcore_id) {
- if (thread_id == lcore_config[lcore_id].thread_id)
- break;
- }
- if (lcore_id == RTE_MAX_LCORE)
- rte_panic("cannot retrieve lcore id\n");
m2w = lcore_config[lcore_id].pipe_main2worker[0];
w2m = lcore_config[lcore_id].pipe_worker2main[1];
ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
- lcore_id, (uintptr_t)thread_id, cpuset, ret == 0 ? "" : "...");
+ lcore_id, (uintptr_t)pthread_self(), cpuset,
+ ret == 0 ? "" : "...");
rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
lcore_config[i].state = WAIT;
/* create a thread for each lcore */
- if (eal_thread_create(&lcore_config[i].thread_id) != 0)
+ if (eal_thread_create(&lcore_config[i].thread_id, i) != 0)
rte_panic("Cannot create thread\n");
ret = pthread_setaffinity_np(lcore_config[i].thread_id,
sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
/* main loop of threads */
void *
-eal_thread_loop(void *arg __rte_unused)
+eal_thread_loop(void *arg)
{
+ unsigned int lcore_id = (uintptr_t)arg;
char c;
int n, ret;
- unsigned int lcore_id;
- pthread_t thread_id;
int m2w, w2m;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
- thread_id = pthread_self();
-
- /* retrieve our lcore_id from the configuration structure */
- RTE_LCORE_FOREACH_WORKER(lcore_id) {
- if (thread_id == lcore_config[lcore_id].thread_id)
- break;
- }
- if (lcore_id == RTE_MAX_LCORE)
- rte_panic("cannot retrieve lcore id\n");
-
m2w = lcore_config[lcore_id].pipe_main2worker[0];
w2m = lcore_config[lcore_id].pipe_worker2main[1];
__rte_thread_init(lcore_id, &lcore_config[lcore_id].cpuset);
RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
- lcore_id, (uintptr_t)thread_id, cpuset);
+ lcore_id, (uintptr_t)pthread_self(), cpuset);
/* read on our pipe to get commands */
while (1) {
/* function to create threads */
int
-eal_thread_create(pthread_t *thread)
+eal_thread_create(pthread_t *thread, unsigned int lcore_id)
{
HANDLE th;
th = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
- NULL, CREATE_SUSPENDED, (LPDWORD)thread);
+ (LPVOID)(uintptr_t)lcore_id,
+ CREATE_SUSPENDED,
+ (LPDWORD)thread);
if (!th)
return -1;
*
* @param thread
* The location to store the thread id if successful.
+ * @param lcore_id
+ * The lcore_id of this worker thread.
* @return
* 0 for success, -1 if the thread is not created.
*/
-int eal_thread_create(pthread_t *thread);
+int eal_thread_create(pthread_t *thread, unsigned int lcore_id);
/**
* Get system NUMA node number for a socket ID.