2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2014-02-10 11:49:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <pthread_np.h>
|
|
|
|
#include <sys/queue.h>
|
2015-02-17 10:08:06 +08:00
|
|
|
#include <sys/thr.h>
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
#include <rte_debug.h>
|
|
|
|
#include <rte_atomic.h>
|
|
|
|
#include <rte_launch.h>
|
|
|
|
#include <rte_log.h>
|
|
|
|
#include <rte_memory.h>
|
|
|
|
#include <rte_per_lcore.h>
|
|
|
|
#include <rte_eal.h>
|
|
|
|
#include <rte_lcore.h>
|
2020-04-23 00:33:37 +05:30
|
|
|
#include <rte_eal_trace.h>
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
#include "eal_private.h"
|
|
|
|
#include "eal_thread.h"
|
|
|
|
|
2015-02-17 10:08:11 +08:00
|
|
|
RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY;
|
|
|
|
RTE_DEFINE_PER_LCORE(unsigned, _socket_id) = (unsigned)SOCKET_ID_ANY;
|
2015-02-17 10:08:03 +08:00
|
|
|
RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a message to a slave lcore identified by slave_id to call a
|
|
|
|
* function f with argument arg. Once the execution is done, the
|
|
|
|
* remote lcore switch in FINISHED state.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
char c = 0;
|
|
|
|
int m2s = lcore_config[slave_id].pipe_master2slave[1];
|
|
|
|
int s2m = lcore_config[slave_id].pipe_slave2master[0];
|
2020-04-23 00:33:37 +05:30
|
|
|
int rc = -EBUSY;
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
if (lcore_config[slave_id].state != WAIT)
|
2020-04-23 00:33:37 +05:30
|
|
|
goto finish;
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
lcore_config[slave_id].f = f;
|
|
|
|
lcore_config[slave_id].arg = arg;
|
|
|
|
|
|
|
|
/* send message */
|
|
|
|
n = 0;
|
|
|
|
while (n == 0 || (n < 0 && errno == EINTR))
|
|
|
|
n = write(m2s, &c, 1);
|
|
|
|
if (n < 0)
|
|
|
|
rte_panic("cannot write on configuration pipe\n");
|
|
|
|
|
|
|
|
/* wait ack */
|
|
|
|
do {
|
|
|
|
n = read(s2m, &c, 1);
|
|
|
|
} while (n < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (n <= 0)
|
|
|
|
rte_panic("cannot read on configuration pipe\n");
|
|
|
|
|
2020-04-23 00:33:37 +05:30
|
|
|
rc = 0;
|
|
|
|
finish:
|
|
|
|
rte_eal_trace_thread_remote_launch(f, arg, slave_id, rc);
|
|
|
|
return rc;
|
2014-02-10 11:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set affinity for current thread */
|
|
|
|
static int
|
|
|
|
eal_thread_set_affinity(void)
|
|
|
|
{
|
2015-02-17 10:08:07 +08:00
|
|
|
unsigned lcore_id = rte_lcore_id();
|
2014-02-10 11:49:10 +00:00
|
|
|
|
2015-02-17 10:08:07 +08:00
|
|
|
/* acquire system unique id */
|
|
|
|
rte_gettid();
|
2014-02-10 11:49:10 +00:00
|
|
|
|
2015-02-17 10:08:07 +08:00
|
|
|
/* update EAL thread core affinity */
|
|
|
|
return rte_thread_set_affinity(&lcore_config[lcore_id].cpuset);
|
2014-02-10 11:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void eal_thread_init_master(unsigned lcore_id)
|
|
|
|
{
|
|
|
|
/* set the lcore ID in per-lcore memory area */
|
|
|
|
RTE_PER_LCORE(_lcore_id) = lcore_id;
|
|
|
|
|
|
|
|
/* set CPU affinity */
|
|
|
|
if (eal_thread_set_affinity() < 0)
|
|
|
|
rte_panic("cannot set affinity\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main loop of threads */
|
2020-02-09 21:24:18 +01:00
|
|
|
__rte_noreturn void *
|
2020-02-09 16:54:54 +01:00
|
|
|
eal_thread_loop(__rte_unused void *arg)
|
2014-02-10 11:49:10 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
int n, ret;
|
|
|
|
unsigned lcore_id;
|
|
|
|
pthread_t thread_id;
|
|
|
|
int m2s, s2m;
|
2015-02-17 10:08:07 +08:00
|
|
|
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
|
2014-02-10 11:49:10 +00:00
|
|
|
|
|
|
|
thread_id = pthread_self();
|
|
|
|
|
|
|
|
/* retrieve our lcore_id from the configuration structure */
|
|
|
|
RTE_LCORE_FOREACH_SLAVE(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");
|
|
|
|
|
|
|
|
m2s = lcore_config[lcore_id].pipe_master2slave[0];
|
|
|
|
s2m = lcore_config[lcore_id].pipe_slave2master[1];
|
|
|
|
|
|
|
|
/* set the lcore ID in per-lcore memory area */
|
|
|
|
RTE_PER_LCORE(_lcore_id) = lcore_id;
|
|
|
|
|
|
|
|
/* set CPU affinity */
|
|
|
|
if (eal_thread_set_affinity() < 0)
|
|
|
|
rte_panic("cannot set affinity\n");
|
|
|
|
|
2018-04-24 16:46:47 +02:00
|
|
|
ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
|
2015-02-17 10:08:07 +08:00
|
|
|
|
|
|
|
RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
|
|
|
|
lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
|
|
|
|
|
2020-04-23 00:33:32 +05:30
|
|
|
__rte_trace_mem_per_thread_alloc();
|
2020-04-23 00:33:37 +05:30
|
|
|
rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
|
2020-04-23 00:33:32 +05:30
|
|
|
|
2014-02-10 11:49:10 +00:00
|
|
|
/* read on our pipe to get commands */
|
|
|
|
while (1) {
|
|
|
|
void *fct_arg;
|
|
|
|
|
|
|
|
/* wait command */
|
|
|
|
do {
|
|
|
|
n = read(m2s, &c, 1);
|
|
|
|
} while (n < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
if (n <= 0)
|
|
|
|
rte_panic("cannot read on configuration pipe\n");
|
|
|
|
|
|
|
|
lcore_config[lcore_id].state = RUNNING;
|
|
|
|
|
|
|
|
/* send ack */
|
|
|
|
n = 0;
|
|
|
|
while (n == 0 || (n < 0 && errno == EINTR))
|
|
|
|
n = write(s2m, &c, 1);
|
|
|
|
if (n < 0)
|
|
|
|
rte_panic("cannot write on configuration pipe\n");
|
|
|
|
|
|
|
|
if (lcore_config[lcore_id].f == NULL)
|
|
|
|
rte_panic("NULL function pointer\n");
|
|
|
|
|
|
|
|
/* call the function and store the return value */
|
|
|
|
fct_arg = lcore_config[lcore_id].arg;
|
|
|
|
ret = lcore_config[lcore_id].f(fct_arg);
|
|
|
|
lcore_config[lcore_id].ret = ret;
|
|
|
|
rte_wmb();
|
|
|
|
lcore_config[lcore_id].state = FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* never reached */
|
|
|
|
/* pthread_exit(NULL); */
|
|
|
|
/* return NULL; */
|
|
|
|
}
|
2015-02-17 10:08:06 +08:00
|
|
|
|
|
|
|
/* require calling thread tid by gettid() */
|
|
|
|
int rte_sys_gettid(void)
|
|
|
|
{
|
|
|
|
long lwpid;
|
|
|
|
thr_self(&lwpid);
|
|
|
|
return (int)lwpid;
|
|
|
|
}
|
2016-06-17 14:48:16 +02:00
|
|
|
|
|
|
|
int rte_thread_setname(pthread_t id, const char *name)
|
|
|
|
{
|
|
|
|
/* this BSD function returns no error */
|
|
|
|
pthread_set_name_np(id, name);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-23 00:33:18 +05:30
|
|
|
|
|
|
|
int rte_thread_getname(pthread_t id, char *name, size_t len)
|
|
|
|
{
|
|
|
|
RTE_SET_USED(id);
|
|
|
|
RTE_SET_USED(name);
|
|
|
|
RTE_SET_USED(len);
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|