Path: blob/master/drivers/misc/sgi-gru/gruprocfs.c
15112 views
/*1* SN Platform GRU Driver2*3* PROC INTERFACES4*5* This file supports the /proc interfaces for the GRU driver6*7* Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*/2324#include <linux/proc_fs.h>25#include <linux/device.h>26#include <linux/seq_file.h>27#include <linux/uaccess.h>28#include "gru.h"29#include "grulib.h"30#include "grutables.h"3132#define printstat(s, f) printstat_val(s, &gru_stats.f, #f)3334static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)35{36unsigned long val = atomic_long_read(v);3738seq_printf(s, "%16lu %s\n", val, id);39}4041static int statistics_show(struct seq_file *s, void *p)42{43printstat(s, vdata_alloc);44printstat(s, vdata_free);45printstat(s, gts_alloc);46printstat(s, gts_free);47printstat(s, gms_alloc);48printstat(s, gms_free);49printstat(s, gts_double_allocate);50printstat(s, assign_context);51printstat(s, assign_context_failed);52printstat(s, free_context);53printstat(s, load_user_context);54printstat(s, load_kernel_context);55printstat(s, lock_kernel_context);56printstat(s, unlock_kernel_context);57printstat(s, steal_user_context);58printstat(s, steal_kernel_context);59printstat(s, steal_context_failed);60printstat(s, nopfn);61printstat(s, asid_new);62printstat(s, asid_next);63printstat(s, asid_wrap);64printstat(s, asid_reuse);65printstat(s, intr);66printstat(s, intr_cbr);67printstat(s, intr_tfh);68printstat(s, intr_spurious);69printstat(s, intr_mm_lock_failed);70printstat(s, call_os);71printstat(s, call_os_wait_queue);72printstat(s, user_flush_tlb);73printstat(s, user_unload_context);74printstat(s, user_exception);75printstat(s, set_context_option);76printstat(s, check_context_retarget_intr);77printstat(s, check_context_unload);78printstat(s, tlb_dropin);79printstat(s, tlb_preload_page);80printstat(s, tlb_dropin_fail_no_asid);81printstat(s, tlb_dropin_fail_upm);82printstat(s, tlb_dropin_fail_invalid);83printstat(s, tlb_dropin_fail_range_active);84printstat(s, tlb_dropin_fail_idle);85printstat(s, tlb_dropin_fail_fmm);86printstat(s, tlb_dropin_fail_no_exception);87printstat(s, tfh_stale_on_fault);88printstat(s, mmu_invalidate_range);89printstat(s, mmu_invalidate_page);90printstat(s, flush_tlb);91printstat(s, flush_tlb_gru);92printstat(s, flush_tlb_gru_tgh);93printstat(s, flush_tlb_gru_zero_asid);94printstat(s, copy_gpa);95printstat(s, read_gpa);96printstat(s, mesq_receive);97printstat(s, mesq_receive_none);98printstat(s, mesq_send);99printstat(s, mesq_send_failed);100printstat(s, mesq_noop);101printstat(s, mesq_send_unexpected_error);102printstat(s, mesq_send_lb_overflow);103printstat(s, mesq_send_qlimit_reached);104printstat(s, mesq_send_amo_nacked);105printstat(s, mesq_send_put_nacked);106printstat(s, mesq_qf_locked);107printstat(s, mesq_qf_noop_not_full);108printstat(s, mesq_qf_switch_head_failed);109printstat(s, mesq_qf_unexpected_error);110printstat(s, mesq_noop_unexpected_error);111printstat(s, mesq_noop_lb_overflow);112printstat(s, mesq_noop_qlimit_reached);113printstat(s, mesq_noop_amo_nacked);114printstat(s, mesq_noop_put_nacked);115printstat(s, mesq_noop_page_overflow);116return 0;117}118119static ssize_t statistics_write(struct file *file, const char __user *userbuf,120size_t count, loff_t *data)121{122memset(&gru_stats, 0, sizeof(gru_stats));123return count;124}125126static int mcs_statistics_show(struct seq_file *s, void *p)127{128int op;129unsigned long total, count, max;130static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",131"cch_interrupt_sync", "cch_deallocate", "tfh_write_only",132"tfh_write_restart", "tgh_invalidate"};133134seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");135for (op = 0; op < mcsop_last; op++) {136count = atomic_long_read(&mcs_op_statistics[op].count);137total = atomic_long_read(&mcs_op_statistics[op].total);138max = mcs_op_statistics[op].max;139seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,140count ? total / count : 0, max);141}142return 0;143}144145static ssize_t mcs_statistics_write(struct file *file,146const char __user *userbuf, size_t count, loff_t *data)147{148memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));149return count;150}151152static int options_show(struct seq_file *s, void *p)153{154seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");155seq_printf(s, "0x%lx\n", gru_options);156return 0;157}158159static ssize_t options_write(struct file *file, const char __user *userbuf,160size_t count, loff_t *data)161{162char buf[20];163164if (count >= sizeof(buf))165return -EINVAL;166if (copy_from_user(buf, userbuf, count))167return -EFAULT;168buf[count] = '\0';169if (strict_strtoul(buf, 0, &gru_options))170return -EINVAL;171172return count;173}174175static int cch_seq_show(struct seq_file *file, void *data)176{177long gid = *(long *)data;178int i;179struct gru_state *gru = GID_TO_GRU(gid);180struct gru_thread_state *ts;181const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };182183if (gid == 0)184seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid",185"ctx#", "asid", "pid", "cbrs", "dsbytes", "mode");186if (gru)187for (i = 0; i < GRU_NUM_CCH; i++) {188ts = gru->gs_gts[i];189if (!ts)190continue;191seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",192gru->gs_gid, gru->gs_blade_id, i,193is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,194is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,195ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,196ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,197mode[ts->ts_user_options &198GRU_OPT_MISS_MASK]);199}200201return 0;202}203204static int gru_seq_show(struct seq_file *file, void *data)205{206long gid = *(long *)data, ctxfree, cbrfree, dsrfree;207struct gru_state *gru = GID_TO_GRU(gid);208209if (gid == 0) {210seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",211"ctx", "cbr", "dsr", "ctx", "cbr", "dsr");212seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",213"busy", "busy", "free", "free", "free");214}215if (gru) {216ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;217cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;218dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;219seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",220gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,221GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,222ctxfree, cbrfree, dsrfree);223}224225return 0;226}227228static void seq_stop(struct seq_file *file, void *data)229{230}231232static void *seq_start(struct seq_file *file, loff_t *gid)233{234if (*gid < gru_max_gids)235return gid;236return NULL;237}238239static void *seq_next(struct seq_file *file, void *data, loff_t *gid)240{241(*gid)++;242if (*gid < gru_max_gids)243return gid;244return NULL;245}246247static const struct seq_operations cch_seq_ops = {248.start = seq_start,249.next = seq_next,250.stop = seq_stop,251.show = cch_seq_show252};253254static const struct seq_operations gru_seq_ops = {255.start = seq_start,256.next = seq_next,257.stop = seq_stop,258.show = gru_seq_show259};260261static int statistics_open(struct inode *inode, struct file *file)262{263return single_open(file, statistics_show, NULL);264}265266static int mcs_statistics_open(struct inode *inode, struct file *file)267{268return single_open(file, mcs_statistics_show, NULL);269}270271static int options_open(struct inode *inode, struct file *file)272{273return single_open(file, options_show, NULL);274}275276static int cch_open(struct inode *inode, struct file *file)277{278return seq_open(file, &cch_seq_ops);279}280281static int gru_open(struct inode *inode, struct file *file)282{283return seq_open(file, &gru_seq_ops);284}285286/* *INDENT-OFF* */287static 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};294295static 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};302303static 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};310311static const struct file_operations cch_fops = {312.open = cch_open,313.read = seq_read,314.llseek = seq_lseek,315.release = seq_release,316};317static const struct file_operations gru_fops = {318.open = gru_open,319.read = seq_read,320.llseek = seq_lseek,321.release = seq_release,322};323324static struct proc_entry {325char *name;326int mode;327const struct file_operations *fops;328struct proc_dir_entry *entry;329} proc_files[] = {330{"statistics", 0644, &statistics_fops},331{"mcs_statistics", 0644, &mcs_statistics_fops},332{"debug_options", 0644, &options_fops},333{"cch_status", 0444, &cch_fops},334{"gru_status", 0444, &gru_fops},335{NULL}336};337/* *INDENT-ON* */338339static struct proc_dir_entry *proc_gru __read_mostly;340341static int create_proc_file(struct proc_entry *p)342{343p->entry = proc_create(p->name, p->mode, proc_gru, p->fops);344if (!p->entry)345return -1;346return 0;347}348349static void delete_proc_files(void)350{351struct proc_entry *p;352353if (proc_gru) {354for (p = proc_files; p->name; p++)355if (p->entry)356remove_proc_entry(p->name, proc_gru);357remove_proc_entry("gru", proc_gru->parent);358}359}360361int gru_proc_init(void)362{363struct proc_entry *p;364365proc_gru = proc_mkdir("sgi_uv/gru", NULL);366367for (p = proc_files; p->name; p++)368if (create_proc_file(p))369goto err;370return 0;371372err:373delete_proc_files();374return -1;375}376377void gru_proc_exit(void)378{379delete_proc_files();380}381382383