Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'x86-topology-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 topology updates from Ingo Molnar:
"Implement multi-die topology support on Intel CPUs and expose the die
topology to user-space tooling, by Len Brown, Kan Liang and Zhang Rui.

These changes should have no effect on the kernel's existing
understanding of topologies, i.e. there should be no behavioral impact
on cache, NUMA, scheduler, perf and other topologies and overall
system performance"

* 'x86-topology-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/x86/intel/rapl: Cosmetic rename internal variables in response to multi-die/pkg support
perf/x86/intel/uncore: Cosmetic renames in response to multi-die/pkg support
hwmon/coretemp: Cosmetic: Rename internal variables to zones from packages
thermal/x86_pkg_temp_thermal: Cosmetic: Rename internal variables to zones from packages
perf/x86/intel/cstate: Support multi-die/package
perf/x86/intel/rapl: Support multi-die/package
perf/x86/intel/uncore: Support multi-die/package
topology: Create core_cpus and die_cpus sysfs attributes
topology: Create package_cpus sysfs attribute
hwmon/coretemp: Support multi-die/package
powercap/intel_rapl: Update RAPL domain name and debug messages
thermal/x86_pkg_temp_thermal: Support multi-die/package
powercap/intel_rapl: Support multi-die/package
powercap/intel_rapl: Simplify rapl_find_package()
x86/topology: Define topology_logical_die_id()
x86/topology: Define topology_die_id()
cpu/topology: Export die_id
x86/topology: Create topology_max_die_per_package()
x86/topology: Add CPUID.1F multi-die/package support

