Skip to content

Commit 2e4c54d

Browse files
lenbKAGA-KOKO
authored andcommitted
topology: Create core_cpus and die_cpus sysfs attributes
Create CPU topology sysfs attributes: "core_cpus" and "core_cpus_list" These attributes represent all of the logical CPUs that share the same core. These attriutes is synonymous with the existing "thread_siblings" and "thread_siblings_list" attribute, which will be deprecated. Create CPU topology sysfs attributes: "die_cpus" and "die_cpus_list". These attributes represent all of the logical CPUs that share the same die. Suggested-by: Brice Goglin <[email protected]> Signed-off-by: Len Brown <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/071c23a298cd27ede6ed0b6460cae190d193364f.1557769318.git.len.brown@intel.com
1 parent b73ed8d commit 2e4c54d

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

Documentation/cputopology.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ drawer_id:
3636
identifier (rather than the kernel's). The actual value is
3737
architecture and platform dependent.
3838

39-
thread_siblings:
39+
core_cpus:
4040

41-
internal kernel map of cpuX's hardware threads within the same
42-
core as cpuX.
41+
internal kernel map of CPUs within the same core.
42+
(deprecated name: "thread_siblings")
4343

44-
thread_siblings_list:
44+
core_cpus_list:
4545

46-
human-readable list of cpuX's hardware threads within the same
47-
core as cpuX.
46+
human-readable list of CPUs within the same core.
47+
(deprecated name: "thread_siblings_list");
4848

4949
package_cpus:
5050

@@ -56,6 +56,14 @@ package_cpus_list:
5656
human-readable list of CPUs sharing the same physical_package_id.
5757
(deprecated name: "core_siblings_list")
5858

59+
die_cpus:
60+
61+
internal kernel map of CPUs within the same die.
62+
63+
die_cpus_list:
64+
65+
human-readable list of CPUs within the same die.
66+
5967
book_siblings:
6068

6169
internal kernel map of cpuX's hardware threads within the same
@@ -93,6 +101,7 @@ these macros in include/asm-XXX/topology.h::
93101
#define topology_drawer_id(cpu)
94102
#define topology_sibling_cpumask(cpu)
95103
#define topology_core_cpumask(cpu)
104+
#define topology_die_cpumask(cpu)
96105
#define topology_book_cpumask(cpu)
97106
#define topology_drawer_cpumask(cpu)
98107

arch/x86/include/asm/smp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern unsigned int num_processors;
2323

2424
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
2525
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
26+
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
2627
/* cpus sharing the last level cache: */
2728
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
2829
DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);

arch/x86/include/asm/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
111111
#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
112112

113113
#ifdef CONFIG_SMP
114+
#define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu))
114115
#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
115116
#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
116117

arch/x86/kernel/smpboot.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
9191
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
9292
EXPORT_PER_CPU_SYMBOL(cpu_core_map);
9393

94+
/* representing HT, core, and die siblings of each logical CPU */
95+
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
96+
EXPORT_PER_CPU_SYMBOL(cpu_die_map);
97+
9498
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
9599

96100
/* Per CPU bogomips and other parameters */
@@ -509,6 +513,15 @@ static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
509513
return false;
510514
}
511515

516+
static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
517+
{
518+
if ((c->phys_proc_id == o->phys_proc_id) &&
519+
(c->cpu_die_id == o->cpu_die_id))
520+
return true;
521+
return false;
522+
}
523+
524+
512525
#if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC)
513526
static inline int x86_sched_itmt_flags(void)
514527
{
@@ -571,6 +584,7 @@ void set_cpu_sibling_map(int cpu)
571584
cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu));
572585
cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu));
573586
cpumask_set_cpu(cpu, topology_core_cpumask(cpu));
587+
cpumask_set_cpu(cpu, topology_die_cpumask(cpu));
574588
c->booted_cores = 1;
575589
return;
576590
}
@@ -619,6 +633,9 @@ void set_cpu_sibling_map(int cpu)
619633
}
620634
if (match_pkg(c, o) && !topology_same_node(c, o))
621635
x86_has_numa_in_package = true;
636+
637+
if ((i == cpu) || (has_mp && match_die(c, o)))
638+
link_mask(topology_die_cpumask, cpu, i);
622639
}
623640

