gruprocfs.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. if (val)
  36. seq_printf(s, "%16lu %s\n", val, id);
  37. }
  38. static int statistics_show(struct seq_file *s, void *p)
  39. {
  40. printstat(s, vdata_alloc);
  41. printstat(s, vdata_free);
  42. printstat(s, gts_alloc);
  43. printstat(s, gts_free);
  44. printstat(s, vdata_double_alloc);
  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_context);
  50. printstat(s, unload_context);
  51. printstat(s, steal_context);
  52. printstat(s, steal_context_failed);
  53. printstat(s, nopfn);
  54. printstat(s, break_cow);
  55. printstat(s, asid_new);
  56. printstat(s, asid_next);
  57. printstat(s, asid_wrap);
  58. printstat(s, asid_reuse);
  59. printstat(s, intr);
  60. printstat(s, intr_mm_lock_failed);
  61. printstat(s, call_os);
  62. printstat(s, call_os_offnode_reference);
  63. printstat(s, call_os_check_for_bug);
  64. printstat(s, call_os_wait_queue);
  65. printstat(s, user_flush_tlb);
  66. printstat(s, user_unload_context);
  67. printstat(s, user_exception);
  68. printstat(s, set_task_slice);
  69. printstat(s, migrate_check);
  70. printstat(s, migrated_retarget);
  71. printstat(s, migrated_unload);
  72. printstat(s, migrated_unload_delay);
  73. printstat(s, migrated_nopfn_retarget);
  74. printstat(s, migrated_nopfn_unload);
  75. printstat(s, tlb_dropin);
  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, mmu_invalidate_range);
  83. printstat(s, mmu_invalidate_page);
  84. printstat(s, mmu_clear_flush_young);
  85. printstat(s, flush_tlb);
  86. printstat(s, flush_tlb_gru);
  87. printstat(s, flush_tlb_gru_tgh);
  88. printstat(s, flush_tlb_gru_zero_asid);
  89. printstat(s, copy_gpa);
  90. printstat(s, mesq_receive);
  91. printstat(s, mesq_receive_none);
  92. printstat(s, mesq_send);
  93. printstat(s, mesq_send_failed);
  94. printstat(s, mesq_noop);
  95. printstat(s, mesq_send_unexpected_error);
  96. printstat(s, mesq_send_lb_overflow);
  97. printstat(s, mesq_send_qlimit_reached);
  98. printstat(s, mesq_send_amo_nacked);
  99. printstat(s, mesq_send_put_nacked);
  100. printstat(s, mesq_qf_not_full);
  101. printstat(s, mesq_qf_locked);
  102. printstat(s, mesq_qf_noop_not_full);
  103. printstat(s, mesq_qf_switch_head_failed);
  104. printstat(s, mesq_qf_unexpected_error);
  105. printstat(s, mesq_noop_unexpected_error);
  106. printstat(s, mesq_noop_lb_overflow);
  107. printstat(s, mesq_noop_qlimit_reached);
  108. printstat(s, mesq_noop_amo_nacked);
  109. printstat(s, mesq_noop_put_nacked);
  110. return 0;
  111. }
  112. static ssize_t statistics_write(struct file *file, const char __user *userbuf,
  113. size_t count, loff_t *data)
  114. {
  115. memset(&gru_stats, 0, sizeof(gru_stats));
  116. return count;
  117. }
  118. static int options_show(struct seq_file *s, void *p)
  119. {
  120. seq_printf(s, "0x%lx\n", gru_options);
  121. return 0;
  122. }
  123. static ssize_t options_write(struct file *file, const char __user *userbuf,
  124. size_t count, loff_t *data)
  125. {
  126. unsigned long val;
  127. char buf[80];
  128. if (copy_from_user
  129. (buf, userbuf, count < sizeof(buf) ? count : sizeof(buf)))
  130. return -EFAULT;
  131. if (!strict_strtoul(buf, 10, &val))
  132. gru_options = val;
  133. return count;
  134. }
  135. static int cch_seq_show(struct seq_file *file, void *data)
  136. {
  137. long gid = *(long *)data;
  138. int i;
  139. struct gru_state *gru = GID_TO_GRU(gid);
  140. struct gru_thread_state *ts;
  141. const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
  142. if (gid == 0)
  143. seq_printf(file, "#%5s%5s%6s%9s%6s%8s%8s\n", "gid", "bid",
  144. "ctx#", "pid", "cbrs", "dsbytes", "mode");
  145. if (gru)
  146. for (i = 0; i < GRU_NUM_CCH; i++) {
  147. ts = gru->gs_gts[i];
  148. if (!ts)
  149. continue;
  150. seq_printf(file, " %5d%5d%6d%9d%6d%8d%8s\n",
  151. gru->gs_gid, gru->gs_blade_id, i,
  152. ts->ts_tgid_owner,
  153. ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
  154. ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
  155. mode[ts->ts_user_options &
  156. GRU_OPT_MISS_MASK]);
  157. }
  158. return 0;
  159. }
  160. static int gru_seq_show(struct seq_file *file, void *data)
  161. {
  162. long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
  163. struct gru_state *gru = GID_TO_GRU(gid);
  164. if (gid == 0) {
  165. seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
  166. "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
  167. seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
  168. "busy", "busy", "free", "free", "free");
  169. }
  170. if (gru) {
  171. ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
  172. cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
  173. dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
  174. seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
  175. gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
  176. GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
  177. ctxfree, cbrfree, dsrfree);
  178. }
  179. return 0;
  180. }
  181. static void seq_stop(struct seq_file *file, void *data)
  182. {
  183. }
  184. static void *seq_start(struct seq_file *file, loff_t *gid)
  185. {
  186. if (*gid < GRU_MAX_GRUS)
  187. return gid;
  188. return NULL;
  189. }
  190. static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
  191. {
  192. (*gid)++;
  193. if (*gid < GRU_MAX_GRUS)
  194. return gid;
  195. return NULL;
  196. }
  197. static const struct seq_operations cch_seq_ops = {
  198. .start = seq_start,
  199. .next = seq_next,
  200. .stop = seq_stop,
  201. .show = cch_seq_show
  202. };
  203. static const struct seq_operations gru_seq_ops = {
  204. .start = seq_start,
  205. .next = seq_next,
  206. .stop = seq_stop,
  207. .show = gru_seq_show
  208. };
  209. static int statistics_open(struct inode *inode, struct file *file)
  210. {
  211. return single_open(file, statistics_show, NULL);
  212. }
  213. static int options_open(struct inode *inode, struct file *file)
  214. {
  215. return single_open(file, options_show, NULL);
  216. }
  217. static int cch_open(struct inode *inode, struct file *file)
  218. {
  219. return seq_open(file, &cch_seq_ops);
  220. }
  221. static int gru_open(struct inode *inode, struct file *file)
  222. {
  223. return seq_open(file, &gru_seq_ops);
  224. }
  225. /* *INDENT-OFF* */
  226. static const struct file_operations statistics_fops = {
  227. .open = statistics_open,
  228. .read = seq_read,
  229. .write = statistics_write,
  230. .llseek = seq_lseek,
  231. .release = single_release,
  232. };
  233. static const struct file_operations options_fops = {
  234. .open = options_open,
  235. .read = seq_read,
  236. .write = options_write,
  237. .llseek = seq_lseek,
  238. .release = single_release,
  239. };
  240. static const struct file_operations cch_fops = {
  241. .open = cch_open,
  242. .read = seq_read,
  243. .llseek = seq_lseek,
  244. .release = seq_release,
  245. };
  246. static const struct file_operations gru_fops = {
  247. .open = gru_open,
  248. .read = seq_read,
  249. .llseek = seq_lseek,
  250. .release = seq_release,
  251. };
  252. static struct proc_entry {
  253. char *name;
  254. int mode;
  255. const struct file_operations *fops;
  256. struct proc_dir_entry *entry;
  257. } proc_files[] = {
  258. {"statistics", 0644, &statistics_fops},
  259. {"debug_options", 0644, &options_fops},
  260. {"cch_status", 0444, &cch_fops},
  261. {"gru_status", 0444, &gru_fops},
  262. {NULL}
  263. };
  264. /* *INDENT-ON* */
  265. static struct proc_dir_entry *proc_gru __read_mostly;
  266. static int create_proc_file(struct proc_entry *p)
  267. {
  268. p->entry = create_proc_entry(p->name, p->mode, proc_gru);
  269. if (!p->entry)
  270. return -1;
  271. p->entry->proc_fops = p->fops;
  272. return 0;
  273. }
  274. static void delete_proc_files(void)
  275. {
  276. struct proc_entry *p;
  277. if (proc_gru) {
  278. for (p = proc_files; p->name; p++)
  279. if (p->entry)
  280. remove_proc_entry(p->name, proc_gru);
  281. remove_proc_entry("gru", NULL);
  282. }
  283. }
  284. int gru_proc_init(void)
  285. {
  286. struct proc_entry *p;
  287. proc_gru = proc_mkdir("sgi_uv/gru", NULL);
  288. for (p = proc_files; p->name; p++)
  289. if (create_proc_file(p))
  290. goto err;
  291. return 0;
  292. err:
  293. delete_proc_files();
  294. return -1;
  295. }
  296. void gru_proc_exit(void)
  297. {
  298. delete_proc_files();
  299. }