Linux Audio

Check our new training course

Loading...
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  Copyright IBM Corp. 2008
  4 *  Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  5 */
  6
  7#define KMSG_COMPONENT "cpu"
  8#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9
 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>
 20
 21#include <asm/diag.h>
 22#include <asm/facility.h>
 23#include <asm/elf.h>
 24#include <asm/lowcore.h>
 25#include <asm/param.h>
 26#include <asm/smp.h>
 27
 28struct cpu_info {
 29	unsigned int cpu_mhz_dynamic;
 30	unsigned int cpu_mhz_static;
 31	struct cpuid cpu_id;
 32};
 33
 34static DEFINE_PER_CPU(struct cpu_info, cpu_info);
 35static DEFINE_PER_CPU(int, cpu_relax_retry);
 36
 37static bool machine_has_cpu_mhz;
 38
 39void __init cpu_detect_mhz_feature(void)
 40{
 41	if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE, 0) != -1UL)
 42		machine_has_cpu_mhz = true;
 43}
 44
 45static void update_cpu_mhz(void *arg)
 46{
 47	unsigned long mhz;
 48	struct cpu_info *c;
 49
 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;
 54}
 55
 56void s390_update_cpu_mhz(void)
 57{
 58	s390_adjust_jiffies();
 59	if (machine_has_cpu_mhz)
 60		on_each_cpu(update_cpu_mhz, NULL, 0);
 61}
 62
 63void notrace stop_machine_yield(const struct cpumask *cpumask)
 64{
 65	int cpu, this_cpu;
 66
 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)
 72			return;
 73		if (arch_vcpu_is_preempted(cpu))
 74			smp_yield_cpu(cpu);
 75	}
 
 76}
 
 77
 78/*
 79 * cpu_init - initializes state that is per-CPU.
 80 */
 81void cpu_init(void)
 82{
 83	struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
 84
 85	get_cpu_id(id);
 86	if (machine_has_cpu_mhz)
 87		update_cpu_mhz(NULL);
 88	mmgrab(&init_mm);
 89	current->active_mm = &init_mm;
 90	BUG_ON(current->mm);
 91	enter_lazy_tlb(&init_mm, current);
 92}
 93
 94/*
 95 * cpu_have_feature - Test CPU features on module initialization
 96 */
 97int cpu_have_feature(unsigned int num)
 98{
 99	return elf_hwcap & (1UL << num);
100}
101EXPORT_SYMBOL(cpu_have_feature);
102
103static void show_facilities(struct seq_file *m)
104{
105	unsigned int bit;
106
107	seq_puts(m, "facilities      :");
108	for_each_set_bit_inv(bit, (long *)&stfle_fac_list, MAX_FACILITY_BIT)
109		seq_printf(m, " %d", bit);
110	seq_putc(m, '\n');
111}
112
113static void show_cpu_summary(struct seq_file *m, void *v)
114{
115	static const char *hwcap_str[] = {
116		"esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
117		"edat", "etf3eh", "highgprs", "te", "vx", "vxd", "vxe", "gs",
118		"vxe2", "vxp", "sort", "dflt"
119	};
120	static const char * const int_hwcap_str[] = {
121		"sie"
122	};
123	int i, cpu;
124
125	seq_printf(m, "vendor_id       : IBM/S390\n"
126		   "# processors    : %i\n"
127		   "bogomips per cpu: %lu.%02lu\n",
128		   num_online_cpus(), loops_per_jiffy/(500000/HZ),
129		   (loops_per_jiffy/(5000/HZ))%100);
130	seq_printf(m, "max thread id   : %d\n", smp_cpu_mtid);
131	seq_puts(m, "features\t: ");
132	for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
133		if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
134			seq_printf(m, "%s ", hwcap_str[i]);
135	for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
136		if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
137			seq_printf(m, "%s ", int_hwcap_str[i]);
138	seq_puts(m, "\n");
139	show_facilities(m);
140	show_cacheinfo(m);
141	for_each_online_cpu(cpu) {
142		struct cpuid *id = &per_cpu(cpu_info.cpu_id, cpu);
143
144		seq_printf(m, "processor %d: "
145			   "version = %02X,  "
146			   "identification = %06X,  "
147			   "machine = %04X\n",
148			   cpu, id->version, id->ident, id->machine);
149	}
150}
151
152static void show_cpu_topology(struct seq_file *m, unsigned long n)
153{
154#ifdef CONFIG_SCHED_TOPOLOGY
155	seq_printf(m, "physical id     : %d\n", topology_physical_package_id(n));
156	seq_printf(m, "core id         : %d\n", topology_core_id(n));
157	seq_printf(m, "book id         : %d\n", topology_book_id(n));
158	seq_printf(m, "drawer id       : %d\n", topology_drawer_id(n));
159	seq_printf(m, "dedicated       : %d\n", topology_cpu_dedicated(n));
160	seq_printf(m, "address         : %d\n", smp_cpu_get_cpu_address(n));
161	seq_printf(m, "siblings        : %d\n", cpumask_weight(topology_core_cpumask(n)));
162	seq_printf(m, "cpu cores       : %d\n", topology_booted_cores(n));
163#endif /* CONFIG_SCHED_TOPOLOGY */
164}
165
166static void show_cpu_ids(struct seq_file *m, unsigned long n)
167{
168	struct cpuid *id = &per_cpu(cpu_info.cpu_id, n);
169
170	seq_printf(m, "version         : %02X\n", id->version);
171	seq_printf(m, "identification  : %06X\n", id->ident);
172	seq_printf(m, "machine         : %04X\n", id->machine);
173}
174
175static void show_cpu_mhz(struct seq_file *m, unsigned long n)
176{
177	struct cpu_info *c = per_cpu_ptr(&cpu_info, n);
178
179	if (!machine_has_cpu_mhz)
180		return;
181	seq_printf(m, "cpu MHz dynamic : %d\n", c->cpu_mhz_dynamic);
182	seq_printf(m, "cpu MHz static  : %d\n", c->cpu_mhz_static);
183}
184
185/*
186 * show_cpuinfo - Get information on one CPU for use by procfs.
187 */
188static int show_cpuinfo(struct seq_file *m, void *v)
189{
190	unsigned long n = (unsigned long) v - 1;
191	unsigned long first = cpumask_first(cpu_online_mask);
192
193	if (n == first)
194		show_cpu_summary(m, v);
 
 
195	seq_printf(m, "\ncpu number      : %ld\n", n);
196	show_cpu_topology(m, n);
197	show_cpu_ids(m, n);
198	show_cpu_mhz(m, n);
199	return 0;
200}
201
202static inline void *c_update(loff_t *pos)
203{
204	if (*pos)
205		*pos = cpumask_next(*pos - 1, cpu_online_mask);
206	else
207		*pos = cpumask_first(cpu_online_mask);
208	return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
209}
210
211static void *c_start(struct seq_file *m, loff_t *pos)
212{
213	get_online_cpus();
214	return c_update(pos);
215}
216
217static void *c_next(struct seq_file *m, void *v, loff_t *pos)
218{
219	++*pos;
220	return c_update(pos);
221}
222
223static void c_stop(struct seq_file *m, void *v)
224{
225	put_online_cpus();
226}
227
228const struct seq_operations cpuinfo_op = {
229	.start	= c_start,
230	.next	= c_next,
231	.stop	= c_stop,
232	.show	= show_cpuinfo,
233};
234
235int s390_isolate_bp(void)
236{
237	if (!test_facility(82))
238		return -EOPNOTSUPP;
239	set_thread_flag(TIF_ISOLATE_BP);
240	return 0;
241}
242EXPORT_SYMBOL(s390_isolate_bp);
243
244int s390_isolate_bp_guest(void)
245{
246	if (!test_facility(82))
247		return -EOPNOTSUPP;
248	set_thread_flag(TIF_ISOLATE_BP_GUEST);
249	return 0;
250}
251EXPORT_SYMBOL(s390_isolate_bp_guest);
v4.10.11
 
  1/*
  2 *  Copyright IBM Corp. 2008
  3 *  Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  4 */
  5
  6#define KMSG_COMPONENT "cpu"
  7#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  8
 
  9#include <linux/cpufeature.h>
 
 10#include <linux/kernel.h>
 
 11#include <linux/init.h>
 12#include <linux/seq_file.h>
 
 13#include <linux/delay.h>
 14#include <linux/cpu.h>
 
 15#include <asm/diag.h>
 16#include <asm/facility.h>
 17#include <asm/elf.h>
 18#include <asm/lowcore.h>
 19#include <asm/param.h>
 20#include <asm/smp.h>
 21
 22struct cpu_info {
 23	unsigned int cpu_mhz_dynamic;
 24	unsigned int cpu_mhz_static;
 25	struct cpuid cpu_id;
 26};
 27
 28static DEFINE_PER_CPU(struct cpu_info, cpu_info);
 
 29
 30static bool machine_has_cpu_mhz;
 31
 32void __init cpu_detect_mhz_feature(void)
 33{
 34	if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE, 0) != -1UL)
 35		machine_has_cpu_mhz = 1;
 36}
 37
 38static void update_cpu_mhz(void *arg)
 39{
 40	unsigned long mhz;
 41	struct cpu_info *c;
 42
 43	mhz = __ecag(ECAG_CPU_ATTRIBUTE, 0);
 44	c = this_cpu_ptr(&cpu_info);
 45	c->cpu_mhz_dynamic = mhz >> 32;
 46	c->cpu_mhz_static = mhz & 0xffffffff;
 47}
 48
 49void s390_update_cpu_mhz(void)
 50{
 51	s390_adjust_jiffies();
 52	if (machine_has_cpu_mhz)
 53		on_each_cpu(update_cpu_mhz, NULL, 0);
 54}
 55
 56void notrace cpu_relax_yield(void)
 57{
 58	if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
 59		diag_stat_inc(DIAG_STAT_X044);
 60		asm volatile("diag 0,0,0x44");
 
 
 
 
 
 
 
 61	}
 62	barrier();
 63}
 64EXPORT_SYMBOL(cpu_relax_yield);
 65
 66/*
 67 * cpu_init - initializes state that is per-CPU.
 68 */
 69void cpu_init(void)
 70{
 71	struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
 72
 73	get_cpu_id(id);
 74	if (machine_has_cpu_mhz)
 75		update_cpu_mhz(NULL);
 76	atomic_inc(&init_mm.mm_count);
 77	current->active_mm = &init_mm;
 78	BUG_ON(current->mm);
 79	enter_lazy_tlb(&init_mm, current);
 80}
 81
 82/*
 83 * cpu_have_feature - Test CPU features on module initialization
 84 */
 85int cpu_have_feature(unsigned int num)
 86{
 87	return elf_hwcap & (1UL << num);
 88}
 89EXPORT_SYMBOL(cpu_have_feature);
 90
 
 
 
 
 
 
 
 
 
 
 91static void show_cpu_summary(struct seq_file *m, void *v)
 92{
 93	static const char *hwcap_str[] = {
 94		"esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
 95		"edat", "etf3eh", "highgprs", "te", "vx"
 
 96	};
 97	static const char * const int_hwcap_str[] = {
 98		"sie"
 99	};
100	int i, cpu;
101
102	seq_printf(m, "vendor_id       : IBM/S390\n"
103		   "# processors    : %i\n"
104		   "bogomips per cpu: %lu.%02lu\n",
105		   num_online_cpus(), loops_per_jiffy/(500000/HZ),
106		   (loops_per_jiffy/(5000/HZ))%100);
107	seq_printf(m, "max thread id   : %d\n", smp_cpu_mtid);
108	seq_puts(m, "features\t: ");
109	for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
110		if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
111			seq_printf(m, "%s ", hwcap_str[i]);
112	for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
113		if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
114			seq_printf(m, "%s ", int_hwcap_str[i]);
115	seq_puts(m, "\n");
 
116	show_cacheinfo(m);
117	for_each_online_cpu(cpu) {
118		struct cpuid *id = &per_cpu(cpu_info.cpu_id, cpu);
119
120		seq_printf(m, "processor %d: "
121			   "version = %02X,  "
122			   "identification = %06X,  "
123			   "machine = %04X\n",
124			   cpu, id->version, id->ident, id->machine);
125	}
126}
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128static void show_cpu_mhz(struct seq_file *m, unsigned long n)
129{
130	struct cpu_info *c = per_cpu_ptr(&cpu_info, n);
131
 
 
132	seq_printf(m, "cpu MHz dynamic : %d\n", c->cpu_mhz_dynamic);
133	seq_printf(m, "cpu MHz static  : %d\n", c->cpu_mhz_static);
134}
135
136/*
137 * show_cpuinfo - Get information on one CPU for use by procfs.
138 */
139static int show_cpuinfo(struct seq_file *m, void *v)
140{
141	unsigned long n = (unsigned long) v - 1;
 
142
143	if (!n)
144		show_cpu_summary(m, v);
145	if (!machine_has_cpu_mhz)
146		return 0;
147	seq_printf(m, "\ncpu number      : %ld\n", n);
 
 
148	show_cpu_mhz(m, n);
149	return 0;
150}
151
152static inline void *c_update(loff_t *pos)
153{
154	if (*pos)
155		*pos = cpumask_next(*pos - 1, cpu_online_mask);
 
 
156	return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
157}
158
159static void *c_start(struct seq_file *m, loff_t *pos)
160{
161	get_online_cpus();
162	return c_update(pos);
163}
164
165static void *c_next(struct seq_file *m, void *v, loff_t *pos)
166{
167	++*pos;
168	return c_update(pos);
169}
170
171static void c_stop(struct seq_file *m, void *v)
172{
173	put_online_cpus();
174}
175
176const struct seq_operations cpuinfo_op = {
177	.start	= c_start,
178	.next	= c_next,
179	.stop	= c_stop,
180	.show	= show_cpuinfo,
181};