1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/cpumask.h>
3 #include <linux/debugfs.h>
5 #include <linux/init.h>
6 #include <linux/percpu.h>
7 #include <linux/types.h>
9 #include <asm/fpu_emulator.h>
10 #include <asm/local.h>
12 DEFINE_PER_CPU(struct mips_fpu_emulator_stats
, fpuemustats
);
14 static int fpuemu_stat_get(void *data
, u64
*val
)
17 unsigned long sum
= 0;
19 for_each_online_cpu(cpu
) {
20 struct mips_fpu_emulator_stats
*ps
;
23 ps
= &per_cpu(fpuemustats
, cpu
);
24 pv
= (void *)ps
+ (unsigned long)data
;
25 sum
+= local_read(pv
);
30 DEFINE_SIMPLE_ATTRIBUTE(fops_fpuemu_stat
, fpuemu_stat_get
, NULL
, "%llu\n");
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.
40 static void adjust_instruction_counter_name(char *out_name
, char *in_name
)
44 strcpy(out_name
, in_name
);
45 while (in_name
[i
] != '\0') {
46 if (out_name
[i
] == '_')
52 static int fpuemustats_clear_show(struct seq_file
*s
, void *unused
)
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);
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);
186 DEFINE_SHOW_ATTRIBUTE(fpuemustats_clear
);
188 static int __init
debugfs_fpuemu(void)
190 struct dentry
*fpuemu_debugfs_base_dir
;
191 struct dentry
*fpuemu_debugfs_inst_dir
;
194 fpuemu_debugfs_base_dir
= debugfs_create_dir("fpuemustats",
197 debugfs_create_file("fpuemustats_clear", 0444, mips_debugfs_dir
, NULL
,
198 &fpuemustats_clear_fops
);
200 #define FPU_EMU_STAT_OFFSET(m) \
201 offsetof(struct mips_fpu_emulator_stats, m)
203 #define FPU_STAT_CREATE(m) \
205 debugfs_create_file(#m, 0444, fpuemu_debugfs_base_dir, \
206 (void *)FPU_EMU_STAT_OFFSET(m), \
207 &fops_fpuemu_stat); \
210 FPU_STAT_CREATE(emulated
);
211 FPU_STAT_CREATE(loads
);
212 FPU_STAT_CREATE(stores
);
213 FPU_STAT_CREATE(branches
);
214 FPU_STAT_CREATE(cp1ops
);
215 FPU_STAT_CREATE(cp1xops
);
216 FPU_STAT_CREATE(errors
);
217 FPU_STAT_CREATE(ieee754_inexact
);
218 FPU_STAT_CREATE(ieee754_underflow
);
219 FPU_STAT_CREATE(ieee754_overflow
);
220 FPU_STAT_CREATE(ieee754_zerodiv
);
221 FPU_STAT_CREATE(ieee754_invalidop
);
222 FPU_STAT_CREATE(ds_emul
);
224 fpuemu_debugfs_inst_dir
= debugfs_create_dir("instructions",
225 fpuemu_debugfs_base_dir
);
227 #define FPU_STAT_CREATE_EX(m) \
229 adjust_instruction_counter_name(name, #m); \
231 debugfs_create_file(name, 0444, fpuemu_debugfs_inst_dir, \
232 (void *)FPU_EMU_STAT_OFFSET(m), \
233 &fops_fpuemu_stat); \
236 FPU_STAT_CREATE_EX(abs_s
);
237 FPU_STAT_CREATE_EX(abs_d
);
238 FPU_STAT_CREATE_EX(add_s
);
239 FPU_STAT_CREATE_EX(add_d
);
240 FPU_STAT_CREATE_EX(bc1eqz
);
241 FPU_STAT_CREATE_EX(bc1nez
);
242 FPU_STAT_CREATE_EX(ceil_w_s
);
243 FPU_STAT_CREATE_EX(ceil_w_d
);
244 FPU_STAT_CREATE_EX(ceil_l_s
);
245 FPU_STAT_CREATE_EX(ceil_l_d
);
246 FPU_STAT_CREATE_EX(class_s
);
247 FPU_STAT_CREATE_EX(class_d
);
248 FPU_STAT_CREATE_EX(cmp_af_s
);
249 FPU_STAT_CREATE_EX(cmp_af_d
);
250 FPU_STAT_CREATE_EX(cmp_eq_s
);
251 FPU_STAT_CREATE_EX(cmp_eq_d
);
252 FPU_STAT_CREATE_EX(cmp_le_s
);
253 FPU_STAT_CREATE_EX(cmp_le_d
);
254 FPU_STAT_CREATE_EX(cmp_lt_s
);
255 FPU_STAT_CREATE_EX(cmp_lt_d
);
256 FPU_STAT_CREATE_EX(cmp_ne_s
);
257 FPU_STAT_CREATE_EX(cmp_ne_d
);
258 FPU_STAT_CREATE_EX(cmp_or_s
);
259 FPU_STAT_CREATE_EX(cmp_or_d
);
260 FPU_STAT_CREATE_EX(cmp_ueq_s
);
261 FPU_STAT_CREATE_EX(cmp_ueq_d
);
262 FPU_STAT_CREATE_EX(cmp_ule_s
);
263 FPU_STAT_CREATE_EX(cmp_ule_d
);
264 FPU_STAT_CREATE_EX(cmp_ult_s
);
265 FPU_STAT_CREATE_EX(cmp_ult_d
);
266 FPU_STAT_CREATE_EX(cmp_un_s
);
267 FPU_STAT_CREATE_EX(cmp_un_d
);
268 FPU_STAT_CREATE_EX(cmp_une_s
);
269 FPU_STAT_CREATE_EX(cmp_une_d
);
270 FPU_STAT_CREATE_EX(cmp_saf_s
);
271 FPU_STAT_CREATE_EX(cmp_saf_d
);
272 FPU_STAT_CREATE_EX(cmp_seq_s
);
273 FPU_STAT_CREATE_EX(cmp_seq_d
);
274 FPU_STAT_CREATE_EX(cmp_sle_s
);
275 FPU_STAT_CREATE_EX(cmp_sle_d
);
276 FPU_STAT_CREATE_EX(cmp_slt_s
);
277 FPU_STAT_CREATE_EX(cmp_slt_d
);
278 FPU_STAT_CREATE_EX(cmp_sne_s
);
279 FPU_STAT_CREATE_EX(cmp_sne_d
);
280 FPU_STAT_CREATE_EX(cmp_sor_s
);
281 FPU_STAT_CREATE_EX(cmp_sor_d
);
282 FPU_STAT_CREATE_EX(cmp_sueq_s
);
283 FPU_STAT_CREATE_EX(cmp_sueq_d
);
284 FPU_STAT_CREATE_EX(cmp_sule_s
);
285 FPU_STAT_CREATE_EX(cmp_sule_d
);
286 FPU_STAT_CREATE_EX(cmp_sult_s
);
287 FPU_STAT_CREATE_EX(cmp_sult_d
);
288 FPU_STAT_CREATE_EX(cmp_sun_s
);
289 FPU_STAT_CREATE_EX(cmp_sun_d
);
290 FPU_STAT_CREATE_EX(cmp_sune_s
);
291 FPU_STAT_CREATE_EX(cmp_sune_d
);
292 FPU_STAT_CREATE_EX(cvt_d_l
);
293 FPU_STAT_CREATE_EX(cvt_d_s
);
294 FPU_STAT_CREATE_EX(cvt_d_w
);
295 FPU_STAT_CREATE_EX(cvt_l_s
);
296 FPU_STAT_CREATE_EX(cvt_l_d
);
297 FPU_STAT_CREATE_EX(cvt_s_d
);
298 FPU_STAT_CREATE_EX(cvt_s_l
);
299 FPU_STAT_CREATE_EX(cvt_s_w
);
300 FPU_STAT_CREATE_EX(cvt_w_s
);
301 FPU_STAT_CREATE_EX(cvt_w_d
);
302 FPU_STAT_CREATE_EX(div_s
);
303 FPU_STAT_CREATE_EX(div_d
);
304 FPU_STAT_CREATE_EX(floor_w_s
);
305 FPU_STAT_CREATE_EX(floor_w_d
);
306 FPU_STAT_CREATE_EX(floor_l_s
);
307 FPU_STAT_CREATE_EX(floor_l_d
);
308 FPU_STAT_CREATE_EX(maddf_s
);
309 FPU_STAT_CREATE_EX(maddf_d
);
310 FPU_STAT_CREATE_EX(max_s
);
311 FPU_STAT_CREATE_EX(max_d
);
312 FPU_STAT_CREATE_EX(maxa_s
);
313 FPU_STAT_CREATE_EX(maxa_d
);
314 FPU_STAT_CREATE_EX(min_s
);
315 FPU_STAT_CREATE_EX(min_d
);
316 FPU_STAT_CREATE_EX(mina_s
);
317 FPU_STAT_CREATE_EX(mina_d
);
318 FPU_STAT_CREATE_EX(mov_s
);
319 FPU_STAT_CREATE_EX(mov_d
);
320 FPU_STAT_CREATE_EX(msubf_s
);
321 FPU_STAT_CREATE_EX(msubf_d
);
322 FPU_STAT_CREATE_EX(mul_s
);
323 FPU_STAT_CREATE_EX(mul_d
);
324 FPU_STAT_CREATE_EX(neg_s
);
325 FPU_STAT_CREATE_EX(neg_d
);
326 FPU_STAT_CREATE_EX(recip_s
);
327 FPU_STAT_CREATE_EX(recip_d
);
328 FPU_STAT_CREATE_EX(rint_s
);
329 FPU_STAT_CREATE_EX(rint_d
);
330 FPU_STAT_CREATE_EX(round_w_s
);
331 FPU_STAT_CREATE_EX(round_w_d
);
332 FPU_STAT_CREATE_EX(round_l_s
);
333 FPU_STAT_CREATE_EX(round_l_d
);
334 FPU_STAT_CREATE_EX(rsqrt_s
);
335 FPU_STAT_CREATE_EX(rsqrt_d
);
336 FPU_STAT_CREATE_EX(sel_s
);
337 FPU_STAT_CREATE_EX(sel_d
);
338 FPU_STAT_CREATE_EX(seleqz_s
);
339 FPU_STAT_CREATE_EX(seleqz_d
);
340 FPU_STAT_CREATE_EX(selnez_s
);
341 FPU_STAT_CREATE_EX(selnez_d
);
342 FPU_STAT_CREATE_EX(sqrt_s
);
343 FPU_STAT_CREATE_EX(sqrt_d
);
344 FPU_STAT_CREATE_EX(sub_s
);
345 FPU_STAT_CREATE_EX(sub_d
);
346 FPU_STAT_CREATE_EX(trunc_w_s
);
347 FPU_STAT_CREATE_EX(trunc_w_d
);
348 FPU_STAT_CREATE_EX(trunc_l_s
);
349 FPU_STAT_CREATE_EX(trunc_l_d
);
353 arch_initcall(debugfs_fpuemu
);