Skip to content

Commit ca74b31

Browse files
atishp04paul-walmsley-sifive
authored andcommitted
arm: Use common cpu_topology structure and functions.
Currently, ARM32 and ARM64 uses different data structures to represent their cpu topologies. Since, we are moving the ARM64 topology to common code to be used by other architectures, we can reuse that for ARM32 as well. Take this opprtunity to remove the redundant functions from ARM32 and reuse the common code instead. To: Russell King <linux@armlinux.org.uk> Signed-off-by: Atish Patra <atish.patra@wdc.com> Tested-by: Sudeep Holla <sudeep.holla@arm.com> (on TC2) Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
1 parent 60c1b22 commit ca74b31

4 files changed

Lines changed: 11 additions & 79 deletions

File tree

arch/arm/include/asm/topology.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@
55
#ifdef CONFIG_ARM_CPU_TOPOLOGY
66

77
#include <linux/cpumask.h>
8-
9-
struct cputopo_arm {
10-
int thread_id;
11-
int core_id;
12-
int socket_id;
13-
cpumask_t thread_sibling;
14-
cpumask_t core_sibling;
15-
};
16-
17-
extern struct cputopo_arm cpu_topology[NR_CPUS];
18-
19-
#define topology_physical_package_id(cpu) (cpu_topology[cpu].socket_id)
20-
#define topology_core_id(cpu) (cpu_topology[cpu].core_id)
21-
#define topology_core_cpumask(cpu) (&cpu_topology[cpu].core_sibling)
22-
#define topology_sibling_cpumask(cpu) (&cpu_topology[cpu].thread_sibling)
23-
24-
void init_cpu_topology(void);
25-
void store_cpu_topology(unsigned int cpuid);
26-
const struct cpumask *cpu_coregroup_mask(int cpu);
27-
288
#include <linux/arch_topology.h>
299

3010
/* Replace task scheduler's default frequency-invariant accounting */

arch/arm/kernel/topology.c

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,6 @@ static inline void parse_dt_topology(void) {}
177177
static inline void update_cpu_capacity(unsigned int cpuid) {}
178178
#endif
179179

180-
/*
181-
* cpu topology table
182-
*/
183-
struct cputopo_arm cpu_topology[NR_CPUS];
184-
EXPORT_SYMBOL_GPL(cpu_topology);
185-
186-
const struct cpumask *cpu_coregroup_mask(int cpu)
187-
{
188-
return &cpu_topology[cpu].core_sibling;
189-
}
190-
191180
/*
192181
* The current assumption is that we can power gate each core independently.
193182
* This will be superseded by DT binding once available.
@@ -197,40 +186,14 @@ const struct cpumask *cpu_corepower_mask(int cpu)
197186
return &cpu_topology[cpu].thread_sibling;
198187
}
199188

200-
static void update_siblings_masks(unsigned int cpuid)
201-
{
202-
struct cputopo_arm *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
203-
int cpu;
204-
205-
/* update core and thread sibling masks */
206-
for_each_possible_cpu(cpu) {
207-
cpu_topo = &cpu_topology[cpu];
208-
209-
if (cpuid_topo->socket_id != cpu_topo->socket_id)
210-
continue;
211-
212-
cpumask_set_cpu(cpuid, &cpu_topo->core_sibling);
213-
if (cpu != cpuid)
214-
cpumask_set_cpu(cpu, &cpuid_topo->core_sibling);
215-
216-
if (cpuid_topo->core_id != cpu_topo->core_id)
217-
continue;
218-
219-
cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling);
220-
if (cpu != cpuid)
221-
cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling);
222-
}
223-
smp_wmb();
224-
}
225-
226189
/*
227190
* store_cpu_topology is called at boot when only one cpu is running
228191
* and with the mutex cpu_hotplug.lock locked, when several cpus have booted,
229192
* which prevents simultaneous write access to cpu_topology array
230193
*/
231194
void store_cpu_topology(unsigned int cpuid)
232195
{
233-
struct cputopo_arm *cpuid_topo = &cpu_topology[cpuid];
196+
struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
234197
unsigned int mpidr;
235198

236199
/* If the cpu topology has been already set, just return */
@@ -250,12 +213,12 @@ void store_cpu_topology(unsigned int cpuid)
250213
/* core performance interdependency */
251214
cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
252215
cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
253-
cpuid_topo->socket_id = MPIDR_AFFINITY_LEVEL(mpidr, 2);
216+
cpuid_topo->package_id = MPIDR_AFFINITY_LEVEL(mpidr, 2);
254217
} else {
255218
/* largely independent cores */
256219
cpuid_topo->thread_id = -1;
257220
cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
258-
cpuid_topo->socket_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
221+
cpuid_topo->package_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
259222
}
260223
} else {
261224
/*
@@ -265,7 +228,7 @@ void store_cpu_topology(unsigned int cpuid)
265228
*/
266229
cpuid_topo->thread_id = -1;
267230
cpuid_topo->core_id = 0;
268-
cpuid_topo->socket_id = -1;
231+
cpuid_topo->package_id = -1;
269232
}
270233

