Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * arch/arm/kernel/topology.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2011 Linaro Limited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by: Vincent Guittot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * based on arch/sh/kernel/topology.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/arch_topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/node.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sched/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/cputype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * cpu capacity scale management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * cpu capacity table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * This per cpu data structure describes the relative capacity of each core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * On a heteregenous system, cores don't have the same computation capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * and we reflect that difference in the cpu_capacity field so the scheduler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * can take this difference into account during load balance. A per cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * structure is preferred because each CPU updates its own cpu_capacity field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * during the load balance except for idle cores. One idle core is selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * to run the rebalance_domains for all idle cores and the cpu_capacity can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * updated during this sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) struct cpu_efficiency {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	const char *compatible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long efficiency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * Table of relative efficiency of each processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * The efficiency value must fit in 20bit and the final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * cpu_scale value must be in the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *   0 < cpu_scale < 3*SCHED_CAPACITY_SCALE/2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * in order to return at most 1 when DIV_ROUND_CLOSEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * is used to compute the capacity of a CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Processors that are not defined in the table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * use the default SCHED_CAPACITY_SCALE value for cpu_scale.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static const struct cpu_efficiency table_efficiency[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{"arm,cortex-a15", 3891},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	{"arm,cortex-a7",  2048},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{NULL, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static unsigned long *__cpu_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define cpu_capacity(cpu)	__cpu_capacity[cpu]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static unsigned long middle_capacity = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static bool cap_from_dt = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Iterate all CPUs' descriptor in DT and compute the efficiency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * (as per table_efficiency). Also calculate a middle efficiency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * as close as possible to  (max{eff_i} - min{eff_i}) / 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * This is later used to scale the cpu_capacity field such that an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * 'average' CPU is of middle capacity. Also see the comments near
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * table_efficiency[] and update_cpu_capacity().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void __init parse_dt_topology(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	const struct cpu_efficiency *cpu_eff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct device_node *cn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned long min_capacity = ULONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned long max_capacity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	unsigned long capacity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int cpu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	__cpu_capacity = kcalloc(nr_cpu_ids, sizeof(*__cpu_capacity),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				 GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		const __be32 *rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		/* too early to use cpu->of_node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		cn = of_get_cpu_node(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (!cn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			pr_err("missing device node for CPU %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (topology_parse_cpu_capacity(cn, cpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			of_node_put(cn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		cap_from_dt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		for (cpu_eff = table_efficiency; cpu_eff->compatible; cpu_eff++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			if (of_device_is_compatible(cn, cpu_eff->compatible))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		if (cpu_eff->compatible == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		rate = of_get_property(cn, "clock-frequency", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if (!rate || len != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			pr_err("%pOF missing clock-frequency property\n", cn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		capacity = ((be32_to_cpup(rate)) >> 20) * cpu_eff->efficiency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		/* Save min capacity of the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if (capacity < min_capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			min_capacity = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		/* Save max capacity of the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (capacity > max_capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			max_capacity = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		cpu_capacity(cpu) = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* If min and max capacities are equals, we bypass the update of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * cpu_scale because all CPUs have the same capacity. Otherwise, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 * compute a middle_capacity factor that will ensure that the capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 * of an 'average' CPU of the system will be as close as possible to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 * SCHED_CAPACITY_SCALE, which is the default value, but with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * constraint explained near table_efficiency[].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (4*max_capacity < (3*(max_capacity + min_capacity)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		middle_capacity = (min_capacity + max_capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				>> (SCHED_CAPACITY_SHIFT+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		middle_capacity = ((max_capacity / 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				>> (SCHED_CAPACITY_SHIFT-1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (cap_from_dt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		topology_normalize_cpu_scale();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Look for a customed capacity of a CPU in the cpu_capacity table during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * boot. The update of all CPUs is in O(n^2) for heteregeneous system but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * function returns directly for SMP system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void update_cpu_capacity(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!cpu_capacity(cpu) || cap_from_dt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	topology_set_cpu_scale(cpu, cpu_capacity(cpu) / middle_capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	pr_info("CPU%u: update cpu_capacity %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		cpu, topology_get_cpu_scale(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static inline void parse_dt_topology(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static inline void update_cpu_capacity(unsigned int cpuid) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * store_cpu_topology is called at boot when only one cpu is running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * and with the mutex cpu_hotplug.lock locked, when several cpus have booted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * which prevents simultaneous write access to cpu_topology array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) void store_cpu_topology(unsigned int cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	unsigned int mpidr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (cpuid_topo->package_id != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto topology_populated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	mpidr = read_cpuid_mpidr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	/* create cpu topology mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if ((mpidr & MPIDR_SMP_BITMASK) == MPIDR_SMP_VALUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		 * This is a multiprocessor system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		 * multiprocessor format & multiprocessor mode field are set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (mpidr & MPIDR_MT_BITMASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			/* core performance interdependency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			cpuid_topo->package_id = MPIDR_AFFINITY_LEVEL(mpidr, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			/* largely independent cores */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			cpuid_topo->thread_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			cpuid_topo->package_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		 * This is an uniprocessor system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		 * we are in multiprocessor format but uniprocessor system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		 * or in the old uniprocessor format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		cpuid_topo->thread_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		cpuid_topo->core_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		cpuid_topo->package_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	update_cpu_capacity(cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	pr_info("CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		cpuid, cpu_topology[cpuid].thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		cpu_topology[cpuid].core_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		cpu_topology[cpuid].package_id, mpidr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) topology_populated:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	update_siblings_masks(cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * init_cpu_topology is called at boot when only one cpu is running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * which prevent simultaneous write access to cpu_topology array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void __init init_cpu_topology(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	reset_cpu_topology();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	parse_dt_topology();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }