blob: 0f6cd6b73a61372c61eac5ad42222f332438999f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Juri Lelli615ffd62017-05-31 17:59:30 +01002/*
3 * include/linux/arch_topology.h - arch specific cpu topology information
4 */
5#ifndef _LINUX_ARCH_TOPOLOGY_H_
6#define _LINUX_ARCH_TOPOLOGY_H_
7
Viresh Kumar805df292017-06-23 14:55:32 +05308#include <linux/types.h>
Dietmar Eggemann0e27c562017-09-26 17:41:10 +01009#include <linux/percpu.h>
Viresh Kumar805df292017-06-23 14:55:32 +053010
Juri Lelli4ca4f262017-05-31 17:59:31 +010011void topology_normalize_cpu_scale(void);
Morten Rasmussenbb1fbdd2018-07-20 14:32:32 +010012int topology_update_cpu_topology(void);
Juri Lelli615ffd62017-05-31 17:59:30 +010013
14struct device_node;
Viresh Kumar805df292017-06-23 14:55:32 +053015bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu);
Juri Lelli615ffd62017-05-31 17:59:30 +010016
Dietmar Eggemann8216f582017-09-26 17:41:11 +010017DECLARE_PER_CPU(unsigned long, cpu_scale);
18
Dietmar Eggemann99c73ce2020-02-11 19:15:15 +010019static inline unsigned long topology_get_cpu_scale(int cpu)
Dietmar Eggemann8216f582017-09-26 17:41:11 +010020{
21 return per_cpu(cpu_scale, cpu);
22}
Juri Lelli615ffd62017-05-31 17:59:30 +010023
Juri Lelli4ca4f262017-05-31 17:59:31 +010024void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
Juri Lelli615ffd62017-05-31 17:59:30 +010025
Dietmar Eggemann0e27c562017-09-26 17:41:10 +010026DECLARE_PER_CPU(unsigned long, freq_scale);
27
Dietmar Eggemann99c73ce2020-02-11 19:15:15 +010028static inline unsigned long topology_get_freq_scale(int cpu)
Dietmar Eggemann0e27c562017-09-26 17:41:10 +010029{
30 return per_cpu(freq_scale, cpu);
31}
32
Ionela Voinescua20b7052020-09-24 13:30:15 +010033void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
34 unsigned long max_freq);
Valentin Schneider15e5d5b2020-09-01 21:55:49 +010035bool topology_scale_freq_invariant(void);
36
Valentin Schneiderecddc3a2020-09-01 21:55:48 +010037bool arch_freq_counters_available(const struct cpumask *cpus);
Ionela Voinescucd0ed032020-03-05 09:06:26 +000038
Thara Gopinathad58cc52020-02-21 19:52:07 -050039DECLARE_PER_CPU(unsigned long, thermal_pressure);
40
41static inline unsigned long topology_get_thermal_pressure(int cpu)
42{
43 return per_cpu(thermal_pressure, cpu);
44}
45
Valentin Schneider25980c72020-07-12 17:59:15 +010046void topology_set_thermal_pressure(const struct cpumask *cpus,
47 unsigned long th_pressure);
Thara Gopinathad58cc52020-02-21 19:52:07 -050048
Atish Patra60c1b222019-06-27 12:52:58 -070049struct cpu_topology {
50 int thread_id;
51 int core_id;
52 int package_id;
53 int llc_id;
54 cpumask_t thread_sibling;
55 cpumask_t core_sibling;
56 cpumask_t llc_sibling;
57};
58
59#ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
60extern struct cpu_topology cpu_topology[NR_CPUS];
61
62#define topology_physical_package_id(cpu) (cpu_topology[cpu].package_id)
63#define topology_core_id(cpu) (cpu_topology[cpu].core_id)
64#define topology_core_cpumask(cpu) (&cpu_topology[cpu].core_sibling)
65#define topology_sibling_cpumask(cpu) (&cpu_topology[cpu].thread_sibling)
66#define topology_llc_cpumask(cpu) (&cpu_topology[cpu].llc_sibling)
67void init_cpu_topology(void);
68void store_cpu_topology(unsigned int cpuid);
69const struct cpumask *cpu_coregroup_mask(int cpu);
Atish Patra60c1b222019-06-27 12:52:58 -070070void update_siblings_masks(unsigned int cpu);
Atish Patra60c1b222019-06-27 12:52:58 -070071void remove_cpu_topology(unsigned int cpuid);
Atish Patraca74b312019-06-27 12:52:59 -070072void reset_cpu_topology(void);
Ben Dooks (Codethink)edb44e842019-10-22 09:43:23 +010073int parse_acpi_topology(void);
Atish Patraca74b312019-06-27 12:52:59 -070074#endif
Atish Patra60c1b222019-06-27 12:52:58 -070075
Juri Lelli615ffd62017-05-31 17:59:30 +010076#endif /* _LINUX_ARCH_TOPOLOGY_H_ */