gruprocfs.c 8.9 KB

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