summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2019-05-13 13:58:56 -0400
committerThomas Gleixner <tglx@linutronix.de>2019-05-23 04:08:34 -0400
commit2e4c54dac7b360c3820399bdf06cde9134a4495b (patch)
tree21c10b11e98d2d5b13096de21fb339590baab13e
parentb73ed8dc0597c11ec5064d06b9bbd4e541b6d4e7 (diff)
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 <Brice.Goglin@inria.fr> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Ingo Molnar <mingo@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/071c23a298cd27ede6ed0b6460cae190d193364f.1557769318.git.len.brown@intel.com
-rw-r--r--Documentation/cputopology.txt21
-rw-r--r--arch/x86/include/asm/smp.h1
-rw-r--r--arch/x86/include/asm/topology.h1
-rw-r--r--arch/x86/kernel/smpboot.c22
-rw-r--r--arch/x86/xen/smp_pv.c1
-rw-r--r--drivers/base/topology.c12
-rw-r--r--include/linux/topology.h3
7 files changed, 55 insertions, 6 deletions
diff --git a/Documentation/cputopology.txt b/Documentation/cputopology.txt
index 48af5c290e20..b90dafcc8237 100644
--- a/Documentation/cputopology.txt
+++ b/Documentation/cputopology.txt
@@ -36,15 +36,15 @@ drawer_id:
36 identifier (rather than the kernel's). The actual value is 36 identifier (rather than the kernel's). The actual value is
37 architecture and platform dependent. 37 architecture and platform dependent.
38 38
39thread_siblings: 39core_cpus:
40 40
41 internal kernel map of cpuX's hardware threads within the same 41 internal kernel map of CPUs within the same core.
42 core as cpuX. 42 (deprecated name: "thread_siblings")
43 43
44thread_siblings_list: 44core_cpus_list:
45 45
46 human-readable list of cpuX's hardware threads within the same 46 human-readable list of CPUs within the same core.
47 core as cpuX. 47 (deprecated name: "thread_siblings_list");
48 48
49package_cpus: 49package_cpus:
50 50
@@ -56,6 +56,14 @@ package_cpus_list:
56 human-readable list of CPUs sharing the same physical_package_id. 56 human-readable list of CPUs sharing the same physical_package_id.
57 (deprecated name: "core_siblings_list") 57 (deprecated name: "core_siblings_list")
58 58
59die_cpus:
60
61 internal kernel map of CPUs within the same die.
62
63die_cpus_list:
64
65 human-readable list of CPUs within the same die.
66
59book_siblings: 67book_siblings:
60 68
61 internal kernel map of cpuX's hardware threads within the same 69 internal kernel map of cpuX's hardware threads within the same
@@ -93,6 +101,7 @@ these macros in include/asm-XXX/topology.h::
93 #define topology_drawer_id(cpu) 101 #define topology_drawer_id(cpu)
94 #define topology_sibling_cpumask(cpu) 102 #define topology_sibling_cpumask(cpu)
95 #define topology_core_cpumask(cpu) 103 #define topology_core_cpumask(cpu)
104 #define topology_die_cpumask(cpu)
96 #define topology_book_cpumask(cpu) 105 #define topology_book_cpumask(cpu)
97 #define topology_drawer_cpumask(cpu) 106 #define topology_drawer_cpumask(cpu)
98 107
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index da545df207b2..b673a226ad6c 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -23,6 +23,7 @@ extern unsigned int num_processors;
23 23
24DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); 24DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
25DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); 25DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
26DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
26/* cpus sharing the last level cache: */ 27/* cpus sharing the last level cache: */
27DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); 28DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
28DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id); 29DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 9de16b4f6023..4b14d2318251 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -111,6 +111,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
111#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) 111#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id)
112 112
113#ifdef CONFIG_SMP 113#ifdef CONFIG_SMP
114#define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu))
114#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 115#define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
115#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 116#define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
116 117
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index a6e01b6c2709..1a19a5171949 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -91,6 +91,10 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
91DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); 91DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
92EXPORT_PER_CPU_SYMBOL(cpu_core_map); 92EXPORT_PER_CPU_SYMBOL(cpu_core_map);
93 93
94/* representing HT, core, and die siblings of each logical CPU */
95DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
96EXPORT_PER_CPU_SYMBOL(cpu_die_map);
97
94DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); 98DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
95 99
96/* Per CPU bogomips and other parameters */ 100/* Per CPU bogomips and other parameters */
@@ -509,6 +513,15 @@ static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
509 return false; 513 return false;
510} 514}
511 515
516static 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
512#if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC) 525#if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC)
513static inline int x86_sched_itmt_flags(void) 526static inline int x86_sched_itmt_flags(void)
514{ 527{
@@ -571,6 +584,7 @@ void set_cpu_sibling_map(int cpu)
571 cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu)); 584 cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu));
572 cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu)); 585 cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu));
573 cpumask_set_cpu(cpu, topology_core_cpumask(cpu)); 586 cpumask_set_cpu(cpu, topology_core_cpumask(cpu));
587 cpumask_set_cpu(cpu, topology_die_cpumask(cpu));
574 c->booted_cores = 1; 588 c->booted_cores = 1;
575 return; 589 return;
576 } 590 }
@@ -619,6 +633,9 @@ void set_cpu_sibling_map(int cpu)
619 } 633 }
620 if (match_pkg(c, o) && !topology_same_node(c, o)) 634 if (match_pkg(c, o) && !topology_same_node(c, o))
621 x86_has_numa_in_package = true; 635 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);
622 } 639 }
623 640
624 threads = cpumask_weight(topology_sibling_cpumask(cpu)); 641 threads = cpumask_weight(topology_sibling_cpumask(cpu));
@@ -1223,6 +1240,7 @@ static __init void disable_smp(void)
1223 physid_set_mask_of_physid(0, &phys_cpu_present_map); 1240 physid_set_mask_of_physid(0, &phys_cpu_present_map);
1224 cpumask_set_cpu(0, topology_sibling_cpumask(0)); 1241 cpumask_set_cpu(0, topology_sibling_cpumask(0));
1225 cpumask_set_cpu(0, topology_core_cpumask(0)); 1242 cpumask_set_cpu(0, topology_core_cpumask(0));
1243 cpumask_set_cpu(0, topology_die_cpumask(0));
1226} 1244}
1227 1245
1228/* 1246/*
@@ -1318,6 +1336,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
1318 for_each_possible_cpu(i) { 1336 for_each_possible_cpu(i) {
1319 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); 1337 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
1320 zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); 1338 zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
1339 zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
1321 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); 1340 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
1322 } 1341 }
1323 1342
@@ -1538,6 +1557,8 @@ static void remove_siblinginfo(int cpu)
1538 cpu_data(sibling).booted_cores--; 1557 cpu_data(sibling).booted_cores--;
1539 } 1558 }
1540 1559
1560 for_each_cpu(sibling, topology_die_cpumask(cpu))
1561 cpumask_clear_cpu(cpu, topology_die_cpumask(sibling));
1541 for_each_cpu(sibling, topology_sibling_cpumask(cpu)) 1562 for_each_cpu(sibling, topology_sibling_cpumask(cpu))
1542 cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling)); 1563 cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling));
1543 for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) 1564 for_each_cpu(sibling, cpu_llc_shared_mask(cpu))
@@ -1545,6 +1566,7 @@ static void remove_siblinginfo(int cpu)
1545 cpumask_clear(cpu_llc_shared_mask(cpu)); 1566 cpumask_clear(cpu_llc_shared_mask(cpu));
1546 cpumask_clear(topology_sibling_cpumask(cpu)); 1567 cpumask_clear(topology_sibling_cpumask(cpu));
1547 cpumask_clear(topology_core_cpumask(cpu)); 1568 cpumask_clear(topology_core_cpumask(cpu));
1569 cpumask_clear(topology_die_cpumask(cpu));
1548 c->cpu_core_id = 0; 1570 c->cpu_core_id = 0;
1549 c->booted_cores = 0; 1571 c->booted_cores = 0;
1550 cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); 1572 cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
index 590fcf863006..77d81c1a63e9 100644
--- a/arch/x86/xen/smp_pv.c
+++ b/arch/x86/xen/smp_pv.c
@@ -251,6 +251,7 @@ static void __init xen_pv_smp_prepare_cpus(unsigned int max_cpus)
251 for_each_possible_cpu(i) { 251 for_each_possible_cpu(i) {
252 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); 252 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
253 zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); 253 zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
254 zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
254 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); 255 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
255 } 256 }
256 set_cpu_sibling_map(0); 257 set_cpu_sibling_map(0);
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index dc3c19b482f3..4e033d4cc0dc 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -53,10 +53,18 @@ define_siblings_show_func(thread_siblings, sibling_cpumask);
53static DEVICE_ATTR_RO(thread_siblings); 53static DEVICE_ATTR_RO(thread_siblings);
54static DEVICE_ATTR_RO(thread_siblings_list); 54static DEVICE_ATTR_RO(thread_siblings_list);
55 55
56define_siblings_show_func(core_cpus, sibling_cpumask);
57static DEVICE_ATTR_RO(core_cpus);
58static DEVICE_ATTR_RO(core_cpus_list);
59
56define_siblings_show_func(core_siblings, core_cpumask); 60define_siblings_show_func(core_siblings, core_cpumask);
57static DEVICE_ATTR_RO(core_siblings); 61static DEVICE_ATTR_RO(core_siblings);
58static DEVICE_ATTR_RO(core_siblings_list); 62static DEVICE_ATTR_RO(core_siblings_list);
59 63
64define_siblings_show_func(die_cpus, die_cpumask);
65static DEVICE_ATTR_RO(die_cpus);
66static DEVICE_ATTR_RO(die_cpus_list);
67
60define_siblings_show_func(package_cpus, core_cpumask); 68define_siblings_show_func(package_cpus, core_cpumask);
61static DEVICE_ATTR_RO(package_cpus); 69static DEVICE_ATTR_RO(package_cpus);
62static DEVICE_ATTR_RO(package_cpus_list); 70static DEVICE_ATTR_RO(package_cpus_list);
@@ -83,8 +91,12 @@ static struct attribute *default_attrs[] = {
83 &dev_attr_core_id.attr, 91 &dev_attr_core_id.attr,
84 &dev_attr_thread_siblings.attr, 92 &dev_attr_thread_siblings.attr,
85 &dev_attr_thread_siblings_list.attr, 93 &dev_attr_thread_siblings_list.attr,
94 &dev_attr_core_cpus.attr,
95 &dev_attr_core_cpus_list.attr,
86 &dev_attr_core_siblings.attr, 96 &dev_attr_core_siblings.attr,
87 &dev_attr_core_siblings_list.attr, 97 &dev_attr_core_siblings_list.attr,
98 &dev_attr_die_cpus.attr,
99 &dev_attr_die_cpus_list.attr,
88 &dev_attr_package_cpus.attr, 100 &dev_attr_package_cpus.attr,
89 &dev_attr_package_cpus_list.attr, 101 &dev_attr_package_cpus_list.attr,
90#ifdef CONFIG_SCHED_BOOK 102#ifdef CONFIG_SCHED_BOOK
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 5cc8595dd0e4..47a3e3c08036 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -196,6 +196,9 @@ static inline int cpu_to_mem(int cpu)
196#ifndef topology_core_cpumask 196#ifndef topology_core_cpumask
197#define topology_core_cpumask(cpu) cpumask_of(cpu) 197#define topology_core_cpumask(cpu) cpumask_of(cpu)
198#endif 198#endif
199#ifndef topology_die_cpumask
200#define topology_die_cpumask(cpu) cpumask_of(cpu)
201#endif
199 202
200#ifdef CONFIG_SCHED_SMT 203#ifdef CONFIG_SCHED_SMT
201static inline const struct cpumask *cpu_smt_mask(int cpu) 204static inline const struct cpumask *cpu_smt_mask(int cpu)