gruprocfs.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SN Platform GRU Driver
  4. *
  5. * PROC INTERFACES
  6. *
  7. * This file supports the /proc interfaces for the GRU driver
  8. *
  9. * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
  10. */
  11. #include <linux/proc_fs.h>
  12. #include <linux/device.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/uaccess.h>
  15. #include "gru.h"
  16. #include "grulib.h"
  17. #include "grutables.h"
  18. #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
  19. static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
  20. {
  21. unsigned long val = atomic_long_read(v);
  22. seq_printf(s, "%16lu %s\n", val, id);
  23. }
  24. static int statistics_show(struct seq_file *s, void *p)
  25. {
  26. printstat(s, vdata_alloc);
  27. printstat(s, vdata_free);
  28. printstat(s, gts_alloc);
  29. printstat(s, gts_free);
  30. printstat(s, gms_alloc);
  31. printstat(s, gms_free);
  32. printstat(s, gts_double_allocate);
  33. printstat(s, assign_context);
  34. printstat(s, assign_context_failed);
  35. printstat(s, free_context);
  36. printstat(s, load_user_context);
  37. printstat(s, load_kernel_context);
  38. printstat(s, lock_kernel_context);
  39. printstat(s, unlock_kernel_context);
  40. printstat(s, steal_user_context);
  41. printstat(s, steal_kernel_context);
  42. printstat(s, steal_context_failed);
  43. printstat(s, nopfn);
  44. printstat(s, asid_new);
  45. printstat(s, asid_next);
  46. printstat(s, asid_wrap);
  47. printstat(s, asid_reuse);
  48. printstat(s, intr);
  49. printstat(s, intr_cbr);
  50. printstat(s, intr_tfh);
  51. printstat(s, intr_spurious);
  52. printstat(s, intr_mm_lock_failed);
  53. printstat(s, call_os);
  54. printstat(s, call_os_wait_queue);
  55. printstat(s, user_flush_tlb);
  56. printstat(s, user_unload_context);
  57. printstat(s, user_exception);
  58. printstat(s, set_context_option);
  59. printstat(s, check_context_retarget_intr);
  60. printstat(s, check_context_unload);
  61. printstat(s, tlb_dropin);
  62. printstat(s, tlb_preload_page);
  63. printstat(s, tlb_dropin_fail_no_asid);
  64. printstat(s, tlb_dropin_fail_upm);
  65. printstat(s, tlb_dropin_fail_invalid);
  66. printstat(s, tlb_dropin_fail_range_active);
  67. printstat(s, tlb_dropin_fail_idle);
  68. printstat(s, tlb_dropin_fail_fmm);
  69. printstat(s, tlb_dropin_fail_no_exception);
  70. printstat(s, tfh_stale_on_fault);
  71. printstat(s, mmu_invalidate_range);
  72. printstat(s, mmu_invalidate_page);
  73. printstat(s, flush_tlb);
  74. printstat(s, flush_tlb_gru);
  75. printstat(s, flush_tlb_gru_tgh);
  76. printstat(s, flush_tlb_gru_zero_asid);
  77. printstat(s, copy_gpa);
  78. printstat(s, read_gpa);
  79. printstat(s, mesq_receive);
  80. printstat(s, mesq_receive_none);
  81. printstat(s, mesq_send);
  82. printstat(s, mesq_send_failed);
  83. printstat(s, mesq_noop);
  84. printstat(s, mesq_send_unexpected_error);
  85. printstat(s, mesq_send_lb_overflow);
  86. printstat(s, mesq_send_qlimit_reached);
  87. printstat(s, mesq_send_amo_nacked);
  88. printstat(s, mesq_send_put_nacked);
  89. printstat(s, mesq_qf_locked);
  90. printstat(s, mesq_qf_noop_not_full);
  91. printstat(s, mesq_qf_switch_head_failed);
  92. printstat(s, mesq_qf_unexpected_error);
  93. printstat(s, mesq_noop_unexpected_error);
  94. printstat(s, mesq_noop_lb_overflow);
  95. printstat(s, mesq_noop_qlimit_reached);
  96. printstat(s, mesq_noop_amo_nacked);
  97. printstat(s, mesq_noop_put_nacked);
  98. printstat(s, mesq_noop_page_overflow);
  99. return 0;
  100. }
  101. static ssize_t statistics_write(struct file *file, const char __user *userbuf,
  102. size_t count, loff_t *data)
  103. {
  104. memset(&gru_stats, 0, sizeof(gru_stats));
  105. return count;
  106. }
  107. static int mcs_statistics_show(struct seq_file *s, void *p)
  108. {
  109. int op;
  110. unsigned long total, count, max;
  111. static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
  112. "cch_interrupt_sync", "cch_deallocate", "tfh_write_only",
  113. "tfh_write_restart", "tgh_invalidate"};
  114. seq_puts(s, "#id count aver-clks max-clks\n");
  115. for (op = 0; op < mcsop_last; op++) {
  116. count = atomic_long_read(&mcs_op_statistics[op].count);
  117. total = atomic_long_read(&mcs_op_statistics[op].total);
  118. max = mcs_op_statistics[op].max;
  119. seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
  120. count ? total / count : 0, max);
  121. }
  122. return 0;
  123. }
  124. static ssize_t mcs_statistics_write(struct file *file,
  125. const char __user *userbuf, size_t count, loff_t *data)
  126. {
  127. memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
  128. return count;
  129. }
  130. static int options_show(struct seq_file *s, void *p)
  131. {
  132. seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");
  133. seq_printf(s, "0x%lx\n", gru_options);
  134. return 0;
  135. }
  136. static ssize_t options_write(struct file *file, const char __user *userbuf,
  137. size_t count, loff_t *data)
  138. {
  139. int ret;
  140. ret = kstrtoul_from_user(userbuf, count, 0, &gru_options);
  141. if (ret)
  142. return ret;
  143. return count;
  144. }
  145. static int cch_seq_show(struct seq_file *file, void *data)
  146. {
  147. long gid = *(long *)data;
  148. int i;
  149. struct gru_state *gru = GID_TO_GRU(gid);
  150. struct gru_thread_state *ts;
  151. const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
  152. if (gid == 0)
  153. seq_puts(file, "# gid bid ctx# asid pid cbrs dsbytes mode\n");
  154. if (gru)
  155. for (i = 0; i < GRU_NUM_CCH; i++) {
  156. ts = gru->gs_gts[i];
  157. if (!ts)
  158. continue;
  159. seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",
  160. gru->gs_gid, gru->gs_blade_id, i,
  161. is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,
  162. is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,
  163. ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
  164. ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
  165. mode[ts->ts_user_options &
  166. GRU_OPT_MISS_MASK]);
  167. }
  168. return 0;
  169. }
  170. static int gru_seq_show(struct seq_file *file, void *data)
  171. {
  172. long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
  173. struct gru_state *gru = GID_TO_GRU(gid);
  174. if (gid == 0) {
  175. seq_puts(file, "# gid nid ctx cbr dsr ctx cbr dsr\n");
  176. seq_puts(file, "# busy busy busy free free free\n");
  177. }
  178. if (gru) {
  179. ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
  180. cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
  181. dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
  182. seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
  183. gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
  184. GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
  185. ctxfree, cbrfree, dsrfree);
  186. }
  187. return 0;
  188. }
  189. static void seq_stop(struct seq_file *file, void *data)
  190. {
  191. }
  192. static void *seq_start(struct seq_file *file, loff_t *gid)
  193. {
  194. if (*gid < gru_max_gids)
  195. return gid;
  196. return NULL;
  197. }
  198. static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
  199. {
  200. (*gid)++;
  201. if (*gid < gru_max_gids)
  202. return gid;
  203. return NULL;
  204. }
  205. static const struct seq_operations cch_seq_ops = {
  206. .start = seq_start,
  207. .next = seq_next,
  208. .stop = seq_stop,
  209. .show = cch_seq_show
  210. };
  211. static const struct seq_operations gru_seq_ops = {
  212. .start = seq_start,
  213. .next = seq_next,
  214. .stop = seq_stop,
  215. .show = gru_seq_show
  216. };
  217. static int statistics_open(struct inode *inode, struct file *file)
  218. {
  219. return single_open(file, statistics_show, NULL);
  220. }
  221. static int mcs_statistics_open(struct inode *inode, struct file *file)
  222. {
  223. return single_open(file, mcs_statistics_show, NULL);
  224. }
  225. static int options_open(struct inode *inode, struct file *file)
  226. {
  227. return single_open(file, options_show, NULL);
  228. }
  229. /* *INDENT-OFF* */
  230. static const struct proc_ops statistics_proc_ops = {
  231. .proc_open = statistics_open,
  232. .proc_read = seq_read,
  233. .proc_write = statistics_write,
  234. .proc_lseek = seq_lseek,
  235. .proc_release = single_release,
  236. };
  237. static const struct proc_ops mcs_statistics_proc_ops = {
  238. .proc_open = mcs_statistics_open,
  239. .proc_read = seq_read,
  240. .proc_write = mcs_statistics_write,
  241. .proc_lseek = seq_lseek,
  242. .proc_release = single_release,
  243. };
  244. static const struct proc_ops options_proc_ops = {
  245. .proc_open = options_open,
  246. .proc_read = seq_read,
  247. .proc_write = options_write,
  248. .proc_lseek = seq_lseek,
  249. .proc_release = single_release,
  250. };
  251. static struct proc_dir_entry *proc_gru __read_mostly;
  252. int gru_proc_init(void)
  253. {
  254. proc_gru = proc_mkdir("sgi_uv/gru", NULL);
  255. if (!proc_gru)
  256. return -1;
  257. if (!proc_create("statistics", 0644, proc_gru, &statistics_proc_ops))
  258. goto err;
  259. if (!proc_create("mcs_statistics", 0644, proc_gru, &mcs_statistics_proc_ops))
  260. goto err;
  261. if (!proc_create("debug_options", 0644, proc_gru, &options_proc_ops))
  262. goto err;
  263. if (!proc_create_seq("cch_status", 0444, proc_gru, &cch_seq_ops))
  264. goto err;
  265. if (!proc_create_seq("gru_status", 0444, proc_gru, &gru_seq_ops))
  266. goto err;
  267. return 0;
  268. err:
  269. remove_proc_subtree("sgi_uv/gru", NULL);
  270. return -1;
  271. }
  272. void gru_proc_exit(void)
  273. {
  274. remove_proc_subtree("sgi_uv/gru", NULL);
  275. }