Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
f6bf1a8
Documentation
arch
alpha
arm
avr32
blackfin
cris
frv
h8300
hexagon
ia64
m32r
m68k
microblaze
mips
mn10300
openrisc
parisc
powerpc
s390
appldata
boot
crypto
hypfs
include
kernel
vdso32
vdso64
Makefile
asm-offsets.c
audit.c
audit.h
base.S
bitmap.c
compat_audit.c
compat_exec_domain.c
compat_linux.c
compat_linux.h
compat_ptrace.h
compat_signal.c
compat_wrapper.S
cpcmd.c
crash.c
crash_dump.c
debug.c
diag.c
dis.c
early.c
ebcdic.c
entry.S
entry.h
entry64.S
ftrace.c
head.S
head31.S
head64.S
head_kdump.S
init_task.c
ipl.c
irq.c
jump_label.c
kprobes.c
machine_kexec.c
mcount.S
mcount64.S
mem_detect.c
module.c
nmi.c
process.c
processor.c
ptrace.c
reipl.S
reipl64.S
relocate_kernel.S
relocate_kernel64.S
s390_ksyms.c
sclp.S
setup.c
signal.c
smp.c
stacktrace.c
suspend.c
switch_cpu.S
switch_cpu64.S
swsusp_asm64.S
sys_s390.c
syscalls.S
sysinfo.c
time.c
topology.c
traps.c
vdso.c
vmlinux.lds.S
vtime.c
kvm
lib
math-emu
mm
oprofile
Kbuild
Kconfig
Kconfig.debug
Makefile
defconfig
score
sh
sparc
tile
um
unicore32
x86
xtensa
.gitignore
Kconfig
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
arch
/
s390
/
kernel
/
topology.c
Copy path
Blame
Blame
Latest commit
History
History
366 lines (326 loc) · 7.51 KB
Breadcrumbs
linux
/
arch
/
s390
/
kernel
/
topology.c
Top
File metadata and controls
Code
Blame
366 lines (326 loc) · 7.51 KB
Raw
/* * Copyright IBM Corp. 2007 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> */ #define KMSG_COMPONENT "cpu" #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include <linux/kernel.h> #include <linux/mm.h> #include <linux/init.h> #include <linux/device.h> #include <linux/bootmem.h> #include <linux/sched.h> #include <linux/workqueue.h> #include <linux/cpu.h> #include <linux/smp.h> #include <linux/cpuset.h> #include <asm/delay.h> #define PTF_HORIZONTAL (0UL) #define PTF_VERTICAL (1UL) #define PTF_CHECK (2UL) struct mask_info { struct mask_info *next; unsigned char id; cpumask_t mask; }; static int topology_enabled = 1; static void topology_work_fn(struct work_struct *work); static struct sysinfo_15_1_x *tl_info; static struct timer_list topology_timer; static void set_topology_timer(void); static DECLARE_WORK(topology_work, topology_work_fn); /* topology_lock protects the core linked list */ static DEFINE_SPINLOCK(topology_lock); static struct mask_info core_info; cpumask_t cpu_core_map[NR_CPUS]; unsigned char cpu_core_id[NR_CPUS]; #ifdef CONFIG_SCHED_BOOK static struct mask_info book_info; cpumask_t cpu_book_map[NR_CPUS]; unsigned char cpu_book_id[NR_CPUS]; #endif static cpumask_t cpu_group_map(struct mask_info *info, unsigned int cpu) { cpumask_t mask; cpumask_clear(&mask); if (!topology_enabled || !MACHINE_HAS_TOPOLOGY) { cpumask_copy(&mask, cpumask_of(cpu)); return mask; } while (info) { if (cpumask_test_cpu(cpu, &info->mask)) { mask = info->mask; break; } info = info->next; } if (cpumask_empty(&mask)) cpumask_copy(&mask, cpumask_of(cpu)); return mask; } static struct mask_info *add_cpus_to_mask(struct topology_cpu *tl_cpu, struct mask_info *book, struct mask_info *core, int z10) { unsigned int cpu; for (cpu = find_first_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS); cpu < TOPOLOGY_CPU_BITS; cpu = find_next_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS, cpu + 1)) { unsigned int rcpu, lcpu; rcpu = TOPOLOGY_CPU_BITS - 1 - cpu + tl_cpu->origin; for_each_present_cpu(lcpu) { if (cpu_logical_map(lcpu) != rcpu) continue; #ifdef CONFIG_SCHED_BOOK cpumask_set_cpu(lcpu, &book->mask); cpu_book_id[lcpu] = book->id; #endif cpumask_set_cpu(lcpu, &core->mask); if (z10) { cpu_core_id[lcpu] = rcpu; core = core->next; } else { cpu_core_id[lcpu] = core->id; } smp_cpu_polarization[lcpu] = tl_cpu->pp; } } return core; } static void clear_masks(void) { struct mask_info *info; info = &core_info; while (info) { cpumask_clear(&info->mask); info = info->next; } #ifdef CONFIG_SCHED_BOOK info = &book_info; while (info) { cpumask_clear(&info->mask); info = info->next; } #endif } static union topology_entry *next_tle(union topology_entry *tle) { if (!tle->nl) return (union topology_entry *)((struct topology_cpu *)tle + 1); return (union topology_entry *)((struct topology_container *)tle + 1); } static void tl_to_cores(struct sysinfo_15_1_x *info) { #ifdef CONFIG_SCHED_BOOK struct mask_info *book = &book_info; struct cpuid cpu_id; #else struct mask_info *book = NULL; #endif struct mask_info *core = &core_info; union topology_entry *tle, *end; int z10 = 0; #ifdef CONFIG_SCHED_BOOK get_cpu_id(&cpu_id); z10 = cpu_id.machine == 0x2097 || cpu_id.machine == 0x2098; #endif spin_lock_irq(&topology_lock); clear_masks(); tle = info->tle; end = (union topology_entry *)((unsigned long)info + info->length); while (tle < end) { #ifdef CONFIG_SCHED_BOOK if (z10) { switch (tle->nl) { case 1: book = book->next; book->id = tle->container.id; break; case 0: core = add_cpus_to_mask(&tle->cpu, book, core, z10); break; default: clear_masks(); goto out; } tle = next_tle(tle); continue; } #endif switch (tle->nl) { #ifdef CONFIG_SCHED_BOOK case 2: book = book->next; book->id = tle->container.id; break; #endif case 1: core = core->next; core->id = tle->container.id; break; case 0: add_cpus_to_mask(&tle->cpu, book, core, z10); break; default: clear_masks(); goto out; } tle = next_tle(tle); } out: spin_unlock_irq(&topology_lock); } static void topology_update_polarization_simple(void) { int cpu; mutex_lock(&smp_cpu_state_mutex); for_each_possible_cpu(cpu) smp_cpu_polarization[cpu] = POLARIZATION_HRZ; mutex_unlock(&smp_cpu_state_mutex); } static int ptf(unsigned long fc) { int rc; asm volatile( " .insn rre,0xb9a20000,%1,%1\n" " ipm %0\n" " srl %0,28\n" : "=d" (rc) : "d" (fc) : "cc"); return rc; } int topology_set_cpu_management(int fc) { int cpu; int rc; if (!MACHINE_HAS_TOPOLOGY) return -EOPNOTSUPP; if (fc) rc = ptf(PTF_VERTICAL); else rc = ptf(PTF_HORIZONTAL); if (rc) return -EBUSY; for_each_possible_cpu(cpu) smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN; return rc; } static void update_cpu_core_map(void) { unsigned long flags; int cpu; spin_lock_irqsave(&topology_lock, flags); for_each_possible_cpu(cpu) { cpu_core_map[cpu] = cpu_group_map(&core_info, cpu); #ifdef CONFIG_SCHED_BOOK cpu_book_map[cpu] = cpu_group_map(&book_info, cpu); #endif } spin_unlock_irqrestore(&topology_lock, flags); } void store_topology(struct sysinfo_15_1_x *info) { #ifdef CONFIG_SCHED_BOOK int rc; rc = stsi(info, 15, 1, 3); if (rc != -ENOSYS) return; #endif stsi(info, 15, 1, 2); } int arch_update_cpu_topology(void) { struct sysinfo_15_1_x *info = tl_info; struct sys_device *sysdev; int cpu; if (!MACHINE_HAS_TOPOLOGY) { update_cpu_core_map(); topology_update_polarization_simple(); return 0; } store_topology(info); tl_to_cores(info); update_cpu_core_map(); for_each_online_cpu(cpu) { sysdev = get_cpu_sysdev(cpu); kobject_uevent(&sysdev->kobj, KOBJ_CHANGE); } return 1; } static void topology_work_fn(struct work_struct *work) { rebuild_sched_domains(); } void topology_schedule_update(void) { schedule_work(&topology_work); } static void topology_timer_fn(unsigned long ignored) { if (ptf(PTF_CHECK)) topology_schedule_update(); set_topology_timer(); } static void set_topology_timer(void) { topology_timer.function = topology_timer_fn; topology_timer.data = 0; topology_timer.expires = jiffies + 60 * HZ; add_timer(&topology_timer); } static int __init early_parse_topology(char *p) { if (strncmp(p, "off", 3)) return 0; topology_enabled = 0; return 0; } early_param("topology", early_parse_topology); static int __init init_topology_update(void) { int rc; rc = 0; if (!MACHINE_HAS_TOPOLOGY) { topology_update_polarization_simple(); goto out; } init_timer_deferrable(&topology_timer); set_topology_timer(); out: update_cpu_core_map(); return rc; } __initcall(init_topology_update); static void __init alloc_masks(struct sysinfo_15_1_x *info, struct mask_info *mask, int offset) { int i, nr_masks; nr_masks = info->mag[TOPOLOGY_NR_MAG - offset]; for (i = 0; i < info->mnest - offset; i++) nr_masks *= info->mag[TOPOLOGY_NR_MAG - offset - 1 - i]; nr_masks = max(nr_masks, 1); for (i = 0; i < nr_masks; i++) { mask->next = alloc_bootmem(sizeof(struct mask_info)); mask = mask->next; } } void __init s390_init_cpu_topology(void) { struct sysinfo_15_1_x *info; int i; if (!MACHINE_HAS_TOPOLOGY) return; tl_info = alloc_bootmem_pages(PAGE_SIZE); info = tl_info; store_topology(info); pr_info("The CPU configuration topology of the machine is:"); for (i = 0; i < TOPOLOGY_NR_MAG; i++) printk(" %d", info->mag[i]); printk(" / %d\n", info->mnest); alloc_masks(info, &core_info, 1); #ifdef CONFIG_SCHED_BOOK alloc_masks(info, &book_info, 2); #endif }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
You can’t perform that action at this time.