11d09d737SJack Steiner /* 21d09d737SJack Steiner * SN Platform GRU Driver 31d09d737SJack Steiner * 41d09d737SJack Steiner * PROC INTERFACES 51d09d737SJack Steiner * 61d09d737SJack Steiner * This file supports the /proc interfaces for the GRU driver 71d09d737SJack Steiner * 81d09d737SJack Steiner * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved. 91d09d737SJack Steiner * 101d09d737SJack Steiner * This program is free software; you can redistribute it and/or modify 111d09d737SJack Steiner * it under the terms of the GNU General Public License as published by 121d09d737SJack Steiner * the Free Software Foundation; either version 2 of the License, or 131d09d737SJack Steiner * (at your option) any later version. 141d09d737SJack Steiner * 151d09d737SJack Steiner * This program is distributed in the hope that it will be useful, 161d09d737SJack Steiner * but WITHOUT ANY WARRANTY; without even the implied warranty of 171d09d737SJack Steiner * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 181d09d737SJack Steiner * GNU General Public License for more details. 191d09d737SJack Steiner * 201d09d737SJack Steiner * You should have received a copy of the GNU General Public License 211d09d737SJack Steiner * along with this program; if not, write to the Free Software 221d09d737SJack Steiner * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 231d09d737SJack Steiner */ 241d09d737SJack Steiner 251d09d737SJack Steiner #include <linux/proc_fs.h> 261d09d737SJack Steiner #include <linux/device.h> 271d09d737SJack Steiner #include <linux/seq_file.h> 281d09d737SJack Steiner #include <linux/uaccess.h> 291d09d737SJack Steiner #include "gru.h" 301d09d737SJack Steiner #include "grulib.h" 311d09d737SJack Steiner #include "grutables.h" 321d09d737SJack Steiner 331d09d737SJack Steiner #define printstat(s, f) printstat_val(s, &gru_stats.f, #f) 341d09d737SJack Steiner 351d09d737SJack Steiner static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id) 361d09d737SJack Steiner { 371d09d737SJack Steiner unsigned long val = atomic_long_read(v); 381d09d737SJack Steiner 391d09d737SJack Steiner seq_printf(s, "%16lu %s\n", val, id); 401d09d737SJack Steiner } 411d09d737SJack Steiner 421d09d737SJack Steiner static int statistics_show(struct seq_file *s, void *p) 431d09d737SJack Steiner { 441d09d737SJack Steiner printstat(s, vdata_alloc); 451d09d737SJack Steiner printstat(s, vdata_free); 461d09d737SJack Steiner printstat(s, gts_alloc); 471d09d737SJack Steiner printstat(s, gts_free); 48563447d7SJack Steiner printstat(s, gms_alloc); 49563447d7SJack Steiner printstat(s, gms_free); 501d09d737SJack Steiner printstat(s, gts_double_allocate); 511d09d737SJack Steiner printstat(s, assign_context); 521d09d737SJack Steiner printstat(s, assign_context_failed); 531d09d737SJack Steiner printstat(s, free_context); 54836ce679SJack Steiner printstat(s, load_user_context); 55836ce679SJack Steiner printstat(s, load_kernel_context); 56836ce679SJack Steiner printstat(s, lock_kernel_context); 57836ce679SJack Steiner printstat(s, unlock_kernel_context); 58836ce679SJack Steiner printstat(s, steal_user_context); 59836ce679SJack Steiner printstat(s, steal_kernel_context); 601d09d737SJack Steiner printstat(s, steal_context_failed); 611d09d737SJack Steiner printstat(s, nopfn); 621d09d737SJack Steiner printstat(s, asid_new); 631d09d737SJack Steiner printstat(s, asid_next); 641d09d737SJack Steiner printstat(s, asid_wrap); 651d09d737SJack Steiner printstat(s, asid_reuse); 661d09d737SJack Steiner printstat(s, intr); 67563447d7SJack Steiner printstat(s, intr_cbr); 68563447d7SJack Steiner printstat(s, intr_tfh); 692ce4d4c9SJack Steiner printstat(s, intr_spurious); 7043884604SJack Steiner printstat(s, intr_mm_lock_failed); 711d09d737SJack Steiner printstat(s, call_os); 721d09d737SJack Steiner printstat(s, call_os_wait_queue); 731d09d737SJack Steiner printstat(s, user_flush_tlb); 741d09d737SJack Steiner printstat(s, user_unload_context); 751d09d737SJack Steiner printstat(s, user_exception); 7692b39388SJack Steiner printstat(s, set_context_option); 7755484c45SJack Steiner printstat(s, check_context_retarget_intr); 7855484c45SJack Steiner printstat(s, check_context_unload); 791d09d737SJack Steiner printstat(s, tlb_dropin); 80c550222fSJack Steiner printstat(s, tlb_preload_page); 811d09d737SJack Steiner printstat(s, tlb_dropin_fail_no_asid); 821d09d737SJack Steiner printstat(s, tlb_dropin_fail_upm); 831d09d737SJack Steiner printstat(s, tlb_dropin_fail_invalid); 841d09d737SJack Steiner printstat(s, tlb_dropin_fail_range_active); 851d09d737SJack Steiner printstat(s, tlb_dropin_fail_idle); 861d09d737SJack Steiner printstat(s, tlb_dropin_fail_fmm); 87cd1334f0SJack Steiner printstat(s, tlb_dropin_fail_no_exception); 88270952a9SJack Steiner printstat(s, tfh_stale_on_fault); 891d09d737SJack Steiner printstat(s, mmu_invalidate_range); 901d09d737SJack Steiner printstat(s, mmu_invalidate_page); 911d09d737SJack Steiner printstat(s, flush_tlb); 921d09d737SJack Steiner printstat(s, flush_tlb_gru); 931d09d737SJack Steiner printstat(s, flush_tlb_gru_tgh); 941d09d737SJack Steiner printstat(s, flush_tlb_gru_zero_asid); 951d09d737SJack Steiner printstat(s, copy_gpa); 96289750d1SRobin Holt printstat(s, read_gpa); 971d09d737SJack Steiner printstat(s, mesq_receive); 981d09d737SJack Steiner printstat(s, mesq_receive_none); 991d09d737SJack Steiner printstat(s, mesq_send); 1001d09d737SJack Steiner printstat(s, mesq_send_failed); 1011d09d737SJack Steiner printstat(s, mesq_noop); 1021d09d737SJack Steiner printstat(s, mesq_send_unexpected_error); 1031d09d737SJack Steiner printstat(s, mesq_send_lb_overflow); 1041d09d737SJack Steiner printstat(s, mesq_send_qlimit_reached); 1051d09d737SJack Steiner printstat(s, mesq_send_amo_nacked); 1061d09d737SJack Steiner printstat(s, mesq_send_put_nacked); 1071d09d737SJack Steiner printstat(s, mesq_qf_locked); 1081d09d737SJack Steiner printstat(s, mesq_qf_noop_not_full); 1091d09d737SJack Steiner printstat(s, mesq_qf_switch_head_failed); 1101d09d737SJack Steiner printstat(s, mesq_qf_unexpected_error); 1111d09d737SJack Steiner printstat(s, mesq_noop_unexpected_error); 1121d09d737SJack Steiner printstat(s, mesq_noop_lb_overflow); 1131d09d737SJack Steiner printstat(s, mesq_noop_qlimit_reached); 1141d09d737SJack Steiner printstat(s, mesq_noop_amo_nacked); 1151d09d737SJack Steiner printstat(s, mesq_noop_put_nacked); 116563447d7SJack Steiner printstat(s, mesq_noop_page_overflow); 1171d09d737SJack Steiner return 0; 1181d09d737SJack Steiner } 1191d09d737SJack Steiner 1201d09d737SJack Steiner static ssize_t statistics_write(struct file *file, const char __user *userbuf, 1211d09d737SJack Steiner size_t count, loff_t *data) 1221d09d737SJack Steiner { 1231d09d737SJack Steiner memset(&gru_stats, 0, sizeof(gru_stats)); 1241d09d737SJack Steiner return count; 1251d09d737SJack Steiner } 1261d09d737SJack Steiner 127e56484daSJack Steiner static int mcs_statistics_show(struct seq_file *s, void *p) 128e56484daSJack Steiner { 129e56484daSJack Steiner int op; 130e56484daSJack Steiner unsigned long total, count, max; 131e56484daSJack Steiner static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt", 132c550222fSJack Steiner "cch_interrupt_sync", "cch_deallocate", "tfh_write_only", 133c550222fSJack Steiner "tfh_write_restart", "tgh_invalidate"}; 134e56484daSJack Steiner 135563447d7SJack Steiner seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks"); 136e56484daSJack Steiner for (op = 0; op < mcsop_last; op++) { 137e56484daSJack Steiner count = atomic_long_read(&mcs_op_statistics[op].count); 138e56484daSJack Steiner total = atomic_long_read(&mcs_op_statistics[op].total); 139e56484daSJack Steiner max = mcs_op_statistics[op].max; 140e56484daSJack Steiner seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count, 141e56484daSJack Steiner count ? total / count : 0, max); 142e56484daSJack Steiner } 143e56484daSJack Steiner return 0; 144e56484daSJack Steiner } 145e56484daSJack Steiner 146e56484daSJack Steiner static ssize_t mcs_statistics_write(struct file *file, 147e56484daSJack Steiner const char __user *userbuf, size_t count, loff_t *data) 148e56484daSJack Steiner { 149e56484daSJack Steiner memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics)); 150e56484daSJack Steiner return count; 151e56484daSJack Steiner } 152e56484daSJack Steiner 1531d09d737SJack Steiner static int options_show(struct seq_file *s, void *p) 1541d09d737SJack Steiner { 155563447d7SJack Steiner seq_printf(s, "#bitmask: 1=trace, 2=statistics\n"); 1569ca8e40cSJack Steiner seq_printf(s, "0x%lx\n", gru_options); 1571d09d737SJack Steiner return 0; 1581d09d737SJack Steiner } 1591d09d737SJack Steiner 1601d09d737SJack Steiner static ssize_t options_write(struct file *file, const char __user *userbuf, 1611d09d737SJack Steiner size_t count, loff_t *data) 1621d09d737SJack Steiner { 163f7b41276SJingoo Han int ret; 1641d09d737SJack Steiner 165f7b41276SJingoo Han ret = kstrtoul_from_user(userbuf, count, 0, &gru_options); 166f7b41276SJingoo Han if (ret) 167f7b41276SJingoo Han return ret; 1681d09d737SJack Steiner 1691d09d737SJack Steiner return count; 1701d09d737SJack Steiner } 1711d09d737SJack Steiner 1721d09d737SJack Steiner static int cch_seq_show(struct seq_file *file, void *data) 1731d09d737SJack Steiner { 1741d09d737SJack Steiner long gid = *(long *)data; 1751d09d737SJack Steiner int i; 1761d09d737SJack Steiner struct gru_state *gru = GID_TO_GRU(gid); 1771d09d737SJack Steiner struct gru_thread_state *ts; 1781d09d737SJack Steiner const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" }; 1791d09d737SJack Steiner 1801d09d737SJack Steiner if (gid == 0) 181563447d7SJack Steiner seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid", 182563447d7SJack Steiner "ctx#", "asid", "pid", "cbrs", "dsbytes", "mode"); 1831d09d737SJack Steiner if (gru) 1841d09d737SJack Steiner for (i = 0; i < GRU_NUM_CCH; i++) { 1851d09d737SJack Steiner ts = gru->gs_gts[i]; 1861d09d737SJack Steiner if (!ts) 1871d09d737SJack Steiner continue; 188563447d7SJack Steiner seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n", 1891d09d737SJack Steiner gru->gs_gid, gru->gs_blade_id, i, 190563447d7SJack Steiner is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid, 191563447d7SJack Steiner is_kernel_context(ts) ? 0 : ts->ts_tgid_owner, 1921d09d737SJack Steiner ts->ts_cbr_au_count * GRU_CBR_AU_SIZE, 1931d09d737SJack Steiner ts->ts_cbr_au_count * GRU_DSR_AU_BYTES, 1941d09d737SJack Steiner mode[ts->ts_user_options & 1951d09d737SJack Steiner GRU_OPT_MISS_MASK]); 1961d09d737SJack Steiner } 1971d09d737SJack Steiner 1981d09d737SJack Steiner return 0; 1991d09d737SJack Steiner } 2001d09d737SJack Steiner 2011d09d737SJack Steiner static int gru_seq_show(struct seq_file *file, void *data) 2021d09d737SJack Steiner { 2031d09d737SJack Steiner long gid = *(long *)data, ctxfree, cbrfree, dsrfree; 2041d09d737SJack Steiner struct gru_state *gru = GID_TO_GRU(gid); 2051d09d737SJack Steiner 2061d09d737SJack Steiner if (gid == 0) { 2071d09d737SJack Steiner seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid", 2081d09d737SJack Steiner "ctx", "cbr", "dsr", "ctx", "cbr", "dsr"); 2091d09d737SJack Steiner seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy", 2101d09d737SJack Steiner "busy", "busy", "free", "free", "free"); 2111d09d737SJack Steiner } 2121d09d737SJack Steiner if (gru) { 2131d09d737SJack Steiner ctxfree = GRU_NUM_CCH - gru->gs_active_contexts; 2141d09d737SJack Steiner cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE; 2151d09d737SJack Steiner dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES; 2161d09d737SJack Steiner seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n", 2171d09d737SJack Steiner gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree, 2181d09d737SJack Steiner GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree, 2191d09d737SJack Steiner ctxfree, cbrfree, dsrfree); 2201d09d737SJack Steiner } 2211d09d737SJack Steiner 2221d09d737SJack Steiner return 0; 2231d09d737SJack Steiner } 2241d09d737SJack Steiner 2251d09d737SJack Steiner static void seq_stop(struct seq_file *file, void *data) 2261d09d737SJack Steiner { 2271d09d737SJack Steiner } 2281d09d737SJack Steiner 2291d09d737SJack Steiner static void *seq_start(struct seq_file *file, loff_t *gid) 2301d09d737SJack Steiner { 231e1c3219dSJack Steiner if (*gid < gru_max_gids) 2321d09d737SJack Steiner return gid; 2331d09d737SJack Steiner return NULL; 2341d09d737SJack Steiner } 2351d09d737SJack Steiner 2361d09d737SJack Steiner static void *seq_next(struct seq_file *file, void *data, loff_t *gid) 2371d09d737SJack Steiner { 2381d09d737SJack Steiner (*gid)++; 239e1c3219dSJack Steiner if (*gid < gru_max_gids) 2401d09d737SJack Steiner return gid; 2411d09d737SJack Steiner return NULL; 2421d09d737SJack Steiner } 2431d09d737SJack Steiner 2441d09d737SJack Steiner static const struct seq_operations cch_seq_ops = { 2451d09d737SJack Steiner .start = seq_start, 2461d09d737SJack Steiner .next = seq_next, 2471d09d737SJack Steiner .stop = seq_stop, 2481d09d737SJack Steiner .show = cch_seq_show 2491d09d737SJack Steiner }; 2501d09d737SJack Steiner 2511d09d737SJack Steiner static const struct seq_operations gru_seq_ops = { 2521d09d737SJack Steiner .start = seq_start, 2531d09d737SJack Steiner .next = seq_next, 2541d09d737SJack Steiner .stop = seq_stop, 2551d09d737SJack Steiner .show = gru_seq_show 2561d09d737SJack Steiner }; 2571d09d737SJack Steiner 2581d09d737SJack Steiner static int statistics_open(struct inode *inode, struct file *file) 2591d09d737SJack Steiner { 2601d09d737SJack Steiner return single_open(file, statistics_show, NULL); 2611d09d737SJack Steiner } 2621d09d737SJack Steiner 263e56484daSJack Steiner static int mcs_statistics_open(struct inode *inode, struct file *file) 264e56484daSJack Steiner { 265e56484daSJack Steiner return single_open(file, mcs_statistics_show, NULL); 266e56484daSJack Steiner } 267e56484daSJack Steiner 2681d09d737SJack Steiner static int options_open(struct inode *inode, struct file *file) 2691d09d737SJack Steiner { 2701d09d737SJack Steiner return single_open(file, options_show, NULL); 2711d09d737SJack Steiner } 2721d09d737SJack Steiner 2731d09d737SJack Steiner /* *INDENT-OFF* */ 2741d09d737SJack Steiner static const struct file_operations statistics_fops = { 2751d09d737SJack Steiner .open = statistics_open, 2761d09d737SJack Steiner .read = seq_read, 2771d09d737SJack Steiner .write = statistics_write, 2781d09d737SJack Steiner .llseek = seq_lseek, 2791d09d737SJack Steiner .release = single_release, 2801d09d737SJack Steiner }; 2811d09d737SJack Steiner 282e56484daSJack Steiner static const struct file_operations mcs_statistics_fops = { 283e56484daSJack Steiner .open = mcs_statistics_open, 284e56484daSJack Steiner .read = seq_read, 285e56484daSJack Steiner .write = mcs_statistics_write, 286e56484daSJack Steiner .llseek = seq_lseek, 287e56484daSJack Steiner .release = single_release, 288e56484daSJack Steiner }; 289e56484daSJack Steiner 2901d09d737SJack Steiner static const struct file_operations options_fops = { 2911d09d737SJack Steiner .open = options_open, 2921d09d737SJack Steiner .read = seq_read, 2931d09d737SJack Steiner .write = options_write, 2941d09d737SJack Steiner .llseek = seq_lseek, 2951d09d737SJack Steiner .release = single_release, 2961d09d737SJack Steiner }; 2971d09d737SJack Steiner 2981d09d737SJack Steiner static struct proc_dir_entry *proc_gru __read_mostly; 2991d09d737SJack Steiner 3001d09d737SJack Steiner int gru_proc_init(void) 3011d09d737SJack Steiner { 3021d09d737SJack Steiner proc_gru = proc_mkdir("sgi_uv/gru", NULL); 303*978547c5SChristoph Hellwig if (!proc_gru) 304*978547c5SChristoph Hellwig return -1; 305*978547c5SChristoph Hellwig if (!proc_create("statistics", 0644, proc_gru, &statistics_fops)) 306*978547c5SChristoph Hellwig goto err; 307*978547c5SChristoph Hellwig if (!proc_create("mcs_statistics", 0644, proc_gru, &mcs_statistics_fops)) 308*978547c5SChristoph Hellwig goto err; 309*978547c5SChristoph Hellwig if (!proc_create("debug_options", 0644, proc_gru, &options_fops)) 310*978547c5SChristoph Hellwig goto err; 311*978547c5SChristoph Hellwig if (!proc_create_seq("cch_status", 0444, proc_gru, &cch_seq_ops)) 312*978547c5SChristoph Hellwig goto err; 313*978547c5SChristoph Hellwig if (!proc_create_seq("gru_status", 0444, proc_gru, &gru_seq_ops)) 3141d09d737SJack Steiner goto err; 3151d09d737SJack Steiner return 0; 3161d09d737SJack Steiner err: 317*978547c5SChristoph Hellwig remove_proc_subtree("sgi_uv/gru", NULL); 3181d09d737SJack Steiner return -1; 3191d09d737SJack Steiner } 3201d09d737SJack Steiner 3211d09d737SJack Steiner void gru_proc_exit(void) 3221d09d737SJack Steiner { 323*978547c5SChristoph Hellwig remove_proc_subtree("sgi_uv/gru", NULL); 3241d09d737SJack Steiner } 325