Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 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 | |
| 25 | #include <linux/proc_fs.h> |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/seq_file.h> |
| 28 | #include <linux/uaccess.h> |
| 29 | #include "gru.h" |
| 30 | #include "grulib.h" |
| 31 | #include "grutables.h" |
| 32 | |
| 33 | #define printstat(s, f) printstat_val(s, &gru_stats.f, #f) |
| 34 | |
| 35 | static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id) |
| 36 | { |
| 37 | unsigned long val = atomic_long_read(v); |
| 38 | |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 39 | seq_printf(s, "%16lu %s\n", val, id); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static int statistics_show(struct seq_file *s, void *p) |
| 43 | { |
| 44 | printstat(s, vdata_alloc); |
| 45 | printstat(s, vdata_free); |
| 46 | printstat(s, gts_alloc); |
| 47 | printstat(s, gts_free); |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 48 | printstat(s, gms_alloc); |
| 49 | printstat(s, gms_free); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 50 | printstat(s, gts_double_allocate); |
| 51 | printstat(s, assign_context); |
| 52 | printstat(s, assign_context_failed); |
| 53 | printstat(s, free_context); |
Jack Steiner | 836ce67 | 2009-06-17 16:28:22 -0700 | [diff] [blame] | 54 | printstat(s, load_user_context); |
| 55 | printstat(s, load_kernel_context); |
| 56 | printstat(s, lock_kernel_context); |
| 57 | printstat(s, unlock_kernel_context); |
| 58 | printstat(s, steal_user_context); |
| 59 | printstat(s, steal_kernel_context); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 60 | printstat(s, steal_context_failed); |
| 61 | printstat(s, nopfn); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 62 | printstat(s, asid_new); |
| 63 | printstat(s, asid_next); |
| 64 | printstat(s, asid_wrap); |
| 65 | printstat(s, asid_reuse); |
| 66 | printstat(s, intr); |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 67 | printstat(s, intr_cbr); |
| 68 | printstat(s, intr_tfh); |
Jack Steiner | 2ce4d4c | 2009-12-15 16:48:18 -0800 | [diff] [blame] | 69 | printstat(s, intr_spurious); |
Jack Steiner | 4388460 | 2009-04-02 16:59:05 -0700 | [diff] [blame] | 70 | printstat(s, intr_mm_lock_failed); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 71 | printstat(s, call_os); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 72 | printstat(s, call_os_wait_queue); |
| 73 | printstat(s, user_flush_tlb); |
| 74 | printstat(s, user_unload_context); |
| 75 | printstat(s, user_exception); |
Jack Steiner | 92b3938 | 2009-06-17 16:28:32 -0700 | [diff] [blame] | 76 | printstat(s, set_context_option); |
Jack Steiner | 55484c4 | 2009-12-15 16:48:05 -0800 | [diff] [blame] | 77 | printstat(s, check_context_retarget_intr); |
| 78 | printstat(s, check_context_unload); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 79 | printstat(s, tlb_dropin); |
Jack Steiner | c550222 | 2009-12-15 16:48:13 -0800 | [diff] [blame] | 80 | printstat(s, tlb_preload_page); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 81 | printstat(s, tlb_dropin_fail_no_asid); |
| 82 | printstat(s, tlb_dropin_fail_upm); |
| 83 | printstat(s, tlb_dropin_fail_invalid); |
| 84 | printstat(s, tlb_dropin_fail_range_active); |
| 85 | printstat(s, tlb_dropin_fail_idle); |
| 86 | printstat(s, tlb_dropin_fail_fmm); |
Jack Steiner | cd1334f | 2009-06-17 16:28:19 -0700 | [diff] [blame] | 87 | printstat(s, tlb_dropin_fail_no_exception); |
Jack Steiner | 270952a | 2009-06-17 16:28:27 -0700 | [diff] [blame] | 88 | printstat(s, tfh_stale_on_fault); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 89 | printstat(s, mmu_invalidate_range); |
| 90 | printstat(s, mmu_invalidate_page); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 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); |
Robin Holt | 289750d | 2009-12-15 16:47:55 -0800 | [diff] [blame] | 96 | printstat(s, read_gpa); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 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); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 107 | printstat(s, mesq_qf_locked); |
| 108 | printstat(s, mesq_qf_noop_not_full); |
| 109 | printstat(s, mesq_qf_switch_head_failed); |
| 110 | printstat(s, mesq_qf_unexpected_error); |
| 111 | printstat(s, mesq_noop_unexpected_error); |
| 112 | printstat(s, mesq_noop_lb_overflow); |
| 113 | printstat(s, mesq_noop_qlimit_reached); |
| 114 | printstat(s, mesq_noop_amo_nacked); |
| 115 | printstat(s, mesq_noop_put_nacked); |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 116 | printstat(s, mesq_noop_page_overflow); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static ssize_t statistics_write(struct file *file, const char __user *userbuf, |
| 121 | size_t count, loff_t *data) |
| 122 | { |
| 123 | memset(&gru_stats, 0, sizeof(gru_stats)); |
| 124 | return count; |
| 125 | } |
| 126 | |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 127 | static int mcs_statistics_show(struct seq_file *s, void *p) |
| 128 | { |
| 129 | int op; |
| 130 | unsigned long total, count, max; |
| 131 | static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt", |
Jack Steiner | c550222 | 2009-12-15 16:48:13 -0800 | [diff] [blame] | 132 | "cch_interrupt_sync", "cch_deallocate", "tfh_write_only", |
| 133 | "tfh_write_restart", "tgh_invalidate"}; |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 134 | |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 135 | seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks"); |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 136 | for (op = 0; op < mcsop_last; op++) { |
| 137 | count = atomic_long_read(&mcs_op_statistics[op].count); |
| 138 | total = atomic_long_read(&mcs_op_statistics[op].total); |
| 139 | max = mcs_op_statistics[op].max; |
| 140 | seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count, |
| 141 | count ? total / count : 0, max); |
| 142 | } |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static ssize_t mcs_statistics_write(struct file *file, |
| 147 | const char __user *userbuf, size_t count, loff_t *data) |
| 148 | { |
| 149 | memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics)); |
| 150 | return count; |
| 151 | } |
| 152 | |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 153 | static int options_show(struct seq_file *s, void *p) |
| 154 | { |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 155 | seq_printf(s, "#bitmask: 1=trace, 2=statistics\n"); |
Jack Steiner | 9ca8e40c1 | 2008-07-29 22:34:02 -0700 | [diff] [blame] | 156 | seq_printf(s, "0x%lx\n", gru_options); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static ssize_t options_write(struct file *file, const char __user *userbuf, |
| 161 | size_t count, loff_t *data) |
| 162 | { |
Linus Torvalds | d39b7dd | 2009-11-05 10:48:30 -0800 | [diff] [blame] | 163 | char buf[20]; |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 164 | |
Linus Torvalds | d39b7dd | 2009-11-05 10:48:30 -0800 | [diff] [blame] | 165 | if (count >= sizeof(buf)) |
| 166 | return -EINVAL; |
| 167 | if (copy_from_user(buf, userbuf, count)) |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 168 | return -EFAULT; |
Linus Torvalds | d39b7dd | 2009-11-05 10:48:30 -0800 | [diff] [blame] | 169 | buf[count] = '\0'; |
| 170 | if (strict_strtoul(buf, 0, &gru_options)) |
| 171 | return -EINVAL; |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 172 | |
| 173 | return count; |
| 174 | } |
| 175 | |
| 176 | static int cch_seq_show(struct seq_file *file, void *data) |
| 177 | { |
| 178 | long gid = *(long *)data; |
| 179 | int i; |
| 180 | struct gru_state *gru = GID_TO_GRU(gid); |
| 181 | struct gru_thread_state *ts; |
| 182 | const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" }; |
| 183 | |
| 184 | if (gid == 0) |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 185 | seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid", |
| 186 | "ctx#", "asid", "pid", "cbrs", "dsbytes", "mode"); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 187 | if (gru) |
| 188 | for (i = 0; i < GRU_NUM_CCH; i++) { |
| 189 | ts = gru->gs_gts[i]; |
| 190 | if (!ts) |
| 191 | continue; |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 192 | seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n", |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 193 | gru->gs_gid, gru->gs_blade_id, i, |
Jack Steiner | 563447d | 2009-12-15 16:48:12 -0800 | [diff] [blame] | 194 | is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid, |
| 195 | is_kernel_context(ts) ? 0 : ts->ts_tgid_owner, |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 196 | ts->ts_cbr_au_count * GRU_CBR_AU_SIZE, |
| 197 | ts->ts_cbr_au_count * GRU_DSR_AU_BYTES, |
| 198 | mode[ts->ts_user_options & |
| 199 | GRU_OPT_MISS_MASK]); |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int gru_seq_show(struct seq_file *file, void *data) |
| 206 | { |
| 207 | long gid = *(long *)data, ctxfree, cbrfree, dsrfree; |
| 208 | struct gru_state *gru = GID_TO_GRU(gid); |
| 209 | |
| 210 | if (gid == 0) { |
| 211 | seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid", |
| 212 | "ctx", "cbr", "dsr", "ctx", "cbr", "dsr"); |
| 213 | seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy", |
| 214 | "busy", "busy", "free", "free", "free"); |
| 215 | } |
| 216 | if (gru) { |
| 217 | ctxfree = GRU_NUM_CCH - gru->gs_active_contexts; |
| 218 | cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE; |
| 219 | dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES; |
| 220 | seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n", |
| 221 | gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree, |
| 222 | GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree, |
| 223 | ctxfree, cbrfree, dsrfree); |
| 224 | } |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static void seq_stop(struct seq_file *file, void *data) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | static void *seq_start(struct seq_file *file, loff_t *gid) |
| 234 | { |
Jack Steiner | e1c3219 | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 235 | if (*gid < gru_max_gids) |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 236 | return gid; |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | static void *seq_next(struct seq_file *file, void *data, loff_t *gid) |
| 241 | { |
| 242 | (*gid)++; |
Jack Steiner | e1c3219 | 2009-04-02 16:59:10 -0700 | [diff] [blame] | 243 | if (*gid < gru_max_gids) |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 244 | return gid; |
| 245 | return NULL; |
| 246 | } |
| 247 | |
| 248 | static const struct seq_operations cch_seq_ops = { |
| 249 | .start = seq_start, |
| 250 | .next = seq_next, |
| 251 | .stop = seq_stop, |
| 252 | .show = cch_seq_show |
| 253 | }; |
| 254 | |
| 255 | static const struct seq_operations gru_seq_ops = { |
| 256 | .start = seq_start, |
| 257 | .next = seq_next, |
| 258 | .stop = seq_stop, |
| 259 | .show = gru_seq_show |
| 260 | }; |
| 261 | |
| 262 | static int statistics_open(struct inode *inode, struct file *file) |
| 263 | { |
| 264 | return single_open(file, statistics_show, NULL); |
| 265 | } |
| 266 | |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 267 | static int mcs_statistics_open(struct inode *inode, struct file *file) |
| 268 | { |
| 269 | return single_open(file, mcs_statistics_show, NULL); |
| 270 | } |
| 271 | |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 272 | static int options_open(struct inode *inode, struct file *file) |
| 273 | { |
| 274 | return single_open(file, options_show, NULL); |
| 275 | } |
| 276 | |
| 277 | static int cch_open(struct inode *inode, struct file *file) |
| 278 | { |
| 279 | return seq_open(file, &cch_seq_ops); |
| 280 | } |
| 281 | |
| 282 | static int gru_open(struct inode *inode, struct file *file) |
| 283 | { |
| 284 | return seq_open(file, &gru_seq_ops); |
| 285 | } |
| 286 | |
| 287 | /* *INDENT-OFF* */ |
| 288 | static const struct file_operations statistics_fops = { |
| 289 | .open = statistics_open, |
| 290 | .read = seq_read, |
| 291 | .write = statistics_write, |
| 292 | .llseek = seq_lseek, |
| 293 | .release = single_release, |
| 294 | }; |
| 295 | |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 296 | static const struct file_operations mcs_statistics_fops = { |
| 297 | .open = mcs_statistics_open, |
| 298 | .read = seq_read, |
| 299 | .write = mcs_statistics_write, |
| 300 | .llseek = seq_lseek, |
| 301 | .release = single_release, |
| 302 | }; |
| 303 | |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 304 | static const struct file_operations options_fops = { |
| 305 | .open = options_open, |
| 306 | .read = seq_read, |
| 307 | .write = options_write, |
| 308 | .llseek = seq_lseek, |
| 309 | .release = single_release, |
| 310 | }; |
| 311 | |
| 312 | static const struct file_operations cch_fops = { |
| 313 | .open = cch_open, |
| 314 | .read = seq_read, |
| 315 | .llseek = seq_lseek, |
| 316 | .release = seq_release, |
| 317 | }; |
| 318 | static const struct file_operations gru_fops = { |
| 319 | .open = gru_open, |
| 320 | .read = seq_read, |
| 321 | .llseek = seq_lseek, |
| 322 | .release = seq_release, |
| 323 | }; |
| 324 | |
| 325 | static struct proc_entry { |
| 326 | char *name; |
| 327 | int mode; |
| 328 | const struct file_operations *fops; |
| 329 | struct proc_dir_entry *entry; |
| 330 | } proc_files[] = { |
| 331 | {"statistics", 0644, &statistics_fops}, |
Jack Steiner | e56484d | 2009-04-02 16:59:06 -0700 | [diff] [blame] | 332 | {"mcs_statistics", 0644, &mcs_statistics_fops}, |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 333 | {"debug_options", 0644, &options_fops}, |
| 334 | {"cch_status", 0444, &cch_fops}, |
| 335 | {"gru_status", 0444, &gru_fops}, |
| 336 | {NULL} |
| 337 | }; |
| 338 | /* *INDENT-ON* */ |
| 339 | |
| 340 | static struct proc_dir_entry *proc_gru __read_mostly; |
| 341 | |
| 342 | static int create_proc_file(struct proc_entry *p) |
| 343 | { |
Alexey Dobriyan | f8679af | 2009-09-23 15:57:33 -0700 | [diff] [blame] | 344 | p->entry = proc_create(p->name, p->mode, proc_gru, p->fops); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 345 | if (!p->entry) |
| 346 | return -1; |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static void delete_proc_files(void) |
| 351 | { |
| 352 | struct proc_entry *p; |
| 353 | |
| 354 | if (proc_gru) { |
| 355 | for (p = proc_files; p->name; p++) |
| 356 | if (p->entry) |
| 357 | remove_proc_entry(p->name, proc_gru); |
Jack Steiner | f2965d6 | 2009-12-15 16:48:06 -0800 | [diff] [blame] | 358 | remove_proc_entry("gru", proc_gru->parent); |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | int gru_proc_init(void) |
| 363 | { |
| 364 | struct proc_entry *p; |
| 365 | |
Jack Steiner | 1d09d73 | 2008-07-29 22:33:59 -0700 | [diff] [blame] | 366 | proc_gru = proc_mkdir("sgi_uv/gru", NULL); |
| 367 | |
| 368 | for (p = proc_files; p->name; p++) |
| 369 | if (create_proc_file(p)) |
| 370 | goto err; |
| 371 | return 0; |
| 372 | |
| 373 | err: |
| 374 | delete_proc_files(); |
| 375 | return -1; |
| 376 | } |
| 377 | |
| 378 | void gru_proc_exit(void) |
| 379 | { |
| 380 | delete_proc_files(); |
| 381 | } |