blob: 4f76359223949f21e54c5a0bd5a57fae83561ff2 [file] [log] [blame]
Jack Steiner1d09d732008-07-29 22:33:59 -07001/*
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
35static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36{
37 unsigned long val = atomic_long_read(v);
38
Jack Steiner563447d2009-12-15 16:48:12 -080039 seq_printf(s, "%16lu %s\n", val, id);
Jack Steiner1d09d732008-07-29 22:33:59 -070040}
41
42static int statistics_show(struct seq_file *s, void *p)
43{
44 printstat(s, vdata_alloc);
45 printstat(s, vdata_free);
46 printstat(s, gts_alloc);
47 printstat(s, gts_free);
Jack Steiner563447d2009-12-15 16:48:12 -080048 printstat(s, gms_alloc);
49 printstat(s, gms_free);
Jack Steiner1d09d732008-07-29 22:33:59 -070050 printstat(s, gts_double_allocate);
51 printstat(s, assign_context);
52 printstat(s, assign_context_failed);
53 printstat(s, free_context);
Jack Steiner836ce672009-06-17 16:28:22 -070054 printstat(s, load_user_context);
55 printstat(s, load_kernel_context);
56 printstat(s, lock_kernel_context);
57 printstat(s, unlock_kernel_context);
58 printstat(s, steal_user_context);
59 printstat(s, steal_kernel_context);
Jack Steiner1d09d732008-07-29 22:33:59 -070060 printstat(s, steal_context_failed);
61 printstat(s, nopfn);
Jack Steiner1d09d732008-07-29 22:33:59 -070062 printstat(s, asid_new);
63 printstat(s, asid_next);
64 printstat(s, asid_wrap);
65 printstat(s, asid_reuse);
66 printstat(s, intr);
Jack Steiner563447d2009-12-15 16:48:12 -080067 printstat(s, intr_cbr);
68 printstat(s, intr_tfh);
Jack Steiner2ce4d4c2009-12-15 16:48:18 -080069 printstat(s, intr_spurious);
Jack Steiner43884602009-04-02 16:59:05 -070070 printstat(s, intr_mm_lock_failed);
Jack Steiner1d09d732008-07-29 22:33:59 -070071 printstat(s, call_os);
Jack Steiner1d09d732008-07-29 22:33:59 -070072 printstat(s, call_os_wait_queue);
73 printstat(s, user_flush_tlb);
74 printstat(s, user_unload_context);
75 printstat(s, user_exception);
Jack Steiner92b39382009-06-17 16:28:32 -070076 printstat(s, set_context_option);
Jack Steiner55484c42009-12-15 16:48:05 -080077 printstat(s, check_context_retarget_intr);
78 printstat(s, check_context_unload);
Jack Steiner1d09d732008-07-29 22:33:59 -070079 printstat(s, tlb_dropin);
Jack Steinerc5502222009-12-15 16:48:13 -080080 printstat(s, tlb_preload_page);
Jack Steiner1d09d732008-07-29 22:33:59 -070081 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);
Jack Steinercd1334f2009-06-17 16:28:19 -070087 printstat(s, tlb_dropin_fail_no_exception);
Jack Steiner270952a2009-06-17 16:28:27 -070088 printstat(s, tfh_stale_on_fault);
Jack Steiner1d09d732008-07-29 22:33:59 -070089 printstat(s, mmu_invalidate_range);
90 printstat(s, mmu_invalidate_page);
Jack Steiner1d09d732008-07-29 22:33:59 -070091 printstat(s, flush_tlb);
92 printstat(s, flush_tlb_gru);
93 printstat(s, flush_tlb_gru_tgh);
94 printstat(s, flush_tlb_gru_zero_asid);
95 printstat(s, copy_gpa);
Robin Holt289750d2009-12-15 16:47:55 -080096 printstat(s, read_gpa);
Jack Steiner1d09d732008-07-29 22:33:59 -070097 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);
Jack Steiner1d09d732008-07-29 22:33:59 -0700107 printstat(s, mesq_qf_locked);
108 printstat(s, mesq_qf_noop_not_full);
109 printstat(s, mesq_qf_switch_head_failed);
110 printstat(s, mesq_qf_unexpected_error);
111 printstat(s, mesq_noop_unexpected_error);
112 printstat(s, mesq_noop_lb_overflow);
113 printstat(s, mesq_noop_qlimit_reached);
114 printstat(s, mesq_noop_amo_nacked);
115 printstat(s, mesq_noop_put_nacked);
Jack Steiner563447d2009-12-15 16:48:12 -0800116 printstat(s, mesq_noop_page_overflow);
Jack Steiner1d09d732008-07-29 22:33:59 -0700117 return 0;
118}
119
120static 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
Jack Steinere56484d2009-04-02 16:59:06 -0700127static 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",
Jack Steinerc5502222009-12-15 16:48:13 -0800132 "cch_interrupt_sync", "cch_deallocate", "tfh_write_only",
133 "tfh_write_restart", "tgh_invalidate"};
Jack Steinere56484d2009-04-02 16:59:06 -0700134
Jack Steiner563447d2009-12-15 16:48:12 -0800135 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
Jack Steinere56484d2009-04-02 16:59:06 -0700136 for (op = 0; op < mcsop_last; op++) {
137 count = atomic_long_read(&mcs_op_statistics[op].count);
138 total = atomic_long_read(&mcs_op_statistics[op].total);
139 max = mcs_op_statistics[op].max;
140 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
141 count ? total / count : 0, max);
142 }
143 return 0;
144}
145
146static ssize_t mcs_statistics_write(struct file *file,
147 const char __user *userbuf, size_t count, loff_t *data)
148{
149 memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
150 return count;
151}
152
Jack Steiner1d09d732008-07-29 22:33:59 -0700153static int options_show(struct seq_file *s, void *p)
154{
Jack Steiner563447d2009-12-15 16:48:12 -0800155 seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");
Jack Steiner9ca8e40c12008-07-29 22:34:02 -0700156 seq_printf(s, "0x%lx\n", gru_options);
Jack Steiner1d09d732008-07-29 22:33:59 -0700157 return 0;
158}
159
160static ssize_t options_write(struct file *file, const char __user *userbuf,
161 size_t count, loff_t *data)
162{
Jingoo Hanf7b41272013-06-04 13:15:16 +0900163 int ret;
Jack Steiner1d09d732008-07-29 22:33:59 -0700164
Jingoo Hanf7b41272013-06-04 13:15:16 +0900165 ret = kstrtoul_from_user(userbuf, count, 0, &gru_options);
166 if (ret)
167 return ret;
Jack Steiner1d09d732008-07-29 22:33:59 -0700168
169 return count;
170}
171
172static 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)
Jack Steiner563447d2009-12-15 16:48:12 -0800181 seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid",
182 "ctx#", "asid", "pid", "cbrs", "dsbytes", "mode");
Jack Steiner1d09d732008-07-29 22:33:59 -0700183 if (gru)
184 for (i = 0; i < GRU_NUM_CCH; i++) {
185 ts = gru->gs_gts[i];
186 if (!ts)
187 continue;
Jack Steiner563447d2009-12-15 16:48:12 -0800188 seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",
Jack Steiner1d09d732008-07-29 22:33:59 -0700189 gru->gs_gid, gru->gs_blade_id, i,
Jack Steiner563447d2009-12-15 16:48:12 -0800190 is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,
191 is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,
Jack Steiner1d09d732008-07-29 22:33:59 -0700192 ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
193 ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
194 mode[ts->ts_user_options &
195 GRU_OPT_MISS_MASK]);
196 }
197
198 return 0;
199}
200
201static int gru_seq_show(struct seq_file *file, void *data)
202{
203 long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
204 struct gru_state *gru = GID_TO_GRU(gid);
205
206 if (gid == 0) {
207 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
208 "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
209 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
210 "busy", "busy", "free", "free", "free");
211 }
212 if (gru) {
213 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
214 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
215 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
216 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
217 gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
218 GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
219 ctxfree, cbrfree, dsrfree);
220 }
221
222 return 0;
223}
224
225static void seq_stop(struct seq_file *file, void *data)
226{
227}
228
229static void *seq_start(struct seq_file *file, loff_t *gid)
230{
Jack Steinere1c32192009-04-02 16:59:10 -0700231 if (*gid < gru_max_gids)
Jack Steiner1d09d732008-07-29 22:33:59 -0700232 return gid;
233 return NULL;
234}
235
236static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
237{
238 (*gid)++;
Jack Steinere1c32192009-04-02 16:59:10 -0700239 if (*gid < gru_max_gids)
Jack Steiner1d09d732008-07-29 22:33:59 -0700240 return gid;
241 return NULL;
242}
243
244static const struct seq_operations cch_seq_ops = {
245 .start = seq_start,
246 .next = seq_next,
247 .stop = seq_stop,
248 .show = cch_seq_show
249};
250
251static const struct seq_operations gru_seq_ops = {
252 .start = seq_start,
253 .next = seq_next,
254 .stop = seq_stop,
255 .show = gru_seq_show
256};
257
258static int statistics_open(struct inode *inode, struct file *file)
259{
260 return single_open(file, statistics_show, NULL);
261}
262
Jack Steinere56484d2009-04-02 16:59:06 -0700263static int mcs_statistics_open(struct inode *inode, struct file *file)
264{
265 return single_open(file, mcs_statistics_show, NULL);
266}
267
Jack Steiner1d09d732008-07-29 22:33:59 -0700268static int options_open(struct inode *inode, struct file *file)
269{
270 return single_open(file, options_show, NULL);
271}
272
273static int cch_open(struct inode *inode, struct file *file)
274{
275 return seq_open(file, &cch_seq_ops);
276}
277
278static int gru_open(struct inode *inode, struct file *file)
279{
280 return seq_open(file, &gru_seq_ops);
281}
282
283/* *INDENT-OFF* */
284static const struct file_operations statistics_fops = {
285 .open = statistics_open,
286 .read = seq_read,
287 .write = statistics_write,
288 .llseek = seq_lseek,
289 .release = single_release,
290};
291
Jack Steinere56484d2009-04-02 16:59:06 -0700292static const struct file_operations mcs_statistics_fops = {
293 .open = mcs_statistics_open,
294 .read = seq_read,
295 .write = mcs_statistics_write,
296 .llseek = seq_lseek,
297 .release = single_release,
298};
299
Jack Steiner1d09d732008-07-29 22:33:59 -0700300static const struct file_operations options_fops = {
301 .open = options_open,
302 .read = seq_read,
303 .write = options_write,
304 .llseek = seq_lseek,
305 .release = single_release,
306};
307
308static const struct file_operations cch_fops = {
309 .open = cch_open,
310 .read = seq_read,
311 .llseek = seq_lseek,
312 .release = seq_release,
313};
314static const struct file_operations gru_fops = {
315 .open = gru_open,
316 .read = seq_read,
317 .llseek = seq_lseek,
318 .release = seq_release,
319};
320
321static struct proc_entry {
322 char *name;
Al Virod161a132011-07-24 03:36:29 -0400323 umode_t mode;
Jack Steiner1d09d732008-07-29 22:33:59 -0700324 const struct file_operations *fops;
325 struct proc_dir_entry *entry;
326} proc_files[] = {
327 {"statistics", 0644, &statistics_fops},
Jack Steinere56484d2009-04-02 16:59:06 -0700328 {"mcs_statistics", 0644, &mcs_statistics_fops},
Jack Steiner1d09d732008-07-29 22:33:59 -0700329 {"debug_options", 0644, &options_fops},
330 {"cch_status", 0444, &cch_fops},
331 {"gru_status", 0444, &gru_fops},
332 {NULL}
333};
334/* *INDENT-ON* */
335
336static struct proc_dir_entry *proc_gru __read_mostly;
337
338static int create_proc_file(struct proc_entry *p)
339{
Alexey Dobriyanf8679af2009-09-23 15:57:33 -0700340 p->entry = proc_create(p->name, p->mode, proc_gru, p->fops);
Jack Steiner1d09d732008-07-29 22:33:59 -0700341 if (!p->entry)
342 return -1;
Jack Steiner1d09d732008-07-29 22:33:59 -0700343 return 0;
344}
345
346static 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);
David Howellsa8ca16e2013-04-12 17:27:28 +0100354 proc_remove(proc_gru);
Jack Steiner1d09d732008-07-29 22:33:59 -0700355 }
356}
357
358int gru_proc_init(void)
359{
360 struct proc_entry *p;
361
Jack Steiner1d09d732008-07-29 22:33:59 -0700362 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
369err:
370 delete_proc_files();
371 return -1;
372}
373
374void gru_proc_exit(void)
375{
376 delete_proc_files();
377}