me-debugfs.c 12 KB

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