Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/cpumask.h>
0003 #include <linux/debugfs.h>
0004 #include <linux/fs.h>
0005 #include <linux/init.h>
0006 #include <linux/percpu.h>
0007 #include <linux/types.h>
0008 #include <asm/debug.h>
0009 #include <asm/fpu_emulator.h>
0010 #include <asm/local.h>
0011 
0012 DEFINE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats);
0013 
0014 static int fpuemu_stat_get(void *data, u64 *val)
0015 {
0016     int cpu;
0017     unsigned long sum = 0;
0018 
0019     for_each_online_cpu(cpu) {
0020         struct mips_fpu_emulator_stats *ps;
0021         local_t *pv;
0022 
0023         ps = &per_cpu(fpuemustats, cpu);
0024         pv = (void *)ps + (unsigned long)data;
0025         sum += local_read(pv);
0026     }
0027     *val = sum;
0028     return 0;
0029 }
0030 DEFINE_SIMPLE_ATTRIBUTE(fops_fpuemu_stat, fpuemu_stat_get, NULL, "%llu\n");
0031 
0032 /*
0033  * Used to obtain names for a debugfs instruction counter, given field name
0034  * in fpuemustats structure. For example, for input "cmp_sueq_d", the output
0035  * would be "cmp.sueq.d". This is needed since dots are not allowed to be
0036  * used in structure field names, and are, on the other hand, desired to be
0037  * used in debugfs item names to be clearly associated to corresponding
0038  * MIPS FPU instructions.
0039  */
0040 static void adjust_instruction_counter_name(char *out_name, char *in_name)
0041 {
0042     int i = 0;
0043 
0044     strcpy(out_name, in_name);
0045     while (in_name[i] != '\0') {
0046         if (out_name[i] == '_')
0047             out_name[i] = '.';
0048         i++;
0049     }
0050 }
0051 
0052 static int fpuemustats_clear_show(struct seq_file *s, void *unused)
0053 {
0054     __this_cpu_write((fpuemustats).emulated, 0);
0055     __this_cpu_write((fpuemustats).loads, 0);
0056     __this_cpu_write((fpuemustats).stores, 0);
0057     __this_cpu_write((fpuemustats).branches, 0);
0058     __this_cpu_write((fpuemustats).cp1ops, 0);
0059     __this_cpu_write((fpuemustats).cp1xops, 0);
0060     __this_cpu_write((fpuemustats).errors, 0);
0061     __this_cpu_write((fpuemustats).ieee754_inexact, 0);
0062     __this_cpu_write((fpuemustats).ieee754_underflow, 0);
0063     __this_cpu_write((fpuemustats).ieee754_overflow, 0);
0064     __this_cpu_write((fpuemustats).ieee754_zerodiv, 0);
0065     __this_cpu_write((fpuemustats).ieee754_invalidop, 0);
0066     __this_cpu_write((fpuemustats).ds_emul, 0);
0067 
0068     __this_cpu_write((fpuemustats).abs_s, 0);
0069     __this_cpu_write((fpuemustats).abs_d, 0);
0070     __this_cpu_write((fpuemustats).add_s, 0);
0071     __this_cpu_write((fpuemustats).add_d, 0);
0072     __this_cpu_write((fpuemustats).bc1eqz, 0);
0073     __this_cpu_write((fpuemustats).bc1nez, 0);
0074     __this_cpu_write((fpuemustats).ceil_w_s, 0);
0075     __this_cpu_write((fpuemustats).ceil_w_d, 0);
0076     __this_cpu_write((fpuemustats).ceil_l_s, 0);
0077     __this_cpu_write((fpuemustats).ceil_l_d, 0);
0078     __this_cpu_write((fpuemustats).class_s, 0);
0079     __this_cpu_write((fpuemustats).class_d, 0);
0080     __this_cpu_write((fpuemustats).cmp_af_s, 0);
0081     __this_cpu_write((fpuemustats).cmp_af_d, 0);
0082     __this_cpu_write((fpuemustats).cmp_eq_s, 0);
0083     __this_cpu_write((fpuemustats).cmp_eq_d, 0);
0084     __this_cpu_write((fpuemustats).cmp_le_s, 0);
0085     __this_cpu_write((fpuemustats).cmp_le_d, 0);
0086     __this_cpu_write((fpuemustats).cmp_lt_s, 0);
0087     __this_cpu_write((fpuemustats).cmp_lt_d, 0);
0088     __this_cpu_write((fpuemustats).cmp_ne_s, 0);
0089     __this_cpu_write((fpuemustats).cmp_ne_d, 0);
0090     __this_cpu_write((fpuemustats).cmp_or_s, 0);
0091     __this_cpu_write((fpuemustats).cmp_or_d, 0);
0092     __this_cpu_write((fpuemustats).cmp_ueq_s, 0);
0093     __this_cpu_write((fpuemustats).cmp_ueq_d, 0);
0094     __this_cpu_write((fpuemustats).cmp_ule_s, 0);
0095     __this_cpu_write((fpuemustats).cmp_ule_d, 0);
0096     __this_cpu_write((fpuemustats).cmp_ult_s, 0);
0097     __this_cpu_write((fpuemustats).cmp_ult_d, 0);
0098     __this_cpu_write((fpuemustats).cmp_un_s, 0);
0099     __this_cpu_write((fpuemustats).cmp_un_d, 0);
0100     __this_cpu_write((fpuemustats).cmp_une_s, 0);
0101     __this_cpu_write((fpuemustats).cmp_une_d, 0);
0102     __this_cpu_write((fpuemustats).cmp_saf_s, 0);
0103     __this_cpu_write((fpuemustats).cmp_saf_d, 0);
0104     __this_cpu_write((fpuemustats).cmp_seq_s, 0);
0105     __this_cpu_write((fpuemustats).cmp_seq_d, 0);
0106     __this_cpu_write((fpuemustats).cmp_sle_s, 0);
0107     __this_cpu_write((fpuemustats).cmp_sle_d, 0);
0108     __this_cpu_write((fpuemustats).cmp_slt_s, 0);
0109     __this_cpu_write((fpuemustats).cmp_slt_d, 0);
0110     __this_cpu_write((fpuemustats).cmp_sne_s, 0);
0111     __this_cpu_write((fpuemustats).cmp_sne_d, 0);
0112     __this_cpu_write((fpuemustats).cmp_sor_s, 0);
0113     __this_cpu_write((fpuemustats).cmp_sor_d, 0);
0114     __this_cpu_write((fpuemustats).cmp_sueq_s, 0);
0115     __this_cpu_write((fpuemustats).cmp_sueq_d, 0);
0116     __this_cpu_write((fpuemustats).cmp_sule_s, 0);
0117     __this_cpu_write((fpuemustats).cmp_sule_d, 0);
0118     __this_cpu_write((fpuemustats).cmp_sult_s, 0);
0119     __this_cpu_write((fpuemustats).cmp_sult_d, 0);
0120     __this_cpu_write((fpuemustats).cmp_sun_s, 0);
0121     __this_cpu_write((fpuemustats).cmp_sun_d, 0);
0122     __this_cpu_write((fpuemustats).cmp_sune_s, 0);
0123     __this_cpu_write((fpuemustats).cmp_sune_d, 0);
0124     __this_cpu_write((fpuemustats).cvt_d_l, 0);
0125     __this_cpu_write((fpuemustats).cvt_d_s, 0);
0126     __this_cpu_write((fpuemustats).cvt_d_w, 0);
0127     __this_cpu_write((fpuemustats).cvt_l_s, 0);
0128     __this_cpu_write((fpuemustats).cvt_l_d, 0);
0129     __this_cpu_write((fpuemustats).cvt_s_d, 0);
0130     __this_cpu_write((fpuemustats).cvt_s_l, 0);
0131     __this_cpu_write((fpuemustats).cvt_s_w, 0);
0132     __this_cpu_write((fpuemustats).cvt_w_s, 0);
0133     __this_cpu_write((fpuemustats).cvt_w_d, 0);
0134     __this_cpu_write((fpuemustats).div_s, 0);
0135     __this_cpu_write((fpuemustats).div_d, 0);
0136     __this_cpu_write((fpuemustats).floor_w_s, 0);
0137     __this_cpu_write((fpuemustats).floor_w_d, 0);
0138     __this_cpu_write((fpuemustats).floor_l_s, 0);
0139     __this_cpu_write((fpuemustats).floor_l_d, 0);
0140     __this_cpu_write((fpuemustats).maddf_s, 0);
0141     __this_cpu_write((fpuemustats).maddf_d, 0);
0142     __this_cpu_write((fpuemustats).max_s, 0);
0143     __this_cpu_write((fpuemustats).max_d, 0);
0144     __this_cpu_write((fpuemustats).maxa_s, 0);
0145     __this_cpu_write((fpuemustats).maxa_d, 0);
0146     __this_cpu_write((fpuemustats).min_s, 0);
0147     __this_cpu_write((fpuemustats).min_d, 0);
0148     __this_cpu_write((fpuemustats).mina_s, 0);
0149     __this_cpu_write((fpuemustats).mina_d, 0);
0150     __this_cpu_write((fpuemustats).mov_s, 0);
0151     __this_cpu_write((fpuemustats).mov_d, 0);
0152     __this_cpu_write((fpuemustats).msubf_s, 0);
0153     __this_cpu_write((fpuemustats).msubf_d, 0);
0154     __this_cpu_write((fpuemustats).mul_s, 0);
0155     __this_cpu_write((fpuemustats).mul_d, 0);
0156     __this_cpu_write((fpuemustats).neg_s, 0);
0157     __this_cpu_write((fpuemustats).neg_d, 0);
0158     __this_cpu_write((fpuemustats).recip_s, 0);
0159     __this_cpu_write((fpuemustats).recip_d, 0);
0160     __this_cpu_write((fpuemustats).rint_s, 0);
0161     __this_cpu_write((fpuemustats).rint_d, 0);
0162     __this_cpu_write((fpuemustats).round_w_s, 0);
0163     __this_cpu_write((fpuemustats).round_w_d, 0);
0164     __this_cpu_write((fpuemustats).round_l_s, 0);
0165     __this_cpu_write((fpuemustats).round_l_d, 0);
0166     __this_cpu_write((fpuemustats).rsqrt_s, 0);
0167     __this_cpu_write((fpuemustats).rsqrt_d, 0);
0168     __this_cpu_write((fpuemustats).sel_s, 0);
0169     __this_cpu_write((fpuemustats).sel_d, 0);
0170     __this_cpu_write((fpuemustats).seleqz_s, 0);
0171     __this_cpu_write((fpuemustats).seleqz_d, 0);
0172     __this_cpu_write((fpuemustats).selnez_s, 0);
0173     __this_cpu_write((fpuemustats).selnez_d, 0);
0174     __this_cpu_write((fpuemustats).sqrt_s, 0);
0175     __this_cpu_write((fpuemustats).sqrt_d, 0);
0176     __this_cpu_write((fpuemustats).sub_s, 0);
0177     __this_cpu_write((fpuemustats).sub_d, 0);
0178     __this_cpu_write((fpuemustats).trunc_w_s, 0);
0179     __this_cpu_write((fpuemustats).trunc_w_d, 0);
0180     __this_cpu_write((fpuemustats).trunc_l_s, 0);
0181     __this_cpu_write((fpuemustats).trunc_l_d, 0);
0182 
0183     return 0;
0184 }
0185 
0186 DEFINE_SHOW_ATTRIBUTE(fpuemustats_clear);
0187 
0188 static int __init debugfs_fpuemu(void)
0189 {
0190     struct dentry *fpuemu_debugfs_base_dir;
0191     struct dentry *fpuemu_debugfs_inst_dir;
0192     char name[32];
0193 
0194     fpuemu_debugfs_base_dir = debugfs_create_dir("fpuemustats",
0195                              mips_debugfs_dir);
0196 
0197     debugfs_create_file("fpuemustats_clear", 0444, mips_debugfs_dir, NULL,
0198                 &fpuemustats_clear_fops);
0199 
0200 #define FPU_EMU_STAT_OFFSET(m)                      \
0201     offsetof(struct mips_fpu_emulator_stats, m)
0202 
0203 #define FPU_STAT_CREATE(m)                      \
0204 do {                                    \
0205     debugfs_create_file(#m, 0444, fpuemu_debugfs_base_dir,      \
0206                 (void *)FPU_EMU_STAT_OFFSET(m),     \
0207                 &fops_fpuemu_stat);         \
0208 } while (0)
0209 
0210     FPU_STAT_CREATE(emulated);
0211     FPU_STAT_CREATE(loads);
0212     FPU_STAT_CREATE(stores);
0213     FPU_STAT_CREATE(branches);
0214     FPU_STAT_CREATE(cp1ops);
0215     FPU_STAT_CREATE(cp1xops);
0216     FPU_STAT_CREATE(errors);
0217     FPU_STAT_CREATE(ieee754_inexact);
0218     FPU_STAT_CREATE(ieee754_underflow);
0219     FPU_STAT_CREATE(ieee754_overflow);
0220     FPU_STAT_CREATE(ieee754_zerodiv);
0221     FPU_STAT_CREATE(ieee754_invalidop);
0222     FPU_STAT_CREATE(ds_emul);
0223 
0224     fpuemu_debugfs_inst_dir = debugfs_create_dir("instructions",
0225                              fpuemu_debugfs_base_dir);
0226 
0227 #define FPU_STAT_CREATE_EX(m)                       \
0228 do {                                    \
0229     adjust_instruction_counter_name(name, #m);          \
0230                                     \
0231     debugfs_create_file(name, 0444, fpuemu_debugfs_inst_dir,    \
0232                 (void *)FPU_EMU_STAT_OFFSET(m),     \
0233                 &fops_fpuemu_stat);         \
0234 } while (0)
0235 
0236     FPU_STAT_CREATE_EX(abs_s);
0237     FPU_STAT_CREATE_EX(abs_d);
0238     FPU_STAT_CREATE_EX(add_s);
0239     FPU_STAT_CREATE_EX(add_d);
0240     FPU_STAT_CREATE_EX(bc1eqz);
0241     FPU_STAT_CREATE_EX(bc1nez);
0242     FPU_STAT_CREATE_EX(ceil_w_s);
0243     FPU_STAT_CREATE_EX(ceil_w_d);
0244     FPU_STAT_CREATE_EX(ceil_l_s);
0245     FPU_STAT_CREATE_EX(ceil_l_d);
0246     FPU_STAT_CREATE_EX(class_s);
0247     FPU_STAT_CREATE_EX(class_d);
0248     FPU_STAT_CREATE_EX(cmp_af_s);
0249     FPU_STAT_CREATE_EX(cmp_af_d);
0250     FPU_STAT_CREATE_EX(cmp_eq_s);
0251     FPU_STAT_CREATE_EX(cmp_eq_d);
0252     FPU_STAT_CREATE_EX(cmp_le_s);
0253     FPU_STAT_CREATE_EX(cmp_le_d);
0254     FPU_STAT_CREATE_EX(cmp_lt_s);
0255     FPU_STAT_CREATE_EX(cmp_lt_d);
0256     FPU_STAT_CREATE_EX(cmp_ne_s);
0257     FPU_STAT_CREATE_EX(cmp_ne_d);
0258     FPU_STAT_CREATE_EX(cmp_or_s);
0259     FPU_STAT_CREATE_EX(cmp_or_d);
0260     FPU_STAT_CREATE_EX(cmp_ueq_s);
0261     FPU_STAT_CREATE_EX(cmp_ueq_d);
0262     FPU_STAT_CREATE_EX(cmp_ule_s);
0263     FPU_STAT_CREATE_EX(cmp_ule_d);
0264     FPU_STAT_CREATE_EX(cmp_ult_s);
0265     FPU_STAT_CREATE_EX(cmp_ult_d);
0266     FPU_STAT_CREATE_EX(cmp_un_s);
0267     FPU_STAT_CREATE_EX(cmp_un_d);
0268     FPU_STAT_CREATE_EX(cmp_une_s);
0269     FPU_STAT_CREATE_EX(cmp_une_d);
0270     FPU_STAT_CREATE_EX(cmp_saf_s);
0271     FPU_STAT_CREATE_EX(cmp_saf_d);
0272     FPU_STAT_CREATE_EX(cmp_seq_s);
0273     FPU_STAT_CREATE_EX(cmp_seq_d);
0274     FPU_STAT_CREATE_EX(cmp_sle_s);
0275     FPU_STAT_CREATE_EX(cmp_sle_d);
0276     FPU_STAT_CREATE_EX(cmp_slt_s);
0277     FPU_STAT_CREATE_EX(cmp_slt_d);
0278     FPU_STAT_CREATE_EX(cmp_sne_s);
0279     FPU_STAT_CREATE_EX(cmp_sne_d);
0280     FPU_STAT_CREATE_EX(cmp_sor_s);
0281     FPU_STAT_CREATE_EX(cmp_sor_d);
0282     FPU_STAT_CREATE_EX(cmp_sueq_s);
0283     FPU_STAT_CREATE_EX(cmp_sueq_d);
0284     FPU_STAT_CREATE_EX(cmp_sule_s);
0285     FPU_STAT_CREATE_EX(cmp_sule_d);
0286     FPU_STAT_CREATE_EX(cmp_sult_s);
0287     FPU_STAT_CREATE_EX(cmp_sult_d);
0288     FPU_STAT_CREATE_EX(cmp_sun_s);
0289     FPU_STAT_CREATE_EX(cmp_sun_d);
0290     FPU_STAT_CREATE_EX(cmp_sune_s);
0291     FPU_STAT_CREATE_EX(cmp_sune_d);
0292     FPU_STAT_CREATE_EX(cvt_d_l);
0293     FPU_STAT_CREATE_EX(cvt_d_s);
0294     FPU_STAT_CREATE_EX(cvt_d_w);
0295     FPU_STAT_CREATE_EX(cvt_l_s);
0296     FPU_STAT_CREATE_EX(cvt_l_d);
0297     FPU_STAT_CREATE_EX(cvt_s_d);
0298     FPU_STAT_CREATE_EX(cvt_s_l);
0299     FPU_STAT_CREATE_EX(cvt_s_w);
0300     FPU_STAT_CREATE_EX(cvt_w_s);
0301     FPU_STAT_CREATE_EX(cvt_w_d);
0302     FPU_STAT_CREATE_EX(div_s);
0303     FPU_STAT_CREATE_EX(div_d);
0304     FPU_STAT_CREATE_EX(floor_w_s);
0305     FPU_STAT_CREATE_EX(floor_w_d);
0306     FPU_STAT_CREATE_EX(floor_l_s);
0307     FPU_STAT_CREATE_EX(floor_l_d);
0308     FPU_STAT_CREATE_EX(maddf_s);
0309     FPU_STAT_CREATE_EX(maddf_d);
0310     FPU_STAT_CREATE_EX(max_s);
0311     FPU_STAT_CREATE_EX(max_d);
0312     FPU_STAT_CREATE_EX(maxa_s);
0313     FPU_STAT_CREATE_EX(maxa_d);
0314     FPU_STAT_CREATE_EX(min_s);
0315     FPU_STAT_CREATE_EX(min_d);
0316     FPU_STAT_CREATE_EX(mina_s);
0317     FPU_STAT_CREATE_EX(mina_d);
0318     FPU_STAT_CREATE_EX(mov_s);
0319     FPU_STAT_CREATE_EX(mov_d);
0320     FPU_STAT_CREATE_EX(msubf_s);
0321     FPU_STAT_CREATE_EX(msubf_d);
0322     FPU_STAT_CREATE_EX(mul_s);
0323     FPU_STAT_CREATE_EX(mul_d);
0324     FPU_STAT_CREATE_EX(neg_s);
0325     FPU_STAT_CREATE_EX(neg_d);
0326     FPU_STAT_CREATE_EX(recip_s);
0327     FPU_STAT_CREATE_EX(recip_d);
0328     FPU_STAT_CREATE_EX(rint_s);
0329     FPU_STAT_CREATE_EX(rint_d);
0330     FPU_STAT_CREATE_EX(round_w_s);
0331     FPU_STAT_CREATE_EX(round_w_d);
0332     FPU_STAT_CREATE_EX(round_l_s);
0333     FPU_STAT_CREATE_EX(round_l_d);
0334     FPU_STAT_CREATE_EX(rsqrt_s);
0335     FPU_STAT_CREATE_EX(rsqrt_d);
0336     FPU_STAT_CREATE_EX(sel_s);
0337     FPU_STAT_CREATE_EX(sel_d);
0338     FPU_STAT_CREATE_EX(seleqz_s);
0339     FPU_STAT_CREATE_EX(seleqz_d);
0340     FPU_STAT_CREATE_EX(selnez_s);
0341     FPU_STAT_CREATE_EX(selnez_d);
0342     FPU_STAT_CREATE_EX(sqrt_s);
0343     FPU_STAT_CREATE_EX(sqrt_d);
0344     FPU_STAT_CREATE_EX(sub_s);
0345     FPU_STAT_CREATE_EX(sub_d);
0346     FPU_STAT_CREATE_EX(trunc_w_s);
0347     FPU_STAT_CREATE_EX(trunc_w_d);
0348     FPU_STAT_CREATE_EX(trunc_l_s);
0349     FPU_STAT_CREATE_EX(trunc_l_d);
0350 
0351     return 0;
0352 }
0353 arch_initcall(debugfs_fpuemu);