2 * Copyright (c) 2021 The DragonFly Project. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
14 * 3. Neither the name of The DragonFly Project nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific, prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _CPU_TOPOLOGY_H_
33 #define _CPU_TOPOLOGY_H_
35 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
37 #include <sys/param.h>
38 #include <sys/cpumask.h>
40 /* CPU TOPOLOGY DATA AND FUNCTIONS */
42 struct cpu_node * parent_node;
43 struct cpu_node * child_node[MAXCPU];
48 uint8_t compute_unit_id; /* AMD compute unit ID */
51 long phys_mem; /* supplied from vm_numa_organize() */
53 typedef struct cpu_node cpu_node_t;
57 /* Level type for CPU siblings */
58 #define PACKAGE_LEVEL 1
61 #define THREAD_LEVEL 4
63 #define CPUSET_FOREACH(cpu, mask) \
64 for ((cpu) = 0; (cpu) < ncpus; (cpu)++) \
65 if (CPUMASK_TESTBIT(mask, cpu))
71 extern int cpu_topology_levels_number;
72 extern int cpu_topology_ht_ids;
73 extern int cpu_topology_core_ids;
74 extern int cpu_topology_phys_ids;
75 extern cpu_node_t *root_cpu_node;
77 cpumask_t get_cpumask_from_level(int cpuid, uint8_t level_type);
78 cpu_node_t *get_cpu_node_by_cpuid(int cpuid);
79 const cpu_node_t *get_cpu_node_by_chipid(int chip_id);
80 long get_highest_node_memory(void);
81 int get_cpu_ht_id(int cpuid);
82 int get_cpu_core_id(int cpuid);
83 int get_cpu_phys_id(int cpuid);
86 #endif /* _CPU_TOPOLOGY_H_ */