X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fcommon%2Feal_common_thread.c;h=4bc5c3120aad0b8822248a411b334f306ac7eb85;hb=5c307ba2a5b14abb70dcc80a1283ba5a128262d9;hp=b1b69ea58c57d21ec3e2beacbd38292ded923678;hpb=a837d5c5986d01bbeecdaae1b8ab248611dafcdd;p=dpdk.git diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index b1b69ea58c..4bc5c3120a 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -12,9 +12,10 @@ #include #include +#include #include -#include #include +#include #include #include "eal_internal_cfg.h" @@ -241,3 +242,49 @@ fail: pthread_join(*thread, NULL); return -ret; } + +int +rte_thread_register(void) +{ + unsigned int lcore_id; + rte_cpuset_t cpuset; + + /* EAL init flushes all lcores, we can't register before. */ + if (eal_get_internal_configuration()->init_complete != 1) { + RTE_LOG(DEBUG, EAL, "Called %s before EAL init.\n", __func__); + rte_errno = EINVAL; + return -1; + } + if (!__rte_mp_disable()) { + RTE_LOG(ERR, EAL, "Multiprocess in use, registering non-EAL threads is not supported.\n"); + rte_errno = EINVAL; + return -1; + } + if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset), + &cpuset) != 0) + CPU_ZERO(&cpuset); + lcore_id = eal_lcore_non_eal_allocate(); + if (lcore_id >= RTE_MAX_LCORE) + lcore_id = LCORE_ID_ANY; + __rte_thread_init(lcore_id, &cpuset); + if (lcore_id == LCORE_ID_ANY) { + rte_errno = ENOMEM; + return -1; + } + RTE_LOG(DEBUG, EAL, "Registered non-EAL thread as lcore %u.\n", + lcore_id); + return 0; +} + +void +rte_thread_unregister(void) +{ + unsigned int lcore_id = rte_lcore_id(); + + if (lcore_id != LCORE_ID_ANY) + eal_lcore_non_eal_release(lcore_id); + __rte_thread_uninit(); + if (lcore_id != LCORE_ID_ANY) + RTE_LOG(DEBUG, EAL, "Unregistered non-EAL thread (was lcore %u).\n", + lcore_id); +}