]> git.ipfire.org Git - thirdparty/linux.git/blob - arch/mips/math-emu/me-debugfs.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/linux.git] / arch / mips / math-emu / me-debugfs.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/cpumask.h>
3 #include <linux/debugfs.h>
4 #include <linux/fs.h>
5 #include <linux/init.h>
6 #include <linux/percpu.h>
7 #include <linux/types.h>
8 #include <asm/debug.h>
9 #include <asm/fpu_emulator.h>
10 #include <asm/local.h>
11
12 DEFINE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats);
13
14 static int fpuemu_stat_get(void *data, u64 *val)
15 {
16 int cpu;
17 unsigned long sum = 0;
18
19 for_each_online_cpu(cpu) {
20 struct mips_fpu_emulator_stats *ps;
21 local_t *pv;
22
23 ps = &per_cpu(fpuemustats, cpu);
24 pv = (void *)ps + (unsigned long)data;
25 sum += local_read(pv);
26 }
27 *val = sum;
28 return 0;
29 }
30 DEFINE_SIMPLE_ATTRIBUTE(fops_fpuemu_stat, fpuemu_stat_get, NULL, "%llu\n");
31
32 /*
33 * Used to obtain names for a debugfs instruction counter, given field name
34 * in fpuemustats structure. For example, for input "cmp_sueq_d", the output
35 * would be "cmp.sueq.d". This is needed since dots are not allowed to be
36 * used in structure field names, and are, on the other hand, desired to be
37 * used in debugfs item names to be clearly associated to corresponding
38 * MIPS FPU instructions.
39 */
40 static void adjust_instruction_counter_name(char *out_name, char *in_name)
41 {
42 int i = 0;
43
44 strcpy(out_name, in_name);
45 while (in_name[i] != '\0') {
46 if (out_name[i] == '_')
47 out_name[i] = '.';
48 i++;
49 }
50 }
51
52 static int fpuemustats_clear_show(struct seq_file *s, void *unused)
53 {
54 __this_cpu_write((fpuemustats).emulated, 0);
55 __this_cpu_write((fpuemustats).loads, 0);
56 __this_cpu_write((fpuemustats).stores, 0);
57 __this_cpu_write((fpuemustats).branches, 0);
58 __this_cpu_write((fpuemustats).cp1ops, 0);
59 __this_cpu_write((fpuemustats).cp1xops, 0);
60 __this_cpu_write((fpuemustats).errors, 0);
61 __this_cpu_write((fpuemustats).ieee754_inexact, 0);
62 __this_cpu_write((fpuemustats).ieee754_underflow, 0);
63 __this_cpu_write((fpuemustats).ieee754_overflow, 0);
64 __this_cpu_write((fpuemustats).ieee754_zerodiv, 0);
65 __this_cpu_write((fpuemustats).ieee754_invalidop, 0);
66 __this_cpu_write((fpuemustats).ds_emul, 0);
67
68 __this_cpu_write((fpuemustats).abs_s, 0);
69 __this_cpu_write((fpuemustats).abs_d, 0);
70 __this_cpu_write((fpuemustats).add_s, 0);
71 __this_cpu_write((fpuemustats).add_d, 0);
72 __this_cpu_write((fpuemustats).bc1eqz, 0);
73 __this_cpu_write((fpuemustats).bc1nez, 0);
74 __this_cpu_write((fpuemustats).ceil_w_s, 0);
75 __this_cpu_write((fpuemustats).ceil_w_d, 0);
76 __this_cpu_write((fpuemustats).ceil_l_s, 0);
77 __this_cpu_write((fpuemustats).ceil_l_d, 0);
78 __this_cpu_write((fpuemustats).class_s, 0);
79 __this_cpu_write((fpuemustats).class_d, 0);
80 __this_cpu_write((fpuemustats).cmp_af_s, 0);
81 __this_cpu_write((fpuemustats).cmp_af_d, 0);
82 __this_cpu_write((fpuemustats).cmp_eq_s, 0);
83 __this_cpu_write((fpuemustats).cmp_eq_d, 0);
84 __this_cpu_write((fpuemustats).cmp_le_s, 0);
85 __this_cpu_write((fpuemustats).cmp_le_d, 0);
86 __this_cpu_write((fpuemustats).cmp_lt_s, 0);
87 __this_cpu_write((fpuemustats).cmp_lt_d, 0);
88 __this_cpu_write((fpuemustats).cmp_ne_s, 0);
89 __this_cpu_write((fpuemustats).cmp_ne_d, 0);
90 __this_cpu_write((fpuemustats).cmp_or_s, 0);
91 __this_cpu_write((fpuemustats).cmp_or_d, 0);
92 __this_cpu_write((fpuemustats).cmp_ueq_s, 0);
93 __this_cpu_write((fpuemustats).cmp_ueq_d, 0);
94 __this_cpu_write((fpuemustats).cmp_ule_s, 0);
95 __this_cpu_write((fpuemustats).cmp_ule_d, 0);
96 __this_cpu_write((fpuemustats).cmp_ult_s, 0);
97 __this_cpu_write((fpuemustats).cmp_ult_d, 0);
98 __this_cpu_write((fpuemustats).cmp_un_s, 0);
99 __this_cpu_write((fpuemustats).cmp_un_d, 0);
100 __this_cpu_write((fpuemustats).cmp_une_s, 0);
101 __this_cpu_write((fpuemustats).cmp_une_d, 0);
102 __this_cpu_write((fpuemustats).cmp_saf_s, 0);
103 __this_cpu_write((fpuemustats).cmp_saf_d, 0);
104 __this_cpu_write((fpuemustats).cmp_seq_s, 0);
105 __this_cpu_write((fpuemustats).cmp_seq_d, 0);
106 __this_cpu_write((fpuemustats).cmp_sle_s, 0);
107 __this_cpu_write((fpuemustats).cmp_sle_d, 0);
108 __this_cpu_write((fpuemustats).cmp_slt_s, 0);
109 __this_cpu_write((fpuemustats).cmp_slt_d, 0);
110 __this_cpu_write((fpuemustats).cmp_sne_s, 0);
111 __this_cpu_write((fpuemustats).cmp_sne_d, 0);
112 __this_cpu_write((fpuemustats).cmp_sor_s, 0);
113 __this_cpu_write((fpuemustats).cmp_sor_d, 0);
114 __this_cpu_write((fpuemustats).cmp_sueq_s, 0);
115 __this_cpu_write((fpuemustats).cmp_sueq_d, 0);
116 __this_cpu_write((fpuemustats).cmp_sule_s, 0);
117 __this_cpu_write((fpuemustats).cmp_sule_d, 0);
118 __this_cpu_write((fpuemustats).cmp_sult_s, 0);
119 __this_cpu_write((fpuemustats).cmp_sult_d, 0);
120 __this_cpu_write((fpuemustats).cmp_sun_s, 0);
121 __this_cpu_write((fpuemustats).cmp_sun_d, 0);
122 __this_cpu_write((fpuemustats).cmp_sune_s, 0);
123 __this_cpu_write((fpuemustats).cmp_sune_d, 0);
124 __this_cpu_write((fpuemustats).cvt_d_l, 0);
125 __this_cpu_write((fpuemustats).cvt_d_s, 0);
126 __this_cpu_write((fpuemustats).cvt_d_w, 0);
127 __this_cpu_write((fpuemustats).cvt_l_s, 0);
128 __this_cpu_write((fpuemustats).cvt_l_d, 0);
129 __this_cpu_write((fpuemustats).cvt_s_d, 0);
130 __this_cpu_write((fpuemustats).cvt_s_l, 0);
131 __this_cpu_write((fpuemustats).cvt_s_w, 0);
132 __this_cpu_write((fpuemustats).cvt_w_s, 0);
133 __this_cpu_write((fpuemustats).cvt_w_d, 0);
134 __this_cpu_write((fpuemustats).div_s, 0);
135 __this_cpu_write((fpuemustats).div_d, 0);
136 __this_cpu_write((fpuemustats).floor_w_s, 0);
137 __this_cpu_write((fpuemustats).floor_w_d, 0);
138 __this_cpu_write((fpuemustats).floor_l_s, 0);
139 __this_cpu_write((fpuemustats).floor_l_d, 0);
140 __this_cpu_write((fpuemustats).maddf_s, 0);
141 __this_cpu_write((fpuemustats).maddf_d, 0);
142 __this_cpu_write((fpuemustats).max_s, 0);
143 __this_cpu_write((fpuemustats).max_d, 0);
144 __this_cpu_write((fpuemustats).maxa_s, 0);
145 __this_cpu_write((fpuemustats).maxa_d, 0);
146 __this_cpu_write((fpuemustats).min_s, 0);
147 __this_cpu_write((fpuemustats).min_d, 0);
148 __this_cpu_write((fpuemustats).mina_s, 0);
149 __this_cpu_write((fpuemustats).mina_d, 0);
150 __this_cpu_write((fpuemustats).mov_s, 0);
151 __this_cpu_write((fpuemustats).mov_d, 0);
152 __this_cpu_write((fpuemustats).msubf_s, 0);
153 __this_cpu_write((fpuemustats).msubf_d, 0);
154 __this_cpu_write((fpuemustats).mul_s, 0);
155 __this_cpu_write((fpuemustats).mul_d, 0);
156 __this_cpu_write((fpuemustats).neg_s, 0);
157 __this_cpu_write((fpuemustats).neg_d, 0);
158 __this_cpu_write((fpuemustats).recip_s, 0);
159 __this_cpu_write((fpuemustats).recip_d, 0);
160 __this_cpu_write((fpuemustats).rint_s, 0);
161 __this_cpu_write((fpuemustats).rint_d, 0);
162 __this_cpu_write((fpuemustats).round_w_s, 0);
163 __this_cpu_write((fpuemustats).round_w_d, 0);
164 __this_cpu_write((fpuemustats).round_l_s, 0);
165 __this_cpu_write((fpuemustats).round_l_d, 0);
166 __this_cpu_write((fpuemustats).rsqrt_s, 0);
167 __this_cpu_write((fpuemustats).rsqrt_d, 0);
168 __this_cpu_write((fpuemustats).sel_s, 0);
169 __this_cpu_write((fpuemustats).sel_d, 0);
170 __this_cpu_write((fpuemustats).seleqz_s, 0);
171 __this_cpu_write((fpuemustats).seleqz_d, 0);
172 __this_cpu_write((fpuemustats).selnez_s, 0);
173 __this_cpu_write((fpuemustats).selnez_d, 0);
174 __this_cpu_write((fpuemustats).sqrt_s, 0);
175 __this_cpu_write((fpuemustats).sqrt_d, 0);
176 __this_cpu_write((fpuemustats).sub_s, 0);
177 __this_cpu_write((fpuemustats).sub_d, 0);
178 __this_cpu_write((fpuemustats).trunc_w_s, 0);
179 __this_cpu_write((fpuemustats).trunc_w_d, 0);
180 __this_cpu_write((fpuemustats).trunc_l_s, 0);
181 __this_cpu_write((fpuemustats).trunc_l_d, 0);
182
183 return 0;
184 }
185
186 static int fpuemustats_clear_open(struct inode *inode, struct file *file)
187 {
188 return single_open(file, fpuemustats_clear_show, inode->i_private);
189 }
190
191 static const struct file_operations fpuemustats_clear_fops = {
192 .open = fpuemustats_clear_open,
193 .read = seq_read,
194 .llseek = seq_lseek,
195 .release = single_release,
196 };
197
198 static int __init debugfs_fpuemu(void)
199 {
200 struct dentry *fpuemu_debugfs_base_dir;
201 struct dentry *fpuemu_debugfs_inst_dir;
202 struct dentry *d, *reset_file;
203
204 if (!mips_debugfs_dir)
205 return -ENODEV;
206
207 fpuemu_debugfs_base_dir = debugfs_create_dir("fpuemustats",
208 mips_debugfs_dir);
209 if (!fpuemu_debugfs_base_dir)
210 return -ENOMEM;
211
212 reset_file = debugfs_create_file("fpuemustats_clear", 0444,
213 mips_debugfs_dir, NULL,
214 &fpuemustats_clear_fops);
215 if (!reset_file)
216 return -ENOMEM;
217
218 #define FPU_EMU_STAT_OFFSET(m) \
219 offsetof(struct mips_fpu_emulator_stats, m)
220
221 #define FPU_STAT_CREATE(m) \
222 do { \
223 d = debugfs_create_file(#m, 0444, fpuemu_debugfs_base_dir, \
224 (void *)FPU_EMU_STAT_OFFSET(m), \
225 &fops_fpuemu_stat); \
226 if (!d) \
227 return -ENOMEM; \
228 } while (0)
229
230 FPU_STAT_CREATE(emulated);
231 FPU_STAT_CREATE(loads);
232 FPU_STAT_CREATE(stores);
233 FPU_STAT_CREATE(branches);
234 FPU_STAT_CREATE(cp1ops);
235 FPU_STAT_CREATE(cp1xops);
236 FPU_STAT_CREATE(errors);
237 FPU_STAT_CREATE(ieee754_inexact);
238 FPU_STAT_CREATE(ieee754_underflow);
239 FPU_STAT_CREATE(ieee754_overflow);
240 FPU_STAT_CREATE(ieee754_zerodiv);
241 FPU_STAT_CREATE(ieee754_invalidop);
242 FPU_STAT_CREATE(ds_emul);
243
244 fpuemu_debugfs_inst_dir = debugfs_create_dir("instructions",
245 fpuemu_debugfs_base_dir);
246 if (!fpuemu_debugfs_inst_dir)
247 return -ENOMEM;
248
249 #define FPU_STAT_CREATE_EX(m) \
250 do { \
251 char name[32]; \
252 \
253 adjust_instruction_counter_name(name, #m); \
254 \
255 d = debugfs_create_file(name, 0444, fpuemu_debugfs_inst_dir, \
256 (void *)FPU_EMU_STAT_OFFSET(m), \
257 &fops_fpuemu_stat); \
258 if (!d) \
259 return -ENOMEM; \
260 } while (0)
261
262 FPU_STAT_CREATE_EX(abs_s);
263 FPU_STAT_CREATE_EX(abs_d);
264 FPU_STAT_CREATE_EX(add_s);
265 FPU_STAT_CREATE_EX(add_d);
266 FPU_STAT_CREATE_EX(bc1eqz);
267 FPU_STAT_CREATE_EX(bc1nez);
268 FPU_STAT_CREATE_EX(ceil_w_s);
269 FPU_STAT_CREATE_EX(ceil_w_d);
270 FPU_STAT_CREATE_EX(ceil_l_s);
271 FPU_STAT_CREATE_EX(ceil_l_d);
272 FPU_STAT_CREATE_EX(class_s);
273 FPU_STAT_CREATE_EX(class_d);
274 FPU_STAT_CREATE_EX(cmp_af_s);
275 FPU_STAT_CREATE_EX(cmp_af_d);
276 FPU_STAT_CREATE_EX(cmp_eq_s);
277 FPU_STAT_CREATE_EX(cmp_eq_d);
278 FPU_STAT_CREATE_EX(cmp_le_s);
279 FPU_STAT_CREATE_EX(cmp_le_d);
280 FPU_STAT_CREATE_EX(cmp_lt_s);
281 FPU_STAT_CREATE_EX(cmp_lt_d);
282 FPU_STAT_CREATE_EX(cmp_ne_s);
283 FPU_STAT_CREATE_EX(cmp_ne_d);
284 FPU_STAT_CREATE_EX(cmp_or_s);
285 FPU_STAT_CREATE_EX(cmp_or_d);
286 FPU_STAT_CREATE_EX(cmp_ueq_s);
287 FPU_STAT_CREATE_EX(cmp_ueq_d);
288 FPU_STAT_CREATE_EX(cmp_ule_s);
289 FPU_STAT_CREATE_EX(cmp_ule_d);
290 FPU_STAT_CREATE_EX(cmp_ult_s);
291 FPU_STAT_CREATE_EX(cmp_ult_d);
292 FPU_STAT_CREATE_EX(cmp_un_s);
293 FPU_STAT_CREATE_EX(cmp_un_d);
294 FPU_STAT_CREATE_EX(cmp_une_s);
295 FPU_STAT_CREATE_EX(cmp_une_d);
296 FPU_STAT_CREATE_EX(cmp_saf_s);
297 FPU_STAT_CREATE_EX(cmp_saf_d);
298 FPU_STAT_CREATE_EX(cmp_seq_s);
299 FPU_STAT_CREATE_EX(cmp_seq_d);
300 FPU_STAT_CREATE_EX(cmp_sle_s);
301 FPU_STAT_CREATE_EX(cmp_sle_d);
302 FPU_STAT_CREATE_EX(cmp_slt_s);
303 FPU_STAT_CREATE_EX(cmp_slt_d);
304 FPU_STAT_CREATE_EX(cmp_sne_s);
305 FPU_STAT_CREATE_EX(cmp_sne_d);
306 FPU_STAT_CREATE_EX(cmp_sor_s);
307 FPU_STAT_CREATE_EX(cmp_sor_d);
308 FPU_STAT_CREATE_EX(cmp_sueq_s);
309 FPU_STAT_CREATE_EX(cmp_sueq_d);
310 FPU_STAT_CREATE_EX(cmp_sule_s);
311 FPU_STAT_CREATE_EX(cmp_sule_d);
312 FPU_STAT_CREATE_EX(cmp_sult_s);
313 FPU_STAT_CREATE_EX(cmp_sult_d);
314 FPU_STAT_CREATE_EX(cmp_sun_s);
315 FPU_STAT_CREATE_EX(cmp_sun_d);
316 FPU_STAT_CREATE_EX(cmp_sune_s);
317 FPU_STAT_CREATE_EX(cmp_sune_d);
318 FPU_STAT_CREATE_EX(cvt_d_l);
319 FPU_STAT_CREATE_EX(cvt_d_s);
320 FPU_STAT_CREATE_EX(cvt_d_w);
321 FPU_STAT_CREATE_EX(cvt_l_s);
322 FPU_STAT_CREATE_EX(cvt_l_d);
323 FPU_STAT_CREATE_EX(cvt_s_d);
324 FPU_STAT_CREATE_EX(cvt_s_l);
325 FPU_STAT_CREATE_EX(cvt_s_w);
326 FPU_STAT_CREATE_EX(cvt_w_s);
327 FPU_STAT_CREATE_EX(cvt_w_d);
328 FPU_STAT_CREATE_EX(div_s);
329 FPU_STAT_CREATE_EX(div_d);
330 FPU_STAT_CREATE_EX(floor_w_s);
331 FPU_STAT_CREATE_EX(floor_w_d);
332 FPU_STAT_CREATE_EX(floor_l_s);
333 FPU_STAT_CREATE_EX(floor_l_d);
334 FPU_STAT_CREATE_EX(maddf_s);
335 FPU_STAT_CREATE_EX(maddf_d);
336 FPU_STAT_CREATE_EX(max_s);
337 FPU_STAT_CREATE_EX(max_d);
338 FPU_STAT_CREATE_EX(maxa_s);
339 FPU_STAT_CREATE_EX(maxa_d);
340 FPU_STAT_CREATE_EX(min_s);
341 FPU_STAT_CREATE_EX(min_d);
342 FPU_STAT_CREATE_EX(mina_s);
343 FPU_STAT_CREATE_EX(mina_d);
344 FPU_STAT_CREATE_EX(mov_s);
345 FPU_STAT_CREATE_EX(mov_d);
346 FPU_STAT_CREATE_EX(msubf_s);
347 FPU_STAT_CREATE_EX(msubf_d);
348 FPU_STAT_CREATE_EX(mul_s);
349 FPU_STAT_CREATE_EX(mul_d);
350 FPU_STAT_CREATE_EX(neg_s);
351 FPU_STAT_CREATE_EX(neg_d);
352 FPU_STAT_CREATE_EX(recip_s);
353 FPU_STAT_CREATE_EX(recip_d);
354 FPU_STAT_CREATE_EX(rint_s);
355 FPU_STAT_CREATE_EX(rint_d);
356 FPU_STAT_CREATE_EX(round_w_s);
357 FPU_STAT_CREATE_EX(round_w_d);
358 FPU_STAT_CREATE_EX(round_l_s);
359 FPU_STAT_CREATE_EX(round_l_d);
360 FPU_STAT_CREATE_EX(rsqrt_s);
361 FPU_STAT_CREATE_EX(rsqrt_d);
362 FPU_STAT_CREATE_EX(sel_s);
363 FPU_STAT_CREATE_EX(sel_d);
364 FPU_STAT_CREATE_EX(seleqz_s);
365 FPU_STAT_CREATE_EX(seleqz_d);
366 FPU_STAT_CREATE_EX(selnez_s);
367 FPU_STAT_CREATE_EX(selnez_d);
368 FPU_STAT_CREATE_EX(sqrt_s);
369 FPU_STAT_CREATE_EX(sqrt_d);
370 FPU_STAT_CREATE_EX(sub_s);
371 FPU_STAT_CREATE_EX(sub_d);
372 FPU_STAT_CREATE_EX(trunc_w_s);
373 FPU_STAT_CREATE_EX(trunc_w_d);
374 FPU_STAT_CREATE_EX(trunc_l_s);
375 FPU_STAT_CREATE_EX(trunc_l_d);
376
377 return 0;
378 }
379 arch_initcall(debugfs_fpuemu);