New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / bsdapp / eal / eal_lcore.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <unistd.h>
6 #include <sys/sysctl.h>
7
8 #include <rte_log.h>
9 #include <rte_eal.h>
10 #include <rte_lcore.h>
11 #include <rte_common.h>
12 #include <rte_debug.h>
13
14 #include "eal_private.h"
15 #include "eal_thread.h"
16
17 /* No topology information available on FreeBSD including NUMA info */
18 unsigned
19 eal_cpu_core_id(__rte_unused unsigned lcore_id)
20 {
21         return 0;
22 }
23
24 static int
25 eal_get_ncpus(void)
26 {
27         static int ncpu = -1;
28         int mib[2] = {CTL_HW, HW_NCPU};
29         size_t len = sizeof(ncpu);
30
31         if (ncpu < 0) {
32                 sysctl(mib, 2, &ncpu, &len, NULL, 0);
33                 RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu);
34         }
35         return ncpu;
36 }
37
38 unsigned
39 eal_cpu_socket_id(__rte_unused unsigned cpu_id)
40 {
41         return 0;
42 }
43
44 /* Check if a cpu is present by the presence of the
45  * cpu information for it.
46  */
47 int
48 eal_cpu_detected(unsigned lcore_id)
49 {
50         const unsigned ncpus = eal_get_ncpus();
51         return lcore_id < ncpus;
52 }