624641
threads = cpumask_weight(topology_sibling_cpumask(cpu));
@@ -1223,6 +1240,7 @@ static __init void disable_smp(void)
12231240
physid_set_mask_of_physid(0, &phys_cpu_present_map);
12241241
cpumask_set_cpu(0, topology_sibling_cpumask(0));
12251242
cpumask_set_cpu(0, topology_core_cpumask(0));
1243+
cpumask_set_cpu(0, topology_die_cpumask(0));
12261244
}
12271245

12281246
/*
@@ -1318,6 +1336,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
13181336
for_each_possible_cpu(i) {
13191337
zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
13201338
zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
1339+
zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
13211340
zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
13221341
}
13231342

@@ -1538,13 +1557,16 @@ static void remove_siblinginfo(int cpu)
15381557
cpu_data(sibling).booted_cores--;
15391558
}
15401559

1560+
for_each_cpu(sibling, topology_die_cpumask(cpu))
1561+
cpumask_clear_cpu(cpu, topology_die_cpumask(sibling));
15411562
for_each_cpu(sibling, topology_sibling_cpumask(cpu))
15421563
cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling));
15431564
for_each_cpu(sibling, cpu_llc_shared_mask(cpu))
15441565
cpumask_clear_cpu(cpu, cpu_llc_shared_mask(sibling));
15451566
cpumask_clear(cpu_llc_shared_mask(cpu));
15461567
cpumask_clear(topology_sibling_cpumask(cpu));
15471568
cpumask_clear(topology_core_cpumask(cpu));
1569+
cpumask_clear(topology_die_cpumask(cpu));
15481570
c->cpu_core_id = 0;
15491571
c->booted_cores = 0;
15501572
cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);

arch/x86/xen/smp_pv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static void __init xen_pv_smp_prepare_cpus(unsigned int max_cpus)
251251
for_each_possible_cpu(i) {
252252
zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
253253
zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
254+
zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
254255
zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
255256
}
256257
set_cpu_sibling_map(0);

drivers/base/topology.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ define_siblings_show_func(thread_siblings, sibling_cpumask);
5353
static DEVICE_ATTR_RO(thread_siblings);
5454
static DEVICE_ATTR_RO(thread_siblings_list);
5555

56+
define_siblings_show_func(core_cpus, sibling_cpumask);
57+
static DEVICE_ATTR_RO(core_cpus);
58+
static DEVICE_ATTR_RO(core_cpus_list);
59+
5660
define_siblings_show_func(core_siblings, core_cpumask);
5761
static DEVICE_ATTR_RO(core_siblings);
5862
static DEVICE_ATTR_RO(core_siblings_list);
5963

64+
define_siblings_show_func(die_cpus, die_cpumask);
65+
static DEVICE_ATTR_RO(die_cpus);
66+
static DEVICE_ATTR_RO(die_cpus_list);
67+
6068
define_siblings_show_func(package_cpus, core_cpumask);
6169
static DEVICE_ATTR_RO(package_cpus);
6270
static DEVICE_ATTR_RO(package_cpus_list);
@@ -83,8 +91,12 @@ static struct attribute *default_attrs[] = {
8391
&dev_attr_core_id.attr,
8492
&dev_attr_thread_siblings.attr,
8593
&dev_attr_thread_siblings_list.attr,
94+
&dev_attr_core_cpus.attr,
95+
&dev_attr_core_cpus_list.attr,
8696
&dev_attr_core_siblings.attr,
8797
&dev_attr_core_siblings_list.attr,
98+
&dev_attr_die_cpus.attr,
99+
&dev_attr_die_cpus_list.attr,
88100
&dev_attr_package_cpus.attr,
89101
&dev_attr_package_cpus_list.attr,
90102
#ifdef CONFIG_SCHED_BOOK

include/linux/topology.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ static inline int cpu_to_mem(int cpu)
196196
#ifndef topology_core_cpumask
197197
#define topology_core_cpumask(cpu) cpumask_of(cpu)
198198
#endif
199+
#ifndef topology_die_cpumask
200+
#define topology_die_cpumask(cpu) cpumask_of(cpu)
201+
#endif
199202

200203
#ifdef CONFIG_SCHED_SMT
201204
static inline const struct cpumask *cpu_smt_mask(int cpu)

0 commit comments

Comments
 (0)