1a551c94aSIdo Barnea/*-
2a551c94aSIdo Barnea *   BSD LICENSE
3a551c94aSIdo Barnea *
4a551c94aSIdo Barnea *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5a551c94aSIdo Barnea *   All rights reserved.
6a551c94aSIdo Barnea *
7a551c94aSIdo Barnea *   Redistribution and use in source and binary forms, with or without
8a551c94aSIdo Barnea *   modification, are permitted provided that the following conditions
9a551c94aSIdo Barnea *   are met:
10a551c94aSIdo Barnea *
11a551c94aSIdo Barnea *     * Redistributions of source code must retain the above copyright
12a551c94aSIdo Barnea *       notice, this list of conditions and the following disclaimer.
13a551c94aSIdo Barnea *     * Redistributions in binary form must reproduce the above copyright
14a551c94aSIdo Barnea *       notice, this list of conditions and the following disclaimer in
15a551c94aSIdo Barnea *       the documentation and/or other materials provided with the
16a551c94aSIdo Barnea *       distribution.
17a551c94aSIdo Barnea *     * Neither the name of Intel Corporation nor the names of its
18a551c94aSIdo Barnea *       contributors may be used to endorse or promote products derived
19a551c94aSIdo Barnea *       from this software without specific prior written permission.
20a551c94aSIdo Barnea *
21a551c94aSIdo Barnea *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22a551c94aSIdo Barnea *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23a551c94aSIdo Barnea *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24a551c94aSIdo Barnea *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25a551c94aSIdo Barnea *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26a551c94aSIdo Barnea *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27a551c94aSIdo Barnea *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28a551c94aSIdo Barnea *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29a551c94aSIdo Barnea *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30a551c94aSIdo Barnea *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31a551c94aSIdo Barnea *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32a551c94aSIdo Barnea */
33a551c94aSIdo Barnea
34a551c94aSIdo Barnea#include <unistd.h>
35a551c94aSIdo Barnea#include <sys/sysctl.h>
36a551c94aSIdo Barnea
37a551c94aSIdo Barnea#include <rte_log.h>
38a551c94aSIdo Barnea#include <rte_eal.h>
39a551c94aSIdo Barnea#include <rte_lcore.h>
40a551c94aSIdo Barnea#include <rte_common.h>
41a551c94aSIdo Barnea#include <rte_debug.h>
42a551c94aSIdo Barnea
43a551c94aSIdo Barnea#include "eal_private.h"
44a551c94aSIdo Barnea#include "eal_thread.h"
45a551c94aSIdo Barnea
46a551c94aSIdo Barnea/* No topology information available on FreeBSD including NUMA info */
47a551c94aSIdo Barneaunsigned
48a551c94aSIdo Barneaeal_cpu_core_id(__rte_unused unsigned lcore_id)
49a551c94aSIdo Barnea{
50a551c94aSIdo Barnea	return 0;
51a551c94aSIdo Barnea}
52a551c94aSIdo Barnea
53a551c94aSIdo Barneastatic int
54a551c94aSIdo Barneaeal_get_ncpus(void)
55a551c94aSIdo Barnea{
56a551c94aSIdo Barnea	int mib[2] = {CTL_HW, HW_NCPU};
57a551c94aSIdo Barnea	int ncpu;
58a551c94aSIdo Barnea	size_t len = sizeof(ncpu);
59a551c94aSIdo Barnea
60a551c94aSIdo Barnea	sysctl(mib, 2, &ncpu, &len, NULL, 0);
61a551c94aSIdo Barnea	RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu);
62a551c94aSIdo Barnea	return ncpu;
63a551c94aSIdo Barnea}
64a551c94aSIdo Barnea
65a551c94aSIdo Barneaunsigned
66a551c94aSIdo Barneaeal_cpu_socket_id(__rte_unused unsigned cpu_id)
67a551c94aSIdo Barnea{
68a551c94aSIdo Barnea	return 0;
69a551c94aSIdo Barnea}
70a551c94aSIdo Barnea
71a551c94aSIdo Barnea/* Check if a cpu is present by the presence of the
72a551c94aSIdo Barnea * cpu information for it.
73a551c94aSIdo Barnea */
74a551c94aSIdo Barneaint
75a551c94aSIdo Barneaeal_cpu_detected(unsigned lcore_id)
76a551c94aSIdo Barnea{
77a551c94aSIdo Barnea	const unsigned ncpus = eal_get_ncpus();
78a551c94aSIdo Barnea	return lcore_id < ncpus;
79a551c94aSIdo Barnea}
80