]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/misc/sgi-gru/gruprocfs.c
sgi-gru: improvements to GRU debug messages & statistics
[mv-sheeva.git] / drivers / misc / sgi-gru / gruprocfs.c
1 /*
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
35 static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36 {
37         unsigned long val = atomic_long_read(v);
38
39         if (val)
40                 seq_printf(s, "%16lu %s\n", val, id);
41 }
42
43 static int statistics_show(struct seq_file *s, void *p)
44 {
45         printstat(s, vdata_alloc);
46         printstat(s, vdata_free);
47         printstat(s, gts_alloc);
48         printstat(s, gts_free);
49         printstat(s, vdata_double_alloc);
50         printstat(s, gts_double_allocate);
51         printstat(s, assign_context);
52         printstat(s, assign_context_failed);
53         printstat(s, free_context);
54         printstat(s, load_context);
55         printstat(s, unload_context);
56         printstat(s, steal_context);
57         printstat(s, steal_context_failed);
58         printstat(s, nopfn);
59         printstat(s, break_cow);
60         printstat(s, asid_new);
61         printstat(s, asid_next);
62         printstat(s, asid_wrap);
63         printstat(s, asid_reuse);
64         printstat(s, intr);
65         printstat(s, intr_mm_lock_failed);
66         printstat(s, call_os);
67         printstat(s, call_os_offnode_reference);
68         printstat(s, call_os_check_for_bug);
69         printstat(s, call_os_wait_queue);
70         printstat(s, user_flush_tlb);
71         printstat(s, user_unload_context);
72         printstat(s, user_exception);
73         printstat(s, set_task_slice);
74         printstat(s, migrate_check);
75         printstat(s, migrated_retarget);
76         printstat(s, migrated_unload);
77         printstat(s, migrated_unload_delay);
78         printstat(s, migrated_nopfn_retarget);
79         printstat(s, migrated_nopfn_unload);
80         printstat(s, tlb_dropin);
81         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);
87         printstat(s, mmu_invalidate_range);
88         printstat(s, mmu_invalidate_page);
89         printstat(s, mmu_clear_flush_young);
90         printstat(s, flush_tlb);
91         printstat(s, flush_tlb_gru);
92         printstat(s, flush_tlb_gru_tgh);
93         printstat(s, flush_tlb_gru_zero_asid);
94         printstat(s, copy_gpa);
95         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);
105         printstat(s, mesq_qf_not_full);
106         printstat(s, mesq_qf_locked);
107         printstat(s, mesq_qf_noop_not_full);
108         printstat(s, mesq_qf_switch_head_failed);
109         printstat(s, mesq_qf_unexpected_error);
110         printstat(s, mesq_noop_unexpected_error);
111         printstat(s, mesq_noop_lb_overflow);
112         printstat(s, mesq_noop_qlimit_reached);
113         printstat(s, mesq_noop_amo_nacked);
114         printstat(s, mesq_noop_put_nacked);
115         return 0;
116 }
117
118 static 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
125 static int options_show(struct seq_file *s, void *p)
126 {
127         seq_printf(s, "0x%lx\n", gru_options);
128         return 0;
129 }
130
131 static ssize_t options_write(struct file *file, const char __user *userbuf,
132                              size_t count, loff_t *data)
133 {
134         unsigned long val;
135         char buf[80];
136
137         if (copy_from_user
138             (buf, userbuf, count < sizeof(buf) ? count : sizeof(buf)))
139                 return -EFAULT;
140         if (!strict_strtoul(buf, 10, &val))
141                 gru_options = val;
142
143         return count;
144 }
145
146 static int cch_seq_show(struct seq_file *file, void *data)
147 {
148         long gid = *(long *)data;
149         int i;
150         struct gru_state *gru = GID_TO_GRU(gid);
151         struct gru_thread_state *ts;
152         const char *mode[] = { "??", "UPM", "INTR", "OS_POLL" };
153
154         if (gid == 0)
155                 seq_printf(file, "#%5s%5s%6s%9s%6s%8s%8s\n", "gid", "bid",
156                            "ctx#", "pid", "cbrs", "dsbytes", "mode");
157         if (gru)
158                 for (i = 0; i < GRU_NUM_CCH; i++) {
159                         ts = gru->gs_gts[i];
160                         if (!ts)
161                                 continue;
162                         seq_printf(file, " %5d%5d%6d%9d%6d%8d%8s\n",
163                                    gru->gs_gid, gru->gs_blade_id, i,
164                                    ts->ts_tgid_owner,
165                                    ts->ts_cbr_au_count * GRU_CBR_AU_SIZE,
166                                    ts->ts_cbr_au_count * GRU_DSR_AU_BYTES,
167                                    mode[ts->ts_user_options &
168                                         GRU_OPT_MISS_MASK]);
169                 }
170
171         return 0;
172 }
173
174 static int gru_seq_show(struct seq_file *file, void *data)
175 {
176         long gid = *(long *)data, ctxfree, cbrfree, dsrfree;
177         struct gru_state *gru = GID_TO_GRU(gid);
178
179         if (gid == 0) {
180                 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "gid", "nid",
181                            "ctx", "cbr", "dsr", "ctx", "cbr", "dsr");
182                 seq_printf(file, "#%5s%5s%7s%6s%6s%8s%6s%6s\n", "", "", "busy",
183                            "busy", "busy", "free", "free", "free");
184         }
185         if (gru) {
186                 ctxfree = GRU_NUM_CCH - gru->gs_active_contexts;
187                 cbrfree = hweight64(gru->gs_cbr_map) * GRU_CBR_AU_SIZE;
188                 dsrfree = hweight64(gru->gs_dsr_map) * GRU_DSR_AU_BYTES;
189                 seq_printf(file, " %5d%5d%7ld%6ld%6ld%8ld%6ld%6ld\n",
190                            gru->gs_gid, gru->gs_blade_id, GRU_NUM_CCH - ctxfree,
191                            GRU_NUM_CBE - cbrfree, GRU_NUM_DSR_BYTES - dsrfree,
192                            ctxfree, cbrfree, dsrfree);
193         }
194
195         return 0;
196 }
197
198 static void seq_stop(struct seq_file *file, void *data)
199 {
200 }
201
202 static void *seq_start(struct seq_file *file, loff_t *gid)
203 {
204         if (*gid < GRU_MAX_GRUS)
205                 return gid;
206         return NULL;
207 }
208
209 static void *seq_next(struct seq_file *file, void *data, loff_t *gid)
210 {
211         (*gid)++;
212         if (*gid < GRU_MAX_GRUS)
213                 return gid;
214         return NULL;
215 }
216
217 static const struct seq_operations cch_seq_ops = {
218         .start  = seq_start,
219         .next   = seq_next,
220         .stop   = seq_stop,
221         .show   = cch_seq_show
222 };
223
224 static const struct seq_operations gru_seq_ops = {
225         .start  = seq_start,
226         .next   = seq_next,
227         .stop   = seq_stop,
228         .show   = gru_seq_show
229 };
230
231 static int statistics_open(struct inode *inode, struct file *file)
232 {
233         return single_open(file, statistics_show, NULL);
234 }
235
236 static int options_open(struct inode *inode, struct file *file)
237 {
238         return single_open(file, options_show, NULL);
239 }
240
241 static int cch_open(struct inode *inode, struct file *file)
242 {
243         return seq_open(file, &cch_seq_ops);
244 }
245
246 static int gru_open(struct inode *inode, struct file *file)
247 {
248         return seq_open(file, &gru_seq_ops);
249 }
250
251 /* *INDENT-OFF* */
252 static const struct file_operations statistics_fops = {
253         .open           = statistics_open,
254         .read           = seq_read,
255         .write          = statistics_write,
256         .llseek         = seq_lseek,
257         .release        = single_release,
258 };
259
260 static const struct file_operations options_fops = {
261         .open           = options_open,
262         .read           = seq_read,
263         .write          = options_write,
264         .llseek         = seq_lseek,
265         .release        = single_release,
266 };
267
268 static const struct file_operations cch_fops = {
269         .open           = cch_open,
270         .read           = seq_read,
271         .llseek         = seq_lseek,
272         .release        = seq_release,
273 };
274 static const struct file_operations gru_fops = {
275         .open           = gru_open,
276         .read           = seq_read,
277         .llseek         = seq_lseek,
278         .release        = seq_release,
279 };
280
281 static struct proc_entry {
282         char *name;
283         int mode;
284         const struct file_operations *fops;
285         struct proc_dir_entry *entry;
286 } proc_files[] = {
287         {"statistics", 0644, &statistics_fops},
288         {"debug_options", 0644, &options_fops},
289         {"cch_status", 0444, &cch_fops},
290         {"gru_status", 0444, &gru_fops},
291         {NULL}
292 };
293 /* *INDENT-ON* */
294
295 static struct proc_dir_entry *proc_gru __read_mostly;
296
297 static int create_proc_file(struct proc_entry *p)
298 {
299         p->entry = create_proc_entry(p->name, p->mode, proc_gru);
300         if (!p->entry)
301                 return -1;
302         p->entry->proc_fops = p->fops;
303         return 0;
304 }
305
306 static void delete_proc_files(void)
307 {
308         struct proc_entry *p;
309
310         if (proc_gru) {
311                 for (p = proc_files; p->name; p++)
312                         if (p->entry)
313                                 remove_proc_entry(p->name, proc_gru);
314                 remove_proc_entry("gru", NULL);
315         }
316 }
317
318 int gru_proc_init(void)
319 {
320         struct proc_entry *p;
321
322         proc_gru = proc_mkdir("sgi_uv/gru", NULL);
323
324         for (p = proc_files; p->name; p++)
325                 if (create_proc_file(p))
326                         goto err;
327         return 0;
328
329 err:
330         delete_proc_files();
331         return -1;
332 }
333
334 void gru_proc_exit(void)
335 {
336         delete_proc_files();
337 }