Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * SN Platform GRU Driver
0004  *
0005  *              PROC INTERFACES
0006  *
0007  * This file supports the /proc interfaces for the GRU driver
0008  *
0009  *  Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
0010  */
0011 
0012 #include <linux/proc_fs.h>
0013 #include <linux/device.h>
0014 #include <linux/seq_file.h>
0015 #include <linux/uaccess.h>
0016 #include "gru.h"
0017 #include "grulib.h"
0018 #include "grutables.h"
0019 
0020 #define printstat(s, f)     printstat_val(s, &gru_stats.f, #f)
0021 
0022 static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
0023 {
0024     unsigned long val = atomic_long_read(v);
0025 
0026     seq_printf(s, "%16lu %s\n", val, id);
0027 }
0028 
0029 static int statistics_show(struct seq_file *s, void *p)
0030 {
0031     printstat(s, vdata_alloc);
0032     printstat(s, vdata_free);
0033     printstat(s, gts_alloc);
0034     printstat(s, gts_free);
0035     printstat(s, gms_alloc);
0036     printstat(s, gms_free);
0037     printstat(s, gts_double_allocate);
0038     printstat(s, assign_context);
0039     printstat(s, assign_context_failed);
0040     printstat(s, free_context);
0041     printstat(s, load_user_context);
0042     printstat(s, load_kernel_context);
0043     printstat(s, lock_kernel_context);
0044     printstat(s, unlock_kernel_context);
0045     printstat(s, steal_user_context);
0046     printstat(s, steal_kernel_context);
0047     printstat(s, steal_context_failed);
0048     printstat(s, nopfn);
0049     printstat(s, asid_new);
0050     printstat(s, asid_next);
0051     printstat(s, asid_wrap);
0052     printstat(s, asid_reuse);
0053     printstat(s, intr);
0054     printstat(s, intr_cbr);
0055     printstat(s, intr_tfh);
0056     printstat(s, intr_spurious);
0057     printstat(s, intr_mm_lock_failed);
0058     printstat(s, call_os);
0059     printstat(s, call_os_wait_queue);
0060     printstat(s, user_flush_tlb);
0061     printstat(s, user_unload_context);
0062     printstat(s, user_exception);
0063     printstat(s, set_context_option);
0064     printstat(s, check_context_retarget_intr);
0065     printstat(s, check_context_unload);
0066     printstat(s, tlb_dropin);
0067     printstat(s, tlb_preload_page);
0068     printstat(s, tlb_dropin_fail_no_asid);
0069     printstat(s, tlb_dropin_fail_upm);
0070     printstat(s, tlb_dropin_fail_invalid);
0071     printstat(s, tlb_dropin_fail_range_active);
0072     printstat(s, tlb_dropin_fail_idle);
0073     printstat(s, tlb_dropin_fail_fmm);
0074     printstat(s, tlb_dropin_fail_no_exception);
0075     printstat(s, tfh_stale_on_fault);
0076     printstat(s, mmu_invalidate_range);
0077     printstat(s, mmu_invalidate_page);
0078     printstat(s, flush_tlb);
0079     printstat(s, flush_tlb_gru);
0080     printstat(s, flush_tlb_gru_tgh);
0081     printstat(s, flush_tlb_gru_zero_asid);
0082     printstat(s, copy_gpa);
0083     printstat(s, read_gpa);
0084     printstat(s, mesq_receive);
0085     printstat(s, mesq_receive_none);
0086     printstat(s, mesq_send);
0087     printstat(s, mesq_send_failed);
0088     printstat(s, mesq_noop);
0089     printstat(s, mesq_send_unexpected_error);
0090     printstat(s, mesq_send_lb_overflow);
0091     printstat(s, mesq_send_qlimit_reached);
0092     printstat(s, mesq_send_amo_nacked);
0093     printstat(s, mesq_send_put_nacked);
0094     printstat(s, mesq_qf_locked);
0095     printstat(s, mesq_qf_noop_not_full);
0096     printstat(s, mesq_qf_switch_head_failed);
0097     printstat(s, mesq_qf_unexpected_error);
0098     printstat(s, mesq_noop_unexpected_error);
0099     printstat(s, mesq_noop_lb_overflow);
0100     printstat(s, mesq_noop_qlimit_reached);
0101     printstat(s, mesq_noop_amo_nacked);
0102     printstat(s, mesq_noop_put_nacked);
0103     printstat(s, mesq_noop_page_overflow);
0104     return 0;
0105 }
0106 
0107 static ssize_t statistics_write(struct file *file, const char __user *userbuf,
0108                 size_t count, loff_t *data)
0109 {
0110     memset(&gru_stats, 0, sizeof(gru_stats));
0111     return count;
0112 }
0113 
0114 static int mcs_statistics_show(struct seq_file *s, void *p)
0115 {
0116     int op;
0117     unsigned long total, count, max;
0118     static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
0119         "cch_interrupt_sync", "cch_deallocate", "tfh_write_only",
0120         "tfh_write_restart", "tgh_invalidate"};
0121 
0122     seq_puts(s, "#id                        count   aver-clks    max-clks\n");
0123     for (op = 0; op < mcsop_last; op++) {
0124         count = atomic_long_read(&mcs_op_statistics[op].count);
0125         total = atomic_long_read(&mcs_op_statistics[op].total);
0126         max = mcs_op_statistics[op].max;
0127         seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
0128                count ? total / count : 0, max);
0129     }
0130     return 0;
0131 }
0132 
0133 static ssize_t mcs_statistics_write(struct file *file,
0134             const char __user *userbuf, size_t count, loff_t *data)
0135 {
0136     memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
0137     return count;
0138 }
0139 
0140 static int options_show(struct seq_file *s, void *p)
0141 {
0142     seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");
0143     seq_printf(s, "0x%lx\n", gru_options);
0144     return 0;
0145 }
0146 
0147 static ssize_t options_write(struct file *file, const char __user *userbuf,
0148                  size_t count, loff_t *data)
0149 {
0150     int ret;
0151 
0152     ret = kstrtoul_from_user(userbuf, count, 0, &gru_options);
0153     if (ret)
0154         return ret;
0155 
0156     return count;
0157 }
0158 
0159 static int cch_seq_show(struct seq_file *file, void *data)
0160 {
0161     long gid = *(long *)data;
0162     int i;
0163     struct gru_state *gru = GID_TO_GRU(gid);
0164     struct gru_thread_state *ts;
0165     const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
0166 
0167     if (gid == 0)
0168         seq_puts(file, "#  gid  bid  ctx#   asid      pid  cbrs dsbytes    mode\n");
0169     if (gru)
0170         for (i = 0; i < GRU_NUM_CCH; i++) {
0171             ts = gru->gs_gts[i];
0172             if (!ts)
0173                 continue;
0174             seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",
0175                    gru->gs_gid, gru->gs_blade_id, i,
0176                    is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,
0177                    is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,
0178                    ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
0179                    ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
0180                    mode[ts->ts_user_options &
0181                     GRU_OPT_MISS_MASK]);
0182         }
0183 
0184     return 0;
0185 }
0186 
0187 static int gru_seq_show(struct seq_file *file, void *data)
0188 {
0189     long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
0190     struct gru_state *gru = GID_TO_GRU(gid);
0191 
0192     if (gid == 0) {
0193         seq_puts(file, "#  gid  nid    ctx   cbr   dsr     ctx   cbr   dsr\n");
0194         seq_puts(file, "#             busy  busy  busy    free  free  free\n");
0195     }
0196     if (gru) {
0197         ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
0198         cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
0199         dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
0200         seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
0201                gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
0202                GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
0203                ctxfree, cbrfree, dsrfree);
0204     }
0205 
0206     return 0;
0207 }
0208 
0209 static void seq_stop(struct seq_file *file, void *data)
0210 {
0211 }
0212 
0213 static void *seq_start(struct seq_file *file, loff_t *gid)
0214 {
0215     if (*gid < gru_max_gids)
0216         return gid;
0217     return NULL;
0218 }
0219 
0220 static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
0221 {
0222     (*gid)++;
0223     if (*gid < gru_max_gids)
0224         return gid;
0225     return NULL;
0226 }
0227 
0228 static const struct seq_operations cch_seq_ops = {
0229     .start  = seq_start,
0230     .next   = seq_next,
0231     .stop   = seq_stop,
0232     .show   = cch_seq_show
0233 };
0234 
0235 static const struct seq_operations gru_seq_ops = {
0236     .start  = seq_start,
0237     .next   = seq_next,
0238     .stop   = seq_stop,
0239     .show   = gru_seq_show
0240 };
0241 
0242 static int statistics_open(struct inode *inode, struct file *file)
0243 {
0244     return single_open(file, statistics_show, NULL);
0245 }
0246 
0247 static int mcs_statistics_open(struct inode *inode, struct file *file)
0248 {
0249     return single_open(file, mcs_statistics_show, NULL);
0250 }
0251 
0252 static int options_open(struct inode *inode, struct file *file)
0253 {
0254     return single_open(file, options_show, NULL);
0255 }
0256 
0257 /* *INDENT-OFF* */
0258 static const struct proc_ops statistics_proc_ops = {
0259     .proc_open  = statistics_open,
0260     .proc_read  = seq_read,
0261     .proc_write = statistics_write,
0262     .proc_lseek = seq_lseek,
0263     .proc_release   = single_release,
0264 };
0265 
0266 static const struct proc_ops mcs_statistics_proc_ops = {
0267     .proc_open  = mcs_statistics_open,
0268     .proc_read  = seq_read,
0269     .proc_write = mcs_statistics_write,
0270     .proc_lseek = seq_lseek,
0271     .proc_release   = single_release,
0272 };
0273 
0274 static const struct proc_ops options_proc_ops = {
0275     .proc_open  = options_open,
0276     .proc_read  = seq_read,
0277     .proc_write = options_write,
0278     .proc_lseek = seq_lseek,
0279     .proc_release   = single_release,
0280 };
0281 
0282 static struct proc_dir_entry *proc_gru __read_mostly;
0283 
0284 int gru_proc_init(void)
0285 {
0286     proc_gru = proc_mkdir("sgi_uv/gru", NULL);
0287     if (!proc_gru)
0288         return -1;
0289     if (!proc_create("statistics", 0644, proc_gru, &statistics_proc_ops))
0290         goto err;
0291     if (!proc_create("mcs_statistics", 0644, proc_gru, &mcs_statistics_proc_ops))
0292         goto err;
0293     if (!proc_create("debug_options", 0644, proc_gru, &options_proc_ops))
0294         goto err;
0295     if (!proc_create_seq("cch_status", 0444, proc_gru, &cch_seq_ops))
0296         goto err;
0297     if (!proc_create_seq("gru_status", 0444, proc_gru, &gru_seq_ops))
0298         goto err;
0299     return 0;
0300 err:
0301     remove_proc_subtree("sgi_uv/gru", NULL);
0302     return -1;
0303 }
0304 
0305 void gru_proc_exit(void)
0306 {
0307     remove_proc_subtree("sgi_uv/gru", NULL);
0308 }