18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * SN Platform GRU Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * PROC INTERFACES 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This file supports the /proc interfaces for the GRU driver 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/proc_fs.h> 138c2ecf20Sopenharmony_ci#include <linux/device.h> 148c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 158c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 168c2ecf20Sopenharmony_ci#include "gru.h" 178c2ecf20Sopenharmony_ci#include "grulib.h" 188c2ecf20Sopenharmony_ci#include "grutables.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define printstat(s, f) printstat_val(s, &gru_stats.f, #f) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic void printstat_val(struct seq_file *s, atomic_long_t *v, char *id) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci unsigned long val = atomic_long_read(v); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci seq_printf(s, "%16lu %s\n", val, id); 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic int statistics_show(struct seq_file *s, void *p) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci printstat(s, vdata_alloc); 328c2ecf20Sopenharmony_ci printstat(s, vdata_free); 338c2ecf20Sopenharmony_ci printstat(s, gts_alloc); 348c2ecf20Sopenharmony_ci printstat(s, gts_free); 358c2ecf20Sopenharmony_ci printstat(s, gms_alloc); 368c2ecf20Sopenharmony_ci printstat(s, gms_free); 378c2ecf20Sopenharmony_ci printstat(s, gts_double_allocate); 388c2ecf20Sopenharmony_ci printstat(s, assign_context); 398c2ecf20Sopenharmony_ci printstat(s, assign_context_failed); 408c2ecf20Sopenharmony_ci printstat(s, free_context); 418c2ecf20Sopenharmony_ci printstat(s, load_user_context); 428c2ecf20Sopenharmony_ci printstat(s, load_kernel_context); 438c2ecf20Sopenharmony_ci printstat(s, lock_kernel_context); 448c2ecf20Sopenharmony_ci printstat(s, unlock_kernel_context); 458c2ecf20Sopenharmony_ci printstat(s, steal_user_context); 468c2ecf20Sopenharmony_ci printstat(s, steal_kernel_context); 478c2ecf20Sopenharmony_ci printstat(s, steal_context_failed); 488c2ecf20Sopenharmony_ci printstat(s, nopfn); 498c2ecf20Sopenharmony_ci printstat(s, asid_new); 508c2ecf20Sopenharmony_ci printstat(s, asid_next); 518c2ecf20Sopenharmony_ci printstat(s, asid_wrap); 528c2ecf20Sopenharmony_ci printstat(s, asid_reuse); 538c2ecf20Sopenharmony_ci printstat(s, intr); 548c2ecf20Sopenharmony_ci printstat(s, intr_cbr); 558c2ecf20Sopenharmony_ci printstat(s, intr_tfh); 568c2ecf20Sopenharmony_ci printstat(s, intr_spurious); 578c2ecf20Sopenharmony_ci printstat(s, intr_mm_lock_failed); 588c2ecf20Sopenharmony_ci printstat(s, call_os); 598c2ecf20Sopenharmony_ci printstat(s, call_os_wait_queue); 608c2ecf20Sopenharmony_ci printstat(s, user_flush_tlb); 618c2ecf20Sopenharmony_ci printstat(s, user_unload_context); 628c2ecf20Sopenharmony_ci printstat(s, user_exception); 638c2ecf20Sopenharmony_ci printstat(s, set_context_option); 648c2ecf20Sopenharmony_ci printstat(s, check_context_retarget_intr); 658c2ecf20Sopenharmony_ci printstat(s, check_context_unload); 668c2ecf20Sopenharmony_ci printstat(s, tlb_dropin); 678c2ecf20Sopenharmony_ci printstat(s, tlb_preload_page); 688c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_no_asid); 698c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_upm); 708c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_invalid); 718c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_range_active); 728c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_idle); 738c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_fmm); 748c2ecf20Sopenharmony_ci printstat(s, tlb_dropin_fail_no_exception); 758c2ecf20Sopenharmony_ci printstat(s, tfh_stale_on_fault); 768c2ecf20Sopenharmony_ci printstat(s, mmu_invalidate_range); 778c2ecf20Sopenharmony_ci printstat(s, mmu_invalidate_page); 788c2ecf20Sopenharmony_ci printstat(s, flush_tlb); 798c2ecf20Sopenharmony_ci printstat(s, flush_tlb_gru); 808c2ecf20Sopenharmony_ci printstat(s, flush_tlb_gru_tgh); 818c2ecf20Sopenharmony_ci printstat(s, flush_tlb_gru_zero_asid); 828c2ecf20Sopenharmony_ci printstat(s, copy_gpa); 838c2ecf20Sopenharmony_ci printstat(s, read_gpa); 848c2ecf20Sopenharmony_ci printstat(s, mesq_receive); 858c2ecf20Sopenharmony_ci printstat(s, mesq_receive_none); 868c2ecf20Sopenharmony_ci printstat(s, mesq_send); 878c2ecf20Sopenharmony_ci printstat(s, mesq_send_failed); 888c2ecf20Sopenharmony_ci printstat(s, mesq_noop); 898c2ecf20Sopenharmony_ci printstat(s, mesq_send_unexpected_error); 908c2ecf20Sopenharmony_ci printstat(s, mesq_send_lb_overflow); 918c2ecf20Sopenharmony_ci printstat(s, mesq_send_qlimit_reached); 928c2ecf20Sopenharmony_ci printstat(s, mesq_send_amo_nacked); 938c2ecf20Sopenharmony_ci printstat(s, mesq_send_put_nacked); 948c2ecf20Sopenharmony_ci printstat(s, mesq_qf_locked); 958c2ecf20Sopenharmony_ci printstat(s, mesq_qf_noop_not_full); 968c2ecf20Sopenharmony_ci printstat(s, mesq_qf_switch_head_failed); 978c2ecf20Sopenharmony_ci printstat(s, mesq_qf_unexpected_error); 988c2ecf20Sopenharmony_ci printstat(s, mesq_noop_unexpected_error); 998c2ecf20Sopenharmony_ci printstat(s, mesq_noop_lb_overflow); 1008c2ecf20Sopenharmony_ci printstat(s, mesq_noop_qlimit_reached); 1018c2ecf20Sopenharmony_ci printstat(s, mesq_noop_amo_nacked); 1028c2ecf20Sopenharmony_ci printstat(s, mesq_noop_put_nacked); 1038c2ecf20Sopenharmony_ci printstat(s, mesq_noop_page_overflow); 1048c2ecf20Sopenharmony_ci return 0; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic ssize_t statistics_write(struct file *file, const char __user *userbuf, 1088c2ecf20Sopenharmony_ci size_t count, loff_t *data) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci memset(&gru_stats, 0, sizeof(gru_stats)); 1118c2ecf20Sopenharmony_ci return count; 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic int mcs_statistics_show(struct seq_file *s, void *p) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci int op; 1178c2ecf20Sopenharmony_ci unsigned long total, count, max; 1188c2ecf20Sopenharmony_ci static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt", 1198c2ecf20Sopenharmony_ci "cch_interrupt_sync", "cch_deallocate", "tfh_write_only", 1208c2ecf20Sopenharmony_ci "tfh_write_restart", "tgh_invalidate"}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci seq_puts(s, "#id count aver-clks max-clks\n"); 1238c2ecf20Sopenharmony_ci for (op = 0; op < mcsop_last; op++) { 1248c2ecf20Sopenharmony_ci count = atomic_long_read(&mcs_op_statistics[op].count); 1258c2ecf20Sopenharmony_ci total = atomic_long_read(&mcs_op_statistics[op].total); 1268c2ecf20Sopenharmony_ci max = mcs_op_statistics[op].max; 1278c2ecf20Sopenharmony_ci seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count, 1288c2ecf20Sopenharmony_ci count ? total / count : 0, max); 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci return 0; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic ssize_t mcs_statistics_write(struct file *file, 1348c2ecf20Sopenharmony_ci const char __user *userbuf, size_t count, loff_t *data) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics)); 1378c2ecf20Sopenharmony_ci return count; 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic int options_show(struct seq_file *s, void *p) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci seq_printf(s, "#bitmask: 1=trace, 2=statistics\n"); 1438c2ecf20Sopenharmony_ci seq_printf(s, "0x%lx\n", gru_options); 1448c2ecf20Sopenharmony_ci return 0; 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic ssize_t options_write(struct file *file, const char __user *userbuf, 1488c2ecf20Sopenharmony_ci size_t count, loff_t *data) 1498c2ecf20Sopenharmony_ci{ 1508c2ecf20Sopenharmony_ci int ret; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci ret = kstrtoul_from_user(userbuf, count, 0, &gru_options); 1538c2ecf20Sopenharmony_ci if (ret) 1548c2ecf20Sopenharmony_ci return ret; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci return count; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic int cch_seq_show(struct seq_file *file, void *data) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci long gid = *(long *)data; 1628c2ecf20Sopenharmony_ci int i; 1638c2ecf20Sopenharmony_ci struct gru_state *gru = GID_TO_GRU(gid); 1648c2ecf20Sopenharmony_ci struct gru_thread_state *ts; 1658c2ecf20Sopenharmony_ci const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" }; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci if (gid == 0) 1688c2ecf20Sopenharmony_ci seq_puts(file, "# gid bid ctx# asid pid cbrs dsbytes mode\n"); 1698c2ecf20Sopenharmony_ci if (gru) 1708c2ecf20Sopenharmony_ci for (i = 0; i < GRU_NUM_CCH; i++) { 1718c2ecf20Sopenharmony_ci ts = gru->gs_gts[i]; 1728c2ecf20Sopenharmony_ci if (!ts) 1738c2ecf20Sopenharmony_ci continue; 1748c2ecf20Sopenharmony_ci seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n", 1758c2ecf20Sopenharmony_ci gru->gs_gid, gru->gs_blade_id, i, 1768c2ecf20Sopenharmony_ci is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid, 1778c2ecf20Sopenharmony_ci is_kernel_context(ts) ? 0 : ts->ts_tgid_owner, 1788c2ecf20Sopenharmony_ci ts->ts_cbr_au_count * GRU_CBR_AU_SIZE, 1798c2ecf20Sopenharmony_ci ts->ts_cbr_au_count * GRU_DSR_AU_BYTES, 1808c2ecf20Sopenharmony_ci mode[ts->ts_user_options & 1818c2ecf20Sopenharmony_ci GRU_OPT_MISS_MASK]); 1828c2ecf20Sopenharmony_ci } 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci return 0; 1858c2ecf20Sopenharmony_ci} 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic int gru_seq_show(struct seq_file *file, void *data) 1888c2ecf20Sopenharmony_ci{ 1898c2ecf20Sopenharmony_ci long gid = *(long *)data, ctxfree, cbrfree, dsrfree; 1908c2ecf20Sopenharmony_ci struct gru_state *gru = GID_TO_GRU(gid); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci if (gid == 0) { 1938c2ecf20Sopenharmony_ci seq_puts(file, "# gid nid ctx cbr dsr ctx cbr dsr\n"); 1948c2ecf20Sopenharmony_ci seq_puts(file, "# busy busy busy free free free\n"); 1958c2ecf20Sopenharmony_ci } 1968c2ecf20Sopenharmony_ci if (gru) { 1978c2ecf20Sopenharmony_ci ctxfree = GRU_NUM_CCH - gru->gs_active_contexts; 1988c2ecf20Sopenharmony_ci cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE; 1998c2ecf20Sopenharmony_ci dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES; 2008c2ecf20Sopenharmony_ci seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n", 2018c2ecf20Sopenharmony_ci gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree, 2028c2ecf20Sopenharmony_ci GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree, 2038c2ecf20Sopenharmony_ci ctxfree, cbrfree, dsrfree); 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci return 0; 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic void seq_stop(struct seq_file *file, void *data) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic void *seq_start(struct seq_file *file, loff_t *gid) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci if (*gid < gru_max_gids) 2168c2ecf20Sopenharmony_ci return gid; 2178c2ecf20Sopenharmony_ci return NULL; 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cistatic void *seq_next(struct seq_file *file, void *data, loff_t *gid) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci (*gid)++; 2238c2ecf20Sopenharmony_ci if (*gid < gru_max_gids) 2248c2ecf20Sopenharmony_ci return gid; 2258c2ecf20Sopenharmony_ci return NULL; 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistatic const struct seq_operations cch_seq_ops = { 2298c2ecf20Sopenharmony_ci .start = seq_start, 2308c2ecf20Sopenharmony_ci .next = seq_next, 2318c2ecf20Sopenharmony_ci .stop = seq_stop, 2328c2ecf20Sopenharmony_ci .show = cch_seq_show 2338c2ecf20Sopenharmony_ci}; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistatic const struct seq_operations gru_seq_ops = { 2368c2ecf20Sopenharmony_ci .start = seq_start, 2378c2ecf20Sopenharmony_ci .next = seq_next, 2388c2ecf20Sopenharmony_ci .stop = seq_stop, 2398c2ecf20Sopenharmony_ci .show = gru_seq_show 2408c2ecf20Sopenharmony_ci}; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic int statistics_open(struct inode *inode, struct file *file) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci return single_open(file, statistics_show, NULL); 2458c2ecf20Sopenharmony_ci} 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic int mcs_statistics_open(struct inode *inode, struct file *file) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci return single_open(file, mcs_statistics_show, NULL); 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic int options_open(struct inode *inode, struct file *file) 2538c2ecf20Sopenharmony_ci{ 2548c2ecf20Sopenharmony_ci return single_open(file, options_show, NULL); 2558c2ecf20Sopenharmony_ci} 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/* *INDENT-OFF* */ 2588c2ecf20Sopenharmony_cistatic const struct proc_ops statistics_proc_ops = { 2598c2ecf20Sopenharmony_ci .proc_open = statistics_open, 2608c2ecf20Sopenharmony_ci .proc_read = seq_read, 2618c2ecf20Sopenharmony_ci .proc_write = statistics_write, 2628c2ecf20Sopenharmony_ci .proc_lseek = seq_lseek, 2638c2ecf20Sopenharmony_ci .proc_release = single_release, 2648c2ecf20Sopenharmony_ci}; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_cistatic const struct proc_ops mcs_statistics_proc_ops = { 2678c2ecf20Sopenharmony_ci .proc_open = mcs_statistics_open, 2688c2ecf20Sopenharmony_ci .proc_read = seq_read, 2698c2ecf20Sopenharmony_ci .proc_write = mcs_statistics_write, 2708c2ecf20Sopenharmony_ci .proc_lseek = seq_lseek, 2718c2ecf20Sopenharmony_ci .proc_release = single_release, 2728c2ecf20Sopenharmony_ci}; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_cistatic const struct proc_ops options_proc_ops = { 2758c2ecf20Sopenharmony_ci .proc_open = options_open, 2768c2ecf20Sopenharmony_ci .proc_read = seq_read, 2778c2ecf20Sopenharmony_ci .proc_write = options_write, 2788c2ecf20Sopenharmony_ci .proc_lseek = seq_lseek, 2798c2ecf20Sopenharmony_ci .proc_release = single_release, 2808c2ecf20Sopenharmony_ci}; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_cistatic struct proc_dir_entry *proc_gru __read_mostly; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ciint gru_proc_init(void) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci proc_gru = proc_mkdir("sgi_uv/gru", NULL); 2878c2ecf20Sopenharmony_ci if (!proc_gru) 2888c2ecf20Sopenharmony_ci return -1; 2898c2ecf20Sopenharmony_ci if (!proc_create("statistics", 0644, proc_gru, &statistics_proc_ops)) 2908c2ecf20Sopenharmony_ci goto err; 2918c2ecf20Sopenharmony_ci if (!proc_create("mcs_statistics", 0644, proc_gru, &mcs_statistics_proc_ops)) 2928c2ecf20Sopenharmony_ci goto err; 2938c2ecf20Sopenharmony_ci if (!proc_create("debug_options", 0644, proc_gru, &options_proc_ops)) 2948c2ecf20Sopenharmony_ci goto err; 2958c2ecf20Sopenharmony_ci if (!proc_create_seq("cch_status", 0444, proc_gru, &cch_seq_ops)) 2968c2ecf20Sopenharmony_ci goto err; 2978c2ecf20Sopenharmony_ci if (!proc_create_seq("gru_status", 0444, proc_gru, &gru_seq_ops)) 2988c2ecf20Sopenharmony_ci goto err; 2998c2ecf20Sopenharmony_ci return 0; 3008c2ecf20Sopenharmony_cierr: 3018c2ecf20Sopenharmony_ci remove_proc_subtree("sgi_uv/gru", NULL); 3028c2ecf20Sopenharmony_ci return -1; 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_civoid gru_proc_exit(void) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci remove_proc_subtree("sgi_uv/gru", NULL); 3088c2ecf20Sopenharmony_ci} 309