271234
update_siblings_masks(cpuid);
@@ -275,7 +238,7 @@ void store_cpu_topology(unsigned int cpuid)
275238
pr_info("CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",
276239
cpuid, cpu_topology[cpuid].thread_id,
277240
cpu_topology[cpuid].core_id,
278-
cpu_topology[cpuid].socket_id, mpidr);
241+
cpu_topology[cpuid].package_id, mpidr);
279242
}
280243

281244
static inline int cpu_corepower_flags(void)
@@ -298,18 +261,7 @@ static struct sched_domain_topology_level arm_topology[] = {
298261
*/
299262
void __init init_cpu_topology(void)
300263
{
301-
unsigned int cpu;
302-
303-
/* init core mask and capacity */
304-
for_each_possible_cpu(cpu) {
305-
struct cputopo_arm *cpu_topo = &(cpu_topology[cpu]);
306-
307-
cpu_topo->thread_id = -1;
308-
cpu_topo->core_id = -1;
309-
cpu_topo->socket_id = -1;
310-
cpumask_clear(&cpu_topo->core_sibling);
311-
cpumask_clear(&cpu_topo->thread_sibling);
312-
}
264+
reset_cpu_topology();
313265
smp_wmb();
314266

315267
parse_dt_topology();

drivers/base/arch_topology.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ static int __init parse_dt_topology(void)
423423
of_node_put(cn);
424424
return ret;
425425
}
426+
#endif
426427

427428
/*
428429
* cpu topology table
@@ -488,7 +489,7 @@ static void clear_cpu_topology(int cpu)
488489
cpumask_set_cpu(cpu, &cpu_topo->thread_sibling);
489490
}
490491

491-
static void __init reset_cpu_topology(void)
492+
void __init reset_cpu_topology(void)
492493
{
493494
unsigned int cpu;
494495

@@ -523,6 +524,7 @@ __weak int __init parse_acpi_topology(void)
523524
return 0;
524525
}
525526

527+
#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
526528
void __init init_cpu_topology(void)
527529
{
528530
reset_cpu_topology();

include/linux/arch_topology.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ extern struct cpu_topology cpu_topology[NR_CPUS];
5454
void init_cpu_topology(void);
5555
void store_cpu_topology(unsigned int cpuid);
5656
const struct cpumask *cpu_coregroup_mask(int cpu);
57-
#endif
58-
59-
#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
6057
void update_siblings_masks(unsigned int cpu);
61-
#endif
6258
void remove_cpu_topology(unsigned int cpuid);
59+
void reset_cpu_topology(void);
60+
#endif
6361

6462
#endif /* _LINUX_ARCH_TOPOLOGY_H_ */

0 commit comments

Comments
 (0)