blob: 453cf38a1c33d5b2452dff29be06ce52b5b30ffb [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 Heof10fcd42009-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)
109#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
Artem Fetishev825600c2014-03-28 13:33:39 -0700110
Sudeep Holla3282e6b2016-05-04 17:50:59 +0100111#ifdef CONFIG_SMP
Rusty Russell7ad728f2009-03-13 14:49:50 +1030112#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
Bartosz Golaszewski06931e62015-05-26 15:11:28 +0200113#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000114
115extern unsigned int __max_logical_packages;
116#define topology_max_packages() (__max_logical_packages)
Andi Kleen70b83012016-05-19 17:09:55 -0700117
118extern int __max_smt_threads;
119
120static inline int topology_max_smt_threads(void)
121{
122 return __max_smt_threads;
123}
124
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000125int topology_update_package_map(unsigned int apicid, unsigned int cpu);
Thomas Gleixner6a4d2652018-05-29 17:50:22 +0200126int topology_phys_to_logical_pkg(unsigned int pkg);
127bool topology_is_primary_thread(unsigned int cpu);
Thomas Gleixnerf048c392018-06-21 10:37:20 +0200128bool topology_smt_supported(void);
Thomas Gleixner1f12e322016-02-22 22:19:15 +0000129#else
130#define topology_max_packages() (1)
131static inline int
132topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
133static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
Andi Kleen70b83012016-05-19 17:09:55 -0700134static inline int topology_max_smt_threads(void) { return 1; }
Thomas Gleixner6a4d2652018-05-29 17:50:22 +0200135static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
Thomas Gleixnerf048c392018-06-21 10:37:20 +0200136static inline bool topology_smt_supported(void) { return false; }
Thomas Gleixner3367e562008-01-30 13:30:38 +0100137#endif
138
Alex Chiangfe086a72008-04-29 15:05:29 -0700139static inline void arch_fix_phys_package_id(int num, u32 slot)
140{
141}
142
Yinghai Lu30a18d62008-02-19 03:21:20 -0800143struct pci_bus;
Bjorn Helgaasafcf21c22014-01-24 11:54:36 -0700144int x86_pci_root_bus_node(int bus);
Bjorn Helgaas2cd69752011-10-28 16:28:14 -0600145void x86_pci_root_bus_resources(int bus, struct list_head *resources);
Yinghai Lu30a18d62008-02-19 03:21:20 -0800146
Tim Chen7d251272016-11-22 12:23:54 -0800147extern bool x86_topology_update;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800148
Tim Chende966cf2016-11-29 10:43:27 -0800149#ifdef CONFIG_SCHED_MC_PRIO
Tim Chen5e76b2a2016-11-22 12:23:55 -0800150#include <asm/percpu.h>
151
152DECLARE_PER_CPU_READ_MOSTLY(int, sched_core_priority);
Tim Chenf9793e342016-11-22 12:23:56 -0800153extern unsigned int __read_mostly sysctl_sched_itmt_enabled;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800154
155/* Interface to set priority of a cpu */
156void sched_set_itmt_core_prio(int prio, int core_cpu);
157
158/* Interface to notify scheduler that system supports ITMT */
Tim Chenf9793e342016-11-22 12:23:56 -0800159int sched_set_itmt_support(void);
Tim Chen5e76b2a2016-11-22 12:23:55 -0800160
161/* Interface to notify scheduler that system revokes ITMT support */
162void sched_clear_itmt_support(void);
163
Tim Chende966cf2016-11-29 10:43:27 -0800164#else /* CONFIG_SCHED_MC_PRIO */
Tim Chen5e76b2a2016-11-22 12:23:55 -0800165
Tim Chenf9793e342016-11-22 12:23:56 -0800166#define sysctl_sched_itmt_enabled 0
Tim Chen5e76b2a2016-11-22 12:23:55 -0800167static inline void sched_set_itmt_core_prio(int prio, int core_cpu)
168{
169}
Tim Chenf9793e342016-11-22 12:23:56 -0800170static inline int sched_set_itmt_support(void)
Tim Chen5e76b2a2016-11-22 12:23:55 -0800171{
Tim Chenf9793e342016-11-22 12:23:56 -0800172 return 0;
Tim Chen5e76b2a2016-11-22 12:23:55 -0800173}
174static inline void sched_clear_itmt_support(void)
175{
176}
Tim Chende966cf2016-11-29 10:43:27 -0800177#endif /* CONFIG_SCHED_MC_PRIO */
Tim Chen5e76b2a2016-11-22 12:23:55 -0800178
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700179#endif /* _ASM_X86_TOPOLOGY_H */