blob: 9239399e54914537c5453c77c234d4af7877b403 [file] [log] [blame]
Thomas Gleixner3367e562008-01-30 13:30:38 +01001/*
2 * Written by: Matthew Dobson, IBM Corporation
3 *
4 * Copyright (C) 2002, IBM Corp.
5 *
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * Send feedback to <colpatch@us.ibm.com>
24 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -070025#ifndef _ASM_X86_TOPOLOGY_H
26#define _ASM_X86_TOPOLOGY_H
Thomas Gleixner3367e562008-01-30 13:30:38 +010027
Lee Schermerhorn4e25b252009-12-14 17:58:23 -080028/*
29 * to preserve the visibility of NUMA_NO_NODE definition,
30 * moved to there from here. May be used independent of
31 * CONFIG_NUMA.
32 */
33#include <linux/numa.h>
Mike Travis23ca4bb2008-05-12 21:21:12 +020034
Thomas Gleixner3367e562008-01-30 13:30:38 +010035#ifdef CONFIG_NUMA
36#include <linux/cpumask.h>
Lee Schermerhorn4e25b252009-12-14 17:58:23 -080037
Thomas Gleixner3367e562008-01-30 13:30:38 +010038#include <asm/mpspec.h>
Paul Gortmaker186f4362016-07-13 20:18:56 -040039#include <asm/percpu.h>
Thomas Gleixner3367e562008-01-30 13:30:38 +010040
Mike Travis23ca4bb2008-05-12 21:21:12 +020041/* Mappings between logical cpu number and node number */
42DECLARE_EARLY_PER_CPU(int, x86_cpu_to_node_map);
Thomas Gleixner3367e562008-01-30 13:30:38 +010043
Mike Travis23ca4bb2008-05-12 21:21:12 +020044#ifdef CONFIG_DEBUG_PER_CPU_MAPS
Lee Schermerhorne534c7c2010-05-26 14:44:58 -070045/*
46 * override generic percpu implementation of cpu_to_node
47 */
48extern int __cpu_to_node(int cpu);
49#define cpu_to_node __cpu_to_node
50
Mike Travis23ca4bb2008-05-12 21:21:12 +020051extern int early_cpu_to_node(int cpu);
Mike Travis23ca4bb2008-05-12 21:21:12 +020052
53#else /* !CONFIG_DEBUG_PER_CPU_MAPS */
54
Mike Travis23ca4bb2008-05-12 21:21:12 +020055/* Same function but used if called before per_cpu areas are setup */
56static inline int early_cpu_to_node(int cpu)
57{
Tejun Heof10fcd472009-01-13 20:41:34 +090058 return early_per_cpu(x86_cpu_to_node_map, cpu);
Mike Travis23ca4bb2008-05-12 21:21:12 +020059}
Mike Travisaa6b5442008-03-31 08:41:55 -070060
Rusty Russell71ee73e2009-03-13 14:49:52 +103061#endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
Thomas Gleixner3367e562008-01-30 13:30:38 +010062
Rusty Russell71ee73e2009-03-13 14:49:52 +103063/* Mappings between node number and cpus on that node. */
Rusty Russellc032ef602009-03-13 14:49:53 +103064extern cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
Rusty Russell71ee73e2009-03-13 14:49:52 +103065
66#ifdef CONFIG_DEBUG_PER_CPU_MAPS
Rusty Russell73e907d2009-03-13 14:49:57 +103067extern const struct cpumask *cpumask_of_node(int node);
Rusty Russell71ee73e2009-03-13 14:49:52 +103068#else
Thomas Gleixner3367e562008-01-30 13:30:38 +010069/* Returns a pointer to the cpumask of CPUs on Node 'node'. */
Rusty Russellc032ef602009-03-13 14:49:53 +103070static inline const struct cpumask *cpumask_of_node(int node)
Thomas Gleixner3367e562008-01-30 13:30:38 +010071{
72 return node_to_cpumask_map[node];
73}
Rusty Russell71ee73e2009-03-13 14:49:52 +103074#endif
Mike Travis23ca4bb2008-05-12 21:21:12 +020075
Brian Gerst6470aff2009-01-27 12:56:47 +090076extern void setup_node_to_cpumask_map(void);
77
Thomas Gleixner3367e562008-01-30 13:30:38 +010078#define pcibus_to_node(bus) __pcibus_to_node(bus)
Thomas Gleixner3367e562008-01-30 13:30:38 +010079
Thomas Gleixner3367e562008-01-30 13:30:38 +010080extern int __node_distance(int, int);
81#define node_distance(a, b) __node_distance(a, b)
Thomas Gleixner3367e562008-01-30 13:30:38 +010082
Mike Travis23ca4bb2008-05-12 21:21:12 +020083#else /* !CONFIG_NUMA */
Thomas Gleixner3367e562008-01-30 13:30:38 +010084
Mike Travisf2a08272009-01-15 09:19:32 -080085static inline int numa_node_id(void)
86{
87 return 0;
88}
Lee Schermerhorn72812012010-05-26 14:44:56 -070089/*
90 * indicate override:
91 */
92#define numa_node_id numa_node_id
Mike Travisf2a08272009-01-15 09:19:32 -080093
Mike Travisf2a08272009-01-15 09:19:32 -080094static inline int early_cpu_to_node(int cpu)
95{
96 return 0;
97}
Mike Travis23ca4bb2008-05-12 21:21:12 +020098
Brian Gerst6470aff2009-01-27 12:56:47 +090099static inline void setup_node_to_cpumask_map(void) { }
100
Thomas Gleixner3367e562008-01-30 13:30:38 +0100101#endif
102
Mike Travisaa6b5442008-03-31 08:41:55 -0700103#include <asm-generic/topology.h>
104
Rusty Russell030bb202008-12-26 22:23:41 +1030105extern const struct cpumask *cpu_coregroup_mask(int cpu);
Thomas Gleixner3367e562008-01-30 13:30:38 +0100106
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000107#define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id)
Thomas Gleixner3367e562008-01-30 13:30:38 +0100108#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id)
Len Brown212bf4f2019-05-13 13:58:49 -0400109#define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id)
Len Brown306a0de2019-05-13 13:58:48 -0400110#define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id)
Thomas Gleixner3367e562008-01-30 13:30:38 +0100111#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
Artem Fetishev825600c2014-03-28 13:33:39 -0700112
Borislav Petkov1eb8f692021-01-14 10:36:59 +0100113extern unsigned int __max_die_per_package;
114
Sudeep Holla3282e6b2016-05-04 17:50:59 +0100115#ifdef CONFIG_SMP
Len Brown2e4c54d2019-05-13 13:58:56 -0400116#define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu))
Rusty Russell7ad728f2009-03-13 14:49:50 +1030117#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
Bartosz Golaszewski06931e62015-05-26 15:11:28 +0200118#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000119
120extern unsigned int __max_logical_packages;
121#define topology_max_packages() (__max_logical_packages)
Andi Kleen70b83012016-05-19 17:09:55 -0700122
Len Brown14d96d62019-05-13 13:58:46 -0400123static inline int topology_max_die_per_package(void)
124{
125 return __max_die_per_package;
126}
127
Andi Kleen70b83012016-05-19 17:09:55 -0700128extern int __max_smt_threads;
129
130static inline int topology_max_smt_threads(void)
131{
132 return __max_smt_threads;
133}
134
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000135int topology_update_package_map(unsigned int apicid, unsigned int cpu);
Len Brown212bf4f2019-05-13 13:58:49 -0400136int topology_update_die_map(unsigned int dieid, unsigned int cpu);
Thomas Gleixner6a4d2652018-05-29 17:50:22 +0200137int topology_phys_to_logical_pkg(unsigned int pkg);
Len Brown212bf4f2019-05-13 13:58:49 -0400138int topology_phys_to_logical_die(unsigned int die, unsigned int cpu);
Thomas Gleixner6a4d2652018-05-29 17:50:22 +0200139bool topology_is_primary_thread(unsigned int cpu);
Thomas Gleixnerf048c392018-06-21 10:37:20 +0200140bool topology_smt_supported(void);
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000141#else
142#define topology_max_packages() (1)
143static inline int
144topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
Len Brown212bf4f2019-05-13 13:58:49 -0400145static inline int
146topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; }
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000147static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
Len Brown14d96d62019-05-13 13:58:46 -0400148static inline int topology_phys_to_logical_die(unsigned int die,
149 unsigned int cpu) { return 0; }
150static inline int topology_max_die_per_package(void) { return 1; }
Andi Kleen70b83012016-05-19 17:09:55 -0700151static inline int topology_max_smt_threads(void) { return 1; }
Thomas Gleixner6a4d2652018-05-29 17:50:22 +0200152static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
Thomas Gleixnerf048c392018-06-21 10:37:20 +0200153static inline bool topology_smt_supported(void) { return false; }
Thomas Gleixner3367e562008-01-30 13:30:38 +0100154#endif
155
Alex Chiangfe086a72008-04-29 15:05:29 -0700156static inline void arch_fix_phys_package_id(int num, u32 slot)
157{
158}
159
Yinghai Lu30a18d62008-02-19 03:21:20 -0800160struct pci_bus;
Bjorn Helgaasafcf21c22014-01-24 11:54:36 -0700161int x86_pci_root_bus_node(int bus);
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600162void x86_pci_root_bus_resources(int bus, struct list_head *resources);
Yinghai Lu30a18d62008-02-19 03:21:20 -0800163
Tim Chen7d251272016-11-22 12:23:54 -0800164extern bool x86_topology_update;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800165
Tim Chende966cf2016-11-29 10:43:27 -0800166#ifdef CONFIG_SCHED_MC_PRIO
Tim Chen5e76b2a2016-11-22 12:23:55 -0800167#include <asm/percpu.h>
168
169DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
Tim Chenf9793e342016-11-22 12:23:56 -0800170extern unsigned int __read_mostly sysctl_sched_itmt_enabled;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800171
172/* Interface to set priority of a cpu */
173void sched_set_itmt_core_prio(int prio, int core_cpu);
174
175/* Interface to notify scheduler that system supports ITMT */
Tim Chenf9793e342016-11-22 12:23:56 -0800176int sched_set_itmt_support(void);
Tim Chen5e76b2a2016-11-22 12:23:55 -0800177
178/* Interface to notify scheduler that system revokes ITMT support */
179void sched_clear_itmt_support(void);
180
Tim Chende966cf2016-11-29 10:43:27 -0800181#else /* CONFIG_SCHED_MC_PRIO */
Tim Chen5e76b2a2016-11-22 12:23:55 -0800182
Tim Chenf9793e342016-11-22 12:23:56 -0800183#define sysctl_sched_itmt_enabled 0
Tim Chen5e76b2a2016-11-22 12:23:55 -0800184static inline void sched_set_itmt_core_prio(int prio, int core_cpu)
185{
186}
Tim Chenf9793e342016-11-22 12:23:56 -0800187static inline int sched_set_itmt_support(void)
Tim Chen5e76b2a2016-11-22 12:23:55 -0800188{
Tim Chenf9793e342016-11-22 12:23:56 -0800189 return 0;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800190}
191static inline void sched_clear_itmt_support(void)
192{
193}
Tim Chende966cf2016-11-29 10:43:27 -0800194#endif /* CONFIG_SCHED_MC_PRIO */
Tim Chen5e76b2a2016-11-22 12:23:55 -0800195
Giovanni Gherdoviche2b0d612020-05-31 20:24:51 +0200196#if defined(CONFIG_SMP) && defined(CONFIG_X86_64)
Giovanni Gherdovich1567c3e32020-01-22 16:16:12 +0100197#include <asm/cpufeature.h>
198
199DECLARE_STATIC_KEY_FALSE(arch_scale_freq_key);
200
201#define arch_scale_freq_invariant() static_branch_likely(&arch_scale_freq_key)
202
203DECLARE_PER_CPU(unsigned long, arch_freq_scale);
204
205static inline long arch_scale_freq_capacity(int cpu)
206{
207 return per_cpu(arch_freq_scale, cpu);
208}
209#define arch_scale_freq_capacity arch_scale_freq_capacity
210
211extern void arch_scale_freq_tick(void);
212#define arch_scale_freq_tick arch_scale_freq_tick
213
Giovanni Gherdovich918229c2020-01-22 16:16:17 +0100214extern void arch_set_max_freq_ratio(bool turbo_disabled);
215#else
216static inline void arch_set_max_freq_ratio(bool turbo_disabled)
217{
218}
Giovanni Gherdovich1567c3e32020-01-22 16:16:12 +0100219#endif
220
Nathan Fontenot41ea6672020-11-12 19:26:12 +0100221#ifdef CONFIG_ACPI_CPPC_LIB
222void init_freq_invariance_cppc(void);
223#define init_freq_invariance_cppc init_freq_invariance_cppc
224#endif
225
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700226#endif /* _ASM_X86_TOPOLOGY_H */