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); 54 printstat(s, load_context); 55 printstat(s, unload_context); 56 printstat(s, steal_context); 57 printstat(s, steal_context_failed); 58 printstat(s, nopfn); 59 printstat(s, break_cow); 60 printstat(s, asid_new); 61 printstat(s, asid_next); 62 printstat(s, asid_wrap); 63 printstat(s, asid_reuse); 64 printstat(s, intr); 65 printstat(s, intr_mm_lock_failed); 66 printstat(s, call_os); 67 printstat(s, call_os_offnode_reference); 68 printstat(s, call_os_check_for_bug); 69 printstat(s, call_os_wait_queue); 70 printstat(s, user_flush_tlb); 71 printstat(s, user_unload_context); 72 printstat(s, user_exception); 73 printstat(s, set_task_slice); 74 printstat(s, migrate_check); 75 printstat(s, migrated_retarget); 76 printstat(s, migrated_unload); 77 printstat(s, migrated_unload_delay); 78 printstat(s, migrated_nopfn_retarget); 79 printstat(s, migrated_nopfn_unload); 80 printstat(s, tlb_dropin); 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); 87 printstat(s, tlb_dropin_fail_no_exception); 88 printstat(s, tlb_dropin_fail_no_exception_war); 89 printstat(s, mmu_invalidate_range); 90 printstat(s, mmu_invalidate_page); 91 printstat(s, mmu_clear_flush_young); 92 printstat(s, flush_tlb); 93 printstat(s, flush_tlb_gru); 94 printstat(s, flush_tlb_gru_tgh); 95 printstat(s, flush_tlb_gru_zero_asid); 96 printstat(s, copy_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 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 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", 132 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"}; 133 134 for (op = 0; op < mcsop_last; op++) { 135 count = atomic_long_read(&mcs_op_statistics[op].count); 136 total = atomic_long_read(&mcs_op_statistics[op].total); 137 max = mcs_op_statistics[op].max; 138 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count, 139 count ? total / count : 0, max); 140 } 141 return 0; 142 } 143 144 static ssize_t mcs_statistics_write(struct file *file, 145 const char __user *userbuf, size_t count, loff_t *data) 146 { 147 memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics)); 148 return count; 149 } 150 151 static int options_show(struct seq_file *s, void *p) 152 { 153 seq_printf(s, "0x%lx\n", gru_options); 154 return 0; 155 } 156 157 static ssize_t options_write(struct file *file, const char __user *userbuf, 158 size_t count, loff_t *data) 159 { 160 unsigned long val; 161 char buf[80]; 162 163 if (strncpy_from_user(buf, userbuf, sizeof(buf) - 1) < 0) 164 return -EFAULT; 165 buf[count - 1] = '\0'; 166 if (!strict_strtoul(buf, 10, &val)) 167 gru_options = val; 168 169 return count; 170 } 171 172 static int cch_seq_show(struct seq_file *file, void *data) 173 { 174 long gid = *(long *)data; 175 int i; 176 struct gru_state *gru = GID_TO_GRU(gid); 177 struct gru_thread_state *ts; 178 const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" }; 179 180 if (gid == 0) 181 seq_printf(file, "#%5s%5s%6s%9s%6s%8s%8s\n", "gid", "bid", 182 "ctx#", "pid", "cbrs", "dsbytes", "mode"); 183 if (gru) 184 for (i = 0; i < GRU_NUM_CCH; i++) { 185 ts = gru->gs_gts[i]; 186 if (!ts) 187 continue; 188 seq_printf(file, " %5d%5d%6d%9d%6d%8d%8s\n", 189 gru->gs_gid, gru->gs_blade_id, i, 190 ts->ts_tgid_owner, 191 ts->ts_cbr_au_count * GRU_CBR_AU_SIZE, 192 ts->ts_cbr_au_count * GRU_DSR_AU_BYTES, 193 mode[ts->ts_user_options & 194 GRU_OPT_MISS_MASK]); 195 } 196 197 return 0; 198 } 199 200 static int gru_seq_show(struct seq_file *file, void *data) 201 { 202 long gid = *(long *)data, ctxfree, cbrfree, dsrfree; 203 struct gru_state *gru = GID_TO_GRU(gid); 204 205 if (gid == 0) { 206 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid", 207 "ctx", "cbr", "dsr", "ctx", "cbr", "dsr"); 208 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy", 209 "busy", "busy", "free", "free", "free"); 210 } 211 if (gru) { 212 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts; 213 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE; 214 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES; 215 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n", 216 gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree, 217 GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree, 218 ctxfree, cbrfree, dsrfree); 219 } 220 221 return 0; 222 } 223 224 static void seq_stop(struct seq_file *file, void *data) 225 { 226 } 227 228 static void *seq_start(struct seq_file *file, loff_t *gid) 229 { 230 if (*gid < gru_max_gids) 231 return gid; 232 return NULL; 233 } 234 235 static void *seq_next(struct seq_file *file, void *data, loff_t *gid) 236 { 237 (*gid)++; 238 if (*gid < gru_max_gids) 239 return gid; 240 return NULL; 241 } 242 243 static const struct seq_operations cch_seq_ops = { 244 .start = seq_start, 245 .next = seq_next, 246 .stop = seq_stop, 247 .show = cch_seq_show 248 }; 249 250 static const struct seq_operations gru_seq_ops = { 251 .start = seq_start, 252 .next = seq_next, 253 .stop = seq_stop, 254 .show = gru_seq_show 255 }; 256 257 static int statistics_open(struct inode *inode, struct file *file) 258 { 259 return single_open(file, statistics_show, NULL); 260 } 261 262 static int mcs_statistics_open(struct inode *inode, struct file *file) 263 { 264 return single_open(file, mcs_statistics_show, NULL); 265 } 266 267 static int options_open(struct inode *inode, struct file *file) 268 { 269 return single_open(file, options_show, NULL); 270 } 271 272 static int cch_open(struct inode *inode, struct file *file) 273 { 274 return seq_open(file, &cch_seq_ops); 275 } 276 277 static int gru_open(struct inode *inode, struct file *file) 278 { 279 return seq_open(file, &gru_seq_ops); 280 } 281 282 /* *INDENT-OFF* */ 283 static const struct file_operations statistics_fops = { 284 .open = statistics_open, 285 .read = seq_read, 286 .write = statistics_write, 287 .llseek = seq_lseek, 288 .release = single_release, 289 }; 290 291 static const struct file_operations mcs_statistics_fops = { 292 .open = mcs_statistics_open, 293 .read = seq_read, 294 .write = mcs_statistics_write, 295 .llseek = seq_lseek, 296 .release = single_release, 297 }; 298 299 static const struct file_operations options_fops = { 300 .open = options_open, 301 .read = seq_read, 302 .write = options_write, 303 .llseek = seq_lseek, 304 .release = single_release, 305 }; 306 307 static const struct file_operations cch_fops = { 308 .open = cch_open, 309 .read = seq_read, 310 .llseek = seq_lseek, 311 .release = seq_release, 312 }; 313 static const struct file_operations gru_fops = { 314 .open = gru_open, 315 .read = seq_read, 316 .llseek = seq_lseek, 317 .release = seq_release, 318 }; 319 320 static struct proc_entry { 321 char *name; 322 int mode; 323 const struct file_operations *fops; 324 struct proc_dir_entry *entry; 325 } proc_files[] = { 326 {"statistics", 0644, &statistics_fops}, 327 {"mcs_statistics", 0644, &mcs_statistics_fops}, 328 {"debug_options", 0644, &options_fops}, 329 {"cch_status", 0444, &cch_fops}, 330 {"gru_status", 0444, &gru_fops}, 331 {NULL} 332 }; 333 /* *INDENT-ON* */ 334 335 static struct proc_dir_entry *proc_gru __read_mostly; 336 337 static int create_proc_file(struct proc_entry *p) 338 { 339 p->entry = create_proc_entry(p->name, p->mode, proc_gru); 340 if (!p->entry) 341 return -1; 342 p->entry->proc_fops = p->fops; 343 return 0; 344 } 345 346 static void delete_proc_files(void) 347 { 348 struct proc_entry *p; 349 350 if (proc_gru) { 351 for (p = proc_files; p->name; p++) 352 if (p->entry) 353 remove_proc_entry(p->name, proc_gru); 354 remove_proc_entry("gru", NULL); 355 } 356 } 357 358 int gru_proc_init(void) 359 { 360 struct proc_entry *p; 361 362 proc_gru = proc_mkdir("sgi_uv/gru", NULL); 363 364 for (p = proc_files; p->name; p++) 365 if (create_proc_file(p)) 366 goto err; 367 return 0; 368 369 err: 370 delete_proc_files(); 371 return -1; 372 } 373 374 void gru_proc_exit(void) 375 { 376 delete_proc_files(); 377 } 378