+422 -214
+33 -15
Documentation/cputopology.txt
··· 12 12 socket number, but the actual value is architecture and platform 13 13 dependent. 14 14 15 + die_id: 16 + 17 + the CPU die ID of cpuX. Typically it is the hardware platform's 18 + identifier (rather than the kernel's). The actual value is 19 + architecture and platform dependent. 20 + 15 21 core_id: 16 22 17 23 the CPU core ID of cpuX. Typically it is the hardware platform's ··· 36 30 identifier (rather than the kernel's). The actual value is 37 31 architecture and platform dependent. 38 32 39 - thread_siblings: 33 + core_cpus: 40 34 41 - internal kernel map of cpuX's hardware threads within the same 42 - core as cpuX. 35 + internal kernel map of CPUs within the same core. 36 + (deprecated name: "thread_siblings") 43 37 44 - thread_siblings_list: 38 + core_cpus_list: 45 39 46 - human-readable list of cpuX's hardware threads within the same 47 - core as cpuX. 40 + human-readable list of CPUs within the same core. 41 + (deprecated name: "thread_siblings_list"); 48 42 49 - core_siblings: 43 + package_cpus: 50 44 51 - internal kernel map of cpuX's hardware threads within the same 52 - physical_package_id. 45 + internal kernel map of the CPUs sharing the same physical_package_id. 46 + (deprecated name: "core_siblings") 53 47 54 - core_siblings_list: 48 + package_cpus_list: 55 49 56 - human-readable list of cpuX's hardware threads within the same 57 - physical_package_id. 50 + human-readable list of CPUs sharing the same physical_package_id. 51 + (deprecated name: "core_siblings_list") 52 + 53 + die_cpus: 54 + 55 + internal kernel map of CPUs within the same die. 56 + 57 + die_cpus_list: 58 + 59 + human-readable list of CPUs within the same die. 58 60 59 61 book_siblings: 60 62 ··· 95 81 these macros in include/asm-XXX/topology.h:: 96 82 97 83 #define topology_physical_package_id(cpu) 84 + #define topology_die_id(cpu) 98 85 #define topology_core_id(cpu) 99 86 #define topology_book_id(cpu) 100 87 #define topology_drawer_id(cpu) 101 88 #define topology_sibling_cpumask(cpu) 102 89 #define topology_core_cpumask(cpu) 90 + #define topology_die_cpumask(cpu) 103 91 #define topology_book_cpumask(cpu) 104 92 #define topology_drawer_cpumask(cpu) 105 93 ··· 115 99 not defined by include/asm-XXX/topology.h: 116 100 117 101 1) topology_physical_package_id: -1 118 - 2) topology_core_id: 0 119 - 3) topology_sibling_cpumask: just the given CPU 120 - 4) topology_core_cpumask: just the given CPU 102 + 2) topology_die_id: -1 103 + 3) topology_core_id: 0 104 + 4) topology_sibling_cpumask: just the given CPU 105 + 5) topology_core_cpumask: just the given CPU 106 + 6) topology_die_cpumask: just the given CPU 121 107 122 108 For architectures that don't support books (CONFIG_SCHED_BOOK) there are no 123 109 default definitions for topology_book_id() and topology_book_cpumask().
+4
Documentation/x86/topology.rst
··· 49 49 50 50 The number of cores in a package. This information is retrieved via CPUID. 51 51 52 + - cpuinfo_x86.x86_max_dies: 53 + 54 + The number of dies in a package. This information is retrieved via CPUID. 55 + 52 56 - cpuinfo_x86.phys_proc_id: 53 57 54 58 The physical ID of the package. This information is retrieved via CPUID
+10 -4
arch/x86/events/intel/cstate.c
··· 302 302 return -EINVAL; 303 303 event->hw.event_base = pkg_msr[cfg].msr; 304 304 cpu = cpumask_any_and(&cstate_pkg_cpu_mask, 305 - topology_core_cpumask(event->cpu)); 305 + topology_die_cpumask(event->cpu)); 306 306 } else { 307 307 return -ENOENT; 308 308 } ··· 385 385 if (has_cstate_pkg && 386 386 cpumask_test_and_clear_cpu(cpu, &cstate_pkg_cpu_mask)) { 387 387 388 - target = cpumask_any_but(topology_core_cpumask(cpu), cpu); 388 + target = cpumask_any_but(topology_die_cpumask(cpu), cpu); 389 389 /* Migrate events if there is a valid target */ 390 390 if (target < nr_cpu_ids) { 391 391 cpumask_set_cpu(target, &cstate_pkg_cpu_mask); ··· 414 414 * in the package cpu mask as the designated reader. 415 415 */ 416 416 target = cpumask_any_and(&cstate_pkg_cpu_mask, 417 - topology_core_cpumask(cpu)); 417 + topology_die_cpumask(cpu)); 418 418 if (has_cstate_pkg && target >= nr_cpu_ids) 419 419 cpumask_set_cpu(cpu, &cstate_pkg_cpu_mask); 420 420 ··· 663 663 } 664 664 665 665 if (has_cstate_pkg) { 666 - err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1); 666 + if (topology_max_die_per_package() > 1) { 667 + err = perf_pmu_register(&cstate_pkg_pmu, 668 + "cstate_die", -1); 669 + } else { 670 + err = perf_pmu_register(&cstate_pkg_pmu, 671 + cstate_pkg_pmu.name, -1); 672 + } 667 673 if (err) { 668 674 has_cstate_pkg = false; 669 675 pr_info("Failed to register cstate pkg pmu\n");
+10 -10
arch/x86/events/intel/rapl.c
··· 149 149 150 150 struct rapl_pmus { 151 151 struct pmu pmu; 152 - unsigned int maxpkg; 152 + unsigned int maxdie; 153 153 struct rapl_pmu *pmus[]; 154 154 }; 155 155 ··· 162 162 163 163 static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) 164 164 { 165 - unsigned int pkgid = topology_logical_package_id(cpu); 165 + unsigned int dieid = topology_logical_die_id(cpu); 166 166 167 167 /* 168 168 * The unsigned check also catches the '-1' return value for non 169 169 * existent mappings in the topology map. 170 170 */ 171 - return pkgid < rapl_pmus->maxpkg ? rapl_pmus->pmus[pkgid] : NULL; 171 + return dieid < rapl_pmus->maxdie ? rapl_pmus->pmus[dieid] : NULL; 172 172 } 173 173 174 174 static inline u64 rapl_read_counter(struct perf_event *event) ··· 572 572 573 573 pmu->cpu = -1; 574 574 /* Find a new cpu to collect rapl events */ 575 - target = cpumask_any_but(topology_core_cpumask(cpu), cpu); 575 + target = cpumask_any_but(topology_die_cpumask(cpu), cpu); 576 576 577 577 /* Migrate rapl events to the new target */ 578 578 if (target < nr_cpu_ids) { ··· 599 599 pmu->timer_interval = ms_to_ktime(rapl_timer_ms); 600 600 rapl_hrtimer_init(pmu); 601 601 602 - rapl_pmus->pmus[topology_logical_package_id(cpu)] = pmu; 602 + rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu; 603 603 } 604 604 605 605 /* 606 606 * Check if there is an online cpu in the package which collects rapl 607 607 * events already. 608 608 */ 609 - target = cpumask_any_and(&rapl_cpu_mask, topology_core_cpumask(cpu)); 609 + target = cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu)); 610 610 if (target < nr_cpu_ids) 611 611 return 0; 612 612 ··· 669 669 { 670 670 int i; 671 671 672 - for (i = 0; i < rapl_pmus->maxpkg; i++) 672 + for (i = 0; i < rapl_pmus->maxdie; i++) 673 673 kfree(rapl_pmus->pmus[i]); 674 674 kfree(rapl_pmus); 675 675 } 676 676 677 677 static int __init init_rapl_pmus(void) 678 678 { 679 - int maxpkg = topology_max_packages(); 679 + int maxdie = topology_max_packages() * topology_max_die_per_package(); 680 680 size_t size; 681 681 682 - size = sizeof(*rapl_pmus) + maxpkg * sizeof(struct rapl_pmu *); 682 + size = sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *); 683 683 rapl_pmus = kzalloc(size, GFP_KERNEL); 684 684 if (!rapl_pmus) 685 685 return -ENOMEM; 686 686 687 - rapl_pmus->maxpkg = maxpkg; 687 + rapl_pmus->maxdie = maxdie; 688 688 rapl_pmus->pmu.attr_groups = rapl_attr_groups; 689 689 rapl_pmus->pmu.task_ctx_nr = perf_invalid_context; 690 690 rapl_pmus->pmu.event_init = rapl_pmu_event_init;
+41 -39
arch/x86/events/intel/uncore.c
··· 15 15 DEFINE_RAW_SPINLOCK(pci2phy_map_lock); 16 16 struct list_head pci2phy_map_head = LIST_HEAD_INIT(pci2phy_map_head); 17 17 struct pci_extra_dev *uncore_extra_pci_dev; 18 - static int max_packages; 18 + static int max_dies; 19 19 20 20 /* mask of cpus that collect uncore events */ 21 21 static cpumask_t uncore_cpu_mask; ··· 101 101 102 102 struct intel_uncore_box *uncore_pmu_to_box(struct intel_uncore_pmu *pmu, int cpu) 103 103 { 104 - unsigned int pkgid = topology_logical_package_id(cpu); 104 + unsigned int dieid = topology_logical_die_id(cpu); 105 105 106 106 /* 107 107 * The unsigned check also catches the '-1' return value for non 108 108 * existent mappings in the topology map. 109 109 */ 110 - return pkgid < max_packages ? pmu->boxes[pkgid] : NULL; 110 + return dieid < max_dies ? pmu->boxes[dieid] : NULL; 111 111 } 112 112 113 113 u64 uncore_msr_read_counter(struct intel_uncore_box *box, struct perf_event *event) ··· 312 312 uncore_pmu_init_hrtimer(box); 313 313 box->cpu = -1; 314 314 box->pci_phys_id = -1; 315 - box->pkgid = -1; 315 + box->dieid = -1; 316 316 317 317 /* set default hrtimer timeout */ 318 318 box->hrtimer_duration = UNCORE_PMU_HRTIMER_INTERVAL; ··· 827 827 828 828 static void uncore_free_boxes(struct intel_uncore_pmu *pmu) 829 829 { 830 - int pkg; 830 + int die; 831 831 832 - for (pkg = 0; pkg < max_packages; pkg++) 833 - kfree(pmu->boxes[pkg]); 832 + for (die = 0; die < max_dies; die++) 833 + kfree(pmu->boxes[die]); 834 834 kfree(pmu->boxes); 835 835 } 836 836 ··· 867 867 if (!pmus) 868 868 return -ENOMEM; 869 869 870 - size = max_packages * sizeof(struct intel_uncore_box *); 870 + size = max_dies * sizeof(struct intel_uncore_box *); 871 871 872 872 for (i = 0; i < type->num_boxes; i++) { 873 873 pmus[i].func_id = setid ? i : -1; ··· 937 937 struct intel_uncore_type *type; 938 938 struct intel_uncore_pmu *pmu = NULL; 939 939 struct intel_uncore_box *box; 940 - int phys_id, pkg, ret; 940 + int phys_id, die, ret; 941 941 942 942 phys_id = uncore_pcibus_to_physid(pdev->bus); 943 943 if (phys_id < 0) 944 944 return -ENODEV; 945 945 946 - pkg = topology_phys_to_logical_pkg(phys_id); 947 - if (pkg < 0) 946 + die = (topology_max_die_per_package() > 1) ? phys_id : 947 + topology_phys_to_logical_pkg(phys_id); 948 + if (die < 0) 948 949 return -EINVAL; 949 950 950 951 if (UNCORE_PCI_DEV_TYPE(id->driver_data) == UNCORE_EXTRA_PCI_DEV) { 951 952 int idx = UNCORE_PCI_DEV_IDX(id->driver_data); 952 953 953 - uncore_extra_pci_dev[pkg].dev[idx] = pdev; 954 + uncore_extra_pci_dev[die].dev[idx] = pdev; 954 955 pci_set_drvdata(pdev, NULL); 955 956 return 0; 956 957 } ··· 990 989 pmu = &type->pmus[UNCORE_PCI_DEV_IDX(id->driver_data)]; 991 990 } 992 991 993 - if (WARN_ON_ONCE(pmu->boxes[pkg] != NULL)) 992 + if (WARN_ON_ONCE(pmu->boxes[die] != NULL)) 994 993 return -EINVAL; 995 994 996 995 box = uncore_alloc_box(type, NUMA_NO_NODE); ··· 1004 1003 1005 1004 atomic_inc(&box->refcnt); 1006 1005 box->pci_phys_id = phys_id; 1007 - box->pkgid = pkg; 1006 + box->dieid = die; 1008 1007 box->pci_dev = pdev; 1009 1008 box->pmu = pmu; 1010 1009 uncore_box_init(box); 1011 1010 pci_set_drvdata(pdev, box); 1012 1011 1013 - pmu->boxes[pkg] = box; 1012 + pmu->boxes[die] = box; 1014 1013 if (atomic_inc_return(&pmu->activeboxes) > 1) 1015 1014 return 0; 1016 1015 ··· 1018 1017 ret = uncore_pmu_register(pmu); 1019 1018 if (ret) { 1020 1019 pci_set_drvdata(pdev, NULL); 1021 - pmu->boxes[pkg] = NULL; 1020 + pmu->boxes[die] = NULL; 1022 1021 uncore_box_exit(box); 1023 1022 kfree(box); 1024 1023 } ··· 1029 1028 { 1030 1029 struct intel_uncore_box *box; 1031 1030 struct intel_uncore_pmu *pmu; 1032 - int i, phys_id, pkg; 1031 + int i, phys_id, die; 1033 1032 1034 1033 phys_id = uncore_pcibus_to_physid(pdev->bus); 1035 1034 1036 1035 box = pci_get_drvdata(pdev); 1037 1036 if (!box) { 1038 - pkg = topology_phys_to_logical_pkg(phys_id); 1037 + die = (topology_max_die_per_package() > 1) ? phys_id : 1038 + topology_phys_to_logical_pkg(phys_id); 1039 1039 for (i = 0; i < UNCORE_EXTRA_PCI_DEV_MAX; i++) { 1040 - if (uncore_extra_pci_dev[pkg].dev[i] == pdev) { 1041 - uncore_extra_pci_dev[pkg].dev[i] = NULL; 1040 + if (uncore_extra_pci_dev[die].dev[i] == pdev) { 1041 + uncore_extra_pci_dev[die].dev[i] = NULL; 1042 1042 break; 1043 1043 } 1044 1044 } ··· 1052 1050 return; 1053 1051 1054 1052 pci_set_drvdata(pdev, NULL); 1055 - pmu->boxes[box->pkgid] = NULL; 1053 + pmu->boxes[box->dieid] = NULL; 1056 1054 if (atomic_dec_return(&pmu->activeboxes) == 0) 1057 1055 uncore_pmu_unregister(pmu); 1058 1056 uncore_box_exit(box); ··· 1064 1062 size_t size; 1065 1063 int ret; 1066 1064 1067 - size = max_packages * sizeof(struct pci_extra_dev); 1065 + size = max_dies * sizeof(struct pci_extra_dev); 1068 1066 uncore_extra_pci_dev = kzalloc(size, GFP_KERNEL); 1069 1067 if (!uncore_extra_pci_dev) { 1070 1068 ret = -ENOMEM; ··· 1111 1109 { 1112 1110 struct intel_uncore_pmu *pmu = type->pmus; 1113 1111 struct intel_uncore_box *box; 1114 - int i, pkg; 1112 + int i, die; 1115 1113 1116 - pkg = topology_logical_package_id(old_cpu < 0 ? new_cpu : old_cpu); 1114 + die = topology_logical_die_id(old_cpu < 0 ? new_cpu : old_cpu); 1117 1115 for (i = 0; i < type->num_boxes; i++, pmu++) { 1118 - box = pmu->boxes[pkg]; 1116 + box = pmu->boxes[die]; 1119 1117 if (!box) 1120 1118 continue; 1121 1119 ··· 1148 1146 struct intel_uncore_type *type, **types = uncore_msr_uncores; 1149 1147 struct intel_uncore_pmu *pmu; 1150 1148 struct intel_uncore_box *box; 1151 - int i, pkg, target; 1149 + int i, die, target; 1152 1150 1153 1151 /* Check if exiting cpu is used for collecting uncore events */ 1154 1152 if (!cpumask_test_and_clear_cpu(cpu, &uncore_cpu_mask)) 1155 1153 goto unref; 1156 1154 /* Find a new cpu to collect uncore events */ 1157 - target = cpumask_any_but(topology_core_cpumask(cpu), cpu); 1155 + target = cpumask_any_but(topology_die_cpumask(cpu), cpu); 1158 1156 1159 1157 /* Migrate uncore events to the new target */ 1160 1158 if (target < nr_cpu_ids) ··· 1167 1165 1168 1166 unref: 1169 1167 /* Clear the references */ 1170 - pkg = topology_logical_package_id(cpu); 1168 + die = topology_logical_die_id(cpu); 1171 1169 for (; *types; types++) { 1172 1170 type = *types; 1173 1171 pmu = type->pmus; 1174 1172 for (i = 0; i < type->num_boxes; i++, pmu++) { 1175 - box = pmu->boxes[pkg]; 1173 + box = pmu->boxes[die]; 1176 1174 if (box && atomic_dec_return(&box->refcnt) == 0) 1177 1175 uncore_box_exit(box); 1178 1176 } ··· 1181 1179 } 1182 1180 1183 1181 static int allocate_boxes(struct intel_uncore_type **types, 1184 - unsigned int pkg, unsigned int cpu) 1182 + unsigned int die, unsigned int cpu) 1185 1183 { 1186 1184 struct intel_uncore_box *box, *tmp; 1187 1185 struct intel_uncore_type *type; ··· 1194 1192 type = *types; 1195 1193 pmu = type->pmus; 1196 1194 for (i = 0; i < type->num_boxes; i++, pmu++) { 1197 - if (pmu->boxes[pkg]) 1195 + if (pmu->boxes[die]) 1198 1196 continue; 1199 1197 box = uncore_alloc_box(type, cpu_to_node(cpu)); 1200 1198 if (!box) 1201 1199 goto cleanup; 1202 1200 box->pmu = pmu; 1203 - box->pkgid = pkg; 1201 + box->dieid = die; 1204 1202 list_add(&box->active_list, &allocated); 1205 1203 } 1206 1204 } 1207 1205 /* Install them in the pmus */ 1208 1206 list_for_each_entry_safe(box, tmp, &allocated, active_list) { 1209 1207 list_del_init(&box->active_list); 1210 - box->pmu->boxes[pkg] = box; 1208 + box->pmu->boxes[die] = box; 1211 1209 } 1212 1210 return 0; 1213 1211 ··· 1224 1222 struct intel_uncore_type *type, **types = uncore_msr_uncores; 1225 1223 struct intel_uncore_pmu *pmu; 1226 1224 struct intel_uncore_box *box; 1227 - int i, ret, pkg, target; 1225 + int i, ret, die, target; 1228 1226 1229 - pkg = topology_logical_package_id(cpu); 1230 - ret = allocate_boxes(types, pkg, cpu); 1227 + die = topology_logical_die_id(cpu); 1228 + ret = allocate_boxes(types, die, cpu); 1231 1229 if (ret) 1232 1230 return ret; 1233 1231 ··· 1235 1233 type = *types; 1236 1234 pmu = type->pmus; 1237 1235 for (i = 0; i < type->num_boxes; i++, pmu++) { 1238 - box = pmu->boxes[pkg]; 1236 + box = pmu->boxes[die]; 1239 1237 if (box && atomic_inc_return(&box->refcnt) == 1) 1240 1238 uncore_box_init(box); 1241 1239 } ··· 1245 1243 * Check if there is an online cpu in the package 1246 1244 * which collects uncore events already. 1247 1245 */ 1248 - target = cpumask_any_and(&uncore_cpu_mask, topology_core_cpumask(cpu)); 1246 + target = cpumask_any_and(&uncore_cpu_mask, topology_die_cpumask(cpu)); 1249 1247 if (target < nr_cpu_ids) 1250 1248 return 0; 1251 1249 ··· 1421 1419 if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) 1422 1420 return -ENODEV; 1423 1421 1424 - max_packages = topology_max_packages(); 1422 + max_dies = topology_max_packages() * topology_max_die_per_package(); 1425 1423 1426 1424 uncore_init = (struct intel_uncore_init_fun *)id->driver_data; 1427 1425 if (uncore_init->pci_init) {
+2 -2
arch/x86/events/intel/uncore.h
··· 108 108 109 109 struct intel_uncore_box { 110 110 int pci_phys_id; 111 - int pkgid; /* Logical package ID */ 111 + int dieid; /* Logical die ID */ 112 112 int n_active; /* number of active events */ 113 113 int n_events; 114 114 int cpu; /* cpu to collect events */ ··· 467 467 468 468 static inline bool uncore_box_is_fake(struct intel_uncore_box *box) 469 469 { 470 - return (box->pkgid < 0); 470 + return (box->dieid < 0); 471 471 } 472 472 473 473 static inline struct intel_uncore_pmu *uncore_event_to_pmu(struct perf_event *event)
+2 -2
arch/x86/events/intel/uncore_snbep.c
··· 1058 1058 1059 1059 if (reg1->idx != EXTRA_REG_NONE) { 1060 1060 int idx = box->pmu->pmu_idx + SNBEP_PCI_QPI_PORT0_FILTER; 1061 - int pkg = box->pkgid; 1062 - struct pci_dev *filter_pdev = uncore_extra_pci_dev[pkg].dev[idx]; 1061 + int die = box->dieid; 1062 + struct pci_dev *filter_pdev = uncore_extra_pci_dev[die].dev[idx]; 1063 1063 1064 1064 if (filter_pdev) { 1065 1065 pci_write_config_dword(filter_pdev, reg1->reg,
+3 -1
arch/x86/include/asm/processor.h
··· 105 105 int x86_power; 106 106 unsigned long loops_per_jiffy; 107 107 /* cpuid returned max cores value: */ 108 - u16 x86_max_cores; 108 + u16 x86_max_cores; 109 109 u16 apicid; 110 110 u16 initial_apicid; 111 111 u16 x86_clflush_size; ··· 117 117 u16 logical_proc_id; 118 118 /* Core id: */ 119 119 u16 cpu_core_id; 120 + u16 cpu_die_id; 121 + u16 logical_die_id; 120 122 /* Index into per_cpu list: */ 121 123 u16 cpu_index; 122 124 u32 microcode;
+1
arch/x86/include/asm/smp.h
··· 23 23 24 24 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); 25 25 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); 26 + DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map); 26 27 /* cpus sharing the last level cache: */ 27 28 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); 28 29 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
+17
arch/x86/include/asm/topology.h
··· 106 106 107 107 #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) 108 108 #define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id) 109 + #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) 110 + #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) 109 111 #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) 110 112 111 113 #ifdef CONFIG_SMP 114 + #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu)) 112 115 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 113 116 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 114 117 115 118 extern unsigned int __max_logical_packages; 116 119 #define topology_max_packages() (__max_logical_packages) 120 + 121 + extern unsigned int __max_die_per_package; 122 + 123 + static inline int topology_max_die_per_package(void) 124 + { 125 + return __max_die_per_package; 126 + } 117 127 118 128 extern int __max_smt_threads; 119 129 ··· 133 123 } 134 124 135 125 int topology_update_package_map(unsigned int apicid, unsigned int cpu); 126 + int topology_update_die_map(unsigned int dieid, unsigned int cpu); 136 127 int topology_phys_to_logical_pkg(unsigned int pkg); 128 + int topology_phys_to_logical_die(unsigned int die, unsigned int cpu); 137 129 bool topology_is_primary_thread(unsigned int cpu); 138 130 bool topology_smt_supported(void); 139 131 #else 140 132 #define topology_max_packages() (1) 141 133 static inline int 142 134 topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; } 135 + static inline int 136 + topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; } 143 137 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; } 138 + static inline int topology_phys_to_logical_die(unsigned int die, 139 + unsigned int cpu) { return 0; } 140 + static inline int topology_max_die_per_package(void) { return 1; } 144 141 static inline int topology_max_smt_threads(void) { return 1; } 145 142 static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } 146 143 static inline bool topology_smt_supported(void) { return false; }
+1
arch/x86/kernel/cpu/common.c
··· 1322 1322 cpu, apicid, c->initial_apicid); 1323 1323 } 1324 1324 BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); 1325 + BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); 1325 1326 #else 1326 1327 c->logical_proc_id = 0; 1327 1328 #endif
+69 -19
arch/x86/kernel/cpu/topology.c
··· 15 15 /* leaf 0xb SMT level */ 16 16 #define SMT_LEVEL 0 17 17 18 - /* leaf 0xb sub-leaf types */ 18 + /* extended topology sub-leaf types */ 19 19 #define INVALID_TYPE 0 20 20 #define SMT_TYPE 1 21 21 #define CORE_TYPE 2 22 + #define DIE_TYPE 5 22 23 23 24 #define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff) 24 25 #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) 25 26 #define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff) 26 27 28 + #ifdef CONFIG_SMP 29 + unsigned int __max_die_per_package __read_mostly = 1; 30 + EXPORT_SYMBOL(__max_die_per_package); 31 + 32 + /* 33 + * Check if given CPUID extended toplogy "leaf" is implemented 34 + */ 35 + static int check_extended_topology_leaf(int leaf) 36 + { 37 + unsigned int eax, ebx, ecx, edx; 38 + 39 + cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); 40 + 41 + if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) 42 + return -1; 43 + 44 + return 0; 45 + } 46 + /* 47 + * Return best CPUID Extended Toplogy Leaf supported 48 + */ 49 + static int detect_extended_topology_leaf(struct cpuinfo_x86 *c) 50 + { 51 + if (c->cpuid_level >= 0x1f) { 52 + if (check_extended_topology_leaf(0x1f) == 0) 53 + return 0x1f; 54 + } 55 + 56 + if (c->cpuid_level >= 0xb) { 57 + if (check_extended_topology_leaf(0xb) == 0) 58 + return 0xb; 59 + } 60 + 61 + return -1; 62 + } 63 + #endif 64 + 27 65 int detect_extended_topology_early(struct cpuinfo_x86 *c) 28 66 { 29 67 #ifdef CONFIG_SMP 30 68 unsigned int eax, ebx, ecx, edx; 69 + int leaf; 31 70 32 - if (c->cpuid_level < 0xb) 33 - return -1; 34 - 35 - cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx); 36 - 37 - /* 38 - * check if the cpuid leaf 0xb is actually implemented. 39 - */ 40 - if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) 71 + leaf = detect_extended_topology_leaf(c); 72 + if (leaf < 0) 41 73 return -1; 42 74 43 75 set_cpu_cap(c, X86_FEATURE_XTOPOLOGY); 44 76 77 + cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); 45 78 /* 46 79 * initial apic id, which also represents 32-bit extended x2apic id. 47 80 */ ··· 85 52 } 86 53 87 54 /* 88 - * Check for extended topology enumeration cpuid leaf 0xb and if it 55 + * Check for extended topology enumeration cpuid leaf, and if it 89 56 * exists, use it for populating initial_apicid and cpu topology 90 57 * detection. 91 58 */ ··· 93 60 { 94 61 #ifdef CONFIG_SMP 95 62 unsigned int eax, ebx, ecx, edx, sub_index; 96 - unsigned int ht_mask_width, core_plus_mask_width; 63 + unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width; 97 64 unsigned int core_select_mask, core_level_siblings; 65 + unsigned int die_select_mask, die_level_siblings; 66 + int leaf; 98 67 99 - if (detect_extended_topology_early(c) < 0) 68 + leaf = detect_extended_topology_leaf(c); 69 + if (leaf < 0) 100 70 return -1; 101 71 102 72 /* 103 73 * Populate HT related information from sub-leaf level 0. 104 74 */ 105 - cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx); 75 + cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); 76 + c->initial_apicid = edx; 106 77 core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx); 107 78 core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); 79 + die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); 80 + die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); 108 81 109 82 sub_index = 1; 110 83 do { 111 - cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx); 84 + cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx); 112 85 113 86 /* 114 87 * Check for the Core type in the implemented sub leaves. ··· 122 83 if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) { 123 84 core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); 124 85 core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); 125 - break; 86 + die_level_siblings = core_level_siblings; 87 + die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); 88 + } 89 + if (LEAFB_SUBTYPE(ecx) == DIE_TYPE) { 90 + die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); 91 + die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); 126 92 } 127 93 128 94 sub_index++; 129 95 } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE); 130 96 131 97 core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width; 98 + die_select_mask = (~(-1 << die_plus_mask_width)) >> 99 + core_plus_mask_width; 132 100 133 - c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, ht_mask_width) 134 - & core_select_mask; 135 - c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, core_plus_mask_width); 101 + c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, 102 + ht_mask_width) & core_select_mask; 103 + c->cpu_die_id = apic->phys_pkg_id(c->initial_apicid, 104 + core_plus_mask_width) & die_select_mask; 105 + c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, 106 + die_plus_mask_width); 136 107 /* 137 108 * Reinit the apicid, now that we have extended initial_apicid. 138 109 */ 139 110 c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); 140 111 141 112 c->x86_max_cores = (core_level_siblings / smp_num_siblings); 113 + __max_die_per_package = (die_level_siblings / core_level_siblings); 142 114 #endif 143 115 return 0; 144 116 }
+69
arch/x86/kernel/smpboot.c
··· 89 89 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); 90 90 EXPORT_PER_CPU_SYMBOL(cpu_core_map); 91 91 92 + /* representing HT, core, and die siblings of each logical CPU */ 93 + DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map); 94 + EXPORT_PER_CPU_SYMBOL(cpu_die_map); 95 + 92 96 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); 93 97 94 98 /* Per CPU bogomips and other parameters */ ··· 103 99 unsigned int __max_logical_packages __read_mostly; 104 100 EXPORT_SYMBOL(__max_logical_packages); 105 101 static unsigned int logical_packages __read_mostly; 102 + static unsigned int logical_die __read_mostly; 106 103 107 104 /* Maximum number of SMT threads on any online core */ 108 105 int __read_mostly __max_smt_threads = 1; ··· 311 306 return -1; 312 307 } 313 308 EXPORT_SYMBOL(topology_phys_to_logical_pkg); 309 + /** 310 + * topology_phys_to_logical_die - Map a physical die id to logical 311 + * 312 + * Returns logical die id or -1 if not found 313 + */ 314 + int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu) 315 + { 316 + int cpu; 317 + int proc_id = cpu_data(cur_cpu).phys_proc_id; 318 + 319 + for_each_possible_cpu(cpu) { 320 + struct cpuinfo_x86 *c = &cpu_data(cpu); 321 + 322 + if (c->initialized && c->cpu_die_id == die_id && 323 + c->phys_proc_id == proc_id) 324 + return c->logical_die_id; 325 + } 326 + return -1; 327 + } 328 + EXPORT_SYMBOL(topology_phys_to_logical_die); 314 329 315 330 /** 316 331 * topology_update_package_map - Update the physical to logical package map ··· 355 330 cpu_data(cpu).logical_proc_id = new; 356 331 return 0; 357 332 } 333 + /** 334 + * topology_update_die_map - Update the physical to logical die map 335 + * @die: The die id as retrieved via CPUID 336 + * @cpu: The cpu for which this is updated 337 + */ 338 + int topology_update_die_map(unsigned int die, unsigned int cpu) 339 + { 340 + int new; 341 + 342 + /* Already available somewhere? */ 343 + new = topology_phys_to_logical_die(die, cpu); 344 + if (new >= 0) 345 + goto found; 346 + 347 + new = logical_die++; 348 + if (new != die) { 349 + pr_info("CPU %u Converting physical %u to logical die %u\n", 350 + cpu, die, new); 351 + } 352 + found: 353 + cpu_data(cpu).logical_die_id = new; 354 + return 0; 355 + } 358 356 359 357 void __init smp_store_boot_cpu_info(void) 360 358 { ··· 387 339 *c = boot_cpu_data; 388 340 c->cpu_index = id; 389 341 topology_update_package_map(c->phys_proc_id, id); 342 + topology_update_die_map(c->cpu_die_id, id); 390 343 c->initialized = true; 391 344 } 392 345 ··· 442 393 int cpu1 = c->cpu_index, cpu2 = o->cpu_index; 443 394 444 395 if (c->phys_proc_id == o->phys_proc_id && 396 + c->cpu_die_id == o->cpu_die_id && 445 397 per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { 446 398 if (c->cpu_core_id == o->cpu_core_id) 447 399 return topology_sane(c, o, "smt"); ··· 454 404 } 455 405 456 406 } else if (c->phys_proc_id == o->phys_proc_id && 407 + c->cpu_die_id == o->cpu_die_id && 457 408 c->cpu_core_id == o->cpu_core_id) { 458 409 return topology_sane(c, o, "smt"); 459 410 } ··· 516 465 return true; 517 466 return false; 518 467 } 468 + 469 + static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) 470 + { 471 + if ((c->phys_proc_id == o->phys_proc_id) && 472 + (c->cpu_die_id == o->cpu_die_id)) 473 + return true; 474 + return false; 475 + } 476 + 519 477 520 478 #if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC) 521 479 static inline int x86_sched_itmt_flags(void) ··· 588 528 cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu)); 589 529 cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu)); 590 530 cpumask_set_cpu(cpu, topology_core_cpumask(cpu)); 531 + cpumask_set_cpu(cpu, topology_die_cpumask(cpu)); 591 532 c->booted_cores = 1; 592 533 return; 593 534 } ··· 637 576 } 638 577 if (match_pkg(c, o) && !topology_same_node(c, o)) 639 578 x86_has_numa_in_package = true; 579 + 580 + if ((i == cpu) || (has_mp && match_die(c, o))) 581 + link_mask(topology_die_cpumask, cpu, i); 640 582 } 641 583 642 584 threads = cpumask_weight(topology_sibling_cpumask(cpu)); ··· 1244 1180 physid_set_mask_of_physid(0, &phys_cpu_present_map); 1245 1181 cpumask_set_cpu(0, topology_sibling_cpumask(0)); 1246 1182 cpumask_set_cpu(0, topology_core_cpumask(0)); 1183 + cpumask_set_cpu(0, topology_die_cpumask(0)); 1247 1184 } 1248 1185 1249 1186 /* ··· 1340 1275 for_each_possible_cpu(i) { 1341 1276 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); 1342 1277 zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); 1278 + zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL); 1343 1279 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); 1344 1280 } 1345 1281 ··· 1561 1495 cpu_data(sibling).booted_cores--; 1562 1496 } 1563 1497 1498 + for_each_cpu(sibling, topology_die_cpumask(cpu)) 1499 + cpumask_clear_cpu(cpu, topology_die_cpumask(sibling)); 1564 1500 for_each_cpu(sibling, topology_sibling_cpumask(cpu)) 1565 1501 cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling)); 1566 1502 for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) ··· 1570 1502 cpumask_clear(cpu_llc_shared_mask(cpu)); 1571 1503 cpumask_clear(topology_sibling_cpumask(cpu)); 1572 1504 cpumask_clear(topology_core_cpumask(cpu)); 1505 + cpumask_clear(topology_die_cpumask(cpu)); 1573 1506 c->cpu_core_id = 0; 1574 1507 c->booted_cores = 0; 1575 1508 cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
+1
arch/x86/xen/smp_pv.c
··· 251 251 for_each_possible_cpu(i) { 252 252 zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); 253 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 255 zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); 255 256 } 256 257 set_cpu_sibling_map(0);
+22
drivers/base/topology.c
··· 43 43 define_id_show_func(physical_package_id); 44 44 static DEVICE_ATTR_RO(physical_package_id); 45 45 46 + define_id_show_func(die_id); 47 + static DEVICE_ATTR_RO(die_id); 48 + 46 49 define_id_show_func(core_id); 47 50 static DEVICE_ATTR_RO(core_id); 48 51 ··· 53 50 static DEVICE_ATTR_RO(thread_siblings); 54 51 static DEVICE_ATTR_RO(thread_siblings_list); 55 52 53 + define_siblings_show_func(core_cpus, sibling_cpumask); 54 + static DEVICE_ATTR_RO(core_cpus); 55 + static DEVICE_ATTR_RO(core_cpus_list); 56 + 56 57 define_siblings_show_func(core_siblings, core_cpumask); 57 58 static DEVICE_ATTR_RO(core_siblings); 58 59 static DEVICE_ATTR_RO(core_siblings_list); 60 + 61 + define_siblings_show_func(die_cpus, die_cpumask); 62 + static DEVICE_ATTR_RO(die_cpus); 63 + static DEVICE_ATTR_RO(die_cpus_list); 64 + 65 + define_siblings_show_func(package_cpus, core_cpumask); 66 + static DEVICE_ATTR_RO(package_cpus); 67 + static DEVICE_ATTR_RO(package_cpus_list); 59 68 60 69 #ifdef CONFIG_SCHED_BOOK 61 70 define_id_show_func(book_id); ··· 87 72 88 73 static struct attribute *default_attrs[] = { 89 74 &dev_attr_physical_package_id.attr, 75 + &dev_attr_die_id.attr, 90 76 &dev_attr_core_id.attr, 91 77 &dev_attr_thread_siblings.attr, 92 78 &dev_attr_thread_siblings_list.attr, 79 + &dev_attr_core_cpus.attr, 80 + &dev_attr_core_cpus_list.attr, 93 81 &dev_attr_core_siblings.attr, 94 82 &dev_attr_core_siblings_list.attr, 83 + &dev_attr_die_cpus.attr, 84 + &dev_attr_die_cpus_list.attr, 85 + &dev_attr_package_cpus.attr, 86 + &dev_attr_package_cpus_list.attr, 95 87 #ifdef CONFIG_SCHED_BOOK 96 88 &dev_attr_book_id.attr, 97 89 &dev_attr_book_siblings.attr,
+18 -18
drivers/hwmon/coretemp.c
··· 96 96 struct device_attribute name_attr; 97 97 }; 98 98 99 - /* Keep track of how many package pointers we allocated in init() */ 100 - static int max_packages __read_mostly; 101 - /* Array of package pointers. Serialized by cpu hotplug lock */ 102 - static struct platform_device **pkg_devices; 99 + /* Keep track of how many zone pointers we allocated in init() */ 100 + static int max_zones __read_mostly; 101 + /* Array of zone pointers. Serialized by cpu hotplug lock */ 102 + static struct platform_device **zone_devices; 103 103 104 104 static ssize_t show_label(struct device *dev, 105 105 struct device_attribute *devattr, char *buf) ··· 422 422 423 423 static struct platform_device *coretemp_get_pdev(unsigned int cpu) 424 424 { 425 - int pkgid = topology_logical_package_id(cpu); 425 + int id = topology_logical_die_id(cpu); 426 426 427 - if (pkgid >= 0 && pkgid < max_packages) 428 - return pkg_devices[pkgid]; 427 + if (id >= 0 && id < max_zones) 428 + return zone_devices[id]; 429 429 return NULL; 430 430 } 431 431 ··· 531 531 struct device *dev = &pdev->dev; 532 532 struct platform_data *pdata; 533 533 534 - /* Initialize the per-package data structures */ 534 + /* Initialize the per-zone data structures */ 535 535 pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL); 536 536 if (!pdata) 537 537 return -ENOMEM; ··· 566 566 567 567 static struct platform_device *coretemp_device_add(unsigned int cpu) 568 568 { 569 - int err, pkgid = topology_logical_package_id(cpu); 569 + int err, zoneid = topology_logical_die_id(cpu); 570 570 struct platform_device *pdev; 571 571 572 - if (pkgid < 0) 572 + if (zoneid < 0) 573 573 return ERR_PTR(-ENOMEM); 574 574 575 - pdev = platform_device_alloc(DRVNAME, pkgid); 575 + pdev = platform_device_alloc(DRVNAME, zoneid); 576 576 if (!pdev) 577 577 return ERR_PTR(-ENOMEM); 578 578 ··· 582 582 return ERR_PTR(err); 583 583 } 584 584 585 - pkg_devices[pkgid] = pdev; 585 + zone_devices[zoneid] = pdev; 586 586 return pdev; 587 587 } 588 588 ··· 690 690 * the rest. 691 691 */ 692 692 if (cpumask_empty(&pd->cpumask)) { 693 - pkg_devices[topology_logical_package_id(cpu)] = NULL; 693 + zone_devices[topology_logical_die_id(cpu)] = NULL; 694 694 platform_device_unregister(pdev); 695 695 return 0; 696 696 } ··· 728 728 if (!x86_match_cpu(coretemp_ids)) 729 729 return -ENODEV; 730 730 731 - max_packages = topology_max_packages(); 732 - pkg_devices = kcalloc(max_packages, sizeof(struct platform_device *), 731 + max_zones = topology_max_packages() * topology_max_die_per_package(); 732 + zone_devices = kcalloc(max_zones, sizeof(struct platform_device *), 733 733 GFP_KERNEL); 734 - if (!pkg_devices) 734 + if (!zone_devices) 735 735 return -ENOMEM; 736 736 737 737 err = platform_driver_register(&coretemp_driver); ··· 747 747 748 748 outdrv: 749 749 platform_driver_unregister(&coretemp_driver); 750 - kfree(pkg_devices); 750 + kfree(zone_devices); 751 751 return err; 752 752 } 753 753 module_init(coretemp_init) ··· 756 756 { 757 757 cpuhp_remove_state(coretemp_hp_online); 758 758 platform_driver_unregister(&coretemp_driver); 759 - kfree(pkg_devices); 759 + kfree(zone_devices); 760 760 } 761 761 module_exit(coretemp_exit) 762 762
+41 -34
drivers/powercap/intel_rapl.c
··· 166 166 #define power_zone_to_rapl_domain(_zone) \ 167 167 container_of(_zone, struct rapl_domain, power_zone) 168 168 169 + /* maximum rapl package domain name: package-%d-die-%d */ 170 + #define PACKAGE_DOMAIN_NAME_LENGTH 30 169 171 170 - /* Each physical package contains multiple domains, these are the common 172 + 173 + /* Each rapl package contains multiple domains, these are the common 171 174 * data across RAPL domains within a package. 172 175 */ 173 176 struct rapl_package { 174 - unsigned int id; /* physical package/socket id */ 177 + unsigned int id; /* logical die id, equals physical 1-die systems */ 175 178 unsigned int nr_domains; 176 179 unsigned long domain_map; /* bit map of active domains */ 177 180 unsigned int power_unit; ··· 189 186 int lead_cpu; /* one active cpu per package for access */ 190 187 /* Track active cpus */ 191 188 struct cpumask cpumask; 189 + char name[PACKAGE_DOMAIN_NAME_LENGTH]; 192 190 }; 193 191 194 192 struct rapl_defaults { ··· 256 252 static struct rapl_domain *platform_rapl_domain; /* Platform (PSys) domain */ 257 253 258 254 /* caller to ensure CPU hotplug lock is held */ 259 - static struct rapl_package *find_package_by_id(int id) 255 + static struct rapl_package *rapl_find_package_domain(int cpu) 260 256 { 257 + int id = topology_logical_die_id(cpu); 261 258 struct rapl_package *rp; 262 259 263 260 list_for_each_entry(rp, &rapl_packages, plist) { ··· 918 913 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET; 919 914 rp->time_unit = 1000000 / (1 << value); 920 915 921 - pr_debug("Core CPU package %d energy=%dpJ, time=%dus, power=%duW\n", 922 - rp->id, rp->energy_unit, rp->time_unit, rp->power_unit); 916 + pr_debug("Core CPU %s energy=%dpJ, time=%dus, power=%duW\n", 917 + rp->name, rp->energy_unit, rp->time_unit, rp->power_unit); 923 918 924 919 return 0; 925 920 } ··· 943 938 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET; 944 939 rp->time_unit = 1000000 / (1 << value); 945 940 946 - pr_debug("Atom package %d energy=%dpJ, time=%dus, power=%duW\n", 947 - rp->id, rp->energy_unit, rp->time_unit, rp->power_unit); 941 + pr_debug("Atom %s energy=%dpJ, time=%dus, power=%duW\n", 942 + rp->name, rp->energy_unit, rp->time_unit, rp->power_unit); 948 943 949 944 return 0; 950 945 } ··· 1173 1168 u64 val; 1174 1169 1175 1170 for (dmn = 0; dmn < rp->nr_domains; dmn++) { 1176 - pr_debug("update package %d domain %s data\n", rp->id, 1171 + pr_debug("update %s domain %s data\n", rp->name, 1177 1172 rp->domains[dmn].name); 1178 1173 /* exclude non-raw primitives */ 1179 1174 for (prim = 0; prim < NR_RAW_PRIMITIVES; prim++) { ··· 1198 1193 static int rapl_package_register_powercap(struct rapl_package *rp) 1199 1194 { 1200 1195 struct rapl_domain *rd; 1201 - char dev_name[17]; /* max domain name = 7 + 1 + 8 for int + 1 for null*/ 1202 1196 struct powercap_zone *power_zone = NULL; 1203 1197 int nr_pl, ret; 1204 1198 ··· 1208 1204 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) { 1209 1205 if (rd->id == RAPL_DOMAIN_PACKAGE) { 1210 1206 nr_pl = find_nr_power_limit(rd); 1211 - pr_debug("register socket %d package domain %s\n", 1212 - rp->id, rd->name); 1213 - memset(dev_name, 0, sizeof(dev_name)); 1214 - snprintf(dev_name, sizeof(dev_name), "%s-%d", 1215 - rd->name, rp->id); 1207 + pr_debug("register package domain %s\n", rp->name); 1216 1208 power_zone = powercap_register_zone(&rd->power_zone, 1217 1209 control_type, 1218 - dev_name, NULL, 1210 + rp->name, NULL, 1219 1211 &zone_ops[rd->id], 1220 1212 nr_pl, 1221 1213 &constraint_ops); 1222 1214 if (IS_ERR(power_zone)) { 1223 - pr_debug("failed to register package, %d\n", 1224 - rp->id); 1215 + pr_debug("failed to register power zone %s\n", 1216 + rp->name); 1225 1217 return PTR_ERR(power_zone); 1226 1218 } 1227 1219 /* track parent zone in per package/socket data */ ··· 1243 1243 &constraint_ops); 1244 1244 1245 1245 if (IS_ERR(power_zone)) { 1246 - pr_debug("failed to register power_zone, %d:%s:%s\n", 1247 - rp->id, rd->name, dev_name); 1246 + pr_debug("failed to register power_zone, %s:%s\n", 1247 + rp->name, rd->name); 1248 1248 ret = PTR_ERR(power_zone); 1249 1249 goto err_cleanup; 1250 1250 } ··· 1257 1257 * failed after the first domain setup. 1258 1258 */ 1259 1259 while (--rd >= rp->domains) { 1260 - pr_debug("unregister package %d domain %s\n", rp->id, rd->name); 1260 + pr_debug("unregister %s domain %s\n", rp->name, rd->name); 1261 1261 powercap_unregister_zone(control_type, &rd->power_zone); 1262 1262 } 1263 1263 ··· 1288 1288 rd->rpl[0].name = pl1_name; 1289 1289 rd->rpl[1].prim_id = PL2_ENABLE; 1290 1290 rd->rpl[1].name = pl2_name; 1291 - rd->rp = find_package_by_id(0); 1291 + rd->rp = rapl_find_package_domain(0); 1292 1292 1293 1293 power_zone = powercap_register_zone(&rd->power_zone, control_type, 1294 1294 "psys", NULL, ··· 1367 1367 /* check if the domain is locked by BIOS, ignore if MSR doesn't exist */ 1368 1368 if (!rapl_read_data_raw(rd, FW_LOCK, false, &val64)) { 1369 1369 if (val64) { 1370 - pr_info("RAPL package %d domain %s locked by BIOS\n", 1371 - rd->rp->id, rd->name); 1370 + pr_info("RAPL %s domain %s locked by BIOS\n", 1371 + rd->rp->name, rd->name); 1372 1372 rd->state |= DOMAIN_STATE_BIOS_LOCKED; 1373 1373 } 1374 1374 } ··· 1397 1397 } 1398 1398 rp->nr_domains = bitmap_weight(&rp->domain_map, RAPL_DOMAIN_MAX); 1399 1399 if (!rp->nr_domains) { 1400 - pr_debug("no valid rapl domains found in package %d\n", rp->id); 1400 + pr_debug("no valid rapl domains found in %s\n", rp->name); 1401 1401 return -ENODEV; 1402 1402 } 1403 - pr_debug("found %d domains on package %d\n", rp->nr_domains, rp->id); 1403 + pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name); 1404 1404 1405 1405 rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain), 1406 1406 GFP_KERNEL); ··· 1433 1433 rd_package = rd; 1434 1434 continue; 1435 1435 } 1436 - pr_debug("remove package, undo power limit on %d: %s\n", 1437 - rp->id, rd->name); 1436 + pr_debug("remove package, undo power limit on %s: %s\n", 1437 + rp->name, rd->name); 1438 1438 powercap_unregister_zone(control_type, &rd->power_zone); 1439 1439 } 1440 1440 /* do parent zone last */ ··· 1444 1444 } 1445 1445 1446 1446 /* called from CPU hotplug notifier, hotplug lock held */ 1447 - static struct rapl_package *rapl_add_package(int cpu, int pkgid) 1447 + static struct rapl_package *rapl_add_package(int cpu) 1448 1448 { 1449 + int id = topology_logical_die_id(cpu); 1449 1450 struct rapl_package *rp; 1451 + struct cpuinfo_x86 *c = &cpu_data(cpu); 1450 1452 int ret; 1451 1453 1452 1454 rp = kzalloc(sizeof(struct rapl_package), GFP_KERNEL); ··· 1456 1454 return ERR_PTR(-ENOMEM); 1457 1455 1458 1456 /* add the new package to the list */ 1459 - rp->id = pkgid; 1457 + rp->id = id; 1460 1458 rp->lead_cpu = cpu; 1459 + 1460 + if (topology_max_die_per_package() > 1) 1461 + snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, 1462 + "package-%d-die-%d", c->phys_proc_id, c->cpu_die_id); 1463 + else 1464 + snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d", 1465 + c->phys_proc_id); 1461 1466 1462 1467 /* check if the package contains valid domains */ 1463 1468 if (rapl_detect_domains(rp, cpu) || ··· 1494 1485 */ 1495 1486 static int rapl_cpu_online(unsigned int cpu) 1496 1487 { 1497 - int pkgid = topology_physical_package_id(cpu); 1498 1488 struct rapl_package *rp; 1499 1489 1500 - rp = find_package_by_id(pkgid); 1490 + rp = rapl_find_package_domain(cpu); 1501 1491 if (!rp) { 1502 - rp = rapl_add_package(cpu, pkgid); 1492 + rp = rapl_add_package(cpu); 1503 1493 if (IS_ERR(rp)) 1504 1494 return PTR_ERR(rp); 1505 1495 } ··· 1508 1500 1509 1501 static int rapl_cpu_down_prep(unsigned int cpu) 1510 1502 { 1511 - int pkgid = topology_physical_package_id(cpu); 1512 1503 struct rapl_package *rp; 1513 1504 int lead_cpu; 1514 1505 1515 - rp = find_package_by_id(pkgid); 1506 + rp = rapl_find_package_domain(cpu); 1516 1507 if (!rp) 1517 1508 return 0; 1518 1509
+72 -70
drivers/thermal/intel/x86_pkg_temp_thermal.c
··· 43 43 */ 44 44 #define MAX_NUMBER_OF_TRIPS 2 45 45 46 - struct pkg_device { 46 + struct zone_device { 47 47 int cpu; 48 48 bool work_scheduled; 49 49 u32 tj_max; ··· 58 58 .no_hwmon = true, 59 59 }; 60 60 61 - /* Keep track of how many package pointers we allocated in init() */ 62 - static int max_packages __read_mostly; 63 - /* Array of package pointers */ 64 - static struct pkg_device **packages; 61 + /* Keep track of how many zone pointers we allocated in init() */ 62 + static int max_id __read_mostly; 63 + /* Array of zone pointers */ 64 + static struct zone_device **zones; 65 65 /* Serializes interrupt notification, work and hotplug */ 66 66 static DEFINE_SPINLOCK(pkg_temp_lock); 67 67 /* Protects zone operation in the work function against hotplug removal */ ··· 108 108 * 109 109 * - Other callsites: Must hold pkg_temp_lock 110 110 */ 111 - static struct pkg_device *pkg_temp_thermal_get_dev(unsigned int cpu) 111 + static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu) 112 112 { 113 - int pkgid = topology_logical_package_id(cpu); 113 + int id = topology_logical_die_id(cpu); 114 114 115 - if (pkgid >= 0 && pkgid < max_packages) 116 - return packages[pkgid]; 115 + if (id >= 0 && id < max_id) 116 + return zones[id]; 117 117 return NULL; 118 118 } 119 119 ··· 138 138 139 139 static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) 140 140 { 141 - struct pkg_device *pkgdev = tzd->devdata; 141 + struct zone_device *zonedev = tzd->devdata; 142 142 u32 eax, edx; 143 143 144 - rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_STATUS, &eax, &edx); 144 + rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_STATUS, 145 + &eax, &edx); 145 146 if (eax & 0x80000000) { 146 - *temp = pkgdev->tj_max - ((eax >> 16) & 0x7f) * 1000; 147 + *temp = zonedev->tj_max - ((eax >> 16) & 0x7f) * 1000; 147 148 pr_debug("sys_get_curr_temp %d\n", *temp); 148 149 return 0; 149 150 } ··· 154 153 static int sys_get_trip_temp(struct thermal_zone_device *tzd, 155 154 int trip, int *temp) 156 155 { 157 - struct pkg_device *pkgdev = tzd->devdata; 156 + struct zone_device *zonedev = tzd->devdata; 158 157 unsigned long thres_reg_value; 159 158 u32 mask, shift, eax, edx; 160 159 int ret; ··· 170 169 shift = THERM_SHIFT_THRESHOLD0; 171 170 } 172 171 173 - ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 172 + ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 174 173 &eax, &edx); 175 174 if (ret < 0) 176 175 return ret; 177 176 178 177 thres_reg_value = (eax & mask) >> shift; 179 178 if (thres_reg_value) 180 - *temp = pkgdev->tj_max - thres_reg_value * 1000; 179 + *temp = zonedev->tj_max - thres_reg_value * 1000; 181 180 else 182 181 *temp = 0; 183 182 pr_debug("sys_get_trip_temp %d\n", *temp); ··· 188 187 static int 189 188 sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) 190 189 { 191 - struct pkg_device *pkgdev = tzd->devdata; 190 + struct zone_device *zonedev = tzd->devdata; 192 191 u32 l, h, mask, shift, intr; 193 192 int ret; 194 193 195 - if (trip >= MAX_NUMBER_OF_TRIPS || temp >= pkgdev->tj_max) 194 + if (trip >= MAX_NUMBER_OF_TRIPS || temp >= zonedev->tj_max) 196 195 return -EINVAL; 197 196 198 - ret = rdmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 197 + ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 199 198 &l, &h); 200 199 if (ret < 0) 201 200 return ret; ··· 217 216 if (!temp) { 218 217 l &= ~intr; 219 218 } else { 220 - l |= (pkgdev->tj_max - temp)/1000 << shift; 219 + l |= (zonedev->tj_max - temp)/1000 << shift; 221 220 l |= intr; 222 221 } 223 222 224 - return wrmsr_on_cpu(pkgdev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); 223 + return wrmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 224 + l, h); 225 225 } 226 226 227 227 static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip, ··· 277 275 { 278 276 struct thermal_zone_device *tzone = NULL; 279 277 int cpu = smp_processor_id(); 280 - struct pkg_device *pkgdev; 278 + struct zone_device *zonedev; 281 279 u64 msr_val, wr_val; 282 280 283 281 mutex_lock(&thermal_zone_mutex); 284 282 spin_lock_irq(&pkg_temp_lock); 285 283 ++pkg_work_cnt; 286 284 287 - pkgdev = pkg_temp_thermal_get_dev(cpu); 288 - if (!pkgdev) { 285 + zonedev = pkg_temp_thermal_get_dev(cpu); 286 + if (!zonedev) { 289 287 spin_unlock_irq(&pkg_temp_lock); 290 288 mutex_unlock(&thermal_zone_mutex); 291 289 return; 292 290 } 293 - pkgdev->work_scheduled = false; 291 + zonedev->work_scheduled = false; 294 292 295 293 rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); 296 294 wr_val = msr_val & ~(THERM_LOG_THRESHOLD0 | THERM_LOG_THRESHOLD1); 297 295 if (wr_val != msr_val) { 298 296 wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS, wr_val); 299 - tzone = pkgdev->tzone; 297 + tzone = zonedev->tzone; 300 298 } 301 299 302 300 enable_pkg_thres_interrupt(); ··· 322 320 static int pkg_thermal_notify(u64 msr_val) 323 321 { 324 322 int cpu = smp_processor_id(); 325 - struct pkg_device *pkgdev; 323 + struct zone_device *zonedev; 326 324 unsigned long flags; 327 325 328 326 spin_lock_irqsave(&pkg_temp_lock, flags); ··· 331 329 disable_pkg_thres_interrupt(); 332 330 333 331 /* Work is per package, so scheduling it once is enough. */ 334 - pkgdev = pkg_temp_thermal_get_dev(cpu); 335 - if (pkgdev && !pkgdev->work_scheduled) { 336 - pkgdev->work_scheduled = true; 337 - pkg_thermal_schedule_work(pkgdev->cpu, &pkgdev->work); 332 + zonedev = pkg_temp_thermal_get_dev(cpu); 333 + if (zonedev && !zonedev->work_scheduled) { 334 + zonedev->work_scheduled = true; 335 + pkg_thermal_schedule_work(zonedev->cpu, &zonedev->work); 338 336 } 339 337 340 338 spin_unlock_irqrestore(&pkg_temp_lock, flags); ··· 343 341 344 342 static int pkg_temp_thermal_device_add(unsigned int cpu) 345 343 { 346 - int pkgid = topology_logical_package_id(cpu); 344 + int id = topology_logical_die_id(cpu); 347 345 u32 tj_max, eax, ebx, ecx, edx; 348 - struct pkg_device *pkgdev; 346 + struct zone_device *zonedev; 349 347 int thres_count, err; 350 348 351 - if (pkgid >= max_packages) 349 + if (id >= max_id) 352 350 return -ENOMEM; 353 351 354 352 cpuid(6, &eax, &ebx, &ecx, &edx); ··· 362 360 if (err) 363 361 return err; 364 362 365 - pkgdev = kzalloc(sizeof(*pkgdev), GFP_KERNEL); 366 - if (!pkgdev) 363 + zonedev = kzalloc(sizeof(*zonedev), GFP_KERNEL); 364 + if (!zonedev) 367 365 return -ENOMEM; 368 366 369 - INIT_DELAYED_WORK(&pkgdev->work, pkg_temp_thermal_threshold_work_fn); 370 - pkgdev->cpu = cpu; 371 - pkgdev->tj_max = tj_max; 372 - pkgdev->tzone = thermal_zone_device_register("x86_pkg_temp", 367 + INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn); 368 + zonedev->cpu = cpu; 369 + zonedev->tj_max = tj_max; 370 + zonedev->tzone = thermal_zone_device_register("x86_pkg_temp", 373 371 thres_count, 374 372 (thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01, 375 - pkgdev, &tzone_ops, &pkg_temp_tz_params, 0, 0); 376 - if (IS_ERR(pkgdev->tzone)) { 377 - err = PTR_ERR(pkgdev->tzone); 378 - kfree(pkgdev); 373 + zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0); 374 + if (IS_ERR(zonedev->tzone)) { 375 + err = PTR_ERR(zonedev->tzone); 376 + kfree(zonedev); 379 377 return err; 380 378 } 381 379 /* Store MSR value for package thermal interrupt, to restore at exit */ 382 - rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, pkgdev->msr_pkg_therm_low, 383 - pkgdev->msr_pkg_therm_high); 380 + rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low, 381 + zonedev->msr_pkg_therm_high); 384 382 385 - cpumask_set_cpu(cpu, &pkgdev->cpumask); 383 + cpumask_set_cpu(cpu, &zonedev->cpumask); 386 384 spin_lock_irq(&pkg_temp_lock); 387 - packages[pkgid] = pkgdev; 385 + zones[id] = zonedev; 388 386 spin_unlock_irq(&pkg_temp_lock); 389 387 return 0; 390 388 } 391 389 392 390 static int pkg_thermal_cpu_offline(unsigned int cpu) 393 391 { 394 - struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu); 392 + struct zone_device *zonedev = pkg_temp_thermal_get_dev(cpu); 395 393 bool lastcpu, was_target; 396 394 int target; 397 395 398 - if (!pkgdev) 396 + if (!zonedev) 399 397 return 0; 400 398 401 - target = cpumask_any_but(&pkgdev->cpumask, cpu); 402 - cpumask_clear_cpu(cpu, &pkgdev->cpumask); 399 + target = cpumask_any_but(&zonedev->cpumask, cpu); 400 + cpumask_clear_cpu(cpu, &zonedev->cpumask); 403 401 lastcpu = target >= nr_cpu_ids; 404 402 /* 405 403 * Remove the sysfs files, if this is the last cpu in the package 406 404 * before doing further cleanups. 407 405 */ 408 406 if (lastcpu) { 409 - struct thermal_zone_device *tzone = pkgdev->tzone; 407 + struct thermal_zone_device *tzone = zonedev->tzone; 410 408 411 409 /* 412 410 * We must protect against a work function calling ··· 415 413 * won't try to call. 416 414 */ 417 415 mutex_lock(&thermal_zone_mutex); 418 - pkgdev->tzone = NULL; 416 + zonedev->tzone = NULL; 419 417 mutex_unlock(&thermal_zone_mutex); 420 418 421 419 thermal_zone_device_unregister(tzone); ··· 429 427 * one. When we drop the lock, then the interrupt notify function 430 428 * will see the new target. 431 429 */ 432 - was_target = pkgdev->cpu == cpu; 433 - pkgdev->cpu = target; 430 + was_target = zonedev->cpu == cpu; 431 + zonedev->cpu = target; 434 432 435 433 /* 436 434 * If this is the last CPU in the package remove the package ··· 439 437 * worker will see the package anymore. 440 438 */ 441 439 if (lastcpu) { 442 - packages[topology_logical_package_id(cpu)] = NULL; 440 + zones[topology_logical_die_id(cpu)] = NULL; 443 441 /* After this point nothing touches the MSR anymore. */ 444 442 wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, 445 - pkgdev->msr_pkg_therm_low, pkgdev->msr_pkg_therm_high); 443 + zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high); 446 444 } 447 445 448 446 /* 449 447 * Check whether there is work scheduled and whether the work is 450 448 * targeted at the outgoing CPU. 451 449 */ 452 - if (pkgdev->work_scheduled && was_target) { 450 + if (zonedev->work_scheduled && was_target) { 453 451 /* 454 452 * To cancel the work we need to drop the lock, otherwise 455 453 * we might deadlock if the work needs to be flushed. 456 454 */ 457 455 spin_unlock_irq(&pkg_temp_lock); 458 - cancel_delayed_work_sync(&pkgdev->work); 456 + cancel_delayed_work_sync(&zonedev->work); 459 457 spin_lock_irq(&pkg_temp_lock); 460 458 /* 461 459 * If this is not the last cpu in the package and the work ··· 463 461 * need to reschedule the work, otherwise the interrupt 464 462 * stays disabled forever. 465 463 */ 466 - if (!lastcpu && pkgdev->work_scheduled) 467 - pkg_thermal_schedule_work(target, &pkgdev->work); 464 + if (!lastcpu && zonedev->work_scheduled) 465 + pkg_thermal_schedule_work(target, &zonedev->work); 468 466 } 469 467 470 468 spin_unlock_irq(&pkg_temp_lock); 471 469 472 470 /* Final cleanup if this is the last cpu */ 473 471 if (lastcpu) 474 - kfree(pkgdev); 472 + kfree(zonedev); 475 473 return 0; 476 474 } 477 475 478 476 static int pkg_thermal_cpu_online(unsigned int cpu) 479 477 { 480 - struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu); 478 + struct zone_device *zonedev = pkg_temp_thermal_get_dev(cpu); 481 479 struct cpuinfo_x86 *c = &cpu_data(cpu); 482 480 483 481 /* Paranoia check */ ··· 485 483 return -ENODEV; 486 484 487 485 /* If the package exists, nothing to do */ 488 - if (pkgdev) { 489 - cpumask_set_cpu(cpu, &pkgdev->cpumask); 486 + if (zonedev) { 487 + cpumask_set_cpu(cpu, &zonedev->cpumask); 490 488 return 0; 491 489 } 492 490 return pkg_temp_thermal_device_add(cpu); ··· 505 503 if (!x86_match_cpu(pkg_temp_thermal_ids)) 506 504 return -ENODEV; 507 505 508 - max_packages = topology_max_packages(); 509 - packages = kcalloc(max_packages, sizeof(struct pkg_device *), 506 + max_id = topology_max_packages() * topology_max_die_per_package(); 507 + zones = kcalloc(max_id, sizeof(struct zone_device *), 510 508 GFP_KERNEL); 511 - if (!packages) 509 + if (!zones) 512 510 return -ENOMEM; 513 511 514 512 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "thermal/x86_pkg:online", ··· 527 525 return 0; 528 526 529 527 err: 530 - kfree(packages); 528 + kfree(zones); 531 529 return ret; 532 530 } 533 531 module_init(pkg_temp_thermal_init) ··· 539 537 540 538 cpuhp_remove_state(pkg_thermal_hp_state); 541 539 debugfs_remove_recursive(debugfs); 542 - kfree(packages); 540 + kfree(zones); 543 541 } 544 542 module_exit(pkg_temp_thermal_exit) 545 543
+6
include/linux/topology.h
··· 184 184 #ifndef topology_physical_package_id 185 185 #define topology_physical_package_id(cpu) ((void)(cpu), -1) 186 186 #endif 187 + #ifndef topology_die_id 188 + #define topology_die_id(cpu) ((void)(cpu), -1) 189 + #endif 187 190 #ifndef topology_core_id 188 191 #define topology_core_id(cpu) ((void)(cpu), 0) 189 192 #endif ··· 195 192 #endif 196 193 #ifndef topology_core_cpumask 197 194 #define topology_core_cpumask(cpu) cpumask_of(cpu) 195 + #endif 196 + #ifndef topology_die_cpumask 197 + #define topology_die_cpumask(cpu) cpumask_of(cpu) 198 198 #endif 199 199 200 200 #ifdef CONFIG_SCHED_SMT