blob: 0a57ab29cd30432a2801bba2ea1183e4d9498486 [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 Steiner43884602009-04-02 16:59:05 -070069 printstat(s, intr_mm_lock_failed);
Jack Steiner1d09d732008-07-29 22:33:59 -070070 printstat(s, call_os);
Jack Steiner1d09d732008-07-29 22:33:59 -070071 printstat(s, call_os_wait_queue);
72 printstat(s, user_flush_tlb);
73 printstat(s, user_unload_context);
74 printstat(s, user_exception);
Jack Steiner92b39382009-06-17 16:28:32 -070075 printstat(s, set_context_option);
Jack Steiner55484c42009-12-15 16:48:05 -080076 printstat(s, check_context_retarget_intr);
77 printstat(s, check_context_unload);
Jack Steiner1d09d732008-07-29 22:33:59 -070078 printstat(s, tlb_dropin);
79 printstat(s, tlb_dropin_fail_no_asid);
80 printstat(s, tlb_dropin_fail_upm);
81 printstat(s, tlb_dropin_fail_invalid);
82 printstat(s, tlb_dropin_fail_range_active);
83 printstat(s, tlb_dropin_fail_idle);
84 printstat(s, tlb_dropin_fail_fmm);
Jack Steinercd1334f2009-06-17 16:28:19 -070085 printstat(s, tlb_dropin_fail_no_exception);
Jack Steiner270952a2009-06-17 16:28:27 -070086 printstat(s, tfh_stale_on_fault);
Jack Steiner1d09d732008-07-29 22:33:59 -070087 printstat(s, mmu_invalidate_range);
88 printstat(s, mmu_invalidate_page);
Jack Steiner1d09d732008-07-29 22:33:59 -070089 printstat(s, flush_tlb);
90 printstat(s, flush_tlb_gru);
91 printstat(s, flush_tlb_gru_tgh);
92 printstat(s, flush_tlb_gru_zero_asid);
93 printstat(s, copy_gpa);
Robin Holt289750d2009-12-15 16:47:55 -080094 printstat(s, read_gpa);
Jack Steiner1d09d732008-07-29 22:33:59 -070095 printstat(s, mesq_receive);
96 printstat(s, mesq_receive_none);
97 printstat(s, mesq_send);
98 printstat(s, mesq_send_failed);
99 printstat(s, mesq_noop);
100 printstat(s, mesq_send_unexpected_error);
101 printstat(s, mesq_send_lb_overflow);
102 printstat(s, mesq_send_qlimit_reached);
103 printstat(s, mesq_send_amo_nacked);
104 printstat(s, mesq_send_put_nacked);
Jack Steiner1d09d732008-07-29 22:33:59 -0700105 printstat(s, mesq_qf_locked);
106 printstat(s, mesq_qf_noop_not_full);
107 printstat(s, mesq_qf_switch_head_failed);
108 printstat(s, mesq_qf_unexpected_error);
109 printstat(s, mesq_noop_unexpected_error);
110 printstat(s, mesq_noop_lb_overflow);
111 printstat(s, mesq_noop_qlimit_reached);
112 printstat(s, mesq_noop_amo_nacked);
113 printstat(s, mesq_noop_put_nacked);
Jack Steiner563447d2009-12-15 16:48:12 -0800114 printstat(s, mesq_noop_page_overflow);
Jack Steiner1d09d732008-07-29 22:33:59 -0700115 return 0;
116}
117
118static ssize_t statistics_write(struct file *file, const char __user *userbuf,
119 size_t count, loff_t *data)
120{
121 memset(&gru_stats, 0, sizeof(gru_stats));
122 return count;
123}
124
Jack Steinere56484d2009-04-02 16:59:06 -0700125static int mcs_statistics_show(struct seq_file *s, void *p)
126{
127 int op;
128 unsigned long total, count, max;
129 static char *id[] = {"cch_allocate", "cch_start", "cch_interrupt",
130 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
131
Jack Steiner563447d2009-12-15 16:48:12 -0800132 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
Jack Steinere56484d2009-04-02 16:59:06 -0700133 for (op = 0; op < mcsop_last; op++) {
134 count = atomic_long_read(&mcs_op_statistics[op].count);
135 total = atomic_long_read(&mcs_op_statistics[op].total);
136 max = mcs_op_statistics[op].max;
137 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
138 count ? total / count : 0, max);
139 }
140 return 0;
141}
142
143static ssize_t mcs_statistics_write(struct file *file,
144 const char __user *userbuf, size_t count, loff_t *data)
145{
146 memset(mcs_op_statistics, 0, sizeof(mcs_op_statistics));
147 return count;
148}
149
Jack Steiner1d09d732008-07-29 22:33:59 -0700150static int options_show(struct seq_file *s, void *p)
151{
Jack Steiner563447d2009-12-15 16:48:12 -0800152 seq_printf(s, "#bitmask: 1=trace, 2=statistics\n");
Jack Steiner9ca8e40c12008-07-29 22:34:02 -0700153 seq_printf(s, "0x%lx\n", gru_options);
Jack Steiner1d09d732008-07-29 22:33:59 -0700154 return 0;
155}
156
157static ssize_t options_write(struct file *file, const char __user *userbuf,
158 size_t count, loff_t *data)
159{
Linus Torvaldsd39b7dd2009-11-05 10:48:30 -0800160 char buf[20];
Jack Steiner1d09d732008-07-29 22:33:59 -0700161
Linus Torvaldsd39b7dd2009-11-05 10:48:30 -0800162 if (count >= sizeof(buf))
163 return -EINVAL;
164 if (copy_from_user(buf, userbuf, count))
Jack Steiner1d09d732008-07-29 22:33:59 -0700165 return -EFAULT;
Linus Torvaldsd39b7dd2009-11-05 10:48:30 -0800166 buf[count] = '\0';
167 if (strict_strtoul(buf, 0, &gru_options))
168 return -EINVAL;
Jack Steiner1d09d732008-07-29 22:33:59 -0700169
170 return count;
171}
172
173static int cch_seq_show(struct seq_file *file, void *data)
174{
175 long gid = *(long *)data;
176 int i;
177 struct gru_state *gru = GID_TO_GRU(gid);
178 struct gru_thread_state *ts;
179 const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
180
181 if (gid == 0)
Jack Steiner563447d2009-12-15 16:48:12 -0800182 seq_printf(file, "#%5s%5s%6s%7s%9s%6s%8s%8s\n", "gid", "bid",
183 "ctx#", "asid", "pid", "cbrs", "dsbytes", "mode");
Jack Steiner1d09d732008-07-29 22:33:59 -0700184 if (gru)
185 for (i = 0; i < GRU_NUM_CCH; i++) {
186 ts = gru->gs_gts[i];
187 if (!ts)
188 continue;
Jack Steiner563447d2009-12-15 16:48:12 -0800189 seq_printf(file, " %5d%5d%6d%7d%9d%6d%8d%8s\n",
Jack Steiner1d09d732008-07-29 22:33:59 -0700190 gru->gs_gid, gru->gs_blade_id, i,
Jack Steiner563447d2009-12-15 16:48:12 -0800191 is_kernel_context(ts) ? 0 : ts->ts_gms->ms_asids[gid].mt_asid,
192 is_kernel_context(ts) ? 0 : ts->ts_tgid_owner,
Jack Steiner1d09d732008-07-29 22:33:59 -0700193 ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
194 ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
195 mode[ts->ts_user_options &
196 GRU_OPT_MISS_MASK]);
197 }
198
199 return 0;
200}
201
202static int gru_seq_show(struct seq_file *file, void *data)
203{
204 long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
205 struct gru_state *gru = GID_TO_GRU(gid);
206
207 if (gid == 0) {
208 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
209 "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
210 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
211 "busy", "busy", "free", "free", "free");
212 }
213 if (gru) {
214 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
215 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
216 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
217 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
218 gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
219 GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
220 ctxfree, cbrfree, dsrfree);
221 }
222
223 return 0;
224}
225
226static void seq_stop(struct seq_file *file, void *data)
227{
228}
229
230static void *seq_start(struct seq_file *file, loff_t *gid)
231{
Jack Steinere1c32192009-04-02 16:59:10 -0700232 if (*gid < gru_max_gids)
Jack Steiner1d09d732008-07-29 22:33:59 -0700233 return gid;
234 return NULL;
235}
236
237static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
238{
239 (*gid)++;
Jack Steinere1c32192009-04-02 16:59:10 -0700240 if (*gid < gru_max_gids)
Jack Steiner1d09d732008-07-29 22:33:59 -0700241 return gid;
242 return NULL;
243}
244
245static const struct seq_operations cch_seq_ops = {
246 .start = seq_start,
247 .next = seq_next,
248 .stop = seq_stop,
249 .show = cch_seq_show
250};
251
252static const struct seq_operations gru_seq_ops = {
253 .start = seq_start,
254 .next = seq_next,
255 .stop = seq_stop,
256 .show = gru_seq_show
257};
258
259static int statistics_open(struct inode *inode, struct file *file)
260{
261 return single_open(file, statistics_show, NULL);
262}
263
Jack Steinere56484d2009-04-02 16:59:06 -0700264static int mcs_statistics_open(struct inode *inode, struct file *file)
265{
266 return single_open(file, mcs_statistics_show, NULL);
267}
268
Jack Steiner1d09d732008-07-29 22:33:59 -0700269static int options_open(struct inode *inode, struct file *file)
270{
271 return single_open(file, options_show, NULL);
272}
273
274static int cch_open(struct inode *inode, struct file *file)
275{
276 return seq_open(file, &cch_seq_ops);
277}
278
279static int gru_open(struct inode *inode, struct file *file)
280{
281 return seq_open(file, &gru_seq_ops);
282}
283
284/* *INDENT-OFF* */
285static const struct file_operations statistics_fops = {
286 .open = statistics_open,
287 .read = seq_read,
288 .write = statistics_write,
289 .llseek = seq_lseek,
290 .release = single_release,
291};
292
Jack Steinere56484d2009-04-02 16:59:06 -0700293static const struct file_operations mcs_statistics_fops = {
294 .open = mcs_statistics_open,
295 .read = seq_read,
296 .write = mcs_statistics_write,
297 .llseek = seq_lseek,
298 .release = single_release,
299};
300
Jack Steiner1d09d732008-07-29 22:33:59 -0700301static const struct file_operations options_fops = {
302 .open = options_open,
303 .read = seq_read,
304 .write = options_write,
305 .llseek = seq_lseek,
306 .release = single_release,
307};
308
309static const struct file_operations cch_fops = {
310 .open = cch_open,
311 .read = seq_read,
312 .llseek = seq_lseek,
313 .release = seq_release,
314};
315static const struct file_operations gru_fops = {
316 .open = gru_open,
317 .read = seq_read,
318 .llseek = seq_lseek,
319 .release = seq_release,
320};
321
322static struct proc_entry {
323 char *name;
324 int mode;
325 const struct file_operations *fops;
326 struct proc_dir_entry *entry;
327} proc_files[] = {
328 {"statistics", 0644, &statistics_fops},
Jack Steinere56484d2009-04-02 16:59:06 -0700329 {"mcs_statistics", 0644, &mcs_statistics_fops},
Jack Steiner1d09d732008-07-29 22:33:59 -0700330 {"debug_options", 0644, &options_fops},
331 {"cch_status", 0444, &cch_fops},
332 {"gru_status", 0444, &gru_fops},
333 {NULL}
334};
335/* *INDENT-ON* */
336
337static struct proc_dir_entry *proc_gru __read_mostly;
338
339static int create_proc_file(struct proc_entry *p)
340{
Alexey Dobriyanf8679af2009-09-23 15:57:33 -0700341 p->entry = proc_create(p->name, p->mode, proc_gru, p->fops);
Jack Steiner1d09d732008-07-29 22:33:59 -0700342 if (!p->entry)
343 return -1;
Jack Steiner1d09d732008-07-29 22:33:59 -0700344 return 0;
345}
346
347static void delete_proc_files(void)
348{
349 struct proc_entry *p;
350
351 if (proc_gru) {
352 for (p = proc_files; p->name; p++)
353 if (p->entry)
354 remove_proc_entry(p->name, proc_gru);
Jack Steinerf2965d62009-12-15 16:48:06 -0800355 remove_proc_entry("gru", proc_gru->parent);
Jack Steiner1d09d732008-07-29 22:33:59 -0700356 }
357}
358
359int gru_proc_init(void)
360{
361 struct proc_entry *p;
362
Jack Steiner1d09d732008-07-29 22:33:59 -0700363 proc_gru = proc_mkdir("sgi_uv/gru", NULL);
364
365 for (p = proc_files; p->name; p++)
366 if (create_proc_file(p))
367 goto err;
368 return 0;
369
370err:
371 delete_proc_files();
372 return -1;
373}
374
375void gru_proc_exit(void)
376{
377 delete_proc_files();
378}