hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/s390/kernel/topology.c
....@@ -8,7 +8,7 @@
88 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
99
1010 #include <linux/workqueue.h>
11
-#include <linux/bootmem.h>
11
+#include <linux/memblock.h>
1212 #include <linux/uaccess.h>
1313 #include <linux/sysctl.h>
1414 #include <linux/cpuset.h>
....@@ -26,7 +26,6 @@
2626 #include <linux/nodemask.h>
2727 #include <linux/node.h>
2828 #include <asm/sysinfo.h>
29
-#include <asm/numa.h>
3029
3130 #define PTF_HORIZONTAL (0UL)
3231 #define PTF_VERTICAL (1UL)
....@@ -63,8 +62,6 @@
6362 struct cpu_topology_s390 cpu_topology[NR_CPUS];
6463 EXPORT_SYMBOL_GPL(cpu_topology);
6564
66
-cpumask_t cpus_with_topology;
67
-
6865 static cpumask_t cpu_group_map(struct mask_info *info, unsigned int cpu)
6966 {
7067 cpumask_t mask;
....@@ -86,11 +83,12 @@
8683 cpumask_copy(&mask, cpu_present_mask);
8784 break;
8885 default:
89
- /* fallthrough */
86
+ fallthrough;
9087 case TOPOLOGY_MODE_SINGLE:
9188 cpumask_copy(&mask, cpumask_of(cpu));
9289 break;
9390 }
91
+ cpumask_and(&mask, &mask, cpu_online_mask);
9492 return mask;
9593 }
9694
....@@ -106,6 +104,7 @@
106104 for (i = 0; i <= smp_cpu_mtid; i++)
107105 if (cpu_present(cpu + i))
108106 cpumask_set_cpu(cpu + i, &mask);
107
+ cpumask_and(&mask, &mask, cpu_online_mask);
109108 return mask;
110109 }
111110
....@@ -138,7 +137,6 @@
138137 cpumask_set_cpu(lcpu + i, &drawer->mask);
139138 cpumask_set_cpu(lcpu + i, &book->mask);
140139 cpumask_set_cpu(lcpu + i, &socket->mask);
141
- cpumask_set_cpu(lcpu + i, &cpus_with_topology);
142140 smp_cpu_set_polarization(lcpu + i, tl_core->pp);
143141 }
144142 }
....@@ -245,10 +243,10 @@
245243 return rc;
246244 }
247245
248
-static void update_cpu_masks(void)
246
+void update_cpu_masks(void)
249247 {
250
- struct cpu_topology_s390 *topo;
251
- int cpu, id;
248
+ struct cpu_topology_s390 *topo, *topo_package, *topo_sibling;
249
+ int cpu, sibling, pkg_first, smt_first, id;
252250
253251 for_each_possible_cpu(cpu) {
254252 topo = &cpu_topology[cpu];
....@@ -256,6 +254,7 @@
256254 topo->core_mask = cpu_group_map(&socket_info, cpu);
257255 topo->book_mask = cpu_group_map(&book_info, cpu);
258256 topo->drawer_mask = cpu_group_map(&drawer_info, cpu);
257
+ topo->booted_cores = 0;
259258 if (topology_mode != TOPOLOGY_MODE_HW) {
260259 id = topology_mode == TOPOLOGY_MODE_PACKAGE ? 0 : cpu;
261260 topo->thread_id = cpu;
....@@ -263,11 +262,23 @@
263262 topo->socket_id = id;
264263 topo->book_id = id;
265264 topo->drawer_id = id;
266
- if (cpu_present(cpu))
267
- cpumask_set_cpu(cpu, &cpus_with_topology);
268265 }
269266 }
270
- numa_update_cpu_topology();
267
+ for_each_online_cpu(cpu) {
268
+ topo = &cpu_topology[cpu];
269
+ pkg_first = cpumask_first(&topo->core_mask);
270
+ topo_package = &cpu_topology[pkg_first];
271
+ if (cpu == pkg_first) {
272
+ for_each_cpu(sibling, &topo->core_mask) {
273
+ topo_sibling = &cpu_topology[sibling];
274
+ smt_first = cpumask_first(&topo_sibling->thread_mask);
275
+ if (sibling == smt_first)
276
+ topo_package->booted_cores++;
277
+ }
278
+ } else {
279
+ topo->booted_cores = topo_package->booted_cores;
280
+ }
281
+ }
271282 }
272283
273284 void store_topology(struct sysinfo_15_1_x *info)
....@@ -289,7 +300,6 @@
289300 int rc = 0;
290301
291302 mutex_lock(&smp_cpu_state_mutex);
292
- cpumask_clear(&cpus_with_topology);
293303 if (MACHINE_HAS_TOPOLOGY) {
294304 rc = 1;
295305 store_topology(info);
....@@ -346,9 +356,9 @@
346356 static void set_topology_timer(void)
347357 {
348358 if (atomic_add_unless(&topology_poll, -1, 0))
349
- mod_timer(&topology_timer, jiffies + HZ / 10);
359
+ mod_timer(&topology_timer, jiffies + msecs_to_jiffies(100));
350360 else
351
- mod_timer(&topology_timer, jiffies + HZ * 60);
361
+ mod_timer(&topology_timer, jiffies + msecs_to_jiffies(60 * MSEC_PER_SEC));
352362 }
353363
354364 void topology_expect_change(void)
....@@ -520,7 +530,10 @@
520530 nr_masks *= info->mag[TOPOLOGY_NR_MAG - offset - 1 - i];
521531 nr_masks = max(nr_masks, 1);
522532 for (i = 0; i < nr_masks; i++) {
523
- mask->next = memblock_virt_alloc(sizeof(*mask->next), 8);
533
+ mask->next = memblock_alloc(sizeof(*mask->next), 8);
534
+ if (!mask->next)
535
+ panic("%s: Failed to allocate %zu bytes align=0x%x\n",
536
+ __func__, sizeof(*mask->next), 8);
524537 mask = mask->next;
525538 }
526539 }
....@@ -538,7 +551,10 @@
538551 }
539552 if (!MACHINE_HAS_TOPOLOGY)
540553 goto out;
541
- tl_info = memblock_virt_alloc(PAGE_SIZE, PAGE_SIZE);
554
+ tl_info = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
555
+ if (!tl_info)
556
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
557
+ __func__, PAGE_SIZE, PAGE_SIZE);
542558 info = tl_info;
543559 store_topology(info);
544560 pr_info("The CPU configuration topology of the machine is: %d %d %d %d %d %d / %d\n",
....@@ -578,19 +594,17 @@
578594 early_param("topology", topology_setup);
579595
580596 static int topology_ctl_handler(struct ctl_table *ctl, int write,
581
- void __user *buffer, size_t *lenp, loff_t *ppos)
597
+ void *buffer, size_t *lenp, loff_t *ppos)
582598 {
583599 int enabled = topology_is_enabled();
584600 int new_mode;
585
- int zero = 0;
586
- int one = 1;
587601 int rc;
588602 struct ctl_table ctl_entry = {
589603 .procname = ctl->procname,
590604 .data = &enabled,
591605 .maxlen = sizeof(int),
592
- .extra1 = &zero,
593
- .extra2 = &one,
606
+ .extra1 = SYSCTL_ZERO,
607
+ .extra2 = SYSCTL_ONE,
594608 };
595609
596610 rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);