1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2008
4 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 #define KMSG_COMPONENT "cpu"
8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10 #include <linux/stop_machine.h>
11 #include <linux/cpufeature.h>
12 #include <linux/bitops.h>
13 #include <linux/kernel.h>
14 #include <linux/sched/mm.h>
15 #include <linux/init.h>
16 #include <linux/seq_file.h>
17 #include <linux/mm_types.h>
18 #include <linux/delay.h>
19 #include <linux/cpu.h>
22 #include <asm/facility.h>
24 #include <asm/lowcore.h>
25 #include <asm/param.h>
29 unsigned int cpu_mhz_dynamic
;
30 unsigned int cpu_mhz_static
;
34 static DEFINE_PER_CPU(struct cpu_info
, cpu_info
);
35 static DEFINE_PER_CPU(int, cpu_relax_retry
);
37 static bool machine_has_cpu_mhz
;
39 void __init
cpu_detect_mhz_feature(void)
41 if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE
, 0) != -1UL)
42 machine_has_cpu_mhz
= true;
45 static void update_cpu_mhz(void *arg
)
50 mhz
= __ecag(ECAG_CPU_ATTRIBUTE
, 0);
51 c
= this_cpu_ptr(&cpu_info
);
52 c
->cpu_mhz_dynamic
= mhz
>> 32;
53 c
->cpu_mhz_static
= mhz
& 0xffffffff;
56 void s390_update_cpu_mhz(void)
58 s390_adjust_jiffies();
59 if (machine_has_cpu_mhz
)
60 on_each_cpu(update_cpu_mhz
, NULL
, 0);
63 void notrace
stop_machine_yield(const struct cpumask
*cpumask
)
67 this_cpu
= smp_processor_id();
68 if (__this_cpu_inc_return(cpu_relax_retry
) >= spin_retry
) {
69 __this_cpu_write(cpu_relax_retry
, 0);
70 cpu
= cpumask_next_wrap(this_cpu
, cpumask
, this_cpu
, false);
71 if (cpu
>= nr_cpu_ids
)
73 if (arch_vcpu_is_preempted(cpu
))
79 * cpu_init - initializes state that is per-CPU.
83 struct cpuid
*id
= this_cpu_ptr(&cpu_info
.cpu_id
);
86 if (machine_has_cpu_mhz
)
89 current
->active_mm
= &init_mm
;
91 enter_lazy_tlb(&init_mm
, current
);
95 * cpu_have_feature - Test CPU features on module initialization
97 int cpu_have_feature(unsigned int num
)
99 return elf_hwcap
& (1UL << num
);
101 EXPORT_SYMBOL(cpu_have_feature
);
103 static void show_facilities(struct seq_file
*m
)
108 facilities
= (long *)&S390_lowcore
.stfle_fac_list
;
109 seq_puts(m
, "facilities :");
110 for_each_set_bit_inv(bit
, facilities
, MAX_FACILITY_BIT
)
111 seq_printf(m
, " %d", bit
);
115 static void show_cpu_summary(struct seq_file
*m
, void *v
)
117 static const char *hwcap_str
[] = {
118 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
119 "edat", "etf3eh", "highgprs", "te", "vx", "vxd", "vxe", "gs",
120 "vxe2", "vxp", "sort", "dflt"
122 static const char * const int_hwcap_str
[] = {
127 seq_printf(m
, "vendor_id : IBM/S390\n"
128 "# processors : %i\n"
129 "bogomips per cpu: %lu.%02lu\n",
130 num_online_cpus(), loops_per_jiffy
/(500000/HZ
),
131 (loops_per_jiffy
/(5000/HZ
))%100);
132 seq_printf(m
, "max thread id : %d\n", smp_cpu_mtid
);
133 seq_puts(m
, "features\t: ");
134 for (i
= 0; i
< ARRAY_SIZE(hwcap_str
); i
++)
135 if (hwcap_str
[i
] && (elf_hwcap
& (1UL << i
)))
136 seq_printf(m
, "%s ", hwcap_str
[i
]);
137 for (i
= 0; i
< ARRAY_SIZE(int_hwcap_str
); i
++)
138 if (int_hwcap_str
[i
] && (int_hwcap
& (1UL << i
)))
139 seq_printf(m
, "%s ", int_hwcap_str
[i
]);
143 for_each_online_cpu(cpu
) {
144 struct cpuid
*id
= &per_cpu(cpu_info
.cpu_id
, cpu
);
146 seq_printf(m
, "processor %d: "
148 "identification = %06X, "
150 cpu
, id
->version
, id
->ident
, id
->machine
);
154 static void show_cpu_topology(struct seq_file
*m
, unsigned long n
)
156 #ifdef CONFIG_SCHED_TOPOLOGY
157 seq_printf(m
, "physical id : %d\n", topology_physical_package_id(n
));
158 seq_printf(m
, "core id : %d\n", topology_core_id(n
));
159 seq_printf(m
, "book id : %d\n", topology_book_id(n
));
160 seq_printf(m
, "drawer id : %d\n", topology_drawer_id(n
));
161 seq_printf(m
, "dedicated : %d\n", topology_cpu_dedicated(n
));
162 seq_printf(m
, "address : %d\n", smp_cpu_get_cpu_address(n
));
163 seq_printf(m
, "siblings : %d\n", cpumask_weight(topology_core_cpumask(n
)));
164 seq_printf(m
, "cpu cores : %d\n", topology_booted_cores(n
));
165 #endif /* CONFIG_SCHED_TOPOLOGY */
168 static void show_cpu_ids(struct seq_file
*m
, unsigned long n
)
170 struct cpuid
*id
= &per_cpu(cpu_info
.cpu_id
, n
);
172 seq_printf(m
, "version : %02X\n", id
->version
);
173 seq_printf(m
, "identification : %06X\n", id
->ident
);
174 seq_printf(m
, "machine : %04X\n", id
->machine
);
177 static void show_cpu_mhz(struct seq_file
*m
, unsigned long n
)
179 struct cpu_info
*c
= per_cpu_ptr(&cpu_info
, n
);
181 if (!machine_has_cpu_mhz
)
183 seq_printf(m
, "cpu MHz dynamic : %d\n", c
->cpu_mhz_dynamic
);
184 seq_printf(m
, "cpu MHz static : %d\n", c
->cpu_mhz_static
);
188 * show_cpuinfo - Get information on one CPU for use by procfs.
190 static int show_cpuinfo(struct seq_file
*m
, void *v
)
192 unsigned long n
= (unsigned long) v
- 1;
193 unsigned long first
= cpumask_first(cpu_online_mask
);
196 show_cpu_summary(m
, v
);
197 seq_printf(m
, "\ncpu number : %ld\n", n
);
198 show_cpu_topology(m
, n
);
204 static inline void *c_update(loff_t
*pos
)
207 *pos
= cpumask_next(*pos
- 1, cpu_online_mask
);
209 *pos
= cpumask_first(cpu_online_mask
);
210 return *pos
< nr_cpu_ids
? (void *)*pos
+ 1 : NULL
;
213 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
216 return c_update(pos
);
219 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
222 return c_update(pos
);
225 static void c_stop(struct seq_file
*m
, void *v
)
230 const struct seq_operations cpuinfo_op
= {
234 .show
= show_cpuinfo
,
237 int s390_isolate_bp(void)
239 if (!test_facility(82))
241 set_thread_flag(TIF_ISOLATE_BP
);
244 EXPORT_SYMBOL(s390_isolate_bp
);
246 int s390_isolate_bp_guest(void)
248 if (!test_facility(82))
250 set_thread_flag(TIF_ISOLATE_BP_GUEST
);
253 EXPORT_SYMBOL(s390_isolate_bp_guest
);