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