gruprocfs.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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_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, break_cow);
  58. printstat(s, asid_new);
  59. printstat(s, asid_next);
  60. printstat(s, asid_wrap);
  61. printstat(s, asid_reuse);
  62. printstat(s, intr);
  63. printstat(s, intr_mm_lock_failed);
  64. printstat(s, call_os);
  65. printstat(s, call_os_offnode_reference);
  66. printstat(s, call_os_check_for_bug);
  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, migrate_check);
  73. printstat(s, migrated_retarget);
  74. printstat(s, migrated_unload);
  75. printstat(s, migrated_unload_delay);
  76. printstat(s, migrated_nopfn_retarget);
  77. printstat(s, migrated_nopfn_unload);
  78. printstat(s, tlb_dropin);
  79. printstat(s, tlb_dropin_fail_no_asid);
  80. printstat(s, tlb_dropin_fail_upm);
  81. printstat(s, tlb_dropin_fail_invalid);
  82. printstat(s, tlb_dropin_fail_range_active);
  83. printstat(s, tlb_dropin_fail_idle);
  84. printstat(s, tlb_dropin_fail_fmm);
  85. printstat(s, tlb_dropin_fail_no_exception);
  86. printstat(s, tlb_dropin_fail_no_exception_war);
  87. printstat(s, tfh_stale_on_fault);
  88. printstat(s, mmu_invalidate_range);
  89. printstat(s, mmu_invalidate_page);
  90. printstat(s, mmu_clear_flush_young);
  91. printstat(s, flush_tlb);
  92. printstat(s, flush_tlb_gru);
  93. printstat(s, flush_tlb_gru_tgh);
  94. printstat(s, flush_tlb_gru_zero_asid);
  95. printstat(s, copy_gpa);
  96. printstat(s, read_gpa);
  97. printstat(s, mesq_receive);
  98. printstat(s, mesq_receive_none);
  99. printstat(s, mesq_send);
  100. printstat(s, mesq_send_failed);
  101. printstat(s, mesq_noop);
  102. printstat(s, mesq_send_unexpected_error);
  103. printstat(s, mesq_send_lb_overflow);
  104. printstat(s, mesq_send_qlimit_reached);
  105. printstat(s, mesq_send_amo_nacked);
  106. printstat(s, mesq_send_put_nacked);
  107. printstat(s, mesq_qf_not_full);
  108. printstat(s, mesq_qf_locked);
  109. printstat(s, mesq_qf_noop_not_full);
  110. printstat(s, mesq_qf_switch_head_failed);
  111. printstat(s, mesq_qf_unexpected_error);
  112. printstat(s, mesq_noop_unexpected_error);
  113. printstat(s, mesq_noop_lb_overflow);
  114. printstat(s, mesq_noop_qlimit_reached);
  115. printstat(s, mesq_noop_amo_nacked);
  116. printstat(s, mesq_noop_put_nacked);
  117. return 0;
  118. }
  119. static ssize_t statistics_write(struct file *file, const char __user *userbuf,
  120. size_t count, loff_t *data)
  121. {
  122. memset(&gru_stats, 0, sizeof(gru_stats));
  123. return count;
  124. }
  125. static int mcs_statistics_show(struct seq_file *s, void *p)
  126. {
  127. int op;
  128. unsigned long total, count, max;
  129. static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
  130. "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
  131. for (op = 0; op < mcsop_last; op++) {
  132. count = atomic_long_read(&mcs_op_statistics[op].count);
  133. total = atomic_long_read(&mcs_op_statistics[op].total);
  134. max = mcs_op_statistics[op].max;
  135. seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
  136. count ? total / count : 0, max);
  137. }
  138. return 0;
  139. }
  140. static ssize_t mcs_statistics_write(struct file *file,
  141. const char __user *userbuf, size_t count, loff_t *data)
  142. {
  143. memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
  144. return count;
  145. }
  146. static int options_show(struct seq_file *s, void *p)
  147. {
  148. seq_printf(s, "0x%lx\n", gru_options);
  149. return 0;
  150. }
  151. static ssize_t options_write(struct file *file, const char __user *userbuf,
  152. size_t count, loff_t *data)
  153. {
  154. char buf[20];
  155. if (count >= sizeof(buf))
  156. return -EINVAL;
  157. if (copy_from_user(buf, userbuf, count))
  158. return -EFAULT;
  159. buf[count] = '\0';
  160. if (strict_strtoul(buf, 0, &gru_options))
  161. return -EINVAL;
  162. return count;
  163. }
  164. static int cch_seq_show(struct seq_file *file, void *data)
  165. {
  166. long gid = *(long *)data;
  167. int i;
  168. struct gru_state *gru = GID_TO_GRU(gid);
  169. struct gru_thread_state *ts;
  170. const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
  171. if (gid == 0)
  172. seq_printf(file, "#%5s%5s%6s%9s%6s%8s%8s\n", "gid", "bid",
  173. "ctx#", "pid", "cbrs", "dsbytes", "mode");
  174. if (gru)
  175. for (i = 0; i < GRU_NUM_CCH; i++) {
  176. ts = gru->gs_gts[i];
  177. if (!ts)
  178. continue;
  179. seq_printf(file, " %5d%5d%6d%9d%6d%8d%8s\n",
  180. gru->gs_gid, gru->gs_blade_id, i,
  181. ts->ts_tgid_owner,
  182. ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
  183. ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
  184. mode[ts->ts_user_options &
  185. GRU_OPT_MISS_MASK]);
  186. }
  187. return 0;
  188. }
  189. static int gru_seq_show(struct seq_file *file, void *data)
  190. {
  191. long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
  192. struct gru_state *gru = GID_TO_GRU(gid);
  193. if (gid == 0) {
  194. seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
  195. "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
  196. seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
  197. "busy", "busy", "free", "free", "free");
  198. }
  199. if (gru) {
  200. ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
  201. cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
  202. dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
  203. seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
  204. gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
  205. GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
  206. ctxfree, cbrfree, dsrfree);
  207. }
  208. return 0;
  209. }
  210. static void seq_stop(struct seq_file *file, void *data)
  211. {
  212. }
  213. static void *seq_start(struct seq_file *file, loff_t *gid)
  214. {
  215. if (*gid < gru_max_gids)
  216. return gid;
  217. return NULL;
  218. }
  219. static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
  220. {
  221. (*gid)++;
  222. if (*gid < gru_max_gids)
  223. return gid;
  224. return NULL;
  225. }
  226. static const struct seq_operations cch_seq_ops = {
  227. .start = seq_start,
  228. .next = seq_next,
  229. .stop = seq_stop,
  230. .show = cch_seq_show
  231. };
  232. static const struct seq_operations gru_seq_ops = {
  233. .start = seq_start,
  234. .next = seq_next,
  235. .stop = seq_stop,
  236. .show = gru_seq_show
  237. };
  238. static int statistics_open(struct inode *inode, struct file *file)
  239. {
  240. return single_open(file, statistics_show, NULL);
  241. }
  242. static int mcs_statistics_open(struct inode *inode, struct file *file)
  243. {
  244. return single_open(file, mcs_statistics_show, NULL);
  245. }
  246. static int options_open(struct inode *inode, struct file *file)
  247. {
  248. return single_open(file, options_show, NULL);
  249. }
  250. static int cch_open(struct inode *inode, struct file *file)
  251. {
  252. return seq_open(file, &cch_seq_ops);
  253. }
  254. static int gru_open(struct inode *inode, struct file *file)
  255. {
  256. return seq_open(file, &gru_seq_ops);
  257. }
  258. /* *INDENT-OFF* */
  259. static const struct file_operations statistics_fops = {
  260. .open = statistics_open,
  261. .read = seq_read,
  262. .write = statistics_write,
  263. .llseek = seq_lseek,
  264. .release = single_release,
  265. };
  266. static const struct file_operations mcs_statistics_fops = {
  267. .open = mcs_statistics_open,
  268. .read = seq_read,
  269. .write = mcs_statistics_write,
  270. .llseek = seq_lseek,
  271. .release = single_release,
  272. };
  273. static const struct file_operations options_fops = {
  274. .open = options_open,
  275. .read = seq_read,
  276. .write = options_write,
  277. .llseek = seq_lseek,
  278. .release = single_release,
  279. };
  280. static const struct file_operations cch_fops = {
  281. .open = cch_open,
  282. .read = seq_read,
  283. .llseek = seq_lseek,
  284. .release = seq_release,
  285. };
  286. static const struct file_operations gru_fops = {
  287. .open = gru_open,
  288. .read = seq_read,
  289. .llseek = seq_lseek,
  290. .release = seq_release,
  291. };
  292. static struct proc_entry {
  293. char *name;
  294. int mode;
  295. const struct file_operations *fops;
  296. struct proc_dir_entry *entry;
  297. } proc_files[] = {
  298. {"statistics", 0644, &statistics_fops},
  299. {"mcs_statistics", 0644, &mcs_statistics_fops},
  300. {"debug_options", 0644, &options_fops},
  301. {"cch_status", 0444, &cch_fops},
  302. {"gru_status", 0444, &gru_fops},
  303. {NULL}
  304. };
  305. /* *INDENT-ON* */
  306. static struct proc_dir_entry *proc_gru __read_mostly;
  307. static int create_proc_file(struct proc_entry *p)
  308. {
  309. p->entry = proc_create(p->name, p->mode, proc_gru, p->fops);
  310. if (!p->entry)
  311. return -1;
  312. return 0;
  313. }
  314. static void delete_proc_files(void)
  315. {
  316. struct proc_entry *p;
  317. if (proc_gru) {
  318. for (p = proc_files; p->name; p++)
  319. if (p->entry)
  320. remove_proc_entry(p->name, proc_gru);
  321. remove_proc_entry("gru", NULL);
  322. }
  323. }
  324. int gru_proc_init(void)
  325. {
  326. struct proc_entry *p;
  327. proc_gru = proc_mkdir("sgi_uv/gru", NULL);
  328. for (p = proc_files; p->name; p++)
  329. if (create_proc_file(p))
  330. goto err;
  331. return 0;
  332. err:
  333. delete_proc_files();
  334. return -1;
  335. }
  336. void gru_proc_exit(void)
  337. {
  338. delete_proc_files();
  339. }